linux-lmsensors.c File Reference

This file has the source code for a component that enables PAPI-C to access hardware monitoring sensors through the libsensors library. This code will dynamically create a native events table for all the sensors that can be accesed by the libsensors library. In order to learn more about libsensors, visit: (http://www.lm-sensors.org). More...

Include dependency graph for linux-lmsensors.c:

Go to the source code of this file.

Data Structures

struct  _lmsensors_register_t
struct  _lmsensors_native_event_entry_t
struct  _lmsensors_reg_alloc_t
struct  _lmsensors_control_state_t
struct  _lmsensors_context_t

Defines

#define LM_SENSORS_MAX_COUNTERS   512
#define LM_SENSORS_REFRESHTIME   200000

Functions

static unsigned detectSensors (void)
static unsigned createNativeEvents (void)
static long_long getEventValue (unsigned event_id)
int _lmsensors_init_thread (hwd_context_t *ctx)
int _lmsensors_init_component (int cidx)
int _lmsensors_init_control_state (hwd_control_state_t *ctl)
int _lmsensors_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
int _lmsensors_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
int _lmsensors_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long_long **events, int flags)
int _lmsensors_shutdown_component (void)
int _lmsensors_shutdown_thread (hwd_context_t *ctx)
int _lmsensors_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
int _lmsensors_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
int _lmsensors_set_domain (hwd_control_state_t *ctl, int domain)
int _lmsensors_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
int _lmsensors_ntv_enum_events (unsigned int *EventCode, int modifier)
int _lmsensors_ntv_code_to_name (unsigned int EventCode, char *name, int len)
int _lmsensors_ntv_code_to_descr (unsigned int EventCode, char *name, int len)

Variables

static
_lmsensors_native_event_entry_t
lm_sensors_native_table
static int num_events = 0
papi_vector_t _lmsensors_vector

Detailed Description

Author:
Daniel Lucio
Joachim Protze
Heike Jagode jagode@eecs.utk.edu

LM_SENSORS component

Tested version of lm_sensors: 3.1.1

Notes:

Definition in file linux-lmsensors.c.


Define Documentation

#define LM_SENSORS_MAX_COUNTERS   512

Definition at line 46 of file linux-lmsensors.c.

#define LM_SENSORS_REFRESHTIME   200000

Definition at line 48 of file linux-lmsensors.c.


Function Documentation

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

Definition at line 400 of file linux-lmsensors.c.

00401 {
00402     ( void ) ctx;
00403     ( void ) code;
00404     ( void ) option;
00405     return PAPI_OK;
00406 }

int _lmsensors_init_component ( int  cidx  ) 

Definition at line 266 of file linux-lmsensors.c.

00267 {
00268     int res;
00269     (void) cidx;
00270 
00271     /* Initialize libsensors library */
00272     if ( ( res = sensors_init( NULL ) ) != 0 ) {
00273        strncpy(_lmsensors_vector.cmp_info.disabled_reason,
00274           "Cannot enable libsensors",PAPI_MAX_STR_LEN);
00275        return res;
00276     }
00277 
00278     /* Create dyanmic events table */
00279     num_events = detectSensors(  );
00280     SUBDBG("Found %d sensors\n",num_events);
00281 
00282     if ( ( lm_sensors_native_table =
00283        calloc( num_events, sizeof ( _lmsensors_native_event_entry_t )))
00284                    == NULL ) {
00285        strncpy(_lmsensors_vector.cmp_info.disabled_reason,
00286           "Could not malloc room",PAPI_MAX_STR_LEN);
00287        return PAPI_ENOMEM;
00288     }
00289 
00290     if ( ( unsigned ) num_events != createNativeEvents(  ) ) {
00291        strncpy(_lmsensors_vector.cmp_info.disabled_reason,
00292           "LM_SENSOR number mismatch",PAPI_MAX_STR_LEN);
00293        return PAPI_ECMP;
00294     }
00295 
00296     _lmsensors_vector.cmp_info.num_native_events=num_events;
00297     _lmsensors_vector.cmp_info.num_cntrs=num_events;
00298 
00299     return PAPI_OK;
00300 }

Here is the call graph for this function:

int _lmsensors_init_control_state ( hwd_control_state_t ctl  ) 

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

00309 {
00310     int i;
00311 
00312     for ( i = 0; i < num_events; i++ )
00313         ( ( _lmsensors_control_state_t * ) ctl )->counts[i] =
00314             getEventValue( i );
00315 
00316     ( ( _lmsensors_control_state_t * ) ctl )->lastupdate =
00317         PAPI_get_real_usec(  );
00318     return PAPI_OK;
00319 }

