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)
static int _lmsensors_init_thread (hwd_context_t *ctx)
static int _lmsensors_init_component (int cidx)
static int _lmsensors_init_control_state (hwd_control_state_t *ctl)
static int _lmsensors_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
static int _lmsensors_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
static int _lmsensors_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long_long **events, int flags)
static int _lmsensors_shutdown_component (void)
static int _lmsensors_shutdown_thread (hwd_context_t *ctx)
static int _lmsensors_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
static int _lmsensors_update_control_state (hwd_control_state_t *ctl, NativeInfo_t *native, int count, hwd_context_t *ctx)
static int _lmsensors_set_domain (hwd_control_state_t *ctl, int domain)
static int _lmsensors_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
static int _lmsensors_ntv_enum_events (unsigned int *EventCode, int modifier)
static int _lmsensors_ntv_code_to_name (unsigned int EventCode, char *name, int len)
static 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

static int _lmsensors_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
) [static]

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

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

static int _lmsensors_init_component ( int  cidx  )  [static]

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

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

Here is the call graph for this function:

static int _lmsensors_init_control_state ( hwd_control_state_t ctl  )  [static]

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

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

Here is the call graph for this function:

static int _lmsensors_init_thread ( hwd_context_t ctx  )  [static]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Here is the call graph for this function:

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

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

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

static int _lmsensors_set_domain ( hwd_control_state_t ctl,
int  domain 
) [static]

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

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

static int _lmsensors_shutdown_component ( void   )  [static]

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

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

static int _lmsensors_shutdown_thread ( hwd_context_t ctx  )  [static]

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

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

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

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

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

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

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

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

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

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

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

static unsigned createNativeEvents ( void   )  [static]

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

00144 {
00145     unsigned id = 0;
00146         unsigned int count;
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                  lm_sensors_native_table[id].description[PAPI_MAX_STR_LEN-1] = '\0';
00198 
00199          /* The selector has to be !=0 . Starts with 1 */
00200          lm_sensors_native_table[id].resources.selector = id + 1;
00201 
00202          /* Save the actual references to this event */
00203          lm_sensors_native_table[id].resources.name = chip_name;
00204          lm_sensors_native_table[id].resources.subfeat_nr = sub->number;
00205 
00206          count = sub->number;
00207 
00208          /* increment the table index counter */
00209          id++;       
00210           }
00211 
00212           //   lm_sensors_native_table[id].count = count + 1;
00213           free( featurelabel );
00214        }
00215     }
00216 
00217     /* Return the number of events created */
00218     return id;
00219 }

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 228 of file linux-lmsensors.c.

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

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 17 Nov 2016 for PAPI by  doxygen 1.6.1