PAPI  5.7.0.0
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)
 
static int _micpower_init_thread (hwd_context_t *ctx)
 
static int _micpower_init_component (int cidx)
 
static int _micpower_init_control_state (hwd_control_state_t *ctl)
 
static int _micpower_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _micpower_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
 
static int _micpower_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _micpower_shutdown_thread (hwd_context_t *ctx)
 
static int _micpower_shutdown_component ()
 
static int _micpower_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
static int _micpower_update_control_state (hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
static int _micpower_set_domain (hwd_control_state_t *cntl, int domain)
 
static int _micpower_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _micpower_ntv_enum_events (unsigned int *EventCode, int modifier)
 
static int _micpower_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
static int _micpower_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
static 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

◆ INVALID_RESULT

#define INVALID_RESULT   -1000000L

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

◆ MICPOWER_NUMBER_OF_NATIVE_EVENTS

#define MICPOWER_NUMBER_OF_NATIVE_EVENTS   16

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

◆ REFRESH_LAT

#define REFRESH_LAT   50000

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

Function Documentation

◆ _micpower_ctl()

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

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 }
#define PAPI_OK
Definition: fpapi.h:105

◆ _micpower_init_component()

static int _micpower_init_component ( int  cidx)
static

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 }
#define PAPI_OK
Definition: fpapi.h:105
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:637
static int num_events
static int is_initialized
papi_vector_t _micpower_vector
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
#define PAPI_ENOCMP
Definition: fpapi.h:122
#define MICPOWER_NUMBER_OF_NATIVE_EVENTS
static int cidx
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43

◆ _micpower_init_control_state()

static int _micpower_init_control_state ( hwd_control_state_t ctl)
static

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 }
#define PAPI_OK
Definition: fpapi.h:105
int retval
Definition: zero_fork.c:53
#define PAPI_ESYS
Definition: fpapi.h:108
long long counts[MICPOWER_MAX_COUNTERS]
static int read_sysfs_file(long long *counts)
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
Here is the call graph for this function:

◆ _micpower_init_thread()

static int _micpower_init_thread ( hwd_context_t ctx)
static

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

181 {
182  ( void ) ctx;
183  return PAPI_OK;
184 }
#define PAPI_OK
Definition: fpapi.h:105

◆ _micpower_ntv_code_to_descr()

static int _micpower_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)
static

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_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
static int num_events
static MICPOWER_native_event_entry_t _micpower_native_events[]
#define PAPI_ENOEVNT
Definition: fpapi.h:112
#define PAPI_NATIVE_AND_MASK

◆ _micpower_ntv_code_to_info()

static int _micpower_ntv_code_to_info ( unsigned int  EventCode,
PAPI_event_info_t info 
)
static

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, sizeof(info->symbol));
454  strncpy( info->long_descr, _micpower_native_events[index].description, sizeof(info->long_descr));
455  strncpy( info->units, _micpower_native_events[index].units, sizeof(info->units));
456  info->units[sizeof(info->units)-1] = '\0';
457 
458  return PAPI_OK;
459 }
#define PAPI_OK
Definition: fpapi.h:105
char name[PAPI_MAX_STR_LEN]
static int num_events
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:976
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:970
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:967
char units[PAPI_MIN_STR_LEN]
static MICPOWER_native_event_entry_t _micpower_native_events[]
#define PAPI_ENOEVNT
Definition: fpapi.h:112
#define PAPI_NATIVE_AND_MASK
char description[PAPI_MAX_STR_LEN]

◆ _micpower_ntv_code_to_name()

static int _micpower_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)
static

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_OK
Definition: fpapi.h:105
static const char * name
Definition: fork_overflow.c:31
static int num_events
static MICPOWER_native_event_entry_t _micpower_native_events[]
#define PAPI_ENOEVNT
Definition: fpapi.h:112
#define PAPI_NATIVE_AND_MASK

◆ _micpower_ntv_enum_events()

static int _micpower_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)
static

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_OK
Definition: fpapi.h:105
static int num_events
#define PAPI_EINVAL
Definition: fpapi.h:106
#define PAPI_ENOEVNT
Definition: fpapi.h:112
#define PAPI_NATIVE_AND_MASK

◆ _micpower_read()

static int _micpower_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long long **  events,
int  flags 
)
static

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 }
#define PAPI_OK
Definition: fpapi.h:105
int retval
Definition: zero_fork.c:53
char events[MAX_EVENTS][BUFSIZ]
#define PAPI_ESYS
Definition: fpapi.h:108
long long counts[MICPOWER_MAX_COUNTERS]
#define REFRESH_LAT
static int read_sysfs_file(long long *counts)
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
Here is the call graph for this function:

◆ _micpower_reset()

static int _micpower_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

368 {
369  ( void ) ctx;
370  ( void ) ctl;
371 
372  return PAPI_OK;
373 }
#define PAPI_OK
Definition: fpapi.h:105

◆ _micpower_set_domain()

static int _micpower_set_domain ( hwd_control_state_t cntl,
int  domain 
)
static

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_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
#define PAPI_DOM_ALL
Definition: fpapi.h:25

◆ _micpower_shutdown_component()

static int _micpower_shutdown_component ( )
static

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 }
#define PAPI_OK
Definition: fpapi.h:105
static int num_events
static int is_initialized

◆ _micpower_shutdown_thread()

static int _micpower_shutdown_thread ( hwd_context_t ctx)
static

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

292 {
293  ( void ) ctx;
294  return PAPI_OK;
295 }
#define PAPI_OK
Definition: fpapi.h:105

◆ _micpower_start()

static int _micpower_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

241 {
242  ( void ) ctx;
243  ( void ) ctl;
244 
245  return PAPI_OK;
246 }
#define PAPI_OK
Definition: fpapi.h:105

◆ _micpower_stop()

static int _micpower_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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 }
#define PAPI_OK
Definition: fpapi.h:105
int retval
Definition: zero_fork.c:53
#define PAPI_ESYS
Definition: fpapi.h:108
long long counts[MICPOWER_MAX_COUNTERS]
#define REFRESH_LAT
static int read_sysfs_file(long long *counts)
long long PAPI_get_real_usec(void)
Definition: papi.c:6264
Here is the call graph for this function:

◆ _micpower_update_control_state()

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

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;
338  native[i].ni_position = _micpower_native_events[index].resources.selector - 1;
339  }
340  return PAPI_OK;
341 }
#define PAPI_OK
Definition: fpapi.h:105
MICPOWER_register_t resources
static int native
static MICPOWER_native_event_entry_t _micpower_native_events[]
unsigned int selector
#define PAPI_NATIVE_AND_MASK
static long count
int i
Definition: fileop.c:140

◆ read_sysfs_file()

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  }
165  retval&= fscanf(fp, "%lld %lld %lld", &counts[i], &counts[i+1], &counts[i+2] );
166  }
167 
168  fclose(fp);
169  return retval;
170 }
int retval
Definition: zero_fork.c:53
static FILE * fp
#define MICPOWER_MAX_COUNTERS
int i
Definition: fileop.c:140
Here is the caller graph for this function:

Variable Documentation

◆ _micpower_native_events

MICPOWER_native_event_entry_t _micpower_native_events[]
static

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

◆ _micpower_vector

papi_vector_t _micpower_vector

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

◆ is_initialized

int is_initialized = 0
static

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

◆ num_events

int num_events = 0
static

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