PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
linux-micpower.c File Reference
Include dependency graph for linux-micpower.c:

Go to the source code of this file.

Macros

#define REFRESH_LAT   50000
 
#define INVALID_RESULT   -1000000L
 
#define MICPOWER_NUMBER_OF_NATIVE_EVENTS   16
 

Functions

static int read_sysfs_file (long long *counts)
 
int _micpower_init_thread (hwd_context_t *ctx)
 
int _micpower_init_component (int cidx)
 
int _micpower_init_control_state (hwd_control_state_t *ctl)
 
int _micpower_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _micpower_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
 
int _micpower_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _micpower_shutdown_thread (hwd_context_t *ctx)
 
int _micpower_shutdown_component ()
 
int _micpower_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
int _micpower_update_control_state (hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
int _micpower_set_domain (hwd_control_state_t *cntl, int domain)
 
int _micpower_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
int _micpower_ntv_enum_events (unsigned int *EventCode, int modifier)
 
int _micpower_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
int _micpower_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
int _micpower_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 

Variables

papi_vector_t _micpower_vector
 
static
MICPOWER_native_event_entry_t 
_micpower_native_events []
 
static int num_events = 0
 
static int is_initialized = 0
 

Macro Definition Documentation

#define INVALID_RESULT   -1000000L

Definition at line 21 of file linux-micpower.c.

#define MICPOWER_NUMBER_OF_NATIVE_EVENTS   16

Definition at line 22 of file linux-micpower.c.

#define REFRESH_LAT   50000

Definition at line 19 of file linux-micpower.c.

Function Documentation

int _micpower_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)

Definition at line 317 of file linux-micpower.c.

318 {
319  ( void ) ctx;
320  ( void ) code;
321  ( void ) option;
322 
323  return PAPI_OK;
324 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _micpower_init_component ( int  cidx)

Definition at line 193 of file linux-micpower.c.

194 {
195  if ( is_initialized )
196  return (PAPI_OK );
197 
198  is_initialized = 1;
199 
200  /* Check that /sys/class/micras/power is readable */
201  if ( 0 != access( "/sys/class/micras/power", R_OK ) ) {
203  "Cannot read /sys/class/micras/power",PAPI_MAX_STR_LEN);
204  return PAPI_ENOCMP;
205  }
206 
207 
208  /* Export the total number of events available */
209  num_events =
211 
212  /* Export the component id */
214 
215  return PAPI_OK;
216 }
static int is_initialized
static int num_events
papi_vector_t _micpower_vector
return PAPI_OK
Definition: linux-nvml.c:458
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
#define MICPOWER_NUMBER_OF_NATIVE_EVENTS
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:633
static int cidx
Definition: event_info.c:40
#define PAPI_ENOCMP
Definition: papi.h:268
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
int _micpower_init_control_state ( hwd_control_state_t ctl)

Definition at line 226 of file linux-micpower.c.

227 {
228  int retval = 0;
229  MICPOWER_control_state_t *micpower_ctl = (MICPOWER_control_state_t *) ctl;
230 
231  retval = read_sysfs_file(micpower_ctl->counts);
232 
233  /* Set last access time for caching results */
234  micpower_ctl->lastupdate = PAPI_get_real_usec();
235 
236  return (retval)?PAPI_OK:PAPI_ESYS;
237 }
return PAPI_OK
Definition: linux-nvml.c:458
long long counts[MICPOWER_MAX_COUNTERS]
#define PAPI_ESYS
Definition: papi.h:253
static int read_sysfs_file(long long *counts)
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

int _micpower_init_thread ( hwd_context_t ctx)

Definition at line 180 of file linux-micpower.c.

181 {
182  ( void ) ctx;
183  return PAPI_OK;
184 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _micpower_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 434 of file linux-micpower.c.

435 {
436  int index = EventCode&PAPI_NATIVE_AND_MASK;
437 
438  if ( index >= 0 && index < num_events ) {
439  strncpy( name, _micpower_native_events[index].description, len );
440  return PAPI_OK;
441  }
442  return PAPI_ENOEVNT;
443 }
#define PAPI_ENOEVNT
Definition: papi.h:258
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
static MICPOWER_native_event_entry_t _micpower_native_events[]
char * name
Definition: iozone.c:23648
#define PAPI_NATIVE_AND_MASK
int _micpower_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)

Definition at line 446 of file linux-micpower.c.

447 {
448 
449  int index = EventCode&PAPI_NATIVE_AND_MASK;
450 
451  if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
452 
453  strncpy( info->symbol, _micpower_native_events[index].name,
454  sizeof(info->symbol));
455 
456  strncpy( info->long_descr, _micpower_native_events[index].description,
457  sizeof(info->long_descr));
458 
459  strncpy( info->units, _micpower_native_events[index].units,
460  sizeof(info->units));
461 
462 
463  return PAPI_OK;
464 }
#define PAPI_ENOEVNT
Definition: papi.h:258
char name[PAPI_MAX_STR_LEN]
static int num_events
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:966
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:963
return PAPI_OK
Definition: linux-nvml.c:458
char units[PAPI_MIN_STR_LEN]
static MICPOWER_native_event_entry_t _micpower_native_events[]
#define PAPI_NATIVE_AND_MASK
char description[PAPI_MAX_STR_LEN]
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:972
int _micpower_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 419 of file linux-micpower.c.

420 {
421  int index = EventCode&PAPI_NATIVE_AND_MASK;
422 
423  if ( index >= 0 && index < num_events ) {
424  strncpy( name, _micpower_native_events[index].name, len );
425  return PAPI_OK;
426  }
427  return PAPI_ENOEVNT;
428 }
#define PAPI_ENOEVNT
Definition: papi.h:258
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
static MICPOWER_native_event_entry_t _micpower_native_events[]
char * name
Definition: iozone.c:23648
#define PAPI_NATIVE_AND_MASK
int _micpower_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)

Definition at line 380 of file linux-micpower.c.

381 {
382 
383  int index;
384 
385  switch ( modifier ) {
386 
387  case PAPI_ENUM_FIRST:
388 
389  if (num_events==0) {
390  return PAPI_ENOEVNT;
391  }
392  *EventCode = 0;
393 
394  return PAPI_OK;
395 
396 
397  case PAPI_ENUM_EVENTS:
398 
399  index = *EventCode&PAPI_NATIVE_AND_MASK;
400 
401  if ( index < num_events - 1 ) {
402  *EventCode = *EventCode + 1;
403  return PAPI_OK;
404  } else {
405  return PAPI_ENOEVNT;
406  }
407  break;
408 
409  default:
410  return PAPI_EINVAL;
411  }
412  return PAPI_EINVAL;
413 }
#define PAPI_ENOEVNT
Definition: papi.h:258
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
return PAPI_EINVAL
Definition: linux-nvml.c:408
#define PAPI_NATIVE_AND_MASK
int _micpower_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)

Definition at line 249 of file linux-micpower.c.

251 {
252  (void) flags;
253  (void) ctx;
254  int retval = 1;
255 
257  long long now = PAPI_get_real_usec();
258 
259  /* Only read the values from the kernel if enough time has passed */
260  /* since the last read. Otherwise return cached values. */
261 
262  if ( now - control->lastupdate > REFRESH_LAT ) {
263  retval = read_sysfs_file(control->counts);
264  control->lastupdate = now;
265  }
266 
267  /* Pass back a pointer to our results */
268  *events = control->counts;
269 
270  return (retval)?PAPI_OK:PAPI_ESYS;
271 }
long long flags
Definition: iozone.c:12330
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
char events[MAX_EVENTS][BUFSIZ]
long long counts[MICPOWER_MAX_COUNTERS]
#define PAPI_ESYS
Definition: papi.h:253
#define REFRESH_LAT
static int read_sysfs_file(long long *counts)
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

