linux-common.c File Reference

Include dependency graph for linux-common.c:

Go to the source code of this file.

Defines

#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, char *line)
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

Define Documentation

#define _PATH_SYS_CPU0   _PATH_SYS_SYSTEM "/cpu/cpu0"

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

#define _PATH_SYS_SYSTEM   "/sys/devices/system"

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


Function Documentation

int _linux_detect_hypervisor ( char *  virtual_vendor_name  ) 

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

00055                                                     {
00056 
00057     int retval=0;
00058 
00059 #if defined(__i386__)||defined(__x86_64__)
00060     retval=_x86_detect_hypervisor(virtual_vendor_name);
00061 #else
00062     (void) virtual_vendor_name;
00063 #endif
00064 
00065     return retval;
00066 }

Here is the call graph for this function:

Here is the caller graph for this function:

int _linux_detect_nmi_watchdog (  ) 

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

00738                                  {
00739 
00740   int watchdog_detected=0,watchdog_value=0;
00741   FILE *fff;
00742 
00743   fff=fopen("/proc/sys/kernel/nmi_watchdog","r");
00744   if (fff!=NULL) {
00745      if (fscanf(fff,"%d",&watchdog_value)==1) {
00746         if (watchdog_value>0) watchdog_detected=1;
00747      }
00748      fclose(fff);
00749   }
00750 
00751   return watchdog_detected;
00752 }

Here is the caller graph for this function:

int _linux_get_cpu_info ( PAPI_hw_info_t hwinfo,
int *  cpuinfo_mhz 
)

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

00338 {
00339     int retval = PAPI_OK;
00340     unsigned int strSize;
00341     char maxargs[PAPI_HUGE_STR_LEN], *t, *s;
00342     float mhz = 0.0;
00343     FILE *f;
00344     char cpuinfo_filename[]="/proc/cpuinfo";
00345 
00346     if ( ( f = fopen( cpuinfo_filename, "r" ) ) == NULL ) {
00347         PAPIERROR( "fopen(/proc/cpuinfo) errno %d", errno );
00348         return PAPI_ESYS;
00349     }
00350 
00351     /* All of this information may be overwritten by the component */
00352 
00353     /***********************/
00354     /* Attempt to find MHz */
00355     /***********************/
00356     rewind( f );
00357     s = search_cpu_info( f, "clock", maxargs );
00358     if ( !s ) {
00359         rewind( f );
00360         s = search_cpu_info( f, "cpu MHz", maxargs );
00361     }
00362     if ( s ) {
00363         sscanf( s + 1, "%f", &mhz );
00364     }
00365     *cpuinfo_mhz = mhz;
00366 
00367     /*******************************/
00368     /* Vendor Name and Vendor Code */
00369     /*******************************/
00370 
00371     /* First try to read "vendor_id" field */
00372     /* Which is the most common field      */
00373     hwinfo->vendor_string[0]=0;
00374     rewind( f );
00375     s = search_cpu_info( f, "vendor_id", maxargs );
00376     strSize = sizeof(hwinfo->vendor_string);
00377     if ( s && ( t = strchr( s + 2, '\n' ) ) ) {
00378         *t = '\0';
00379         if (strlen(s+2) >= strSize-1) {
00380             s[strSize+1] = '\0';
00381         }
00382         strcpy( hwinfo->vendor_string, s + 2 );
00383     }
00384 
00385     /* If not found, try "vendor" which seems to be Itanium specific */
00386     if (!hwinfo->vendor_string[0]) {
00387         rewind( f );
00388         s = search_cpu_info( f, "vendor", maxargs );
00389         if ( s && ( t = strchr( s + 2, '\n' ) ) ) {
00390             *t = '\0';
00391             if (strlen(s+2) >= strSize-1) {
00392                 s[strSize+1] = '\0';
00393             }
00394             strcpy( hwinfo->vendor_string, s + 2 );
00395         }
00396     }
00397 
00398     /* "system type" seems to be MIPS and Alpha */
00399     if (!hwinfo->vendor_string[0]) {
00400         rewind( f );
00401         s = search_cpu_info( f, "system type", maxargs );
00402         if ( s && ( t = strchr( s + 2, '\n' ) ) ) {
00403             *t = '\0';
00404             s = strtok( s + 2, " " );
00405             if (strlen(s) >= strSize-1) {
00406                 s[strSize-1] = '\0';
00407             }
00408             strcpy( hwinfo->vendor_string, s );
00409         }
00410     }
00411 
00412     /* "platform" indicates Power */
00413     if (!hwinfo->vendor_string[0]) {
00414 
00415         rewind( f );
00416         s = search_cpu_info( f, "platform", maxargs );
00417         if ( s && ( t = strchr( s + 2, '\n' ) ) ) {
00418             *t = '\0';
00419             s = strtok( s + 2, " " );
00420             if ( ( strcasecmp( s, "pSeries" ) == 0 ) ||
00421                 ( strcasecmp( s, "PowerNV" ) == 0 ) ||
00422                 ( strcasecmp( s, "PowerMac" ) == 0 ) ) {
00423                 strcpy( hwinfo->vendor_string, "IBM" );
00424             }
00425         }
00426     }
00427 
00428     /* "CPU implementer" indicates ARM */
00429     if (!hwinfo->vendor_string[0]) {
00430 
00431         rewind( f );
00432         s = search_cpu_info( f, "CPU implementer", maxargs );
00433         if ( s ) {
00434             strcpy( hwinfo->vendor_string, "ARM" );
00435         }
00436     }
00437 
00438 
00439     /* Decode the string to an implementer value */
00440     if ( strlen( hwinfo->vendor_string ) ) {
00441         decode_vendor_string( hwinfo->vendor_string, &hwinfo->vendor );
00442     }
00443 
00444     /**********************************************/
00445     /* Provide more stepping/model/family numbers */
00446     /**********************************************/
00447 
00448     if ((hwinfo->vendor==PAPI_VENDOR_INTEL) ||
00449         (hwinfo->vendor==PAPI_VENDOR_AMD)) {
00450 
00451         decode_cpuinfo_x86(f,hwinfo);
00452     }
00453 
00454     if (hwinfo->vendor==PAPI_VENDOR_IBM) {
00455 
00456         decode_cpuinfo_power(f,hwinfo);
00457     }
00458 
00459     if (hwinfo->vendor==PAPI_VENDOR_ARM) {
00460 
00461         decode_cpuinfo_arm(f,hwinfo);
00462     }
00463 
00464 
00465 
00466 
00467     /* The following members are set using the same methodology */
00468     /* used in lscpu.                                           */
00469 
00470     /* Total number of CPUs */
00471     /* The following line assumes totalcpus was initialized to zero! */
00472     while ( path_exist( _PATH_SYS_SYSTEM "/cpu/cpu%d", hwinfo->totalcpus ) )
00473         hwinfo->totalcpus++;
00474 
00475     /* Number of threads per core */
00476     if ( path_exist( _PATH_SYS_CPU0 "/topology/thread_siblings" ) )
00477         hwinfo->threads =
00478             path_sibling( _PATH_SYS_CPU0 "/topology/thread_siblings" );
00479 
00480     /* Number of cores per socket */
00481     if ( path_exist( _PATH_SYS_CPU0 "/topology/core_siblings" ) &&
00482          hwinfo->threads > 0 )
00483         hwinfo->cores =
00484             path_sibling( _PATH_SYS_CPU0 "/topology/core_siblings" ) /
00485             hwinfo->threads;
00486 
00487     /* Number of NUMA nodes */
00488     /* The following line assumes nnodes was initialized to zero! */
00489     while ( path_exist( _PATH_SYS_SYSTEM "/node/node%d", hwinfo->nnodes ) )
00490         hwinfo->nnodes++;
00491 
00492     /* Number of CPUs per node */
00493     hwinfo->ncpu =
00494         hwinfo->nnodes >
00495         1 ? hwinfo->totalcpus / hwinfo->nnodes : hwinfo->totalcpus;
00496 
00497     /* Number of sockets */
00498     if ( hwinfo->threads > 0 && hwinfo->cores > 0 )
00499         hwinfo->sockets = hwinfo->totalcpus / hwinfo->cores / hwinfo->threads;
00500 
00501 #if 0
00502     int *nodecpu;
00503     /* cpumap data is not currently part of the _papi_hw_info struct */
00504         nodecpu = malloc( (unsigned int) hwinfo->nnodes * sizeof(int) );
00505     if ( nodecpu ) {
00506        int i;
00507        for ( i = 0; i < hwinfo->nnodes; ++i ) {
00508            nodecpu[i] = path_sibling( 
00509                              _PATH_SYS_SYSTEM "/node/node%d/cpumap", i );
00510        }
00511     } else {
00512         PAPIERROR( "malloc failed for variable not currently used" );
00513     }
00514 #endif
00515 
00516 
00517     /* Fixup missing Megahertz Value */
00518     /* This is missing from cpuinfo on ARM and MIPS */
00519      if (*cpuinfo_mhz < 1.0) {
00520     rewind( f );
00521 
00522     s = search_cpu_info( f, "BogoMIPS", maxargs );
00523     if ((!s) || (sscanf( s + 1, "%f", &mhz ) != 1)) {
00524        INTDBG("Mhz detection failed. Please edit file %s at line %d.\n",
00525              __FILE__,__LINE__);
00526     }
00527 
00528     if (hwinfo->vendor == PAPI_VENDOR_MIPS) {
00529         /* MIPS has 2x clock multiplier */
00530         *cpuinfo_mhz = 2*(((int)mhz)+1);
00531 
00532         /* Also update version info on MIPS */
00533         rewind( f );
00534         s = search_cpu_info( f, "cpu model", maxargs );
00535         s = strstr(s+1," V")+2;
00536          strtok(s," ");
00537         sscanf(s, "%f ", &hwinfo->revision );
00538     }
00539     else {
00540         /* In general bogomips is proportional to number of CPUs */
00541         if (hwinfo->totalcpus) {
00542            if (mhz!=0) *cpuinfo_mhz = mhz / hwinfo->totalcpus;
00543         }
00544     }
00545      }
00546 
00547     fclose( f );
00548 
00549     return retval;
00550 }

