PAPI 7.1.0.0
Loading...
Searching...
No Matches
linux-coretemp.c File Reference
Include dependency graph for linux-coretemp.c:

Go to the source code of this file.

Data Structures

struct  temp_event
 

Macros

#define REFRESH_LAT   4000
 
#define INVALID_RESULT   -1000000L
 
#define HANDLE_STRING_ERROR   {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}
 
#define NUM_PATHS   2
 

Functions

static int insert_in_list (char *name, char *units, char *description, char *filename)
 
static int generateEventList (char *base_dir)
 
static long long getEventValue (int index)
 
static int _coretemp_init_thread (hwd_context_t *ctx)
 
static int _coretemp_init_component (int cidx)
 
static int _coretemp_init_control_state (hwd_control_state_t *ctl)
 
static int _coretemp_start (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _coretemp_read (hwd_context_t *ctx, hwd_control_state_t *ctl, long long **events, int flags)
 
static int _coretemp_stop (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _coretemp_shutdown_thread (hwd_context_t *ctx)
 
static int _coretemp_shutdown_component ()
 
static int _coretemp_ctl (hwd_context_t *ctx, int code, _papi_int_option_t *option)
 
static int _coretemp_update_control_state (hwd_control_state_t *ptr, NativeInfo_t *native, int count, hwd_context_t *ctx)
 
static int _coretemp_set_domain (hwd_control_state_t *cntl, int domain)
 
static int _coretemp_reset (hwd_context_t *ctx, hwd_control_state_t *ctl)
 
static int _coretemp_ntv_enum_events (unsigned int *EventCode, int modifier)
 
static int _coretemp_ntv_code_to_name (unsigned int EventCode, char *name, int len)
 
static int _coretemp_ntv_code_to_descr (unsigned int EventCode, char *name, int len)
 
static int _coretemp_ntv_code_to_info (unsigned int EventCode, PAPI_event_info_t *info)
 

Variables

papi_vector_t _coretemp_vector
 
static CORETEMP_native_event_entry_t_coretemp_native_events
 
static int num_events = 0
 
static int is_initialized = 0
 
static struct temp_eventroot = NULL
 
static struct temp_eventlast = NULL
 

Macro Definition Documentation

◆ HANDLE_STRING_ERROR

#define HANDLE_STRING_ERROR   {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}

Definition at line 34 of file linux-coretemp.c.

◆ INVALID_RESULT

#define INVALID_RESULT   -1000000L

Definition at line 15 of file linux-coretemp.c.

◆ NUM_PATHS

#define NUM_PATHS   2

◆ REFRESH_LAT

#define REFRESH_LAT   4000

Definition at line 13 of file linux-coretemp.c.

Function Documentation

◆ _coretemp_ctl()

static int _coretemp_ctl ( hwd_context_t ctx,
int  code,
_papi_int_option_t option 
)
static

Definition at line 597 of file linux-coretemp.c.

598{
599 ( void ) ctx;
600 ( void ) code;
601 ( void ) option;
602
603 return PAPI_OK;
604}
#define PAPI_OK
Definition: f90papi.h:73

◆ _coretemp_init_component()

static int _coretemp_init_component ( int  cidx)
static

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

411{
412 int retval = PAPI_OK;
413 int i = 0;
414 struct temp_event *t,*last;
415
416 if ( is_initialized )
417 goto fn_exit;
418
419 is_initialized = 1;
420
421 /* This is the prefered method, all coretemp sensors are symlinked here
422 * see $(kernel_src)/Documentation/hwmon/sysfs-interface */
423
424 num_events = generateEventList("/sys/class/hwmon");
425
426 if ( num_events < 0 ) {
427 char* strCpy;
429 "Cannot open /sys/class/hwmon",PAPI_MAX_STR_LEN);
431 if (strCpy == NULL) HANDLE_STRING_ERROR;
433 goto fn_fail;
434 }
435
436 if ( num_events == 0 ) {
437 char* strCpy=strncpy(_coretemp_vector.cmp_info.disabled_reason,
438 "No coretemp events found",PAPI_MAX_STR_LEN);
440 if (strCpy == NULL) HANDLE_STRING_ERROR;
442 goto fn_fail;
443 }
444
445 t = root;
446
449 if (_coretemp_native_events == NULL) {
450 int strErr=snprintf(_coretemp_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN, "malloc() of _coretemp_native_events failed for %lu bytes.", num_events*sizeof(CORETEMP_native_event_entry_t));
454 goto fn_fail;
455 }
456
457 do {
458 int retlen;
459 retlen = snprintf(_coretemp_native_events[i].name, PAPI_MAX_STR_LEN, "%s", t->name);
460 if (retlen <= 0 || retlen >= PAPI_MAX_STR_LEN) HANDLE_STRING_ERROR;
461
462 retlen = snprintf(_coretemp_native_events[i].path, PATH_MAX, "%s", t->path);
463 if (retlen <= 0 || retlen >= PATH_MAX) HANDLE_STRING_ERROR;
464
465 retlen = snprintf(_coretemp_native_events[i].units, PAPI_MIN_STR_LEN, "%s", t->units);
466 if (retlen <= 0 || retlen >= PAPI_MIN_STR_LEN) HANDLE_STRING_ERROR;
467
469 if (retlen <= 0 || retlen >= PAPI_MAX_STR_LEN) HANDLE_STRING_ERROR;
470
473 last = t;
474 t = t->next;
476 i++;
477 } while (t != NULL);
478 root = NULL;
479
480 /* Export the total number of events available */
482
483 /* Export the component id */
485
486 fn_exit:
487 _papi_hwd[cidx]->cmp_info.disabled = retval;
488 return retval;
489 fn_fail:
490 goto fn_exit;
491}
int i
struct papi_vectors * _papi_hwd[]
#define PAPI_MIN_STR_LEN
Definition: f90papi.h:208
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ECMP
Definition: f90papi.h:214
#define PAPI_ENOMEM
Definition: f90papi.h:16
static int num_events
static struct temp_event * root
static CORETEMP_native_event_entry_t * _coretemp_native_events
static int is_initialized
papi_vector_t _coretemp_vector
static int generateEventList(char *base_dir)
static struct temp_event * last
#define HANDLE_STRING_ERROR
#define papi_calloc(a, b)
Definition: papi_memory.h:37
#define papi_free(a)
Definition: papi_memory.h:35
static int cidx
char units[MAX_EVENTS][BUFSIZ]
Definition: powercap_plot.c:15
const char * name
Definition: rocs.c:225
CORETEMP_register_t resources
int stone
unsigned int selector
char disabled_reason[PAPI_HUGE_STR_LEN]
Definition: papi.h:634
PAPI_component_info_t cmp_info
Definition: papi_vector.h:20
char description[PAPI_MAX_STR_LEN]
struct temp_event * next
char units[PAPI_MIN_STR_LEN]
char path[PATH_MAX]
char name[PAPI_MAX_STR_LEN]
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:

◆ _coretemp_init_control_state()

static int _coretemp_init_control_state ( hwd_control_state_t ctl)
static

Definition at line 501 of file linux-coretemp.c.

502{
503 int i;
504
506
507 for ( i=0; i < num_events; i++ ) {
508 coretemp_ctl->counts[i] = getEventValue(i);
509 }
510
511 /* Set last access time for caching results */
512 coretemp_ctl->lastupdate = PAPI_get_real_usec();
513
514 return PAPI_OK;
515}
get real time counter value in microseconds
int coretemp_ctl(hwd_context_t *ctx, int code, _papi_int_option_t *option)
static long long getEventValue(int index)
Here is the call graph for this function:

◆ _coretemp_init_thread()

static int _coretemp_init_thread ( hwd_context_t ctx)
static

Definition at line 397 of file linux-coretemp.c.

398{
399 ( void ) ctx;
400 return PAPI_OK;
401}

◆ _coretemp_ntv_code_to_descr()

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

Definition at line 713 of file linux-coretemp.c.

714{
715 int index = EventCode;
716
717 if ( index >= 0 && index < num_events ) {
718 strncpy( name, _coretemp_native_events[index].description, len );
719 return PAPI_OK;
720 }
721 return PAPI_ENOEVNT;
722}
#define PAPI_ENOEVNT
Definition: f90papi.h:139

◆ _coretemp_ntv_code_to_info()

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

Definition at line 725 of file linux-coretemp.c.

726{
727
728 int index = EventCode;
729
730 if ( ( index < 0) || (index >= num_events )) return PAPI_ENOEVNT;
731
732 strncpy( info->symbol, _coretemp_native_events[index].name, sizeof(info->symbol));
733 strncpy( info->long_descr, _coretemp_native_events[index].description, sizeof(info->long_descr));
734 strncpy( info->units, _coretemp_native_events[index].units, sizeof(info->units));
735 info->units[sizeof(info->units)-1] = '\0';
736
737 return PAPI_OK;
738}
char units[PAPI_MIN_STR_LEN]
char description[PAPI_MAX_STR_LEN]
char name[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

◆ _coretemp_ntv_code_to_name()

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

Definition at line 698 of file linux-coretemp.c.

699{
700 int index = EventCode;
701
702 if ( index >= 0 && index < num_events ) {
703 strncpy( name, _coretemp_native_events[index].name, len );
704 return PAPI_OK;
705 }
706 return PAPI_ENOEVNT;
707}

◆ _coretemp_ntv_enum_events()

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

Definition at line 659 of file linux-coretemp.c.

660{
661
662 int index;
663
664 switch ( modifier ) {
665
666 case PAPI_ENUM_FIRST:
667
668 if (num_events==0) {
669 return PAPI_ENOEVNT;
670 }
671 *EventCode = 0;
672
673 return PAPI_OK;
674
675
676 case PAPI_ENUM_EVENTS:
677
678 index = *EventCode;
679
680 if ( index < num_events - 1 ) {
681 *EventCode = *EventCode + 1;
682 return PAPI_OK;
683 } else {
684 return PAPI_ENOEVNT;
685 }
686 break;
687
688 default:
689 return PAPI_EINVAL;
690 }
691 return PAPI_EINVAL;
692}
#define PAPI_ENUM_EVENTS
Definition: f90papi.h:224
#define PAPI_ENUM_FIRST
Definition: f90papi.h:85
#define PAPI_EINVAL
Definition: f90papi.h:115

◆ _coretemp_read()

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

Definition at line 527 of file linux-coretemp.c.

529{
530 (void) flags;
531 (void) ctx;
532
534 long long now = PAPI_get_real_usec();
535 int i;
536
537 /* Only read the values from the kernel if enough time has passed */
538 /* since the last read. Otherwise return cached values. */
539
540 if ( now - control->lastupdate > REFRESH_LAT ) {
541 for ( i = 0; i < num_events; i++ ) {
542 control->counts[i] = getEventValue( i );
543 }
544 control->lastupdate = now;
545 }
546
547 /* Pass back a pointer to our results */
548 *events = control->counts;
549
550 return PAPI_OK;
551}
char events[MAX_EVENTS][BUFSIZ]
#define REFRESH_LAT
long long counts[CORETEMP_MAX_COUNTERS]
Here is the call graph for this function:

◆ _coretemp_reset()

static int _coretemp_reset ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 646 of file linux-coretemp.c.

647{
648 ( void ) ctx;
649 ( void ) ctl;
650
651 return PAPI_OK;
652}

◆ _coretemp_set_domain()

static int _coretemp_set_domain ( hwd_control_state_t cntl,
int  domain 
)
static

Definition at line 635 of file linux-coretemp.c.

636{
637 (void) cntl;
638 if ( PAPI_DOM_ALL != domain )
639 return PAPI_EINVAL;
640
641 return PAPI_OK;
642}
#define PAPI_DOM_ALL
Definition: f90papi.h:261

◆ _coretemp_shutdown_component()

static int _coretemp_shutdown_component ( )
static

Definition at line 581 of file linux-coretemp.c.

582{
583 if ( is_initialized ) {
584 is_initialized = 0;
587 }
588 return PAPI_OK;
589}

◆ _coretemp_shutdown_thread()

static int _coretemp_shutdown_thread ( hwd_context_t ctx)
static

Definition at line 570 of file linux-coretemp.c.

571{
572 ( void ) ctx;
573 return PAPI_OK;
574}

◆ _coretemp_start()

static int _coretemp_start ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 518 of file linux-coretemp.c.

519{
520 ( void ) ctx;
521 ( void ) ctl;
522
523 return PAPI_OK;
524}

◆ _coretemp_stop()

static int _coretemp_stop ( hwd_context_t ctx,
hwd_control_state_t ctl 
)
static

Definition at line 554 of file linux-coretemp.c.

555{
556 (void) ctx;
557 /* read values */
559 int i;
560
561 for ( i = 0; i < num_events; i++ ) {
562 control->counts[i] = getEventValue( i );
563 }
564
565 return PAPI_OK;
566}
Here is the call graph for this function:

◆ _coretemp_update_control_state()

static int _coretemp_update_control_state ( hwd_control_state_t ptr,
NativeInfo_t native,
int  count,
hwd_context_t ctx 
)
static

Definition at line 608 of file linux-coretemp.c.

611{
612 int i, index;
613 ( void ) ctx;
614 ( void ) ptr;
615
616 for ( i = 0; i < count; i++ ) {
617 index = native[i].ni_event;
618 native[i].ni_position = _coretemp_native_events[index].resources.selector - 1;
619 }
620 return PAPI_OK;
621}
static long count
static int native

◆ generateEventList()

static int generateEventList ( char *  base_dir)
static

Definition at line 95 of file linux-coretemp.c.

96{
97 char path[PATH_MAX],filename[PATH_MAX];
98 char modulename[PAPI_MIN_STR_LEN],
101 description[PAPI_MAX_STR_LEN],
103 DIR *dir,*d;
104 FILE *fff;
105 int count = 0;
106 struct dirent *hwmonx;
107 int i,pathnum;
108 int retlen;
109
110#define NUM_PATHS 2
111 char paths[NUM_PATHS][PATH_MAX]={
112 "device","."
113 };
114
115 /* Open "/sys/class/hwmon" */
116 dir = opendir(base_dir);
117 if ( dir == NULL ) {
118 SUBDBG("Can't find %s, are you sure the coretemp module is loaded?\n",
119 base_dir);
120 return 0;
121 }
122
123 /* Iterate each /sys/class/hwmonX/device directory */
124 while( (hwmonx = readdir(dir) ) ) {
125 if ( !strncmp("hwmon", hwmonx->d_name, 5) ) {
126
127 /* Found a hwmon directory */
128
129 /* Sometimes the files are in ./, sometimes in device/ */
130 for(pathnum=0;pathnum<NUM_PATHS;pathnum++) {
131
132 retlen = snprintf(path, PATH_MAX, "%s/%s/%s",
133 base_dir, hwmonx->d_name,paths[pathnum]);
134 if (retlen <= 0 || PATH_MAX <= retlen) {
135 SUBDBG("Path length is too long.\n");
136 return PAPI_EINVAL;
137 }
138 SUBDBG("Trying to open %s\n",path);
139 d = opendir(path);
140 if (d==NULL) {
141 continue;
142 }
143
144 /* Get the name of the module */
145
146 retlen = snprintf(filename, PAPI_MAX_STR_LEN, "%s/name",path);
147 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
148 SUBDBG("Module name too long.\n");
149 return PAPI_EINVAL;
150 }
151 fff=fopen(filename,"r");
152 if (fff==NULL) {
153 snprintf(modulename, PAPI_MIN_STR_LEN, "Unknown");
154 } else {
155 if (fgets(modulename,PAPI_MIN_STR_LEN,fff)!=NULL) {
156 modulename[strlen(modulename)-1]='\0';
157 }
158 fclose(fff);
159 }
160
161 SUBDBG("Found module %s\n",modulename);
162
163 /******************************************************/
164 /* Try handling all events starting with in (voltage) */
165 /******************************************************/
166
167
168 /* arbitrary maximum */
169 /* the problem is the numbering can be sparse */
170 /* should probably go back to dirent listing */
171
172 for(i=0;i<32;i++) {
173
174 /* Try looking for a location label */
175 retlen = snprintf(filename, PAPI_MAX_STR_LEN, "%s/in%d_label",
176 path,i);
177 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
178 SUBDBG("Failed to construct location label.\n");
179 return PAPI_EINVAL;
180 }
181 fff=fopen(filename,"r");
182 if (fff==NULL) {
183 strncpy(location,"?",PAPI_MIN_STR_LEN);
184 }
185 else {
186 if (fgets(location,PAPI_MIN_STR_LEN,fff)!=NULL) {
187 location[strlen(location)-1]='\0';
188 }
189 fclose(fff);
190 }
191
192 /* Look for input temperature */
193 retlen = snprintf(filename, PAPI_MAX_STR_LEN, "%s/in%d_input",
194 path,i);
195 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
196 SUBDBG("Failed input temperature string.\n");
197 return PAPI_EINVAL;
198 }
199 fff=fopen(filename,"r");
200 if (fff==NULL) continue;
201 fclose(fff);
202
203 retlen = snprintf(name, PAPI_MAX_STR_LEN, "%s:in%i_input", hwmonx->d_name, i);
204 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
205 SUBDBG("Unable to generate name %s:in%i_input\n", hwmonx->d_name, i);
206 closedir(dir);
207 closedir(d);
208 return ( PAPI_EINVAL );
209 }
210
211 snprintf(units, PAPI_MIN_STR_LEN, "V");
212 retlen = snprintf(description, PAPI_MAX_STR_LEN, "%s, %s module, label %s",
213 units,modulename,
214 location);
215 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
216 SUBDBG("snprintf failed.\n");
217 return PAPI_EINVAL;
218 }
219
220 if (insert_in_list(name,units,description,filename)!=PAPI_OK) {
221 goto done_error;
222 }
223
224 count++;
225
226 }
227
228 /************************************************************/
229 /* Try handling all events starting with temp (temperature) */
230 /************************************************************/
231
232 for(i=0;i<32;i++) {
233
234 /* Try looking for a location label */
235 retlen = snprintf(filename, PAPI_MAX_STR_LEN, "%s/temp%d_label",
236 path,i);
237 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
238 SUBDBG("Location label string failed.\n");
239 return PAPI_EINVAL;
240 }
241 fff=fopen(filename,"r");
242 if (fff==NULL) {
243 strncpy(location,"?",PAPI_MIN_STR_LEN);
244 }
245 else {
246 if (fgets(location,PAPI_MIN_STR_LEN,fff)!=NULL) {
247 location[strlen(location)-1]='\0';
248 }
249 fclose(fff);
250 }
251
252 /* Look for input temperature */
253 retlen = snprintf(filename, PAPI_MAX_STR_LEN, "%s/temp%d_input",
254 path,i);
255 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
256 SUBDBG("Input temperature string failed.\n");
257 return PAPI_EINVAL;
258 }
259 fff=fopen(filename,"r");
260 if (fff==NULL) continue;
261 fclose(fff);
262
263 retlen = snprintf(name, PAPI_MAX_STR_LEN, "%s:temp%i_input", hwmonx->d_name, i);
264 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
265 SUBDBG("Unable to generate name %s:temp%i_input\n", hwmonx->d_name, i);
266 closedir(d);
267 closedir(dir);
268 return ( PAPI_EINVAL );
269 }
270
271 snprintf(units, PAPI_MIN_STR_LEN, "degrees C");
272 retlen = snprintf(description, PAPI_MAX_STR_LEN, "%s, %s module, label %s",
273 units,modulename,
274 location);
275 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
276 SUBDBG("snprintf failed.\n");
277 return PAPI_EINVAL;
278 }
279
280 if (insert_in_list(name,units,description,filename)!=PAPI_OK) {
281 goto done_error;
282 }
283
284 count++;
285 }
286
287 /************************************************************/
288 /* Try handling all events starting with fan (fan) */
289 /************************************************************/
290
291 for(i=0;i<32;i++) {
292
293 /* Try looking for a location label */
294 retlen = snprintf(filename, PAPI_MAX_STR_LEN, "%s/fan%d_label",
295 path,i);
296 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
297 SUBDBG("Failed to write fan label string.\n");
298 return PAPI_EINVAL;
299 }
300 fff=fopen(filename,"r");
301 if (fff==NULL) {
302 strncpy(location,"?",PAPI_MIN_STR_LEN);
303 }
304 else {
305 if (fgets(location,PAPI_MIN_STR_LEN,fff)!=NULL) {
306 location[strlen(location)-1]='\0';
307 }
308 fclose(fff);
309 }
310
311 /* Look for input fan */
312 retlen = snprintf(filename, PAPI_MAX_STR_LEN, "%s/fan%d_input", path,i);
313 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
314 SUBDBG("Unable to generate filename %s/fan%d_input\n", path,i);
315 closedir(d);
316 closedir(dir);
317 return ( PAPI_EINVAL );
318 }
319
320 fff=fopen(filename,"r");
321 if (fff==NULL) continue;
322 fclose(fff);
323
324 retlen = snprintf(name, PAPI_MAX_STR_LEN, "%s:fan%i_input", hwmonx->d_name, i);
325 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
326 SUBDBG("Unable to generate name %s:fan%i_input\n", hwmonx->d_name, i);
327 closedir(d);
328 closedir(dir);
329 return ( PAPI_EINVAL );
330 }
331
332 snprintf(units, PAPI_MIN_STR_LEN, "RPM");
333 retlen = snprintf(description, PAPI_MAX_STR_LEN, "%s, %s module, label %s",
334 units,modulename,
335 location);
336 if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
337 SUBDBG("snprintf failed.\n");
338 return PAPI_EINVAL;
339 }
340
341 if (insert_in_list(name,units,description,filename)!=PAPI_OK) {
342 goto done_error;
343 }
344
345 count++;
346
347 }
348 closedir(d);
349 }
350 }
351 }
352
353 closedir(dir);
354 return count;
355
356done_error:
357 closedir(d);
358 closedir(dir);
359 return PAPI_ECMP;
360}
FILE * fff[MAX_EVENTS]
static int insert_in_list(char *name, char *units, char *description, char *filename)
#define NUM_PATHS
uint16_t location
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
int fclose(FILE *__stream)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEventValue()