int _micpower_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 367 of file linux-micpower.c.

368 {
369  ( void ) ctx;
370  ( void ) ctl;
371 
372  return PAPI_OK;
373 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _micpower_set_domain ( hwd_control_state_t cntl,
int  domain 
)

Definition at line 355 of file linux-micpower.c.

356 {
357  ( void ) cntl;
358 
359  if ( PAPI_DOM_ALL != domain )
360  return PAPI_EINVAL;
361 
362  return PAPI_OK;
363 }
#define PAPI_DOM_ALL
Definition: papi.h:301
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:408
int _micpower_shutdown_component ( )

Definition at line 302 of file linux-micpower.c.

303 {
304  if ( is_initialized ) {
305  is_initialized = 0;
306  num_events = 0;
307  }
308  return PAPI_OK;
309 }
static int is_initialized
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
int _micpower_shutdown_thread ( hwd_context_t ctx)

Definition at line 291 of file linux-micpower.c.

292 {
293  ( void ) ctx;
294  return PAPI_OK;
295 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _micpower_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 240 of file linux-micpower.c.

241 {
242  ( void ) ctx;
243  ( void ) ctl;
244 
245  return PAPI_OK;
246 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _micpower_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 274 of file linux-micpower.c.

275 {
276  (void) ctx;
277  int retval = 1;
278  long long now = PAPI_get_real_usec();
279  /* read values */
281 
282  if ( now - control->lastupdate > REFRESH_LAT ) {
283  retval = read_sysfs_file(control->counts);
284  control->lastupdate = now;
285  }
286  return (retval)?PAPI_OK:PAPI_ESYS;
287 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
long long counts[MICPOWER_MAX_COUNTERS]
#define PAPI_ESYS
Definition: papi.h:253
#define REFRESH_LAT
static int read_sysfs_file(long long *counts)
long long PAPI_get_real_usec(void)
Definition: papi.c:6190
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

int _micpower_update_control_state ( hwd_control_state_t ptr,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Definition at line 328 of file linux-micpower.c.

331 {
332  int i, index;
333  ( void ) ctx;
334  ( void ) ptr;
335 
336  for ( i = 0; i < count; i++ ) {
337  index = native[i].ni_event&PAPI_NATIVE_AND_MASK;
339  }
340  return PAPI_OK;
341 }
return PAPI_OK
Definition: linux-nvml.c:458
MICPOWER_register_t resources
int count
Definition: iozone.c:22422
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
static MICPOWER_native_event_entry_t _micpower_native_events[]
unsigned int selector
#define PAPI_NATIVE_AND_MASK
static int read_sysfs_file ( long long counts)
static

Definition at line 152 of file linux-micpower.c.

153 {
154  FILE* fp = NULL;
155  int i;
156  int retval = 1;
157  fp = fopen( "/sys/class/micras/power", "r" );
158  if (!fp)
159  return 0;
160 
161  for (i=0; i < MICPOWER_MAX_COUNTERS-9; i++) {
162  retval&= fscanf(fp, "%lld", &counts[i]);
163  }
164  for (i=MICPOWER_MAX_COUNTERS-9; i < MICPOWER_MAX_COUNTERS; i+=3) {
165  retval&= fscanf(fp, "%lld %lld %lld", &counts[i], &counts[i+1], &counts[i+2] );
166  }
167 
168  fclose(fp);
169  return retval;
170 }
fclose(thread_wqfd)
int i
Definition: fileop.c:140
static FILE * fp
#define MICPOWER_MAX_COUNTERS
ssize_t retval
Definition: libasync.c:338

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

MICPOWER_native_event_entry_t _micpower_native_events[]
static

Definition at line 26 of file linux-micpower.c.

papi_vector_t _micpower_vector

Definition at line 24 of file linux-micpower.c.

int is_initialized = 0
static

Definition at line 110 of file linux-micpower.c.

int num_events = 0
static

Definition at line 109 of file linux-micpower.c.