PAPI  5.3.0.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 40 of file x86_cpuid_info.c.

41 {
42  int retval = 0;
43  union
44  {
45  struct
46  {
47  unsigned int ax, bx, cx, dx;
48  } e;
49  char vendor[20]; /* leave room for terminator bytes */
50  } reg;
51 
52  /* Don't use cpu_type to determine the processor.
53  * get the information directly from the chip.
54  */
55  reg.e.ax = 0; /* function code 0: vendor string */
56  /* The vendor string is composed of EBX:EDX:ECX.
57  * by swapping the register addresses in the call below,
58  * the string is correctly composed in the char array.
59  */
60  cpuid( &reg.e.ax, &reg.e.bx, &reg.e.dx, &reg.e.cx );
61  reg.vendor[16] = 0;
62  MEMDBG( "Vendor: %s\n", &reg.vendor[4] );
63 
64  init_mem_hierarchy( mh_info );
65 
66  if ( !strncmp( "GenuineIntel", &reg.vendor[4], 12 ) ) {
67  init_intel( mh_info, &mh_info->levels);
68  } else if ( !strncmp( "AuthenticAMD", &reg.vendor[4], 12 ) ) {
69  init_amd( mh_info, &mh_info->levels );
70  } else {
71  MEMDBG( "Unsupported cpu type; Not Intel or AMD x86\n" );
72  return PAPI_ENOIMPL;
73  }
74 
75  /* This works only because an empty cache element is initialized to 0 */
76  MEMDBG( "Detected L1: %d L2: %d L3: %d\n",
77  mh_info->level[0].cache[0].size + mh_info->level[0].cache[1].size,
78  mh_info->level[1].cache[0].size + mh_info->level[1].cache[1].size,
79  mh_info->level[2].cache[0].size + mh_info->level[2].cache[1].size );
80  return retval;
81 }
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 1491 of file x86_cpuid_info.c.

1492 {
1493  unsigned int eax, ebx, ecx, edx;
1494  char hyper_vendor_id[13];
1495 
1496  cpuid2(&eax, &ebx, &ecx, &edx,0x1,0);
1497  /* This is the hypervisor bit, ecx bit 31 */
1498  if (ecx&0x80000000) {
1499  /* There are various values in the 0x4000000X range */
1500  /* It is questionable how standard they are */
1501  /* For now we just return the name. */
1502  cpuid2(&eax, &ebx, &ecx, &edx, 0x40000000,0);
1503  memcpy(hyper_vendor_id + 0, &ebx, 4);
1504  memcpy(hyper_vendor_id + 4, &ecx, 4);
1505  memcpy(hyper_vendor_id + 8, &edx, 4);
1506  hyper_vendor_id[12] = '\0';
1507  strncpy(vendor_name,hyper_vendor_id,PAPI_MAX_STR_LEN);
1508  return 1;
1509  }
1510  else {
1511  strncpy(vendor_name,"none",PAPI_MAX_STR_LEN);
1512  }
1513  return 0;
1514 }
#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: