PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
x86_cpuid_info.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int _x86_cache_info (PAPI_mh_info_t *mh_info)
 
int _x86_detect_hypervisor (char *vendor_name)
 

Function Documentation

int _x86_cache_info ( PAPI_mh_info_t mh_info)

Definition at line 51 of file x86_cpuid_info.c.

52 {
53  int retval = 0;
54  union
55  {
56  struct
57  {
58  unsigned int ax, bx, cx, dx;
59  } e;
60  char vendor[20]; /* leave room for terminator bytes */
61  } reg;
62 
63  /* Don't use cpu_type to determine the processor.
64  * get the information directly from the chip.
65  */
66  reg.e.ax = 0; /* function code 0: vendor string */
67  /* The vendor string is composed of EBX:EDX:ECX.
68  * by swapping the register addresses in the call below,
69  * the string is correctly composed in the char array.
70  */
71  cpuid( &reg.e.ax, &reg.e.bx, &reg.e.dx, &reg.e.cx );
72  reg.vendor[16] = 0;
73  MEMDBG( "Vendor: %s\n", &reg.vendor[4] );
74 
75  init_mem_hierarchy( mh_info );
76 
77  if ( !strncmp( "GenuineIntel", &reg.vendor[4], 12 ) ) {
78  init_intel( mh_info, &mh_info->levels);
79  } else if ( !strncmp( "AuthenticAMD", &reg.vendor[4], 12 ) ) {
80  init_amd( mh_info, &mh_info->levels );
81  } else {
82  MEMDBG( "Unsupported cpu type; Not Intel or AMD x86\n" );
83  return PAPI_ENOIMPL;
84  }
85 
86  /* This works only because an empty cache element is initialized to 0 */
87  MEMDBG( "Detected L1: %d L2: %d L3: %d\n",
88  mh_info->level[0].cache[0].size + mh_info->level[0].cache[1].size,
89  mh_info->level[1].cache[0].size + mh_info->level[1].cache[1].size,
90  mh_info->level[2].cache[0].size + mh_info->level[2].cache[1].size );
91  return retval;
92 }
int levels
Definition: papi.h:769
#define PAPI_ENOIMPL
Definition: fpapi.h:124
static void cpuid(unsigned int *a, unsigned int *b, unsigned int *c, unsigned int *d)
static int init_intel(PAPI_mh_info_t *mh_info, int *levels)
PAPI_mh_cache_info_t cache[PAPI_MH_MAX_LEVELS]
Definition: papi.h:763
PAPI_mh_level_t level[PAPI_MAX_MEM_HIERARCHY_LEVELS]
Definition: papi.h:770
static void init_mem_hierarchy(PAPI_mh_info_t *mh_info)
#define MEMDBG(format, args...)
Definition: papi_debug.h:70
ssize_t retval
Definition: libasync.c:338
static int init_amd(PAPI_mh_info_t *mh_info, int *levels)

Here is the call graph for this function:

int _x86_detect_hypervisor ( char *  vendor_name)

Definition at line 1514 of file x86_cpuid_info.c.

1515 {
1516  unsigned int eax, ebx, ecx, edx;
1517  char hyper_vendor_id[13];
1518 
1519  cpuid2(&eax, &ebx, &ecx, &edx,0x1,0);
1520  /* This is the hypervisor bit, ecx bit 31 */
1521  if (ecx&0x80000000) {
1522  /* There are various values in the 0x4000000X range */
1523  /* It is questionable how standard they are */
1524  /* For now we just return the name. */
1525  cpuid2(&eax, &ebx, &ecx, &edx, 0x40000000,0);
1526  memcpy(hyper_vendor_id + 0, &ebx, 4);
1527  memcpy(hyper_vendor_id + 4, &ecx, 4);
1528  memcpy(hyper_vendor_id + 8, &edx, 4);
1529  hyper_vendor_id[12] = '\0';
1530  strncpy(vendor_name,hyper_vendor_id,PAPI_MAX_STR_LEN);
1531  return 1;
1532  }
1533  else {
1534  strncpy(vendor_name,"none",PAPI_MAX_STR_LEN);
1535  }
1536  return 0;
1537 }
#define PAPI_MAX_STR_LEN
Definition: fpapi.h:43
static void cpuid2(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx, unsigned int index, unsigned int ecx_in)

Here is the call graph for this function:

Here is the caller graph for this function: