14 #include <sys/utsname.h> 31 #if defined(USE_PTHREAD_MUTEXES) 43 #if defined(USE_PTHREAD_MUTEXES) 59 #if defined(__i386__)||defined(__x86_64__) 62 (void) virtual_vendor_name;
69 #define _PATH_SYS_SYSTEM "/sys/devices/system" 70 #define _PATH_SYS_CPU0 _PATH_SYS_SYSTEM "/cpu/cpu0" 83 s=strstr(line,search_str);
106 if ( strcasecmp(
s,
"GenuineIntel" ) == 0 )
108 else if ( ( strcasecmp(
s,
"AMD" ) == 0 ) ||
109 ( strcasecmp(
s,
"AuthenticAMD" ) == 0 ) )
111 else if ( strcasecmp(
s,
"IBM" ) == 0 )
113 else if ( strcasecmp(
s,
"Cray" ) == 0 )
115 else if ( strcasecmp(
s,
"ARM" ) == 0 )
117 else if ( strcasecmp(
s,
"MIPS" ) == 0 )
119 else if ( strcasecmp(
s,
"SiCortex" ) == 0 )
126 xfopen(
const char *path,
const char *mode )
128 FILE *
fd = fopen( path, mode );
130 err( EXIT_FAILURE,
"error: %s", path );
155 while ( (
c = fgetc(
fp ) ) != EOF ) {
156 if ( isxdigit(
c ) ) {
159 for ( n = strtol(
s, NULL, 16 ); n > 0; n /= 2 ) {
177 return access(
pathbuf, F_OK ) == 0;
184 unsigned int strSize;
190 if (sscanf(
s,
"%d", &
tmp ) ==1 ) {
206 sscanf(
s,
"%d", &
tmp );
214 sscanf(
s ,
"%d", &
tmp );
227 unsigned int strSize;
233 sscanf(
s,
"%d", &
tmp );
255 unsigned int strSize;
261 sscanf(
s,
"%d", &
tmp );
295 if (strstr(
s,
"AArch64")) {
327 sscanf(
s,
"%x", &
tmp );
334 sscanf(
s,
"%x", &
tmp );
350 char cpuinfo_filename[]=
"/proc/cpuinfo";
352 if ( (
f = fopen( cpuinfo_filename,
"r" ) ) == NULL ) {
367 sscanf(
s,
"%f", &mhz );
400 if ( ( strcasecmp(
s,
"pSeries" ) == 0 ) ||
401 ( strcasecmp(
s,
"PowerNV" ) == 0 ) ||
402 ( strcasecmp(
s,
"PowerMac" ) == 0 ) ) {
483 nodecpu = malloc( (
unsigned int) hwinfo->
nnodes *
sizeof(
int) );
491 PAPIERROR(
"malloc failed for variable not currently used" );
498 if (*cpuinfo_mhz < 1.0) {
500 if ((!
s) || (sscanf(
s,
"%f", &mhz ) != 1)) {
501 INTDBG(
"MHz detection failed. " 502 "Please edit file %s at line %d.\n",
508 *cpuinfo_mhz = 2*(((int)mhz)+1);
512 s = strstr(
s,
" V")+2;
519 if (mhz!=0) *cpuinfo_mhz = mhz / hwinfo->
totalcpus;
537 fff=fopen(
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq",
"r");
539 result=fscanf(
fff,
"%d",sys_min_mhz);
543 fff=fopen(
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq",
"r");
545 result=fscanf(
fff,
"%d",sys_max_mhz);
559 int cpuinfo_mhz,sys_min_khz,sys_max_khz;
572 sprintf( maxargs,
"/proc/%d/exe", (
int )
pid );
576 PAPIERROR(
"readlink(%s) returned < 0", maxargs );
598 SUBDBG(
"Text: Start %p, End %p, length %d\n",
603 SUBDBG(
"Data: Start %p, End %p, length %d\n",
608 SUBDBG(
"Bss: Start %p, End %p, length %d\n",
656 SUBDBG(
"Found %d %s(%d) %s(%d) CPUs at %d Mhz.\n",
673 int major=0,minor=0,sub=0;
675 struct utsname uname_buffer;
681 uname(&uname_buffer);
683 SUBDBG(
"Native kernel version %s\n",uname_buffer.release);
695 if (ptr!=NULL) major=
atoi(ptr);
697 ptr=strtok(NULL,
".");
698 if (ptr!=NULL) minor=
atoi(ptr);
700 ptr=strtok(NULL,
".");
701 if (ptr!=NULL) sub=
atoi(ptr);
721 int watchdog_detected=0,watchdog_value=0;
724 fff=fopen(
"/proc/sys/kernel/nmi_watchdog",
"r");
726 if (fscanf(
fff,
"%d",&watchdog_value)==1) {
727 if (watchdog_value>0) watchdog_detected=1;
732 return watchdog_detected;
743 #if defined(HAVE_CLOCK_GETTIME) 745 #elif defined(HAVE_GETTIMEOFDAY) 752 #if defined(USE_PROC_PTTIMER) 754 #elif defined(HAVE_CLOCK_GETTIME_THREAD) 756 #elif defined(HAVE_PER_THREAD_TIMES) 758 #elif defined(HAVE_PER_THREAD_GETRUSAGE) 763 #if defined(HAVE_CLOCK_GETTIME) 767 #if defined(HAVE_CLOCK_GETTIME_THREAD)
static void decode_vendor_string(char *s, int *vendor)
long long _linux_get_real_cycles(void)
static int decode_cpuinfo_power(FILE *f, PAPI_hw_info_t *hwinfo)
static char * search_cpu_info(FILE *f, char *search_str)
#define PAPI_INT_MPX_DEF_US
long long _linux_get_virt_usec_gettime(void)
int _papi_hwi_init_os(void)
static char pathbuf[PATH_MAX]
static int path_sibling(const char *path,...)
PAPI_preload_info_t preload_info
static struct timeval start
int _linux_get_mhz(int *sys_min_mhz, int *sys_max_mhz)
Return codes and api definitions.
char name[PAPI_MAX_STR_LEN]
long long _linux_get_real_nsec_gettime(void)
#define INTDBG(format, args...)
int _linux_update_shlib_info(papi_mdi_t *mdi)
papi_os_vector_t _papi_os_vector
static int path_exist(const char *path,...)
static FILE * path_vfopen(const char *mode, const char *path, va_list ap)
int _linux_get_memory_info(PAPI_hw_info_t *hwinfo, int cpu_type)
static FILE * xfopen(const char *path, const char *mode)
PAPI_address_map_t address_info
long long _linux_get_real_usec_cycles(void)
#define PAPI_HUGE_STR_LEN
volatile unsigned int _papi_hwd_lock_data[PAPI_MAX_LOCK]
char model_string[PAPI_MAX_STR_LEN]
#define SUBDBG(format, args...)
void PAPIERROR(char *format,...)
int _linux_get_dmem_info(PAPI_dmem_info_t *d)
char version[PAPI_MAX_STR_LEN]
long long _linux_get_virt_usec_times(void)
PAPI_os_info_t _papi_os_info
#define PAPI_INT_MPX_SIGNAL
int _linux_get_cpu_info(PAPI_hw_info_t *hwinfo, int *cpuinfo_mhz)
static int decode_cpuinfo_x86(FILE *f, PAPI_hw_info_t *hwinfo)
papi_mdi_t _papi_hwi_system_info
char vendor_string[PAPI_MAX_STR_LEN]
static int _linux_init_locks(void)
#define PAPI_VENDOR_INTEL
int _x86_detect_hypervisor(char *vendor_name)
#define LINUX_VERSION(a, b, c)
long long _linux_get_real_usec_gettime(void)
long long _linux_get_virt_usec_pttimer(void)
static int decode_cpuinfo_arm(FILE *f, PAPI_hw_info_t *hwinfo)
char lib_dir_env[PAPI_MAX_STR_LEN]
int(* get_memory_info)(PAPI_hw_info_t *, int)
int _linux_detect_nmi_watchdog()
long long _linux_get_virt_nsec_gettime(void)
int _linux_detect_hypervisor(char *virtual_vendor_name)
char virtual_vendor_string[PAPI_MAX_STR_LEN]
char fullname[PAPI_HUGE_STR_LEN]
char lib_preload_env[PAPI_MAX_STR_LEN]
long long _linux_get_virt_usec_rusage(void)
int _linux_get_system_info(papi_mdi_t *mdi)
char name[PAPI_HUGE_STR_LEN]
long long _linux_get_real_usec_gettimeofday(void)
#define PAPI_VENDOR_UNKNOWN