static long long getEventValue ( int  index)
static

Definition at line 363 of file linux-coretemp.c.

364{
365 char buf[PAPI_MAX_STR_LEN];
366 FILE* fp;
367 long result;
368
369 if (_coretemp_native_events[index].stone) {
370 return _coretemp_native_events[index].value;
371 }
372
373 fp = fopen(_coretemp_native_events[index].path, "r");
374 if (fp==NULL) {
375 return INVALID_RESULT;
376 }
377
378 if (fgets(buf, PAPI_MAX_STR_LEN, fp)==NULL) {
380 }
381 else {
382 result=strtoll(buf, NULL, 10);
383 }
384 fclose(fp);
385
386 return result;
387}
volatile int result
volatile int buf[CACHE_FLUSH_BUFFER_SIZE_INTS]
Definition: do_loops.c:12
#define INVALID_RESULT
static FILE * fp
long value
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_in_list()

static int insert_in_list ( char *  name,
char *  units,
char *  description,
char *  filename 
)
static

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

49 {
50
51
52 struct temp_event *temp;
53
54
55 /* new_event path, events->d_name */
56 temp = (struct temp_event *) papi_calloc(1, sizeof(struct temp_event));
57 if (temp==NULL) {
58 PAPIERROR("out of memory!");
59 /* We should also free any previously allocated data */
60 return PAPI_ENOMEM;
61 }
62
63 temp->next = NULL;
64
65 if (root == NULL) {
66 root = temp;
67 }
68 else if (last) {
69 last->next = temp;
70 }
71 else {
72 /* Because this is a function, it is possible */
73 /* we are called with root!=NULL but no last */
74 /* so add this to keep coverity happy */
75 free(temp);
76 PAPIERROR("This shouldn't be possible\n");
77
78 return PAPI_ECMP;
79 }
80
81 last = temp;
82
83 snprintf(temp->name, PAPI_MAX_STR_LEN, "%s", name);
84 snprintf(temp->units, PAPI_MIN_STR_LEN, "%s", units);
85 snprintf(temp->description, PAPI_MAX_STR_LEN, "%s", description);
86 snprintf(temp->path, PATH_MAX, "%s", filename);
87
88 return PAPI_OK;
89}
void PAPIERROR(char *format,...)
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _coretemp_native_events

CORETEMP_native_event_entry_t* _coretemp_native_events
static

Definition at line 36 of file linux-coretemp.c.

◆ _coretemp_vector

papi_vector_t _coretemp_vector

Definition at line 17 of file linux-coretemp.c.

◆ is_initialized

int is_initialized = 0
static

Definition at line 38 of file linux-coretemp.c.

◆ last

struct temp_event* last = NULL
static

Definition at line 45 of file linux-coretemp.c.

◆ num_events

int num_events = 0
static

Definition at line 37 of file linux-coretemp.c.

◆ root

struct temp_event* root = NULL
static

Definition at line 44 of file linux-coretemp.c.