PAPI  5.3.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
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
static int num_events
papi_vector_t _micpower_vector
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_ENOCMP
Definition: fpapi.h:122
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:632
static int cidx
Definition: event_info.c:40
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]
static int read_sysfs_file(long long *counts)
#define PAPI_ESYS
Definition: fpapi.h:108
long long PAPI_get_real_usec(void)
Definition: papi.c:6125
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 444 of file linux-micpower.c.

445 {
446  int index = EventCode&PAPI_NATIVE_AND_MASK;
447 
448  if ( index >= 0 && index < num_events ) {
449  strncpy( name, _micpower_native_events[index].description, len );
450  return PAPI_OK;
451  }
452  return PAPI_ENOEVNT;
453 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
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 456 of file linux-micpower.c.

457 {
458 
459  int index = EventCode&PAPI_NATIVE_AND_MASK;
460 
461  if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
462 
463  strncpy( info->symbol, _micpower_native_events[index].name,
464  sizeof(info->symbol));
465 
466  strncpy( info->long_descr, _micpower_native_events[index].description,
467  sizeof(info->long_descr));
468 
469  strncpy( info->units, _micpower_native_events[index].units,
470  sizeof(info->units));
471 
472 
473  return PAPI_OK;
474 }
char name[PAPI_MAX_STR_LEN]
#define PAPI_ENOEVNT
Definition: fpapi.h:112
static int num_events
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:964
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:961
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:970
int _micpower_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

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

430 {
431  int index = EventCode&PAPI_NATIVE_AND_MASK;
432 
433  if ( index >= 0 && index < num_events ) {
434  strncpy( name, _micpower_native_events[index].name, len );
435  return PAPI_OK;
436  }
437  return PAPI_ENOEVNT;
438 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
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 390 of file linux-micpower.c.

391 {
392 
393  int index;
394 
395  switch ( modifier ) {
396 
397  case PAPI_ENUM_FIRST:
398 
399  if (num_events==0) {
400  return PAPI_ENOEVNT;
401  }
402  *EventCode = 0;
403 
404  return PAPI_OK;
405 
406 
407  case PAPI_ENUM_EVENTS:
408 
409  index = *EventCode&PAPI_NATIVE_AND_MASK;
410 
411  if ( index < num_events - 1 ) {
412  *EventCode = *EventCode + 1;
413  return PAPI_OK;
414  } else {
415  return PAPI_ENOEVNT;
416  }
417  break;
418 
419  default:
420  return PAPI_EINVAL;
421  }
422  return PAPI_EINVAL;
423 }
#define PAPI_ENOEVNT
Definition: fpapi.h:112
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
long long counts[MICPOWER_MAX_COUNTERS]
char events[MAX_EVENTS][BUFSIZ]
#define REFRESH_LAT
static int read_sysfs_file(long long *counts)
#define PAPI_ESYS
Definition: fpapi.h:108
long long PAPI_get_real_usec(void)
Definition: papi.c:6125
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 377 of file linux-micpower.c.

378 {
379  ( void ) ctx;
380  ( void ) ctl;
381 
382  return PAPI_OK;
383 }
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  int found = 0;
358  ( void ) cntl;
359 
360  if ( PAPI_DOM_USER & domain )
361  found = 1;
362 
363  if ( PAPI_DOM_KERNEL & domain )
364  found = 1;
365 
366  if ( PAPI_DOM_OTHER & domain )
367  found = 1;
368 
369  if ( !found )
370  return PAPI_EINVAL;
371 
372  return PAPI_OK;
373 }
return PAPI_OK
Definition: linux-nvml.c:458
#define PAPI_DOM_OTHER
Definition: fpapi.h:23
#define PAPI_DOM_KERNEL
Definition: fpapi.h:22
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:408
long long found
Definition: libasync.c:735
#define PAPI_DOM_USER
Definition: fpapi.h:21
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 REFRESH_LAT
static int read_sysfs_file(long long *counts)
#define PAPI_ESYS
Definition: fpapi.h:108
long long PAPI_get_real_usec(void)
Definition: papi.c:6125
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.