PAPI 7.1.0.0
Loading...
Searching...
No Matches
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 323 of file linux-micpower.c.

324{
325 ( void ) ctx;
326 ( void ) code;
327 ( void ) option;
328
329 return PAPI_OK;
330}
#define PAPI_OK
Definition: f90papi.h:73

◆ _micpower_init_component()

static int _micpower_init_component ( int  cidx)
static

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

194{
195 int retval = PAPI_OK;
196 if ( is_initialized )
197 return (PAPI_OK );
198
199 is_initialized = 1;
200
201 /* Check that /sys/class/micras/power is readable */
202 if ( 0 != access( "/sys/class/micras/power", R_OK ) ) {
204 "Cannot read /sys/class/micras/power",PAPI_MAX_STR_LEN);
206 goto fn_fail;
207 }
208
209
210 /* Export the total number of events available */
211 num_events =
213
214 /* Export the component id */
216
217 fn_exit:
218 _papi_hwd[cidx]->cmp_info.disabled = retval;
219 return retval;
220 fn_fail:
221 goto fn_exit;
222}
struct papi_vectors * _papi_hwd[]
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ECMP
Definition: f90papi.h:214
static int num_events
papi_vector_t _micpower_vector
static int is_initialized
#define MICPOWER_NUMBER_OF_NATIVE_EVENTS
static int cidx
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
int retval
Definition: zero_fork.c:53

◆ _micpower_init_control_state()

static int _micpower_init_control_state ( hwd_control_state_t ctl)
static

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

233{
234 int retval = 0;
236
237 retval = read_sysfs_file(micpower_ctl->counts);
238
239 /* Set last access time for caching results */
240 micpower_ctl->lastupdate = PAPI_get_real_usec();
241
242 return (retval)?PAPI_OK:PAPI_ESYS;
243}
get real time counter value in microseconds
#define PAPI_ESYS
Definition: f90papi.h:136
static int read_sysfs_file(long long *counts)
long long counts[MICPOWER_MAX_COUNTERS]
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}

◆ _micpower_ntv_code_to_descr()

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

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

441{
442 int index = EventCode&PAPI_NATIVE_AND_MASK;
443
444 if ( index >= 0 && index < num_events ) {
445 strncpy( name, _micpower_native_events[index].description, len );
446 return PAPI_OK;
447 }
448 return PAPI_ENOEVNT;
449}
#define PAPI_ENOEVNT
Definition: f90papi.h:139
static MICPOWER_native_event_entry_t _micpower_native_events[]
#define PAPI_NATIVE_AND_MASK
const char * name
Definition: rocs.c:225

◆ _micpower_ntv_code_to_info()

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

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

453{
454
455 int index = EventCode&PAPI_NATIVE_AND_MASK;
456
457 if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
458
459 strncpy( info->symbol, _micpower_native_events[index].name, sizeof(info->symbol));
460 strncpy( info->long_descr, _micpower_native_events[index].description, sizeof(info->long_descr));
461 strncpy( info->units, _micpower_native_events[index].units, sizeof(info->units));
462 info->units[sizeof(info->units)-1] = '\0';
463
464 return PAPI_OK;
465}
char units[PAPI_MIN_STR_LEN]
char name[PAPI_MAX_STR_LEN]
char description[PAPI_MAX_STR_LEN]
char units[PAPI_MIN_STR_LEN]
Definition: papi.h:969
char symbol[PAPI_HUGE_STR_LEN]
Definition: papi.h:960
char long_descr[PAPI_HUGE_STR_LEN]
Definition: papi.h:963

◆ _micpower_ntv_code_to_name()

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

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

426{
427 int index = EventCode&PAPI_NATIVE_AND_MASK;
428
429 if ( index >= 0 && index < num_events ) {
430 strncpy( name, _micpower_native_events[index].name, len );
431 return PAPI_OK;
432 }
433 return PAPI_ENOEVNT;
434}

◆ _micpower_ntv_enum_events()

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

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

387{
388
389 int index;
390
391 switch ( modifier ) {
392
393 case PAPI_ENUM_FIRST:
394
395 if (num_events==0) {
396 return PAPI_ENOEVNT;
397 }
398 *EventCode = 0;
399
400 return PAPI_OK;
401
402
403 case PAPI_ENUM_EVENTS:
404
405 index = *EventCode&PAPI_NATIVE_AND_MASK;
406
407 if ( index < num_events - 1 ) {
408 *EventCode = *EventCode + 1;
409 return PAPI_OK;
410 } else {
411 return PAPI_ENOEVNT;
412 }
413 break;
414
415 default:
416 return PAPI_EINVAL;
417 }
418 return PAPI_EINVAL;
419}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_EINVAL
Definition: f90papi.h:115

◆ _micpower_read()

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

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

257{
258 (void) flags;
259 (void) ctx;
260 int retval = 1;
261
263 long long now = PAPI_get_real_usec();
264
265 /* Only read the values from the kernel if enough time has passed */
266 /* since the last read. Otherwise return cached values. */
267
268 if ( now - control->lastupdate > REFRESH_LAT ) {
269 retval = read_sysfs_file(control->counts);
270 control->lastupdate = now;
271 }
272
273 /* Pass back a pointer to our results */
274 *events = control->counts;
275
276 return (retval)?PAPI_OK:PAPI_ESYS;
277}
char events[MAX_EVENTS][BUFSIZ]
#define REFRESH_LAT
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 373 of file linux-micpower.c.

374{
375 ( void ) ctx;
376 ( void ) ctl;
377
378 return PAPI_OK;
379}

◆ _micpower_set_domain()

static int _micpower_set_domain ( hwd_control_state_t cntl,
int  domain 
)
static

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

362{
363 ( void ) cntl;
364
365 if ( PAPI_DOM_ALL != domain )
366 return PAPI_EINVAL;
367
368 return PAPI_OK;
369}
#define PAPI_DOM_ALL
Definition: f90papi.h:261

◆ _micpower_shutdown_component()

static int _micpower_shutdown_component ( )
static

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

309{
310 if ( is_initialized ) {
311 is_initialized = 0;
312 num_events = 0;
313 }
314 return PAPI_OK;
315}

◆ _micpower_shutdown_thread()

static int _micpower_shutdown_thread ( hwd_context_t ctx)
static

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

298{
299 ( void ) ctx;
300 return PAPI_OK;
301}

◆ _micpower_start()

static int _micpower_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

247{
248 ( void ) ctx;
249 ( void ) ctl;
250
251 return PAPI_OK;
252}

◆ _micpower_stop()

static int _micpower_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

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

281{
282 (void) ctx;
283 int retval = 1;
284 long long now = PAPI_get_real_usec();
285 /* read values */
287
288 if ( now - control->lastupdate > REFRESH_LAT ) {
289 retval = read_sysfs_file(control->counts);
290 control->lastupdate = now;
291 }
292 return (retval)?PAPI_OK:PAPI_ESYS;
293}
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 334 of file linux-micpower.c.

337{
338 int i, index;
339 ( void ) ctx;
340 ( void ) ptr;
341
342 for ( i = 0; i < count; i++ ) {
343 index = native[i].ni_event&PAPI_NATIVE_AND_MASK;
344 native[i].ni_position = _micpower_native_events[index].resources.selector - 1;
345 }
346 return PAPI_OK;
347}
int i
static long count
static int native
MICPOWER_register_t resources
unsigned int selector

◆ 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}
#define MICPOWER_MAX_COUNTERS
int fclose(FILE *__stream)
static FILE * fp
Here is the call graph for this function:
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.