44 int *cores,
int *threads );
57static unsigned int bit_width(
unsigned int x );
59static void cpuid2(
cpuid_reg_t *reg,
const unsigned int func,
const unsigned int subfunc );
110 memcpy(vendor , ®.
ebx, 4);
111 memcpy(vendor + 4, ®.
edx, 4);
112 memcpy(vendor + 8, ®.
ecx, 4);
121 cpuid(®, 0x80000000);
122 if (reg.
eax < 0x80000004) {
127 cpuid(®, 0x80000002);
129 memcpy(
name + 4 , ®.
ebx, 4);
130 memcpy(
name + 8 , ®.
ecx, 4);
131 memcpy(
name + 12, ®.
edx, 4);
133 cpuid(®, 0x80000003);
134 memcpy(
name + 16, ®.
eax, 4);
135 memcpy(
name + 20, ®.
ebx, 4);
136 memcpy(
name + 24, ®.
ecx, 4);
137 memcpy(
name + 28, ®.
edx, 4);
139 cpuid(®, 0x80000004);
140 memcpy(
name + 32, ®.
eax, 4);
141 memcpy(
name + 36, ®.
ebx, 4);
142 memcpy(
name + 40, ®.
ecx, 4);
143 memcpy(
name + 44, ®.
edx, 4);
215 static int sockets, nodes, cores, threads;
262 if (num_mappings == -1)
298 char vendor[13] = { 0 };
302 if (!strcmp(vendor,
"GenuineIntel")) {
304 }
else if (!strcmp(vendor,
"AuthenticAMD")) {
359 int level = (reg.
eax >> 5) & 0x3;
360 int fully_assoc = (reg.
eax >> 9) & 0x1;
361 int line_size = (reg.
ebx & 0xfff) + 1;
362 int partitions = ((reg.
ebx >> 12) & 0x3ff) + 1;
363 int ways = ((reg.
ebx >> 22) & 0x3ff) + 1;
364 int sets = (reg.
ecx + 1);
368 clevel_ptr[level-1].
cache[*num_caches].
size = (ways * partitions * sets * line_size);
370 clevel_ptr[level-1].
cache[*num_caches].
num_lines = (ways * partitions * sets);
371 clevel_ptr[level-1].
cache[*num_caches].
associativity = (fully_assoc) ? SHRT_MAX : ways;
392 cpuid(®, 0x80000005);
394 unsigned char byt[16];
395 memcpy(byt , ®.
eax, 4);
396 memcpy(byt + 4 , ®.
ebx, 4);
397 memcpy(byt + 8 , ®.
ecx, 4);
398 memcpy(byt + 12, ®.
edx, 4);
402 clevel_ptr[0].
cache[0].
size = byt[11] << 10;
408 clevel_ptr[0].
cache[1].
size = byt[15] << 10;
416 cpuid(®, 0x80000006);
418 memcpy(byt , ®.
eax, 4);
419 memcpy(byt + 4 , ®.
ebx, 4);
420 memcpy(byt + 8 , ®.
ecx, 4);
421 memcpy(byt + 12, ®.
edx, 4);
423 static short int assoc[16] = {
424 0, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, SHRT_MAX
458 int fallback = (reg.
eax < 4 || strcmp(vendor,
"GenuineIntel"));
472 int *cores,
int *threads )
475 int max_num_pkgs = (1 << mask->
pkg_width);
477 int max_num_threads = (1 << mask->
smt_width);
479 int *pkg_arr =
papi_calloc(max_num_pkgs,
sizeof(
int));
483 int *core_arr =
papi_calloc(max_num_cores,
sizeof(
int));
487 int *smt_arr =
papi_calloc(max_num_threads,
sizeof(
int));
492 for (
i = 0;
i < num_mappings; ++
i) {
493 pkg_arr[subids[
i].
pkg] =
494 core_arr[subids[
i].core] =
495 smt_arr[subids[
i].smt] = 1;
499 while (
i < max_num_pkgs) {
500 if (pkg_arr[
i++] != 0)
505 while (
i < max_num_cores) {
506 if (core_arr[
i++] != 0)
511 while (
i < max_num_threads) {
512 if (smt_arr[
i++] != 0)
553 ((reg.
eax >> 4) & 0x0000000f) + ((reg.
eax >> 12) & 0x000000f0) :
554 ((reg.
eax >> 4) & 0x0000000f);
559 if (!strcmp(vendor,
"AuthenticAMD") &&
family == 15) {
583 subid[num_mappings].
smt = ((apic_id & mask->
smt_mask ));
591 int num_mappings = 0;
596 for (
i = 0;
i < os_proc_count; ++
i) {
607 ret = ++num_mappings;
630 int core_reported = 0;
631 int thread_reported = 0;
632 int sub_leaf = 0, level_type, level_shift;
633 unsigned int core_plus_smt_mask = 0;
634 unsigned int core_plus_smt_width = 0;
638 cpuid2(®, 11, sub_leaf);
642 level_type = (reg.
ecx >> 8) & 0x000000ff;
643 level_shift = reg.
eax & 0x0000001f;
658 switch (level_type) {
660 mask->
smt_mask = ~(0xFFFFFFFF << level_shift);
665 core_plus_smt_mask = ~(0xFFFFFFFF << level_shift);
666 core_plus_smt_width = level_shift;
667 mask->
pkg_mask = 0xFFFFFFFF ^ core_plus_smt_mask;
677 if (thread_reported && core_reported) {
680 }
else if (!core_reported && thread_reported) {
697 unsigned int core_plus_smt_max_cnt = (reg.
ebx >> 16) & 0x000000ff;
700 unsigned int core_max_cnt = ((reg.
eax >> 26) & 0x0000003f) + 1;
702 unsigned int core_width =
bit_width(core_max_cnt);
703 unsigned int smt_width =
bit_width(core_plus_smt_max_cnt) - core_width;
705 mask->
smt_mask = ~(0xFFFFFFFF << smt_width);
732 return (reg.
ebx >> 24) & 0x000000ff;
739 double y = (double)
x;
741 while ((
y /= 2) > 1) {
752 :
"=a" (reg->
eax),
"=b" (reg->
ebx),
"=c" (reg->
ecx),
"=d" (reg->
edx)
753 :
"a" (func),
"c" (subfunc));
int cpu_get_cache_info(CPU_attr_e attr, int level, _sysdetect_cache_level_info_t *clevel_ptr, int *value)
@ CPU_ATTR__CACHE_MAX_NUM_LEVELS
@ CPU_ATTR__CACHE_INST_TOT_SIZE
@ CPU_ATTR__HWTHREAD_NUMA_AFFINITY
@ CPU_ATTR__CACHE_UNIF_TOT_SIZE
@ CPU_ATTR__CACHE_DATA_ASSOCIATIVITY
@ CPU_ATTR__CACHE_INST_LINE_SIZE
@ CPU_ATTR__NUMA_MEM_SIZE
@ CPU_ATTR__CACHE_UNIF_LINE_SIZE
@ CPU_ATTR__CACHE_DATA_NUM_LINES
@ CPU_ATTR__CACHE_UNIF_ASSOCIATIVITY
@ CPU_ATTR__CPUID_STEPPING
@ CPU_ATTR__CACHE_INST_PRESENT
@ CPU_ATTR__CACHE_DATA_PRESENT
@ CPU_ATTR__CACHE_DATA_LINE_SIZE
@ CPU_ATTR__CACHE_INST_ASSOCIATIVITY
@ CPU_ATTR__CACHE_INST_NUM_LINES
@ CPU_ATTR__CACHE_UNIF_NUM_LINES
@ CPU_ATTR__CACHE_DATA_TOT_SIZE
@ CPU_ATTR__CACHE_UNIF_PRESENT
#define PAPI_MAX_MEM_HIERARCHY_LEVELS
int os_cpu_get_attribute(CPU_attr_e attr, int *value)
int os_cpu_get_num_supported(void)
int os_cpu_set_affinity(int cpu)
int os_cpu_load_affinity(void)
int os_cpu_get_attribute_at(CPU_attr_e attr, int loc, int *value)
int os_cpu_get_name(char *name)
int os_cpu_store_affinity(void)
#define PAPI_MH_TYPE_DATA
#define PAPI_MH_TYPE_INST
#define PAPI_MH_TYPE_UNKNOWN
#define PAPI_MH_TYPE_UNIFIED
#define papi_calloc(a, b)
PAPI_mh_cache_info_t cache[PAPI_MH_MAX_LEVELS]
static int cpuid_parse_ids(int os_proc_count, apic_subid_mask_t *mask, apic_subid_t *subid)
static int cpuid_get_attribute(CPU_attr_e attr, int *value)
int x86_cpu_get_attribute_at(CPU_attr_e attr, int loc, int *value)
static void cpuid(cpuid_reg_t *reg, const unsigned int func)
static int cpuid_get_topology_info(CPU_attr_e attr, int *value)
static int cpuid_supports_leaves_4_11(void)
static void cpuid2(cpuid_reg_t *reg, const unsigned int func, const unsigned int subfunc)
static int cpuid_get_cache_info(CPU_attr_e attr, int level, int *value)
static int enum_cpu_resources(int num_mappings, apic_subid_mask_t *mask, apic_subid_t *subids, int *sockets, int *cores, int *threads)
static int cpuid_has_leaf4
int x86_cpu_get_vendor(char *vendor)
static int cpuid_get_leaf4_mask(apic_subid_mask_t *mask)
static unsigned int cpuid_get_x2apic_id(void)
static _sysdetect_cache_level_info_t clevel[PAPI_MAX_MEM_HIERARCHY_LEVELS]
static int cpuid_parse_id_foreach_thread(unsigned int num_mappings, apic_subid_mask_t *mask, apic_subid_t *subid)
static unsigned int cpuid_get_apic_id(void)
static int cpuid_get_leaf11_mask(apic_subid_mask_t *mask)
static int cpuid_get_mask(apic_subid_mask_t *mask)
int x86_cpu_finalize(void)
static int intel_get_cache_info(CPU_attr_e attr, int level, int *value)
static unsigned int bit_width(unsigned int x)
static int amd_get_cache_info(CPU_attr_e attr, int level, int *value)
static int cpuid_get_vendor(char *vendor)
int x86_cpu_get_attribute(CPU_attr_e attr, int *value)
int x86_cpu_get_name(char *name)
static int cpuid_get_name(char *name)
static int cpuid_has_leaf11
static int cpuid_get_attribute_at(CPU_attr_e attr, int loc, int *value)
static int cpuid_get_versioning_info(CPU_attr_e attr, int *value)