PAPI  5.7.0.0
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 70 of file linux-common.c.

◆ _PATH_SYS_SYSTEM

#define _PATH_SYS_SYSTEM   "/sys/devices/system"

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

Function Documentation

◆ _linux_detect_hypervisor()

int _linux_detect_hypervisor ( char *  virtual_vendor_name)

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

55  {
56 
57  int retval=0;
58 
59 #if defined(__i386__)||defined(__x86_64__)
60  retval=_x86_detect_hypervisor(virtual_vendor_name);
61 #else
62  (void) virtual_vendor_name;
63 #endif
64 
65  return retval;
66 }
int retval
Definition: zero_fork.c:53
int _x86_detect_hypervisor(char *vendor_name)
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 719 of file linux-common.c.

719  {
720 
721  int watchdog_detected=0,watchdog_value=0;
722  FILE *fff;
723 
724  fff=fopen("/proc/sys/kernel/nmi_watchdog","r");
725  if (fff!=NULL) {
726  if (fscanf(fff,"%d",&watchdog_value)==1) {
727  if (watchdog_value>0) watchdog_detected=1;
728  }
729  fclose(fff);
730  }
731 
732  return watchdog_detected;
733 }
FILE * fff[MAX_EVENTS]

◆ _linux_get_cpu_info()

int _linux_get_cpu_info ( PAPI_hw_info_t hwinfo,
int *  cpuinfo_mhz 
)

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

345 {
346  int retval = PAPI_OK;
347  char *s;
348  float mhz = 0.0;
349  FILE *f;
350  char cpuinfo_filename[]="/proc/cpuinfo";
351 
352  if ( ( f = fopen( cpuinfo_filename, "r" ) ) == NULL ) {
353  PAPIERROR( "fopen(/proc/cpuinfo) errno %d", errno );
354  return PAPI_ESYS;
355  }
356 
357  /* All of this information may be overwritten by the component */
358 
359  /***********************/
360  /* Attempt to find MHz */
361  /***********************/
362  s = search_cpu_info( f, "cpu MHz" );
363  if ( !s ) {
364  s = search_cpu_info( f, "clock" );
365  }
366  if ( s ) {
367  sscanf( s, "%f", &mhz );
368  *cpuinfo_mhz = mhz;
369  }
370  else {
371  // PAPIWARN("Failed to find a clock speed in /proc/cpuinfo");
372  }
373 
374  /*******************************/
375  /* Vendor Name and Vendor Code */
376  /*******************************/
377 
378  /* First try to read "vendor_id" field */
379  /* Which is the most common field */
380  s = search_cpu_info( f, "vendor_id");
381  if ( s ) {
382  strcpy( hwinfo->vendor_string, s );
383  }
384  else {
385  /* If not found, try "vendor" which seems to be Itanium specific */
386  s = search_cpu_info( f, "vendor" );
387  if ( s ) {
388  strcpy( hwinfo->vendor_string, s );
389  }
390  else {
391  /* "system type" seems to be MIPS and Alpha */
392  s = search_cpu_info( f, "system type");
393  if ( s ) {
394  strcpy( hwinfo->vendor_string, s );
395  }
396  else {
397  /* "platform" indicates Power */
398  s = search_cpu_info( f, "platform");
399  if ( s ) {
400  if ( ( strcasecmp( s, "pSeries" ) == 0 ) ||
401  ( strcasecmp( s, "PowerNV" ) == 0 ) ||
402  ( strcasecmp( s, "PowerMac" ) == 0 ) ) {
403  strcpy( hwinfo->vendor_string, "IBM" );
404  }
405  }
406  else {
407  /* "CPU implementer" indicates ARM */
408  s = search_cpu_info( f, "CPU implementer");
409  if ( s ) {
410  strcpy( hwinfo->vendor_string, "ARM" );
411  }
412  }
413  }
414  }
415  }
416 
417  /* Decode the string to a PAPI specific implementer value */
418  if ( strlen( hwinfo->vendor_string ) ) {
419  decode_vendor_string( hwinfo->vendor_string, &hwinfo->vendor );
420  }
421 
422  /**********************************************/
423  /* Provide more stepping/model/family numbers */
424  /**********************************************/
425 
426  if ((hwinfo->vendor==PAPI_VENDOR_INTEL) ||
427  (hwinfo->vendor==PAPI_VENDOR_AMD)) {
428 
429  decode_cpuinfo_x86(f,hwinfo);
430  }
431 
432  if (hwinfo->vendor==PAPI_VENDOR_IBM) {
433 
434  decode_cpuinfo_power(f,hwinfo);
435  }
436 
437  if (hwinfo->vendor==PAPI_VENDOR_ARM) {
438 
439  decode_cpuinfo_arm(f,hwinfo);
440  }
441 
442 
443 
444 
445  /* The following members are set using the same methodology */
446  /* used in lscpu. */
447 
448  /* Total number of CPUs */
449  /* The following line assumes totalcpus was initialized to zero! */
450  while ( path_exist( _PATH_SYS_SYSTEM "/cpu/cpu%d", hwinfo->totalcpus ) )
451  hwinfo->totalcpus++;
452 
453  /* Number of threads per core */
454  if ( path_exist( _PATH_SYS_CPU0 "/topology/thread_siblings" ) )
455  hwinfo->threads =
456  path_sibling( _PATH_SYS_CPU0 "/topology/thread_siblings" );
457 
458  /* Number of cores per socket */
459  if ( path_exist( _PATH_SYS_CPU0 "/topology/core_siblings" ) &&
460  hwinfo->threads > 0 )
461  hwinfo->cores =
462  path_sibling( _PATH_SYS_CPU0 "/topology/core_siblings" ) /
463  hwinfo->threads;
464 
465  /* Number of NUMA nodes */
466  /* The following line assumes nnodes was initialized to zero! */
467  while ( path_exist( _PATH_SYS_SYSTEM "/node/node%d", hwinfo->nnodes ) ) {
468  hwinfo->nnodes++;
469  }
470 
471  /* Number of CPUs per node */
472  hwinfo->ncpu = hwinfo->nnodes > 1 ?
473  hwinfo->totalcpus / hwinfo->nnodes : hwinfo->totalcpus;
474 
475  /* Number of sockets */
476  if ( hwinfo->threads > 0 && hwinfo->cores > 0 ) {
477  hwinfo->sockets = hwinfo->totalcpus / hwinfo->cores / hwinfo->threads;
478  }
479 
480 #if 0
481  int *nodecpu;
482  /* cpumap data is not currently part of the _papi_hw_info struct */
483  nodecpu = malloc( (unsigned int) hwinfo->nnodes * sizeof(int) );
484  if ( nodecpu ) {
485  int i;
486  for ( i = 0; i < hwinfo->nnodes; ++i ) {
487  nodecpu[i] = path_sibling(
488  _PATH_SYS_SYSTEM "/node/node%d/cpumap", i );
489  }
490  } else {
491  PAPIERROR( "malloc failed for variable not currently used" );
492  }
493 #endif
494 
495 
496  /* Fixup missing Megahertz Value */
497  /* This is missing from cpuinfo on ARM and MIPS */
498  if (*cpuinfo_mhz < 1.0) {
499  s = search_cpu_info( f, "BogoMIPS" );
500  if ((!s) || (sscanf( s, "%f", &mhz ) != 1)) {
501  INTDBG("MHz detection failed. "
502  "Please edit file %s at line %d.\n",
503  __FILE__,__LINE__);
504  }
505 
506  if (hwinfo->vendor == PAPI_VENDOR_MIPS) {
507  /* MIPS has 2x clock multiplier */
508  *cpuinfo_mhz = 2*(((int)mhz)+1);
509 
510  /* Also update version info on MIPS */
511  s = search_cpu_info( f, "cpu model");
512  s = strstr(s," V")+2;
513  strtok(s," ");
514  sscanf(s, "%f ", &hwinfo->revision );
515  }
516  else {
517  /* In general bogomips is proportional to number of CPUs */
518  if (hwinfo->totalcpus) {
519  if (mhz!=0) *cpuinfo_mhz = mhz / hwinfo->totalcpus;
520  }
521  }
522  }
523 
524  fclose( f );
525 
526  return retval;
527 }
#define PAPI_OK
Definition: fpapi.h:105
static void decode_vendor_string(char *s, int *vendor)
Definition: linux-common.c:104
int errno
int cores
Definition: papi.h:784
double f(double a)
Definition: cpi.c:23
static int decode_cpuinfo_power(FILE *f, PAPI_hw_info_t *hwinfo)
Definition: linux-common.c:223
static char * search_cpu_info(FILE *f, char *search_str)
Definition: linux-common.c:75
static int path_sibling(const char *path,...)
Definition: linux-common.c:143
int retval
Definition: zero_fork.c:53
#define _PATH_SYS_SYSTEM
Definition: linux-common.c:69
#define INTDBG(format, args...)
Definition: papi_debug.h:65
#define PAPI_ESYS
Definition: fpapi.h:108
int threads
Definition: papi.h:783
#define _PATH_SYS_CPU0
Definition: linux-common.c:70
float revision
Definition: papi.h:792
static int path_exist(const char *path,...)
Definition: linux-common.c:171
#define PAPI_VENDOR_IBM
Definition: papi.h:351
#define PAPI_VENDOR_MIPS
Definition: papi.h:356
int nnodes
Definition: papi.h:786
void PAPIERROR(char *format,...)
double s
Definition: byte_profile.c:36
#define PAPI_VENDOR_ARM
Definition: papi.h:355
static int decode_cpuinfo_x86(FILE *f, PAPI_hw_info_t *hwinfo)
Definition: linux-common.c:181
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:789
#define PAPI_VENDOR_INTEL
Definition: papi.h:349
int vendor
Definition: papi.h:788
static int decode_cpuinfo_arm(FILE *f, PAPI_hw_info_t *hwinfo)
Definition: linux-common.c:251
int totalcpus
Definition: papi.h:787
int sockets
Definition: papi.h:785
#define PAPI_VENDOR_AMD
Definition: papi.h:350
int i
Definition: fileop.c:140
int ncpu
Definition: papi.h:782
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 530 of file linux-common.c.

530  {
531 
532  FILE *fff;
533  int result;
534 
535  /* Try checking for min MHz */
536  /* Assume cpu0 exists */
537  fff=fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq","r");
538  if (fff==NULL) return PAPI_EINVAL;
539  result=fscanf(fff,"%d",sys_min_mhz);
540  fclose(fff);
541  if (result!=1) return PAPI_EINVAL;
542 
543  fff=fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq","r");
544  if (fff==NULL) return PAPI_EINVAL;
545  result=fscanf(fff,"%d",sys_max_mhz);
546  fclose(fff);
547  if (result!=1) return PAPI_EINVAL;
548 
549  return PAPI_OK;
550 
551 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_EINVAL
Definition: fpapi.h:106
FILE * fff[MAX_EVENTS]
Here is the caller graph for this function:

◆ _linux_get_system_info()

int _linux_get_system_info ( papi_mdi_t mdi)

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

554  {
555 
556  int retval;
557  char maxargs[PAPI_HUGE_STR_LEN];
558  pid_t pid;
559  int cpuinfo_mhz,sys_min_khz,sys_max_khz;
560 
561  /* Software info */
562 
563  /* Path and args */
564 
565  pid = getpid( );
566  if ( pid < 0 ) {
567  PAPIERROR( "getpid() returned < 0" );
568  return PAPI_ESYS;
569  }
570  mdi->pid = pid;
571 
572  sprintf( maxargs, "/proc/%d/exe", ( int ) pid );
573  retval = readlink( maxargs, mdi->exe_info.fullname,
574  PAPI_HUGE_STR_LEN-1 );
575  if ( retval < 0 ) {
576  PAPIERROR( "readlink(%s) returned < 0", maxargs );
577  return PAPI_ESYS;
578  }
579 
580  if (retval > PAPI_HUGE_STR_LEN-1) {
582  }
583  mdi->exe_info.fullname[retval] = '\0';
584 
585  /* Careful, basename can modify its argument */
586  strcpy( maxargs, mdi->exe_info.fullname );
587 
588  strncpy( mdi->exe_info.address_info.name, basename( maxargs ),
591 
592  SUBDBG( "Executable is %s\n", mdi->exe_info.address_info.name );
593  SUBDBG( "Full Executable is %s\n", mdi->exe_info.fullname );
594 
595  /* Executable regions, may require reading /proc/pid/maps file */
596 
598  SUBDBG( "Text: Start %p, End %p, length %d\n",
601  ( int ) ( mdi->exe_info.address_info.text_end -
603  SUBDBG( "Data: Start %p, End %p, length %d\n",
606  ( int ) ( mdi->exe_info.address_info.data_end -
608  SUBDBG( "Bss: Start %p, End %p, length %d\n",
611  ( int ) ( mdi->exe_info.address_info.bss_end -
613 
614  /* PAPI_preload_option information */
615 
616  strcpy( mdi->preload_info.lib_preload_env, "LD_PRELOAD" );
617  mdi->preload_info.lib_preload_sep = ' ';
618  strcpy( mdi->preload_info.lib_dir_env, "LD_LIBRARY_PATH" );
619  mdi->preload_info.lib_dir_sep = ':';
620 
621  /* Hardware info */
622 
623  retval = _linux_get_cpu_info( &mdi->hw_info, &cpuinfo_mhz );
624  if ( retval )
625  return retval;
626 
627  /* Handle MHz */
628 
629  retval = _linux_get_mhz( &sys_min_khz, &sys_max_khz );
630  if ( retval ) {
631 
632  mdi->hw_info.cpu_max_mhz=cpuinfo_mhz;
633  mdi->hw_info.cpu_min_mhz=cpuinfo_mhz;
634 
635  /*
636  mdi->hw_info.mhz=cpuinfo_mhz;
637  mdi->hw_info.clock_mhz=cpuinfo_mhz;
638  */
639  }
640  else {
641  mdi->hw_info.cpu_max_mhz=sys_max_khz/1000;
642  mdi->hw_info.cpu_min_mhz=sys_min_khz/1000;
643 
644  /*
645  mdi->hw_info.mhz=sys_max_khz/1000;
646  mdi->hw_info.clock_mhz=sys_max_khz/1000;
647  */
648  }
649 
650  /* Set Up Memory */
651 
653  if ( retval )
654  return retval;
655 
656  SUBDBG( "Found %d %s(%d) %s(%d) CPUs at %d Mhz.\n",
657  mdi->hw_info.totalcpus,
658  mdi->hw_info.vendor_string,
659  mdi->hw_info.vendor,
660  mdi->hw_info.model_string,
661  mdi->hw_info.model,
662  mdi->hw_info.cpu_max_mhz);
663 
664  /* Get virtualization info */
666 
667  return PAPI_OK;
668 }
#define PAPI_OK
Definition: fpapi.h:105
caddr_t text_end
Definition: papi.h:699
int cpu_min_mhz
Definition: papi.h:798
caddr_t bss_start
Definition: papi.h:702
PAPI_preload_info_t preload_info
PAPI_exe_info_t exe_info
int retval
Definition: zero_fork.c:53
int _linux_get_mhz(int *sys_min_mhz, int *sys_max_mhz)
Definition: linux-common.c:530
#define PAPI_ESYS
Definition: fpapi.h:108
int _linux_update_shlib_info(papi_mdi_t *mdi)
int _linux_get_memory_info(PAPI_hw_info_t *hwinfo, int cpu_type)
static int pid
char lib_preload_sep
Definition: papi.h:623
caddr_t text_start
Definition: papi.h:698
PAPI_address_map_t address_info
Definition: papi.h:710
#define PAPI_HUGE_STR_LEN
Definition: fpapi.h:42
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:791
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
void PAPIERROR(char *format,...)
int _linux_get_cpu_info(PAPI_hw_info_t *hwinfo, int *cpuinfo_mhz)
Definition: linux-common.c:344
PAPI_hw_info_t hw_info
char vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:789
caddr_t data_start
Definition: papi.h:700
int vendor
Definition: papi.h:788
int model
Definition: papi.h:790
int cpu_max_mhz
Definition: papi.h:797
caddr_t bss_end
Definition: papi.h:703
caddr_t data_end
Definition: papi.h:701
char lib_dir_env[PAPI_MAX_STR_LEN]
Definition: papi.h:624
int totalcpus
Definition: papi.h:787
int _linux_detect_hypervisor(char *virtual_vendor_name)
Definition: linux-common.c:55
char virtual_vendor_string[PAPI_MAX_STR_LEN]
Definition: papi.h:802
char fullname[PAPI_HUGE_STR_LEN]
Definition: papi.h:709
int virtualized
Definition: papi.h:801
char lib_preload_env[PAPI_MAX_STR_LEN]
Definition: papi.h:622
char lib_dir_sep
Definition: papi.h:625
char name[PAPI_HUGE_STR_LEN]
Definition: papi.h:697
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 38 of file linux-common.c.

38  {
39 
40  int i;
41 
42  for ( i = 0; i < PAPI_MAX_LOCK; i++ ) {
43 #if defined(USE_PTHREAD_MUTEXES)
44  pthread_mutex_init(&_papi_hwd_lock_data[i],NULL);
45 #else
47 #endif
48  }
49 
50  return PAPI_OK;
51 }
#define PAPI_OK
Definition: fpapi.h:105
#define PAPI_MAX_LOCK
Definition: papi_lock.h:18
volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK]
Definition: linux-common.c:34
#define MUTEX_OPEN
Definition: perfctr-ppc64.h:75
int i
Definition: fileop.c:140
Here is the caller graph for this function:

◆ _papi_hwi_init_os()

int _papi_hwi_init_os ( void  )

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

671  {
672 
673  int major=0,minor=0,sub=0;
674  char *ptr;
675  struct utsname uname_buffer;
676 
677  /* Initialize the locks */
679 
680  /* Get the kernel info */
681  uname(&uname_buffer);
682 
683  SUBDBG("Native kernel version %s\n",uname_buffer.release);
684 
685  strncpy(_papi_os_info.name,uname_buffer.sysname,PAPI_MAX_STR_LEN);
686 
687 #ifdef ASSUME_KERNEL
688  strncpy(_papi_os_info.version,ASSUME_KERNEL,PAPI_MAX_STR_LEN);
689  SUBDBG("Assuming kernel version %s\n",_papi_os_info.name);
690 #else
691  strncpy(_papi_os_info.version,uname_buffer.release,PAPI_MAX_STR_LEN);
692 #endif
693 
694  ptr=strtok(_papi_os_info.version,".");
695  if (ptr!=NULL) major=atoi(ptr);
696 
697  ptr=strtok(NULL,".");
698  if (ptr!=NULL) minor=atoi(ptr);
699 
700  ptr=strtok(NULL,".");
701  if (ptr!=NULL) sub=atoi(ptr);
702 
703  _papi_os_info.os_version=LINUX_VERSION(major,minor,sub);
704 
709  _papi_os_info.clock_ticks = sysconf( _SC_CLK_TCK );
710 
711  /* Get Linux-specific system info */
713 
714  return PAPI_OK;
715 }
#define PAPI_OK
Definition: fpapi.h:105
int atoi()
#define PAPI_INT_MPX_DEF_US
Definition: papi_internal.h:65
char name[PAPI_MAX_STR_LEN]
#define SUBDBG(format, args...)
Definition: papi_debug.h:63
#define PAPI_INT_ITIMER
Definition: papi_internal.h:54
char version[PAPI_MAX_STR_LEN]
PAPI_os_info_t _papi_os_info
Definition: linux-common.c:27
#define PAPI_INT_MPX_SIGNAL
Definition: papi_internal.h:52
papi_mdi_t _papi_hwi_system_info
Definition: papi_internal.c:56
static int _linux_init_locks(void)
Definition: linux-common.c:38
#define LINUX_VERSION(a, b, c)
Definition: linux-common.h:4
int _linux_get_system_info(papi_mdi_t *mdi)
Definition: linux-common.c:554
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
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 251 of file linux-common.c.

252 {
253 
254  int tmp;
255  unsigned int strSize;
256  char *s, *t;
257 
258  /* revision */
259  s = search_cpu_info( f, "CPU revision");
260  if ( s ) {
261  sscanf( s, "%d", &tmp );
262  hwinfo->revision = ( float ) tmp;
263  /* For compatability with old PAPI */
264  hwinfo->model = tmp;
265  }
266 
267  /* Model Name */
268  s = search_cpu_info( f, "model name");
269  strSize = sizeof(hwinfo->model_string);
270  if ( s ) {
271  strncpy( hwinfo->model_string, s, strSize );
272  }
273 
274  /* Architecture (ARMv6, ARMv7, ARMv8, etc.) */
275 
276  /* Parsing this is a bit fragile. */
277  /* On ARM64 the "CPU architecture field" */
278  /* Prior to Linux 3.19: always "AArch64" */
279  /* Since Linux 3.19: always "8" */
280  /* On ARM32 the "CPU architecture field" is a value and not */
281  /* necessarily an integer, so it might be 7 or 7M */
282  /* also, unknown architectures are assigned a value */
283  /* such as (10) where 10 does not mean version 10, just */
284  /* the 10th element in an array */
285  /* Note the original Raspberry Pi lies in the CPU architecture line */
286  /* (it's ARMv6 not ARMv7) */
287  /* So we should actually get the value from the */
288  /* Processor/ model name line */
289 
290 
291  s = search_cpu_info( f, "CPU architecture");
292  if ( s ) {
293 
294  /* Handle old (prior to Linux 3.19) ARM64 */
295  if (strstr(s,"AArch64")) {
296  hwinfo->cpuid_family = 8;
297  }
298  else {
299  hwinfo->cpuid_family=strtol(s, NULL, 10);
300  }
301 
302  /* Old Fallbacks if the above didn't work */
303  if (hwinfo->cpuid_family<0) {
304 
305  /* Try the processor field and look inside of parens */
306  s = search_cpu_info( f, "Processor" );
307  if (s) {
308  t=strchr(s,'(');
309  tmp=*(t+2)-'0';
310  hwinfo->cpuid_family = tmp;
311  }
312  /* Try the model name and look inside of parens */
313  else {
314  s = search_cpu_info( f, "model name" );
315  if (s) {
316  t=strchr(s,'(');
317  tmp=*(t+2)-'0';
318  hwinfo->cpuid_family = tmp;
319  }
320  }
321  }
322  }
323 
324  /* CPU Model */
325  s = search_cpu_info( f, "CPU part" );
326  if ( s ) {
327  sscanf( s, "%x", &tmp );
328  hwinfo->cpuid_model = tmp;
329  }
330 
331  /* CPU Variant */
332  s = search_cpu_info( f, "CPU variant" );
333  if ( s ) {
334  sscanf( s, "%x", &tmp );
335  hwinfo->cpuid_stepping = tmp;
336  }
337 
338  return PAPI_OK;
339 
340 }
#define PAPI_OK
Definition: fpapi.h:105
double f(double a)
Definition: cpi.c:23
static char * search_cpu_info(FILE *f, char *search_str)
Definition: linux-common.c:75
double tmp
int cpuid_stepping
Definition: papi.h:795
float revision
Definition: papi.h:792
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:791
int cpuid_model
Definition: papi.h:794
double s
Definition: byte_profile.c:36
int cpuid_family
Definition: papi.h:793
int model
Definition: papi.h:790
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 223 of file linux-common.c.

224 {
225 
226  int tmp;
227  unsigned int strSize;
228  char *s;
229 
230  /* Revision */
231  s = search_cpu_info( f, "revision");
232  if ( s ) {
233  sscanf( s, "%d", &tmp );
234  hwinfo->revision = ( float ) tmp;
235  hwinfo->cpuid_stepping = tmp;
236  }
237 
238  /* Model Name */
239  s = search_cpu_info( f, "model");
240  strSize = sizeof(hwinfo->model_string);
241  if ( s ) {
242  strncpy( hwinfo->model_string, s, strSize);
243  }
244 
245  return PAPI_OK;
246 }
#define PAPI_OK
Definition: fpapi.h:105
double f(double a)
Definition: cpi.c:23
static char * search_cpu_info(FILE *f, char *search_str)
Definition: linux-common.c:75
double tmp
int cpuid_stepping
Definition: papi.h:795
float revision
Definition: papi.h:792
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:791
double s
Definition: byte_profile.c:36
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 181 of file linux-common.c.

182 {
183  int tmp;
184  unsigned int strSize;
185  char *s;
186 
187  /* Stepping */
188  s = search_cpu_info( f, "stepping");
189  if ( s ) {
190  if (sscanf( s, "%d", &tmp ) ==1 ) {
191  hwinfo->revision = ( float ) tmp;
192  hwinfo->cpuid_stepping = tmp;
193  }
194  }
195 
196  /* Model Name */
197  s = search_cpu_info( f, "model name");
198  strSize = sizeof(hwinfo->model_string);
199  if ( s ) {
200  strncpy( hwinfo->model_string, s, strSize);
201  }
202 
203  /* Family */
204  s = search_cpu_info( f, "cpu family");
205  if ( s ) {
206  sscanf( s, "%d", &tmp );
207  hwinfo->cpuid_family = tmp;
208  }
209 
210 
211  /* CPU Model */
212  s = search_cpu_info( f, "model");
213  if ( s ) {
214  sscanf( s , "%d", &tmp );
215  hwinfo->model = tmp;
216  hwinfo->cpuid_model = tmp;
217  }
218 
219  return PAPI_OK;
220 }
#define PAPI_OK
Definition: fpapi.h:105
double f(double a)
Definition: cpi.c:23
static char * search_cpu_info(FILE *f, char *search_str)
Definition: linux-common.c:75
double tmp
int cpuid_stepping
Definition: papi.h:795
float revision
Definition: papi.h:792
char model_string[PAPI_MAX_STR_LEN]
Definition: papi.h:791
int cpuid_model
Definition: papi.h:794
double s
Definition: byte_profile.c:36
int cpuid_family
Definition: papi.h:793
int model
Definition: papi.h:790
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 104 of file linux-common.c.

105 {
106  if ( strcasecmp( s, "GenuineIntel" ) == 0 )
107  *vendor = PAPI_VENDOR_INTEL;
108  else if ( ( strcasecmp( s, "AMD" ) == 0 ) ||
109  ( strcasecmp( s, "AuthenticAMD" ) == 0 ) )
110  *vendor = PAPI_VENDOR_AMD;
111  else if ( strcasecmp( s, "IBM" ) == 0 )
112  *vendor = PAPI_VENDOR_IBM;
113  else if ( strcasecmp( s, "Cray" ) == 0 )
114  *vendor = PAPI_VENDOR_CRAY;
115  else if ( strcasecmp( s, "ARM" ) == 0 )
116  *vendor = PAPI_VENDOR_ARM;
117  else if ( strcasecmp( s, "MIPS" ) == 0 )
118  *vendor = PAPI_VENDOR_MIPS;
119  else if ( strcasecmp( s, "SiCortex" ) == 0 )
120  *vendor = PAPI_VENDOR_MIPS;
121  else
122  *vendor = PAPI_VENDOR_UNKNOWN;
123 }
#define PAPI_VENDOR_IBM
Definition: papi.h:351
#define PAPI_VENDOR_MIPS
Definition: papi.h:356
double s
Definition: byte_profile.c:36
#define PAPI_VENDOR_ARM
Definition: papi.h:355
#define PAPI_VENDOR_CRAY
Definition: papi.h:352
#define PAPI_VENDOR_INTEL
Definition: papi.h:349
#define PAPI_VENDOR_AMD
Definition: papi.h:350
#define PAPI_VENDOR_UNKNOWN
Definition: papi.h:348
Here is the caller graph for this function:

◆ path_exist()

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

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

172 {
173  va_list ap;
174  va_start( ap, path );
175  vsnprintf( pathbuf, sizeof ( pathbuf ), path, ap );
176  va_end( ap );
177  return access( pathbuf, F_OK ) == 0;
178 }
static char pathbuf[PATH_MAX]
Definition: linux-common.c:72
va_start(arg_list, fmt)
va_end(arg_list)
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 143 of file linux-common.c.

144 {
145  int c;
146  long n;
147  int result = 0;
148  char s[2];
149  FILE *fp;
150  va_list ap;
151  va_start( ap, path );
152  fp = path_vfopen( "r", path, ap );
153  va_end( ap );
154 
155  while ( ( c = fgetc( fp ) ) != EOF ) {
156  if ( isxdigit( c ) ) {
157  s[0] = ( char ) c;
158  s[1] = '\0';
159  for ( n = strtol( s, NULL, 16 ); n > 0; n /= 2 ) {
160  if ( n % 2 )
161  result++;
162  }
163  }
164  }
165 
166  fclose( fp );
167  return result;
168 }
va_start(arg_list, fmt)
static FILE * fp
double c
Definition: multiplex.c:22
static FILE * path_vfopen(const char *mode, const char *path, va_list ap)
Definition: linux-common.c:135
double s
Definition: byte_profile.c:36
va_end(arg_list)
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 135 of file linux-common.c.

136 {
137  vsnprintf( pathbuf, sizeof ( pathbuf ), path, ap );
138  return xfopen( pathbuf, mode );
139 }
static char pathbuf[PATH_MAX]
Definition: linux-common.c:72
static FILE * xfopen(const char *path, const char *mode)
Definition: linux-common.c:126
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 75 of file linux-common.c.

76 {
77  static char line[PAPI_HUGE_STR_LEN] = "";
78  char *s, *start = NULL;
79 
80  rewind(f);
81 
82  while (fgets(line,PAPI_HUGE_STR_LEN,f)!=NULL) {
83  s=strstr(line,search_str);
84  if (s!=NULL) {
85  /* skip all characters in line up to the colon */
86  /* and then spaces */
87  s=strchr(s,':');
88  if (s==NULL) break;
89  s++;
90  while (isspace(*s)) {
91  s++;
92  }
93  start = s;
94  /* Find and clear newline */
95  s=strrchr(start,'\n');
96  if (s!=NULL) *s = 0;
97  break;
98  }
99  }
100  return start;
101 }
double f(double a)
Definition: cpi.c:23
static struct timeval start
#define PAPI_HUGE_STR_LEN
Definition: fpapi.h:42
double s
Definition: byte_profile.c:36
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 126 of file linux-common.c.

127 {
128  FILE *fd = fopen( path, mode );
129  if ( !fd )
130  err( EXIT_FAILURE, "error: %s", path );
131  return fd;
132 }
int fd
Definition: iozone.c:1291
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 34 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 735 of file linux-common.c.

◆ pathbuf

char pathbuf[PATH_MAX] = "/"
static

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