Here is the call graph for this function:

Here is the caller graph for this function:

int _linux_get_mhz ( int *  sys_min_mhz,
int *  sys_max_mhz 
)

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

00553                                                      {
00554 
00555   FILE *fff;
00556   int result;
00557 
00558   /* Try checking for min MHz */
00559   /* Assume cpu0 exists */
00560   fff=fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq","r");
00561   if (fff==NULL) return PAPI_EINVAL;
00562   result=fscanf(fff,"%d",sys_min_mhz);
00563   fclose(fff);
00564   if (result!=1) return PAPI_EINVAL;
00565 
00566   fff=fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq","r");
00567   if (fff==NULL) return PAPI_EINVAL;
00568   result=fscanf(fff,"%d",sys_max_mhz);
00569   fclose(fff);
00570   if (result!=1) return PAPI_EINVAL;
00571 
00572   return PAPI_OK;
00573 
00574 }

Here is the caller graph for this function:

int _linux_get_system_info ( papi_mdi_t mdi  ) 

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

00577                                           {
00578 
00579     int retval;
00580 
00581     char maxargs[PAPI_HUGE_STR_LEN];
00582     pid_t pid;
00583 
00584     int cpuinfo_mhz,sys_min_khz,sys_max_khz;
00585 
00586     /* Software info */
00587 
00588     /* Path and args */
00589 
00590     pid = getpid(  );
00591     if ( pid < 0 ) {
00592         PAPIERROR( "getpid() returned < 0" );
00593         return PAPI_ESYS;
00594     }
00595     mdi->pid = pid;
00596 
00597     sprintf( maxargs, "/proc/%d/exe", ( int ) pid );
00598    if ( (retval = readlink( maxargs, mdi->exe_info.fullname, PAPI_HUGE_STR_LEN-1 )) < 0 ) {
00599         PAPIERROR( "readlink(%s) returned < 0", maxargs );
00600         return PAPI_ESYS;
00601     }
00602    if (retval > PAPI_HUGE_STR_LEN-1)   retval=PAPI_HUGE_STR_LEN-1;
00603    mdi->exe_info.fullname[retval] = '\0';
00604 
00605     /* Careful, basename can modify it's argument */
00606 
00607     strcpy( maxargs, mdi->exe_info.fullname );
00608    strncpy( mdi->exe_info.address_info.name, basename( maxargs ), PAPI_HUGE_STR_LEN-1);
00609    mdi->exe_info.address_info.name[PAPI_HUGE_STR_LEN-1] = '\0';
00610 
00611     SUBDBG( "Executable is %s\n", mdi->exe_info.address_info.name );
00612     SUBDBG( "Full Executable is %s\n", mdi->exe_info.fullname );
00613 
00614     /* Executable regions, may require reading /proc/pid/maps file */
00615 
00616     retval = _linux_update_shlib_info( mdi );
00617     SUBDBG( "Text: Start %p, End %p, length %d\n",
00618             mdi->exe_info.address_info.text_start,
00619             mdi->exe_info.address_info.text_end,
00620             ( int ) ( mdi->exe_info.address_info.text_end -
00621                       mdi->exe_info.address_info.text_start ) );
00622     SUBDBG( "Data: Start %p, End %p, length %d\n",
00623             mdi->exe_info.address_info.data_start,
00624             mdi->exe_info.address_info.data_end,
00625             ( int ) ( mdi->exe_info.address_info.data_end -
00626                       mdi->exe_info.address_info.data_start ) );
00627     SUBDBG( "Bss: Start %p, End %p, length %d\n",
00628             mdi->exe_info.address_info.bss_start,
00629             mdi->exe_info.address_info.bss_end,
00630             ( int ) ( mdi->exe_info.address_info.bss_end -
00631                       mdi->exe_info.address_info.bss_start ) );
00632 
00633     /* PAPI_preload_option information */
00634 
00635     strcpy( mdi->preload_info.lib_preload_env, "LD_PRELOAD" );
00636     mdi->preload_info.lib_preload_sep = ' ';
00637     strcpy( mdi->preload_info.lib_dir_env, "LD_LIBRARY_PATH" );
00638     mdi->preload_info.lib_dir_sep = ':';
00639 
00640     /* Hardware info */
00641 
00642     retval = _linux_get_cpu_info( &mdi->hw_info, &cpuinfo_mhz );
00643     if ( retval )
00644         return retval;
00645 
00646     /* Handle MHz */
00647 
00648     retval = _linux_get_mhz( &sys_min_khz, &sys_max_khz );
00649     if ( retval ) {
00650 
00651        mdi->hw_info.cpu_max_mhz=cpuinfo_mhz;
00652        mdi->hw_info.cpu_min_mhz=cpuinfo_mhz;
00653 
00654        /*
00655        mdi->hw_info.mhz=cpuinfo_mhz;
00656        mdi->hw_info.clock_mhz=cpuinfo_mhz;
00657        */
00658     }
00659     else {
00660        mdi->hw_info.cpu_max_mhz=sys_max_khz/1000;
00661        mdi->hw_info.cpu_min_mhz=sys_min_khz/1000;
00662 
00663        /*
00664        mdi->hw_info.mhz=sys_max_khz/1000;
00665        mdi->hw_info.clock_mhz=sys_max_khz/1000;
00666        */
00667     }
00668 
00669     /* Set Up Memory */
00670 
00671     retval = _linux_get_memory_info( &mdi->hw_info, mdi->hw_info.model );
00672     if ( retval )
00673         return retval;
00674 
00675     SUBDBG( "Found %d %s(%d) %s(%d) CPUs at %d Mhz.\n",
00676             mdi->hw_info.totalcpus,
00677             mdi->hw_info.vendor_string,
00678             mdi->hw_info.vendor, 
00679                 mdi->hw_info.model_string, 
00680                 mdi->hw_info.model,
00681                 mdi->hw_info.cpu_max_mhz);
00682 
00683     /* Get virtualization info */
00684     mdi->hw_info.virtualized=_linux_detect_hypervisor(mdi->hw_info.virtual_vendor_string);
00685 
00686     return PAPI_OK;
00687 }

Here is the call graph for this function:

Here is the caller graph for this function:

static int _linux_init_locks ( void   )  [static]

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

00038                                    {
00039 
00040    int i;
00041 
00042    for ( i = 0; i < PAPI_MAX_LOCK; i++ ) {
00043 #if defined(USE_PTHREAD_MUTEXES)
00044        pthread_mutex_init(&_papi_hwd_lock_data[i],NULL);
00045 #else
00046        _papi_hwd_lock_data[i] = MUTEX_OPEN;
00047 #endif
00048    }
00049 
00050    return PAPI_OK;
00051 }

Here is the caller graph for this function:

int _papi_hwi_init_os ( void   ) 

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

00690                         {
00691 
00692     int major=0,minor=0,sub=0;
00693     char *ptr;
00694     struct utsname uname_buffer;
00695 
00696     /* Initialize the locks */
00697     _linux_init_locks();
00698 
00699     /* Get the kernel info */
00700     uname(&uname_buffer);
00701 
00702     SUBDBG("Native kernel version %s\n",uname_buffer.release);
00703 
00704     strncpy(_papi_os_info.name,uname_buffer.sysname,PAPI_MAX_STR_LEN);
00705 
00706 #ifdef ASSUME_KERNEL
00707     strncpy(_papi_os_info.version,ASSUME_KERNEL,PAPI_MAX_STR_LEN);
00708     SUBDBG("Assuming kernel version %s\n",_papi_os_info.name);
00709 #else
00710     strncpy(_papi_os_info.version,uname_buffer.release,PAPI_MAX_STR_LEN);
00711 #endif
00712 
00713     ptr=strtok(_papi_os_info.version,".");
00714     if (ptr!=NULL) major=atoi(ptr);
00715 
00716     ptr=strtok(NULL,".");
00717     if (ptr!=NULL) minor=atoi(ptr);
00718 
00719     ptr=strtok(NULL,".");
00720     if (ptr!=NULL) sub=atoi(ptr);
00721 
00722    _papi_os_info.os_version=LINUX_VERSION(major,minor,sub);
00723 
00724    _papi_os_info.itimer_sig = PAPI_INT_MPX_SIGNAL;
00725    _papi_os_info.itimer_num = PAPI_INT_ITIMER;
00726    _papi_os_info.itimer_ns = PAPI_INT_MPX_DEF_US * 1000;
00727    _papi_os_info.itimer_res_ns = 1;
00728    _papi_os_info.clock_ticks = sysconf( _SC_CLK_TCK );
00729 
00730    /* Get Linux-specific system info */
00731    _linux_get_system_info( &_papi_hwi_system_info );
00732 
00733    return PAPI_OK;
00734 }

Here is the call graph for this function:

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

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

00255 {
00256 
00257     int tmp;
00258     unsigned int strSize;
00259     char maxargs[PAPI_HUGE_STR_LEN], *t, *s;
00260 
00261     /* revision */
00262     rewind( f );
00263     s = search_cpu_info( f, "CPU revision", maxargs );
00264     if ( s ) {
00265         sscanf( s + 1, "%d", &tmp );
00266         hwinfo->revision = ( float ) tmp;
00267         /* For compatability with old PAPI */
00268         hwinfo->model = tmp;
00269     }
00270 
00271        /* Model Name */
00272     rewind( f );
00273     s = search_cpu_info( f, "model name", maxargs );
00274     strSize = sizeof(hwinfo->model_string);
00275     if ( s && ( t = strchr( s + 2, '\n' ) ) ) {
00276         *t = '\0';
00277         if (strlen(s+2) >= strSize-1) {
00278             s[strSize+1] = '\0';
00279         }
00280         strcpy( hwinfo->model_string, s + 2 );
00281     }
00282 
00283     /* Architecture (ARMv6, ARMv7, ARMv8, etc.) */
00284     /* Note the Raspberry Pi lies in the CPU architecture line */
00285     /* (it's ARMv6 not ARMv7)                                  */
00286     /* So we should actually get the value from the            */
00287     /*  Processor/ model name line                         */
00288     rewind( f );
00289     s = search_cpu_info( f, "CPU architecture", maxargs );
00290     if ( s ) {
00291 
00292         if (strstr(s,"AArch64")) {
00293             hwinfo->cpuid_family = 8;
00294         }
00295         else {
00296             rewind( f );
00297             s = search_cpu_info( f, "Processor", maxargs );
00298             if (s) {
00299                 t=strchr(s,'(');
00300                 tmp=*(t+2)-'0';
00301                 hwinfo->cpuid_family = tmp;
00302             }
00303             else {
00304                 rewind( f );
00305                 s = search_cpu_info( f, "model name", maxargs );
00306                 if (s) {
00307                     t=strchr(s,'(');
00308                     tmp=*(t+2)-'0';
00309                     hwinfo->cpuid_family = tmp;
00310                 }
00311             }
00312         }
00313     }
00314 
00315     /* CPU Model */
00316     rewind( f );
00317     s = search_cpu_info( f, "CPU part", maxargs );
00318     if ( s ) {
00319         sscanf( s + 1, "%x", &tmp );
00320         hwinfo->cpuid_model = tmp;
00321     }
00322 
00323     /* CPU Variant */
00324     rewind( f );
00325     s = search_cpu_info( f, "CPU variant", maxargs );
00326     if ( s ) {
00327         sscanf( s + 1, "%x", &tmp );
00328         hwinfo->cpuid_stepping = tmp;
00329     }
00330 
00331     return PAPI_OK;
00332 
00333 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

00221 {
00222 
00223     int tmp;
00224     unsigned int strSize;
00225     char maxargs[PAPI_HUGE_STR_LEN], *t, *s;
00226 
00227     /* Revision */
00228     rewind( f );
00229     s = search_cpu_info( f, "revision", maxargs );
00230     if ( s ) {
00231         sscanf( s + 1, "%d", &tmp );
00232         hwinfo->revision = ( float ) tmp;
00233         hwinfo->cpuid_stepping = tmp;
00234     }
00235 
00236        /* Model Name */
00237     rewind( f );
00238     s = search_cpu_info( f, "model", maxargs );
00239     strSize = sizeof(hwinfo->model_string);
00240     if ( s && ( t = strchr( s + 2, '\n' ) ) ) {
00241         *t = '\0';
00242         if (strlen(s+2) >= strSize-1) {
00243             s[strSize+1] = '\0';
00244         }
00245         strcpy( hwinfo->model_string, s + 2 );
00246     }
00247 
00248     return PAPI_OK;
00249 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

00172 {
00173     int tmp;
00174     unsigned int strSize;
00175     char maxargs[PAPI_HUGE_STR_LEN], *t, *s;
00176 
00177     /* Stepping */
00178     rewind( f );
00179     s = search_cpu_info( f, "stepping", maxargs );
00180     if ( s ) {
00181         sscanf( s + 1, "%d", &tmp );
00182         hwinfo->revision = ( float ) tmp;
00183         hwinfo->cpuid_stepping = tmp;
00184     }
00185 
00186     /* Model Name */
00187     rewind( f );
00188     s = search_cpu_info( f, "model name", maxargs );
00189     strSize = sizeof(hwinfo->model_string);
00190     if ( s && ( t = strchr( s + 2, '\n' ) ) ) {
00191         *t = '\0';
00192         if (strlen(s+2) >= strSize-1) {
00193             s[strSize+1] = '\0';
00194         }
00195         strcpy( hwinfo->model_string, s + 2 );
00196     }
00197 
00198     /* Family */
00199     rewind( f );
00200     s = search_cpu_info( f, "cpu family", maxargs );
00201     if ( s ) {
00202         sscanf( s + 1, "%d", &tmp );
00203         hwinfo->cpuid_family = tmp;
00204     }
00205 
00206 
00207     /* CPU Model */
00208     rewind( f );
00209     s = search_cpu_info( f, "model", maxargs );
00210     if ( s ) {
00211         sscanf( s + 1, "%d", &tmp );
00212         hwinfo->model = tmp;
00213         hwinfo->cpuid_model = tmp;
00214     }
00215 
00216     return PAPI_OK;
00217 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

00095 {
00096     if ( strcasecmp( s, "GenuineIntel" ) == 0 )
00097         *vendor = PAPI_VENDOR_INTEL;
00098     else if ( ( strcasecmp( s, "AMD" ) == 0 ) ||
00099               ( strcasecmp( s, "AuthenticAMD" ) == 0 ) )
00100         *vendor = PAPI_VENDOR_AMD;
00101     else if ( strcasecmp( s, "IBM" ) == 0 )
00102         *vendor = PAPI_VENDOR_IBM;
00103     else if ( strcasecmp( s, "Cray" ) == 0 )
00104         *vendor = PAPI_VENDOR_CRAY;
00105     else if ( strcasecmp( s, "ARM" ) == 0 )
00106         *vendor = PAPI_VENDOR_ARM;
00107     else if ( strcasecmp( s, "MIPS" ) == 0 )
00108         *vendor = PAPI_VENDOR_MIPS;
00109     else if ( strcasecmp( s, "SiCortex" ) == 0 )
00110         *vendor = PAPI_VENDOR_MIPS;
00111     else
00112         *vendor = PAPI_VENDOR_UNKNOWN;
00113 }

Here is the caller graph for this function:

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

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

00162 {
00163     va_list ap;
00164     va_start( ap, path );
00165     vsnprintf( pathbuf, sizeof ( pathbuf ), path, ap );
00166     va_end( ap );
00167     return access( pathbuf, F_OK ) == 0;
00168 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

00134 {
00135     int c;
00136     long n;
00137     int result = 0;
00138     char s[2];
00139     FILE *fp;
00140     va_list ap;
00141     va_start( ap, path );
00142     fp = path_vfopen( "r", path, ap );
00143     va_end( ap );
00144 
00145     while ( ( c = fgetc( fp ) ) != EOF ) {
00146         if ( isxdigit( c ) ) {
00147             s[0] = ( char ) c;
00148             s[1] = '\0';
00149             for ( n = strtol( s, NULL, 16 ); n > 0; n /= 2 ) {
00150                 if ( n % 2 )
00151                     result++;
00152             }
00153         }
00154     }
00155 
00156     fclose( fp );
00157     return result;
00158 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

00126 {
00127     vsnprintf( pathbuf, sizeof ( pathbuf ), path, ap );
00128     return xfopen( pathbuf, mode );
00129 }

Here is the call graph for this function:

Here is the caller graph for this function:

static char* search_cpu_info ( FILE *  f,
char *  search_str,
char *  line 
) [static]

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

00077 {
00078     /* This function courtesy of Rudolph Berrendorf! */
00079     /* See the home page for the German version of PAPI. */
00080     char *s;
00081 
00082     while ( fgets( line, 256, f ) != NULL ) {
00083         if ( strstr( line, search_str ) != NULL ) {
00084             /* ignore all characters in line up to : */
00085             for ( s = line; *s && ( *s != ':' ); ++s );
00086             if ( *s )
00087                 return s;
00088         }
00089     }
00090     return NULL;
00091 }

Here is the caller graph for this function:

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

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

00117 {
00118     FILE *fd = fopen( path, mode );
00119     if ( !fd )
00120         err( EXIT_FAILURE, "error: %s", path );
00121     return fd;
00122 }

Here is the caller graph for this function:


Variable Documentation

volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK]

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

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

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

char pathbuf[PATH_MAX] = "/" [static]

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


Generated on 26 Jan 2016 for PAPI by  doxygen 1.6.1