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

Go to the source code of this file.

Macros

#define _PATH_SYS_SYSTEM   "/sys/devices/system"
 
#define _PATH_SYS_CPU0   _PATH_SYS_SYSTEM "/cpu/cpu0"
 

Functions

static int _linux_init_locks (void)
 
int _linux_detect_hypervisor (char *virtual_vendor_name)
 
static char * search_cpu_info (FILE *f, char *search_str)
 
static void decode_vendor_string (char *s, int *vendor)
 
static FILE * xfopen (const char *path, const char *mode)
 
static FILE * path_vfopen (const char *mode, const char *path, va_list ap)
 
static int path_sibling (const char *path,...)
 
static int path_exist (const char *path,...)
 
static int decode_cpuinfo_x86 (FILE *f, PAPI_hw_info_t *hwinfo)
 
static int decode_cpuinfo_power (FILE *f, PAPI_hw_info_t *hwinfo)
 
static int decode_cpuinfo_arm (FILE *f, PAPI_hw_info_t *hwinfo)
 
int _linux_get_cpu_info (PAPI_hw_info_t *hwinfo, int *cpuinfo_mhz)
 
int _linux_get_mhz (int *sys_min_mhz, int *sys_max_mhz)
 
int _linux_get_system_info (papi_mdi_t *mdi)
 
int _papi_hwi_init_os (void)
 
int _linux_detect_nmi_watchdog ()
 

Variables

PAPI_os_info_t _papi_os_info
 
volatile unsigned int _papi_hwd_lock_data [PAPI_MAX_LOCK]
 
static char pathbuf [PATH_MAX] = "/"
 
papi_os_vector_t _papi_os_vector
 

Macro Definition Documentation

◆ _PATH_SYS_CPU0

#define _PATH_SYS_CPU0   _PATH_SYS_SYSTEM "/cpu/cpu0"

Definition at line 74 of file linux-common.c.

◆ _PATH_SYS_SYSTEM

#define _PATH_SYS_SYSTEM   "/sys/devices/system"

Definition at line 73 of file linux-common.c.

Function Documentation

◆ _linux_detect_hypervisor()

int _linux_detect_hypervisor ( char *  virtual_vendor_name)

Definition at line 59 of file linux-common.c.

59 {
60
61 int retval=0;
62
63#if defined(__i386__)||defined(__x86_64__)
64 retval=_x86_detect_hypervisor(virtual_vendor_name);
65#else
66 (void) virtual_vendor_name;
67#endif
68
69 return retval;
70}
int _x86_detect_hypervisor(char *vendor_name)
int retval
Definition: zero_fork.c:53
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _linux_detect_nmi_watchdog()

int _linux_detect_nmi_watchdog ( )

Definition at line 768 of file linux-common.c.

768 {
769
770 int watchdog_detected=0,watchdog_value=0;
771 FILE *fff;
772
773 fff=fopen("/proc/sys/kernel/nmi_watchdog","r");
774 if (fff!=NULL) {
775 if (fscanf(fff,"%d",&watchdog_value)==1) {
776 if (watchdog_value>0) watchdog_detected=1;
777 }
778 fclose(fff);
779 }
780
781 return watchdog_detected;
782}
FILE * fff[MAX_EVENTS]
int fclose(FILE *__stream)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _linux_get_cpu_info()

int _linux_get_cpu_info ( PAPI_hw_info_t hwinfo,
int cpuinfo_mhz 
)

Definition at line 360 of file linux-common.c.

