PAPI  5.4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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
 

Macros

#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 jagod.nosp@m.e@ee.nosp@m.cs.ut.nosp@m.k.ed.nosp@m.u

LM_SENSORS component

Tested version of lm_sensors: 3.1.1

Notes:

  • I used the ACPI and MX components to write this component. A lot of the code in this file mimics what other components already do.
  • The return values are scaled by 1000 because PAPI can not return decimals.
  • A call of PAPI_read can take up to 2 seconds while using lm_sensors!
  • Please remember that libsensors uses the GPL license.

Definition in file linux-lmsensors.c.

Macro Definition 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.

401 {
402  ( void ) ctx;
403  ( void ) code;
404  ( void ) option;
405  return PAPI_OK;
406 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _lmsensors_init_component ( int  cidx)

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

267 {
268  int res;
269  (void) cidx;
270 
271  /* Initialize libsensors library */
272  if ( ( res = sensors_init( NULL ) ) != 0 ) {
274  "Cannot enable libsensors",PAPI_MAX_STR_LEN);
275  return res;
276  }
277 
278  /* Create dyanmic events table */
280  SUBDBG("Found %d sensors\n",num_events);
281 
282  if ( ( lm_sensors_native_table =
283  calloc( num_events, sizeof ( _lmsensors_native_event_entry_t )))
284  == NULL ) {
286  "Could not malloc room",PAPI_MAX_STR_LEN);
287  return PAPI_ENOMEM;
288  }
289 
290  if ( ( unsigned ) num_events != createNativeEvents( ) ) {
292  "LM_SENSOR number mismatch",PAPI_MAX_STR_LEN);
293  return PAPI_ECMP;
294  }
295 
298 
299  return PAPI_OK;
300 }
static int num_events
static unsigned createNativeEvents(void)
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
char disabled_reason[PAPI_MAX_STR_LEN]
Definition: papi.h:633
static unsigned detectSensors(void)
static int cidx
Definition: event_info.c:40
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PAPI_ECMP
Definition: papi.h:254
static _lmsensors_native_event_entry_t * lm_sensors_native_table
#define PAPI_ENOMEM
Definition: papi.h:252
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
papi_vector_t _lmsensors_vector

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.

309 {
310  int i;
311 
312  for ( i = 0; i < num_events; i++ )
313  ( ( _lmsensors_control_state_t * ) ctl )->counts[i] =
314  getEventValue( i );
315 
316  ( ( _lmsensors_control_state_t * ) ctl )->lastupdate =
318  return PAPI_OK;
319 }
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
static long_long getEventValue(unsigned event_id)
int i
Definition: fileop.c:140
long long PAPI_get_real_usec(void)
Definition: papi.c:6190

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.