Here is the call graph for this function:

int _lmsensors_init_thread ( hwd_context_t ctx  ) 

Definition at line 254 of file linux-lmsensors.c.

00255 {
00256     ( void ) ctx;
00257     return PAPI_OK;
00258 }

int _lmsensors_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 505 of file linux-lmsensors.c.

00506 {
00507     int index = EventCode;
00508 
00509     if (index>=0 && index<num_events) {
00510        strncpy( name, lm_sensors_native_table[index].description, len );
00511     }
00512     return PAPI_OK;
00513 }

int _lmsensors_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

Definition at line 490 of file linux-lmsensors.c.

00491 {
00492     int index = EventCode;
00493 
00494     if (index>=0 && index<num_events) {
00495        strncpy( name, lm_sensors_native_table[index].name, len );
00496     }
00497 
00498     return PAPI_OK;
00499 }

int _lmsensors_ntv_enum_events ( unsigned int *  EventCode,
int  modifier 
)

Definition at line 458 of file linux-lmsensors.c.

00459 {
00460 
00461     switch ( modifier ) {
00462     case PAPI_ENUM_FIRST:
00463         *EventCode = 0;
00464 
00465         return PAPI_OK;
00466         break;
00467 
00468     case PAPI_ENUM_EVENTS:
00469     {
00470         int index = *EventCode;
00471 
00472         if ( index < num_events - 1 ) {
00473             *EventCode = *EventCode + 1;
00474             return PAPI_OK;
00475         } else
00476             return PAPI_ENOEVNT;
00477 
00478         break;
00479     }
00480     default:
00481         return PAPI_EINVAL;
00482     }
00483     return PAPI_EINVAL;
00484 }

int _lmsensors_read ( hwd_context_t ctx,
hwd_control_state_t ctl,
long_long **  events,
int  flags 
)

Definition at line 352 of file linux-lmsensors.c.

00354 {
00355     ( void ) ctx;
00356     ( void ) flags;
00357     long long start = PAPI_get_real_usec(  );
00358     int i;
00359  
00360     _lmsensors_control_state_t *control=(_lmsensors_control_state_t *)ctl;
00361 
00362     if ( start - control->lastupdate > 200000 ) {   // cache refresh
00363        
00364        for ( i = 0; i < num_events; i++ ) {
00365        control->counts[i] = getEventValue( i );
00366        }
00367        control->lastupdate = PAPI_get_real_usec(  );
00368     }
00369 
00370     *events = control->counts;
00371     return PAPI_OK;
00372 }

Here is the call graph for this function:

int _lmsensors_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

00447 {
00448     ( void ) ctx;
00449     ( void ) ctl;
00450     return PAPI_OK;
00451 }

int _lmsensors_set_domain ( hwd_control_state_t ctl,
int  domain 
)

Definition at line 432 of file linux-lmsensors.c.

00433 {
00434     (void) ctl;
00435     if ( PAPI_DOM_ALL != domain )
00436         return ( PAPI_EINVAL );
00437 
00438     return ( PAPI_OK );
00439 }

int _lmsensors_shutdown_component ( void   ) 

Definition at line 376 of file linux-lmsensors.c.

00377 {
00378 
00379     /* Call the libsensors cleaning function before leaving */
00380     sensors_cleanup(  );
00381 
00382     return PAPI_OK;
00383 }

int _lmsensors_shutdown_thread ( hwd_context_t ctx  ) 

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

00387 {
00388     ( void ) ctx;
00389 
00390     return PAPI_OK;
00391 }

int _lmsensors_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 326 of file linux-lmsensors.c.

00327 {
00328     ( void ) ctx;
00329     ( void ) ctl;
00330 
00331     return PAPI_OK;
00332 }

int _lmsensors_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

Definition at line 339 of file linux-lmsensors.c.

00340 {
00341     ( void ) ctx;
00342     ( void ) ctl;
00343 
00344     return PAPI_OK;
00345 }

int _lmsensors_update_control_state ( hwd_control_state_t ctl,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)

Definition at line 410 of file linux-lmsensors.c.

00414 {
00415     int i, index;
00416     ( void ) ctx;
00417     ( void ) ctl;
00418 
00419     for ( i = 0; i < count; i++ ) {
00420     index = native[i].ni_event;
00421     native[i].ni_position =
00422             lm_sensors_native_table[index].resources.selector - 1;
00423     }
00424     return PAPI_OK;
00425 }

static unsigned createNativeEvents ( void   )  [static]

Definition at line 143 of file linux-lmsensors.c.

