linux-micpower.c File Reference

Include dependency graph for linux-micpower.c:

Go to the source code of this file.

Defines

#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

Define 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

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.

00318 {
00319         ( void ) ctx;
00320         ( void ) code;
00321         ( void ) option;
00322 
00323         return PAPI_OK;
00324 }

static int _micpower_init_component ( int  cidx  )  [static]

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

00194 {
00195         if ( is_initialized )
00196                 return (PAPI_OK );
00197 
00198         is_initialized = 1;
00199 
00200         /* Check that /sys/class/micras/power is readable */
00201         if ( 0 != access( "/sys/class/micras/power", R_OK ) ) {
00202                 strncpy(_micpower_vector.cmp_info.disabled_reason,
00203                                 "Cannot read /sys/class/micras/power",PAPI_MAX_STR_LEN);
00204                 return PAPI_ENOCMP;
00205         }
00206 
00207 
00208         /* Export the total number of events available */
00209         num_events =
00210                 _micpower_vector.cmp_info.num_native_events = MICPOWER_NUMBER_OF_NATIVE_EVENTS;
00211 
00212         /* Export the component id */
00213         _micpower_vector.cmp_info.CmpIdx = cidx;
00214 
00215         return PAPI_OK;
00216 }

static int _micpower_init_control_state ( hwd_control_state_t ctl  )  [static]

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

00227 {
00228         int retval = 0;
00229         MICPOWER_control_state_t *micpower_ctl = (MICPOWER_control_state_t *) ctl;
00230 
00231         retval = read_sysfs_file(micpower_ctl->counts);
00232 
00233         /* Set last access time for caching results */
00234         micpower_ctl->lastupdate = PAPI_get_real_usec();
00235 
00236         return (retval)?PAPI_OK:PAPI_ESYS;
00237 }

Here is the call graph for this function:

static int _micpower_init_thread ( hwd_context_t ctx  )  [static]

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

00181 {
00182         ( void ) ctx;
00183         return PAPI_OK;
00184 }

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

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

00435 {
00436         int index = EventCode&PAPI_NATIVE_AND_MASK;
00437 
00438         if ( index >= 0 && index < num_events ) {
00439                 strncpy( name, _micpower_native_events[index].description, len );
00440                 return PAPI_OK;
00441         }
00442         return PAPI_ENOEVNT;
00443 }

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.

00447 {
00448 
00449         int index = EventCode&PAPI_NATIVE_AND_MASK;
00450 
00451         if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
00452 
00453         strncpy( info->symbol, _micpower_native_events[index].name, sizeof(info->symbol));
00454         strncpy( info->long_descr, _micpower_native_events[index].description, sizeof(info->long_descr));
00455         strncpy( info->units, _micpower_native_events[index].units, sizeof(info->units));
00456         info->units[sizeof(info->units)-1] = '\0';
00457 
00458         return PAPI_OK;
00459 }

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

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

00420 {
00421         int index = EventCode&PAPI_NATIVE_AND_MASK;
00422 
00423         if ( index >= 0 && index < num_events ) {
00424                 strncpy( name, _micpower_native_events[index].name, len );
00425                 return PAPI_OK;
00426         }
00427         return PAPI_ENOEVNT;
00428 }

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

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

00381 {
00382 
00383         int index;
00384 
00385         switch ( modifier ) {
00386 
00387                 case PAPI_ENUM_FIRST:
00388 
00389                         if (num_events==0) {
00390                                 return PAPI_ENOEVNT;
00391                         }
00392                         *EventCode = 0;
00393 
00394                         return PAPI_OK;
00395 
00396 
00397                 case PAPI_ENUM_EVENTS:
00398 
00399                         index = *EventCode&PAPI_NATIVE_AND_MASK;
00400 
00401                         if ( index < num_events - 1 ) {
00402                                 *EventCode = *EventCode + 1;
00403                                 return PAPI_OK;
00404                         } else {
00405                                 return PAPI_ENOEVNT;
00406                         }
00407                         break;
00408 
00409                 default:
00410                         return PAPI_EINVAL;
00411         }
00412         return PAPI_EINVAL;
00413 }

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.