255 {
256  ( void ) ctx;
257  return PAPI_OK;
258 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _lmsensors_ntv_code_to_descr ( unsigned int  EventCode,
char *  name,
int  len 
)

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

506 {
507  int index = EventCode;
508 
509  if (index>=0 && index<num_events) {
510  strncpy( name, lm_sensors_native_table[index].description, len );
511  }
512  return PAPI_OK;
513 }
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
static _lmsensors_native_event_entry_t * lm_sensors_native_table
char * name
Definition: iozone.c:23648
int _lmsensors_ntv_code_to_name ( unsigned int  EventCode,
char *  name,
int  len 
)

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

491 {
492  int index = EventCode;
493 
494  if (index>=0 && index<num_events) {
495  strncpy( name, lm_sensors_native_table[index].name, len );
496  }
497 
498  return PAPI_OK;
499 }
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
static _lmsensors_native_event_entry_t * lm_sensors_native_table
char * name
Definition: iozone.c:23648
int _lmsensors_ntv_enum_events ( unsigned int EventCode,
int  modifier 
)

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

459 {
460 
461  switch ( modifier ) {
462  case PAPI_ENUM_FIRST:
463  *EventCode = 0;
464 
465  return PAPI_OK;
466  break;
467 
468  case PAPI_ENUM_EVENTS:
469  {
470  int index = *EventCode;
471 
472  if ( index < num_events - 1 ) {
473  *EventCode = *EventCode + 1;
474  return PAPI_OK;
475  } else
476  return PAPI_ENOEVNT;
477 
478  break;
479  }
480  default:
481  return PAPI_EINVAL;
482  }
483  return PAPI_EINVAL;
484 }
#define PAPI_ENOEVNT
Definition: papi.h:258
static int num_events
return PAPI_OK
Definition: linux-nvml.c:458
return PAPI_EINVAL
Definition: linux-nvml.c:408
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.

354 {
355  ( void ) ctx;
356  ( void ) flags;
357  long long start = PAPI_get_real_usec( );
358  int i;
359 
361 
362  if ( start - control->lastupdate > 200000 ) { // cache refresh
363 
364  for ( i = 0; i < num_events; i++ ) {
365  control->counts[i] = getEventValue( i );
366  }
367  control->lastupdate = PAPI_get_real_usec( );
368  }
369 
370  *events = control->counts;
371  return PAPI_OK;
372 }
long long flags
Definition: iozone.c:12330
start
Definition: iozone.c:22736
static int num_events
long_long counts[LM_SENSORS_MAX_COUNTERS]
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
char events[MAX_EVENTS][BUFSIZ]
static long_long getEventValue(unsigned event_id)
int i
Definition: fileop.c:140
long long PAPI_get_real_usec(void)
Definition: papi.c:6190

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.

447 {
448  ( void ) ctx;
449  ( void ) ctl;
450  return PAPI_OK;
451 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _lmsensors_set_domain ( hwd_control_state_t ctl,
int  domain 
)

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

433 {
434  (void) ctl;
435  if ( PAPI_DOM_ALL != domain )
436  return ( PAPI_EINVAL );
437 
438  return ( PAPI_OK );
439 }
#define PAPI_DOM_ALL
Definition: papi.h:301
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
return PAPI_EINVAL
Definition: linux-nvml.c:408
int _lmsensors_shutdown_component ( void  )

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

377 {
378 
379  /* Call the libsensors cleaning function before leaving */
380  sensors_cleanup( );
381 
382  return PAPI_OK;
383 }
return PAPI_OK
Definition: linux-nvml.c:458
int _lmsensors_shutdown_thread ( hwd_context_t ctx)

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

387 {
388  ( void ) ctx;
389 
390  return PAPI_OK;
391 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _lmsensors_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

327 {
328  ( void ) ctx;
329  ( void ) ctl;
330 
331  return PAPI_OK;
332 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
int _lmsensors_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)

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

340 {
341  ( void ) ctx;
342  ( void ) ctl;
343 
344  return PAPI_OK;
345 }
return PAPI_OK
Definition: linux-nvml.c:458
void
Definition: iozone.c:18627
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.

414 {
415  int i, index;
416  ( void ) ctx;
417  ( void ) ctl;
418 
419  for ( i = 0; i < count; i++ ) {
420  index = native[i].ni_event;
421  native[i].ni_position =
423  }
424  return PAPI_OK;
425 }
return PAPI_OK
Definition: linux-nvml.c:458
int count
Definition: iozone.c:22422
void
Definition: iozone.c:18627
int i
Definition: fileop.c:140
static _lmsensors_native_event_entry_t * lm_sensors_native_table
_lmsensors_register_t resources
static unsigned createNativeEvents ( void  )
static

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

144 {
145  unsigned id = 0;
146  unsigned int count = 0;
147 
148  int chip_nr = 0;
149  const sensors_chip_name *chip_name;
150 
151  /* component name and description */
152  strcpy( _lmsensors_vector.cmp_info.short_name, "LM_SENSORS" );
154  "lm-sensors provides tools for monitoring the hardware health" );
155 
156 
157  /* Loop through all the chips found */
158  while ( ( chip_name =
159  sensors_get_detected_chips( NULL, &chip_nr ) ) != NULL ) {
160  int a, b;
161  const sensors_feature *feature;
162  const sensors_subfeature *sub;
163  char chipnamestring[PAPI_MIN_STR_LEN];
164 
165  // lm_sensors_native_table[id].count = 0;
166 
167  /* get chip name from its internal representation */
168  sensors_snprintf_chip_name( chipnamestring,
169  PAPI_MIN_STR_LEN, chip_name );
170 
171  a = 0;
172 
173  /* Loop through all the features found */
174  while ( ( feature = sensors_get_features( chip_name, &a ) ) ) {
175  char *featurelabel;
176 
177  if ( !( featurelabel = sensors_get_label( chip_name, feature ))) {
178  fprintf( stderr, "ERROR: Can't get label of feature %s!\n",
179  feature->name );
180  continue;
181  }
182 
183  b = 0;
184 
185  /* Loop through all the subfeatures found */
186  while ((sub=sensors_get_all_subfeatures(chip_name,feature,&b))) {
187 
188  count = 0;
189 
190  /* Save native event data */
191  sprintf( lm_sensors_native_table[id].name, "%s.%s.%s.%s",
193  chipnamestring, featurelabel, sub->name );
194 
195  strncpy( lm_sensors_native_table[id].description,
197 
198  /* The selector has to be !=0 . Starts with 1 */
200 
201  /* Save the actual references to this event */
204 
205  count = sub->number;
206 
207  /* increment the table index counter */
208  id++;
209  }
210 
211  // lm_sensors_native_table[id].count = count + 1;
212  free( featurelabel );
213  }
214  }
215 
216  /* Return the number of events created */
217  return id;
218 }
sprintf(splash[splash_line++],"\tIozone: Performance Test of File I/O\n")
int count
Definition: iozone.c:22422
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
char short_name[PAPI_MIN_STR_LEN]
Definition: papi.h:627
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
free(dummyfile[xx])
static _lmsensors_native_event_entry_t * lm_sensors_native_table
char description[PAPI_MAX_STR_LEN]
Definition: papi.h:629
uint32_t id
Definition: linux-cuda.c:293
strcpy(filename, default_filename)
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38
char * name
Definition: iozone.c:23648
#define PAPI_MIN_STR_LEN
Definition: papi.h:462
#define PAPI_MAX_STR_LEN
Definition: papi.h:463
papi_vector_t _lmsensors_vector
const sensors_chip_name * name
_lmsensors_register_t resources

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned detectSensors ( void  )
static

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

115 {
116  unsigned id = 0;
117  int chip_nr = 0;
118  const sensors_chip_name *chip_name;
119 
120  /* Loop through all the chips, features, subfeatures found */
121  while ( ( chip_name =
122  sensors_get_detected_chips( NULL, &chip_nr ) ) != NULL ) {
123  int a = 0, b;
124  const sensors_feature *feature;
125 
126  while ( ( feature = sensors_get_features( chip_name, &a ) ) ) {
127  b = 0;
128  while ( ( sensors_get_all_subfeatures( chip_name, feature,
129  &b ) ) ) {
130  id++;
131  }
132  }
133  }
134 
135  return id;
136 }
static double a[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:37
uint32_t id
Definition: linux-cuda.c:293
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: rapl_basic.c:38

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.

228 {
229  double value;
230  int res;
231 
232  res = sensors_get_value( lm_sensors_native_table[event_id].resources.name,
234  subfeat_nr, &value );
235 
236  if ( res < 0 ) {
237  fprintf( stderr, "libsensors(): Could not read event #%d!\n",
238  event_id );
239  return -1;
240  }
241 
242  return ( ( long_long ) ( value * 1000 ) );
243 }
void double value
Definition: iozone.c:18781
static _lmsensors_native_event_entry_t * lm_sensors_native_table
char name[PAPI_MAX_STR_LEN]
#define long_long
Definition: papi.h:550
_lmsensors_register_t resources

Here is the caller graph for this function:

Variable Documentation

papi_vector_t _lmsensors_vector

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

_lmsensors_native_event_entry_t* lm_sensors_native_table
static

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

int num_events = 0
static

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