00144 {
00145     unsigned id = 0;
00146     unsigned int count = 0;
00147 
00148     int chip_nr = 0;
00149     const sensors_chip_name *chip_name;
00150 
00151     /* component name and description */
00152     strcpy( _lmsensors_vector.cmp_info.short_name, "LM_SENSORS" );
00153     strcpy( _lmsensors_vector.cmp_info.description,
00154             "lm-sensors provides tools for monitoring the hardware health" );
00155 
00156 
00157     /* Loop through all the chips found */
00158     while ( ( chip_name =
00159               sensors_get_detected_chips( NULL, &chip_nr ) ) != NULL ) {
00160        int a, b;
00161        const sensors_feature *feature;
00162        const sensors_subfeature *sub;
00163        char chipnamestring[PAPI_MIN_STR_LEN];
00164 
00165        //      lm_sensors_native_table[id].count = 0;
00166 
00167         /* get chip name from its internal representation */
00168        sensors_snprintf_chip_name( chipnamestring,
00169                         PAPI_MIN_STR_LEN, chip_name );
00170 
00171        a = 0;
00172 
00173        /* Loop through all the features found */
00174        while ( ( feature = sensors_get_features( chip_name, &a ) ) ) {
00175           char *featurelabel;
00176 
00177           if ( !( featurelabel = sensors_get_label( chip_name, feature ))) {
00178          fprintf( stderr, "ERROR: Can't get label of feature %s!\n",
00179                          feature->name );
00180          continue;
00181           }
00182 
00183           b = 0;
00184 
00185           /* Loop through all the subfeatures found */
00186           while ((sub=sensors_get_all_subfeatures(chip_name,feature,&b))) {
00187 
00188              count = 0;
00189 
00190          /* Save native event data */
00191          sprintf( lm_sensors_native_table[id].name, "%s.%s.%s.%s",
00192               _lmsensors_vector.cmp_info.short_name,
00193               chipnamestring, featurelabel, sub->name );
00194 
00195          strncpy( lm_sensors_native_table[id].description,
00196               lm_sensors_native_table[id].name, PAPI_MAX_STR_LEN );
00197 
00198          /* The selector has to be !=0 . Starts with 1 */
00199          lm_sensors_native_table[id].resources.selector = id + 1;
00200 
00201          /* Save the actual references to this event */
00202          lm_sensors_native_table[id].resources.name = chip_name;
00203          lm_sensors_native_table[id].resources.subfeat_nr = sub->number;
00204 
00205          count = sub->number;
00206 
00207          /* increment the table index counter */
00208          id++;       
00209           }
00210 
00211           //   lm_sensors_native_table[id].count = count + 1;
00212           free( featurelabel );
00213        }
00214     }
00215 
00216     /* Return the number of events created */
00217     return id;
00218 }

Here is the caller graph for this function:

static unsigned detectSensors ( void   )  [static]

Definition at line 114 of file linux-lmsensors.c.

00115 {
00116     unsigned id = 0;
00117     int chip_nr = 0;
00118     const sensors_chip_name *chip_name;
00119 
00120     /* Loop through all the chips, features, subfeatures found */
00121     while ( ( chip_name =
00122               sensors_get_detected_chips( NULL, &chip_nr ) ) != NULL ) {
00123         int a = 0, b;
00124         const sensors_feature *feature;
00125 
00126         while ( ( feature = sensors_get_features( chip_name, &a ) ) ) {
00127             b = 0;
00128             while ( ( sensors_get_all_subfeatures( chip_name, feature,
00129                                                    &b ) ) ) {
00130                 id++;
00131             }
00132         }
00133     }
00134 
00135     return id;
00136 }

Here is the caller graph for this function:

static long_long getEventValue ( unsigned  event_id  )  [static]

Definition at line 227 of file linux-lmsensors.c.

00228 {
00229     double value;
00230     int res;
00231 
00232     res = sensors_get_value( lm_sensors_native_table[event_id].resources.name,
00233                              lm_sensors_native_table[event_id].resources.
00234                              subfeat_nr, &value );
00235 
00236     if ( res < 0 ) {
00237         fprintf( stderr, "libsensors(): Could not read event #%d!\n",
00238                  event_id );
00239         return -1;
00240     }
00241 
00242     return ( ( long_long ) ( value * 1000 ) );
00243 }

Here is the caller graph for this function:


Variable Documentation

Definition at line 105 of file linux-lmsensors.c.

Definition at line 99 of file linux-lmsensors.c.

int num_events = 0 [static]

Definition at line 101 of file linux-lmsensors.c.


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1