361{
362 int retval = PAPI_OK;
363 char *s;
364 float mhz = 0.0;
365 FILE *f;
366 char cpuinfo_filename[]="/proc/cpuinfo";
367
368 if ( ( f = fopen( cpuinfo_filename, "r" ) ) == NULL ) {
369 PAPIERROR( "fopen(/proc/cpuinfo) errno %d", errno );
370 return PAPI_ESYS;
371 }
372
373 /* All of this information may be overwritten by the component */
374
375 /***********************/
376 /* Attempt to find MHz */
377 /***********************/
378 s = search_cpu_info( f, "cpu MHz" );
379 if ( !s ) {
380 s = search_cpu_info( f, "clock" );
381 }
382 if ( s ) {
383 sscanf( s, "%f", &mhz );
384 *cpuinfo_mhz = mhz;
385 }
386 else {
387 *cpuinfo_mhz = -1; // Could not find it.
388 // PAPIWARN("Failed to find a clock speed in /proc/cpuinfo");
389 }
390
391 /*******************************/
392 /* Vendor Name and Vendor Code */
393 /*******************************/
394
395 /* First try to read "vendor_id" field */
396 /* Which is the most common field */
397 s = search_cpu_info( f, "vendor_id");
398 if ( s ) {
399 strncpy( hwinfo->vendor_string, s, PAPI_MAX_STR_LEN );
400 hwinfo->vendor_string[PAPI_MAX_STR_LEN-1]=0;
401 }
402 else {
403 /* If not found, try "vendor" which seems to be Itanium specific */
404 s = search_cpu_info( f, "vendor" );
405 if ( s ) {
406 strncpy( hwinfo->vendor_string, s, PAPI_MAX_STR_LEN );
407 hwinfo->vendor_string[PAPI_MAX_STR_LEN-1]=0;
408 }
409 else {
410 /* "system type" seems to be MIPS and Alpha */
411 s = search_cpu_info( f, "system type");
412 if ( s ) {
413 strncpy( hwinfo->vendor_string, s, PAPI_MAX_STR_LEN );
414 hwinfo->vendor_string[PAPI_MAX_STR_LEN-1]=0;
415 }
416 else {
417 /* "platform" indicates Power */
418 s = search_cpu_info( f, "platform");
419 if ( s ) {
420 if ( ( strcasecmp( s, "pSeries" ) == 0 ) ||
421 ( strcasecmp( s, "PowerNV" ) == 0 ) ||
422 ( strcasecmp( s, "PowerMac" ) == 0 ) ) {
423 strcpy( hwinfo->vendor_string, "IBM" );
424 }
425 }
426 else {
427 /* "CPU implementer" indicates ARM */
428 /* For ARM processors, hwinfo->vendor >= PAPI_VENDOR_ARM_ARM(0x41). */
429 /* If implementer is ARM Limited., hwinfo->vendor == PAPI_VENDOR_ARM_ARM. */
430 /* If implementer is Cavium Inc., hwinfo->vendor == PAPI_VENDOR_ARM_CAVIUM(0x43). */
431 s = search_cpu_info( f, "CPU implementer");
432 if ( s ) {
433 int tmp;
434 sscanf( s, "%x", &tmp );
435 switch( tmp ) {
437 strcpy( hwinfo->vendor_string, "ARM_ARM" );
438 break;
440 strcpy( hwinfo->vendor_string, "ARM_BROADCOM" );
441 break;
443 strcpy( hwinfo->vendor_string, "ARM_CAVIUM" );
444 break;
446 strcpy( hwinfo->vendor_string, "ARM_FUJITSU" );
447 break;
449 strcpy( hwinfo->vendor_string, "ARM_HISILICON" );
450 break;
452 strcpy( hwinfo->vendor_string, "ARM_APM" );
453 break;
455 strcpy( hwinfo->vendor_string, "ARM_QUALCOMM" );
456 break;
457 default:
458 strcpy( hwinfo->vendor_string, "ARM_UNKNOWN" );
459 }
460 }
461 }
462 }
463 }
464 }
465
466 /* Decode the string to a PAPI specific implementer value */
467 if ( strlen( hwinfo->vendor_string ) ) {
468 decode_vendor_string( hwinfo->vendor_string, &hwinfo->vendor );
469 }
470
471 /**********************************************/
472 /* Provide more stepping/model/family numbers */
473 /**********************************************/
474
475 if ((hwinfo->vendor==PAPI_VENDOR_INTEL) ||
476 (hwinfo->vendor==PAPI_VENDOR_AMD)) {
477
478 decode_cpuinfo_x86(f,hwinfo);
479 }
480
481 if (hwinfo->vendor==PAPI_VENDOR_IBM) {
482
483 decode_cpuinfo_power(f,hwinfo);
484 }
485
486 if (hwinfo->vendor>=PAPI_VENDOR_ARM_ARM) {
487
488 decode_cpuinfo_arm(f,hwinfo);
489 }
490
491
492
493
494 /* The following members are set using the same methodology */
495 /* used in lscpu. */
496
497 /* Total number of CPUs */
498 /* The following line assumes totalcpus was initialized to zero! */
499 while ( path_exist( _PATH_SYS_SYSTEM "/cpu/cpu%d", hwinfo->totalcpus ) )
500 hwinfo->totalcpus++;
501
502 /* Number of threads per core */
503 if ( path_exist( _PATH_SYS_CPU0 "/topology/thread_siblings" ) )
504 hwinfo->threads =
505 path_sibling( _PATH_SYS_CPU0 "/topology/thread_siblings" );
506
507 /* Number of cores per socket */
508 if ( path_exist( _PATH_SYS_CPU0 "/topology/core_siblings" ) &&
509 hwinfo->threads > 0 )
510 hwinfo->cores =
511 path_sibling( _PATH_SYS_CPU0 "/topology/core_siblings" ) /
512 hwinfo->threads;
513
514 /* Number of NUMA nodes */
515 /* The following line assumes nnodes was initialized to zero! */
516 while ( path_exist( _PATH_SYS_SYSTEM "/node/node%d", hwinfo->nnodes ) ) {
517 hwinfo->nnodes++;
518 }
519
520 /* Number of CPUs per node */
521 hwinfo->ncpu = hwinfo->nnodes > 1 ?
522 hwinfo->totalcpus / hwinfo->nnodes : hwinfo->totalcpus;
523
524 /* Number of sockets */
525 if ( hwinfo->threads > 0 && hwinfo->cores > 0 ) {
526 hwinfo->sockets = hwinfo->totalcpus / hwinfo->cores / hwinfo->threads;
527 }
528
529#if 0
530 int *nodecpu;
531 /* cpumap data is not currently part of the _papi_hw_info struct */
532 nodecpu = malloc( (unsigned int) hwinfo->nnodes * sizeof(int) );
533 if ( nodecpu ) {
534 int i;
535 for ( i = 0; i < hwinfo->nnodes; ++i ) {
536 nodecpu[i] = path_sibling(
537 _PATH_SYS_SYSTEM "/node/node%d/cpumap", i );
538 }
539 } else {
540 PAPIERROR( "malloc failed for variable not currently used" );
541 }
542#endif
543
544
545 /* Fixup missing Megahertz Value */
546 /* This is missing from cpuinfo on ARM and MIPS */
547 if (*cpuinfo_mhz < 1.0) {
548 s = search_cpu_info( f, "BogoMIPS" );
549 if ((!s) || (sscanf( s, "%f", &mhz ) != 1)) {
550 INTDBG("MHz detection failed. "
551 "Please edit file %s at line %d.\n",
552 __FILE__,__LINE__);
553 }
554
555 if (hwinfo->vendor == PAPI_VENDOR_MIPS) {
556 /* MIPS has 2x clock multiplier */
557 *cpuinfo_mhz = 2*(((int)mhz)+1);
558
559 /* Also update version info on MIPS */
560 s = search_cpu_info( f, "cpu model");
561 s = strstr(s," V")+2;
562 strtok(s," ");
563 sscanf(s, "%f ", &hwinfo->revision );
564 }
565 else {
566 /* In general bogomips is proportional to number of CPUs */
567 if (hwinfo->totalcpus) {
568 if (mhz!=0) *cpuinfo_mhz = mhz / hwinfo->totalcpus;
569 }
570 }
571 }
572
573 fclose( f );
574
575 return retval;
576}
double tmp
int i
int errno
double s
Definition: byte_profile.c:36
double f(double a)
Definition: cpi.c:23
#define PAPI_OK
Definition: f90papi.h:73
#define PAPI_VENDOR_ARM_CAVIUM
Definition: f90papi.h:91
#define PAPI_VENDOR_ARM_BROADCOM
Definition: f90papi.h:57
#define PAPI_VENDOR_IBM
Definition: f90papi.h:61
#define PAPI_VENDOR_ARM_HISILICON
Definition: f90papi.h:220
#define PAPI_VENDOR_ARM_QUALCOMM
Definition: f90papi.h:229
#define PAPI_VENDOR_ARM_ARM
Definition: f90papi.h:102
#define PAPI_VENDOR_ARM_FUJITSU
Definition: f90papi.h:245
#define PAPI_VENDOR_INTEL
Definition: f90papi.h:275
#define PAPI_VENDOR_AMD
Definition: f90papi.h:230
#define PAPI_MAX_STR_LEN
Definition: f90papi.h:77
#define PAPI_ESYS
Definition: f90papi.h:136
#define PAPI_VENDOR_ARM_APM
Definition: f90papi.h:38
#define PAPI_VENDOR_MIPS
Definition: f90papi.h:74
static char * search_cpu_info(FILE *f, char *search_str)
Definition: linux-common.c:79
static void decode_vendor_string(char *s, int *vendor)
Definition: linux-common.c:108
static int decode_cpuinfo_arm(FILE *f, PAPI_hw_info_t *hwinfo)
Definition: linux-common.c:267
#define _PATH_SYS_CPU0
Definition: linux-common.c:74
static int decode_cpuinfo_power(FILE *f, PAPI_hw_info_t *hwinfo)
Definition: linux-common.c:239
static int decode_cpuinfo_x86(FILE *f, PAPI_hw_info_t *hwinfo)
Definition: linux-common.c:197
#define _PATH_SYS_SYSTEM
Definition: linux-common.c:73
static int path_exist(const char *path,...)
Definition: linux-common.c:187
static int path_sibling(const char *path,...)
Definition: linux-common.c:159
#define INTDBG(format, args...)
Definition: papi_debug.h:66
void PAPIERROR(char *format,...)
int
Definition: sde_internal.h:89
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:782
int nnodes
Definition: papi.h:779
int totalcpus
Definition: papi.h:780
int sockets
Definition: papi.h:778
int vendor
Definition: papi.h:781
float revision
Definition: papi.h:785
int ncpu
Definition: papi.h:775
int cores
Definition: papi.h:777
int threads
Definition: papi.h:776
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _linux_get_mhz()