00251 {
00252         (void) flags;
00253         (void) ctx;
00254         int retval = 1;
00255 
00256         MICPOWER_control_state_t* control = (MICPOWER_control_state_t*) ctl;
00257         long long now = PAPI_get_real_usec();
00258 
00259         /* Only read the values from the kernel if enough time has passed */
00260         /* since the last read.  Otherwise return cached values.          */
00261 
00262         if ( now - control->lastupdate > REFRESH_LAT ) {
00263                 retval = read_sysfs_file(control->counts);
00264                 control->lastupdate = now;
00265         }
00266 
00267         /* Pass back a pointer to our results */
00268         *events = control->counts;
00269 
00270         return (retval)?PAPI_OK:PAPI_ESYS;
00271 }

Here is the call graph for this function:

static int _micpower_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
) [static]

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

00368 {
00369         ( void ) ctx;
00370         ( void ) ctl;
00371 
00372         return PAPI_OK;
00373 }

static int _micpower_set_domain ( hwd_control_state_t cntl,
int  domain 
) [static]

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

00356 {
00357         ( void ) cntl;
00358 
00359         if ( PAPI_DOM_ALL != domain )
00360             return PAPI_EINVAL;
00361 
00362         return PAPI_OK;
00363 }

static int _micpower_shutdown_component (  )  [static]

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

00303 {
00304         if ( is_initialized ) {
00305                 is_initialized = 0;
00306                 num_events = 0;
00307         }
00308         return PAPI_OK;
00309 }

static int _micpower_shutdown_thread ( hwd_context_t ctx  )  [static]

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

00292 {
00293         ( void ) ctx;
00294         return PAPI_OK;
00295 }

static int _micpower_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
) [static]

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

00241 {
00242         ( void ) ctx;
00243         ( void ) ctl;
00244 
00245         return PAPI_OK;
00246 }

static int _micpower_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
) [static]

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

00275 {
00276         (void) ctx;
00277         int retval = 1;
00278         long long now = PAPI_get_real_usec();
00279         /* read values */
00280         MICPOWER_control_state_t* control = (MICPOWER_control_state_t*) ctl;
00281 
00282         if ( now - control->lastupdate > REFRESH_LAT ) {
00283                 retval = read_sysfs_file(control->counts);
00284                 control->lastupdate = now;
00285         }
00286         return (retval)?PAPI_OK:PAPI_ESYS;
00287 }

Here is the call graph for this function:

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.

00331 {
00332         int i, index;
00333         ( void ) ctx;
00334         ( void ) ptr;
00335 
00336         for ( i = 0; i < count; i++ ) {
00337                 index = native[i].ni_event&PAPI_NATIVE_AND_MASK;
00338                 native[i].ni_position = _micpower_native_events[index].resources.selector - 1;
00339         }
00340         return PAPI_OK;
00341 }

static int read_sysfs_file ( long long *  counts  )  [static]

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

00153 {
00154         FILE* fp = NULL;
00155         int i;
00156         int retval = 1;
00157         fp = fopen( "/sys/class/micras/power", "r" );
00158         if (!fp)
00159             return 0;
00160 
00161         for (i=0; i < MICPOWER_MAX_COUNTERS-9; i++) {
00162                 retval&= fscanf(fp, "%lld", &counts[i]);
00163         }
00164         for (i=MICPOWER_MAX_COUNTERS-9; i < MICPOWER_MAX_COUNTERS; i+=3) {
00165                 retval&= fscanf(fp, "%lld %lld %lld", &counts[i], &counts[i+1], &counts[i+2] );
00166         }
00167 
00168         fclose(fp);
00169         return retval;
00170 }

Here is the caller graph for this function:


Variable Documentation

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

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.


Generated on 17 Nov 2016 for PAPI by  doxygen 1.6.1