int _linux_get_mhz ( int sys_min_mhz,
int sys_max_mhz 
)

Definition at line 579 of file linux-common.c.

579 {
580
581 FILE *fff;
582 int result;
583
584 /* Try checking for min MHz */
585 /* Assume cpu0 exists */
586 fff=fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq","r");
587 if (fff==NULL) return PAPI_EINVAL;
588 result=fscanf(fff,"%d",sys_min_mhz);
589 fclose(fff);
590 if (result!=1) return PAPI_EINVAL;
591
592 fff=fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq","r");
593 if (fff==NULL) return PAPI_EINVAL;
594 result=fscanf(fff,"%d",sys_max_mhz);
595 fclose(fff);
596 if (result!=1) return PAPI_EINVAL;
597
598 return PAPI_OK;
599
600}
volatile int result
#define PAPI_EINVAL
Definition: f90papi.h:115
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _linux_get_system_info()

int _linux_get_system_info ( papi_mdi_t mdi)

Definition at line 603 of file linux-common.c.

603 {
604
605 int retval;
606 char maxargs[PAPI_HUGE_STR_LEN];
607 pid_t pid;
608 int cpuinfo_mhz,sys_min_khz,sys_max_khz;
609
610 /* Software info */
611
612 /* Path and args */
613
614 pid = getpid( );
615 if ( pid < 0 ) {
616 PAPIERROR( "getpid() returned < 0" );
617 return PAPI_ESYS;
618 }
619 mdi->pid = pid;
620
621 sprintf( maxargs, "/proc/%d/exe", ( int ) pid );
622 retval = readlink( maxargs, mdi->exe_info.fullname,
624 if ( retval < 0 ) {
625 PAPIERROR( "readlink(%s) returned < 0", maxargs );
626 return PAPI_ESYS;
627 }
628
629 if (retval > PAPI_HUGE_STR_LEN-1) {
631 }
632 mdi->exe_info.fullname[retval] = '\0';
633
634 /* Careful, basename can modify its argument */
635 strcpy( maxargs, mdi->exe_info.fullname );
636
637 strncpy( mdi->exe_info.address_info.name, basename( maxargs ),
640
641 SUBDBG( "Executable is %s\n", mdi->exe_info.address_info.name );
642 SUBDBG( "Full Executable is %s\n", mdi->exe_info.fullname );
643
644 /* Executable regions, may require reading /proc/pid/maps file */
645
647 SUBDBG( "Text: Start %p, End %p, length %d\n",
650 ( int ) ( mdi->exe_info.address_info.text_end -
652 SUBDBG( "Data: Start %p, End %p, length %d\n",
655 ( int ) ( mdi->exe_info.address_info.data_end -
657 SUBDBG( "Bss: Start %p, End %p, length %d\n",
660 ( int ) ( mdi->exe_info.address_info.bss_end -
662
663 /* PAPI_preload_option information */
664
665 strcpy( mdi->preload_info.lib_preload_env, "LD_PRELOAD" );
666 mdi->preload_info.lib_preload_sep = ' ';
667 strcpy( mdi->preload_info.lib_dir_env, "LD_LIBRARY_PATH" );
668 mdi->preload_info.lib_dir_sep = ':';
669
670 /* Hardware info */
671
672 retval = _linux_get_cpu_info( &mdi->hw_info, &cpuinfo_mhz );
673 if ( retval )
674 return retval;
675
676 /* Handle MHz */
677
678 retval = _linux_get_mhz( &sys_min_khz, &sys_max_khz );
679 if ( retval ) {
680
681 mdi->hw_info.cpu_max_mhz=cpuinfo_mhz;
682 mdi->hw_info.cpu_min_mhz=cpuinfo_mhz;
683
684 /*
685 mdi->hw_info.mhz=cpuinfo_mhz;
686 mdi->hw_info.clock_mhz=cpuinfo_mhz;
687 */
688 }
689 else {
690 mdi->hw_info.cpu_max_mhz=sys_max_khz/1000;
691 mdi->hw_info.cpu_min_mhz=sys_min_khz/1000;
692
693 /*
694 mdi->hw_info.mhz=sys_max_khz/1000;
695 mdi->hw_info.clock_mhz=sys_max_khz/1000;
696 */
697 }
698
699 /* Set Up Memory */
700
702 if ( retval )
703 return retval;
704
705 SUBDBG( "Found %d %s(%d) %s(%d) CPUs at %d Mhz.\n",
706 mdi->hw_info.totalcpus,
708 mdi->hw_info.vendor,
710 mdi->hw_info.model,
711 mdi->hw_info.cpu_max_mhz);
712
713 /* Get virtualization info */
715
716 return PAPI_OK;
717}
#define PAPI_HUGE_STR_LEN
Definition: f90papi.h:120
int _linux_get_mhz(int *sys_min_mhz, int *sys_max_mhz)
Definition: linux-common.c:579
int _linux_get_cpu_info(PAPI_hw_info_t *hwinfo, int *cpuinfo_mhz)
Definition: linux-common.c:360
int _linux_detect_hypervisor(char *virtual_vendor_name)
Definition: linux-common.c:59
int _linux_get_memory_info(PAPI_hw_info_t *hwinfo, int cpu_type)
int _linux_update_shlib_info(papi_mdi_t *mdi)
#define SUBDBG(format, args...)
Definition: papi_debug.h:64
static int pid
vptr_t text_start
Definition: papi.h:686
char name[PAPI_HUGE_STR_LEN]
Definition: papi.h:685
vptr_t text_end
Definition: papi.h:687
vptr_t bss_start
Definition: papi.h:690
vptr_t data_end
Definition: papi.h:689
vptr_t data_start
Definition: papi.h:688
vptr_t bss_end
Definition: papi.h:691
char fullname[PAPI_HUGE_STR_LEN]
Definition: papi.h:697
PAPI_address_map_t address_info
Definition: papi.h:698
int model
Definition: papi.h:783
char virtual_vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:795
int cpu_min_mhz
Definition: papi.h:791
int virtualized
Definition: papi.h:794
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:784
int cpu_max_mhz
Definition: papi.h:790
char lib_dir_sep
Definition: papi.h:622
char lib_preload_sep
Definition: papi.h:620
char lib_dir_env[PAPI_MAX_STR_LEN]
Definition: papi.h:621
char lib_preload_env[PAPI_MAX_STR_LEN]
Definition: papi.h:619
PAPI_exe_info_t exe_info
PAPI_hw_info_t hw_info
PAPI_preload_info_t preload_info
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _linux_init_locks()

static int _linux_init_locks ( void  )
static

Definition at line 40 of file linux-common.c.

40 {
41
42 int i;
43
44 for ( i = 0; i < PAPI_MAX_LOCK; i++ ) {
45#if defined(USE_PTHREAD_MUTEXES)
46 pthread_mutex_init(&_papi_hwd_lock_data[i],NULL);
47#elif defined(USE_LIBAO_ATOMICS)
49#else
51#endif
52 }
53
54 return PAPI_OK;
55}
#define AO_TS_INITIALIZER
Definition: atomic_ops.h:161
volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK]
Definition: linux-common.c:36
#define PAPI_MAX_LOCK
Definition: papi_lock.h:18
#define MUTEX_OPEN
Definition: perfctr-ppc64.h:75
Here is the caller graph for this function:

◆ _papi_hwi_init_os()

int _papi_hwi_init_os ( void  )

Definition at line 720 of file linux-common.c.

720 {
721
722 int major=0,minor=0,sub=0;
723 char *ptr;
724 struct utsname uname_buffer;
725
726 /* Initialize the locks */
728
729 /* Get the kernel info */
730 uname(&uname_buffer);
731
732 SUBDBG("Native kernel version %s\n",uname_buffer.release);
733
734 strncpy(_papi_os_info.name,uname_buffer.sysname,PAPI_MAX_STR_LEN);
735
736#ifdef ASSUME_KERNEL
737 strncpy(_papi_os_info.version,ASSUME_KERNEL,PAPI_MAX_STR_LEN);
738 SUBDBG("Assuming kernel version %s\n",_papi_os_info.name);
739#else
740 strncpy(_papi_os_info.version,uname_buffer.release,PAPI_MAX_STR_LEN);
741#endif
742
743 ptr=strtok(_papi_os_info.version,".");
744 if (ptr!=NULL) major=atoi(ptr);
745
746 ptr=strtok(NULL,".");
747 if (ptr!=NULL) minor=atoi(ptr);
748
749 ptr=strtok(NULL,".");
750 if (ptr!=NULL) sub=atoi(ptr);
751
752 _papi_os_info.os_version=LINUX_VERSION(major,minor,sub);
753
758 _papi_os_info.clock_ticks = sysconf( _SC_CLK_TCK );
759
760 /* Get Linux-specific system info */
762
763 return PAPI_OK;
764}
static int _linux_init_locks(void)
Definition: linux-common.c:40
PAPI_os_info_t _papi_os_info
Definition: linux-common.c:27
int _linux_get_system_info(papi_mdi_t *mdi)
Definition: linux-common.c:603
#define LINUX_VERSION(a, b, c)
Definition: linux-common.h:4
#define PAPI_INT_MPX_SIGNAL
Definition: papi_internal.h:51
#define PAPI_INT_MPX_DEF_US
Definition: papi_internal.h:64
#define PAPI_INT_ITIMER
Definition: papi_internal.h:53
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
char version[PAPI_MAX_STR_LEN]
char name[PAPI_MAX_STR_LEN]
Here is the call graph for this function:

◆ decode_cpuinfo_arm()

static int decode_cpuinfo_arm ( FILE *  f,
PAPI_hw_info_t hwinfo 
)
static

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

268{
269
270 int tmp;
271 unsigned int strSize;
272 char *s, *t;
273
274 /* revision */
275 s = search_cpu_info( f, "CPU revision");
276 if ( s ) {
277 sscanf( s, "%d", &tmp );
278 hwinfo->revision = ( float ) tmp;
279 /* For compatability with old PAPI */
280 hwinfo->model = tmp;
281 }
282
283 /* Model Name */
284 s = search_cpu_info( f, "model name");
285 strSize = sizeof(hwinfo->model_string);
286 if ( s ) {
287 strncpy( hwinfo->model_string, s, strSize - 1);
288 }
289
290 /* Architecture (ARMv6, ARMv7, ARMv8, etc.) */
291
292 /* Parsing this is a bit fragile. */
293 /* On ARM64 the "CPU architecture field" */
294 /* Prior to Linux 3.19: always "AArch64" */
295 /* Since Linux 3.19: always "8" */
296 /* On ARM32 the "CPU architecture field" is a value and not */
297 /* necessarily an integer, so it might be 7 or 7M */
298 /* also, unknown architectures are assigned a value */
299 /* such as (10) where 10 does not mean version 10, just */
300 /* the 10th element in an array */
301 /* Note the original Raspberry Pi lies in the CPU architecture line */
302 /* (it's ARMv6 not ARMv7) */
303 /* So we should actually get the value from the */
304 /* Processor/ model name line */
305
306
307 s = search_cpu_info( f, "CPU architecture");
308 if ( s ) {
309
310 /* Handle old (prior to Linux 3.19) ARM64 */
311 if (strstr(s,"AArch64")) {
312 hwinfo->cpuid_family = 8;
313 }
314 else {
315 hwinfo->cpuid_family=strtol(s, NULL, 10);
316 }
317
318 /* Old Fallbacks if the above didn't work */
319 if (hwinfo->cpuid_family<0) {
320
321 /* Try the processor field and look inside of parens */
322 s = search_cpu_info( f, "Processor" );
323 if (s) {
324 t=strchr(s,'(');
325 tmp=*(t+2)-'0';
326 hwinfo->cpuid_family = tmp;
327 }
328 /* Try the model name and look inside of parens */
329 else {
330 s = search_cpu_info( f, "model name" );
331 if (s) {
332 t=strchr(s,'(');
333 tmp=*(t+2)-'0';
334 hwinfo->cpuid_family = tmp;
335 }
336 }
337 }
338 }
339
340 /* CPU Model */
341 s = search_cpu_info( f, "CPU part" );
342 if ( s ) {
343 sscanf( s, "%x", &tmp );
344 hwinfo->cpuid_model = tmp;
345 }
346
347 /* CPU Variant */
348 s = search_cpu_info( f, "CPU variant" );
349 if ( s ) {
350 sscanf( s, "%x", &tmp );
351 hwinfo->cpuid_stepping = tmp;
352 }
353
354 return PAPI_OK;
355
356}
int cpuid_family
Definition: papi.h:786
int cpuid_model
Definition: papi.h:787
int cpuid_stepping
Definition: papi.h:788
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_cpuinfo_power()

static int decode_cpuinfo_power ( FILE *  f,
PAPI_hw_info_t hwinfo 
)
static

Definition at line 239 of file linux-common.c.

240{
241
242 int tmp;
243 unsigned int strSize;
244 char *s;
245
246 /* Revision */
247 s = search_cpu_info( f, "revision");
248 if ( s ) {
249 sscanf( s, "%d", &tmp );
250 hwinfo->revision = ( float ) tmp;
251 hwinfo->cpuid_stepping = tmp;
252 }
253
254 /* Model Name */
255 s = search_cpu_info( f, "model");
256 strSize = sizeof(hwinfo->model_string);
257 if ( s ) {
258 strncpy( hwinfo->model_string, s, strSize - 1);
259 }
260
261 return PAPI_OK;
262}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_cpuinfo_x86()

static int decode_cpuinfo_x86 ( FILE *  f,
PAPI_hw_info_t hwinfo 
)
static

Definition at line 197 of file linux-common.c.

198{
199 int tmp;
200 unsigned int strSize;
201 char *s;
202
203 /* Stepping */
204 s = search_cpu_info( f, "stepping");
205 if ( s ) {
206 if (sscanf( s, "%d", &tmp ) ==1 ) {
207 hwinfo->revision = ( float ) tmp;
208 hwinfo->cpuid_stepping = tmp;
209 }
210 }
211
212 /* Model Name */
213 s = search_cpu_info( f, "model name");
214 strSize = sizeof(hwinfo->model_string);
215 if ( s ) {
216 strncpy( hwinfo->model_string, s, strSize - 1);
217 }
218
219 /* Family */
220 s = search_cpu_info( f, "cpu family");
221 if ( s ) {
222 sscanf( s, "%d", &tmp );
223 hwinfo->cpuid_family = tmp;
224 }
225
226
227 /* CPU Model */
228 s = search_cpu_info( f, "model");
229 if ( s ) {
230 sscanf( s , "%d", &tmp );
231 hwinfo->model = tmp;
232 hwinfo->cpuid_model = tmp;
233 }
234
235 return PAPI_OK;
236}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_vendor_string()

static void decode_vendor_string ( char *  s,
int vendor 
)
static

Definition at line 108 of file linux-common.c.

109{
110 if ( strcasecmp( s, "GenuineIntel" ) == 0 )
111 *vendor = PAPI_VENDOR_INTEL;
112 else if ( ( strcasecmp( s, "AMD" ) == 0 ) ||
113 ( strcasecmp( s, "AuthenticAMD" ) == 0 ) )
114 *vendor = PAPI_VENDOR_AMD;
115 else if ( strcasecmp( s, "IBM" ) == 0 )
116 *vendor = PAPI_VENDOR_IBM;
117 else if ( strcasecmp( s, "Cray" ) == 0 )
118 *vendor = PAPI_VENDOR_CRAY;
119 else if ( strcasecmp( s, "ARM_ARM" ) == 0 )
120 *vendor = PAPI_VENDOR_ARM_ARM;
121 else if ( strcasecmp( s, "ARM_BROADCOM" ) == 0 )
122 *vendor = PAPI_VENDOR_ARM_BROADCOM;
123 else if ( strcasecmp( s, "ARM_CAVIUM" ) == 0 )
124 *vendor = PAPI_VENDOR_ARM_CAVIUM;
125 else if ( strcasecmp( s, "ARM_FUJITSU" ) == 0 )
126 *vendor = PAPI_VENDOR_ARM_FUJITSU;
127 else if ( strcasecmp( s, "ARM_HISILICON") == 0 )
129 else if ( strcasecmp( s, "ARM_APM" ) == 0 )
130 *vendor = PAPI_VENDOR_ARM_APM;
131 else if ( strcasecmp( s, "ARM_QUALCOMM" ) == 0 )
132 *vendor = PAPI_VENDOR_ARM_QUALCOMM;
133 else if ( strcasecmp( s, "MIPS" ) == 0 )
134 *vendor = PAPI_VENDOR_MIPS;
135 else if ( strcasecmp( s, "SiCortex" ) == 0 )
136 *vendor = PAPI_VENDOR_MIPS;
137 else
138 *vendor = PAPI_VENDOR_UNKNOWN;
139}
#define PAPI_VENDOR_UNKNOWN
Definition: f90papi.h:104
#define PAPI_VENDOR_CRAY
Definition: f90papi.h:211
Here is the caller graph for this function:

◆ path_exist()

static int path_exist ( const char *  path,
  ... 
)
static

Definition at line 187 of file linux-common.c.

188{
189 va_list ap;
190 va_start( ap, path );
191 vsnprintf( pathbuf, sizeof ( pathbuf ), path, ap );
192 va_end( ap );
193 return access( pathbuf, F_OK ) == 0;
194}
static char pathbuf[PATH_MAX]
Definition: linux-common.c:76
__gnuc_va_list va_list
va_end(arg_list)
va_start(arg_list, fmt)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_sibling()

static int path_sibling ( const char *  path,
  ... 
)
static

Definition at line 159 of file linux-common.c.

160{
161 int c;
162 long n;
163 int result = 0;
164 char s[2];
165 FILE *fp;
166 va_list ap;
167 va_start( ap, path );
168 fp = path_vfopen( "r", path, ap );
169 va_end( ap );
170
171 while ( ( c = fgetc( fp ) ) != EOF ) {
172 if ( isxdigit( c ) ) {
173 s[0] = ( char ) c;
174 s[1] = '\0';
175 for ( n = strtol( s, NULL, 16 ); n > 0; n /= 2 ) {
176 if ( n % 2 )
177 result++;
178 }
179 }
180 }
181
182 fclose( fp );
183 return result;
184}
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
static FILE * path_vfopen(const char *mode, const char *path, va_list ap)
Definition: linux-common.c:151
static FILE * fp
Here is the call graph for this function:
Here is the caller graph for this function:

◆ path_vfopen()

static FILE * path_vfopen ( const char *  mode,
const char *  path,
va_list  ap 
)
static

Definition at line 151 of file linux-common.c.

152{
153 vsnprintf( pathbuf, sizeof ( pathbuf ), path, ap );
154 return xfopen( pathbuf, mode );
155}
static FILE * xfopen(const char *path, const char *mode)
Definition: linux-common.c:142
Here is the call graph for this function:
Here is the caller graph for this function:

◆ search_cpu_info()

static char * search_cpu_info ( FILE *  f,
char *  search_str 
)
static

Definition at line 79 of file linux-common.c.

80{
81 static char line[PAPI_HUGE_STR_LEN] = "";
82 char *s, *start = NULL;
83
84 rewind(f);
85
86 while (fgets(line,PAPI_HUGE_STR_LEN,f)!=NULL) {
87 s=strstr(line,search_str);
88 if (s!=NULL) {
89 /* skip all characters in line up to the colon */
90 /* and then spaces */
91 s=strchr(s,':');
92 if (s==NULL) break;
93 s++;
94 while (isspace(*s)) {
95 s++;
96 }
97 start = s;
98 /* Find and clear newline */
99 s=strrchr(start,'\n');
100 if (s!=NULL) *s = 0;
101 break;
102 }
103 }
104 return start;
105}
static struct timeval start
Here is the call graph for this function:
Here is the caller graph for this function:

◆ xfopen()

static FILE * xfopen ( const char *  path,
const char *  mode 
)
static

Definition at line 142 of file linux-common.c.

143{
144 FILE *fd = fopen( path, mode );
145 if ( !fd )
146 err( EXIT_FAILURE, "error: %s", path );
147 return fd;
148}
Here is the caller graph for this function:

Variable Documentation

◆ _papi_hwd_lock_data

volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK]

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

◆ _papi_os_info

PAPI_os_info_t _papi_os_info

Definition at line 27 of file linux-common.c.

◆ _papi_os_vector

papi_os_vector_t _papi_os_vector

Definition at line 784 of file linux-common.c.

◆ pathbuf

char pathbuf[PATH_MAX] = "/"
static

Definition at line 76 of file linux-common.c.