|
#include <stdio.h> |
|
#include <stdint.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <alloca.h> |
|
|
|
#include <errno.h> |
|
#include <sys/types.h> |
|
#include <sys/sysctl.h> |
|
#include <mach/machine.h> |
|
|
|
#include <cpuinfo.h> |
|
#include <mach/api.h> |
|
#include <cpuinfo/internal-api.h> |
|
#include <cpuinfo/log.h> |
|
|
|
|
|
#ifndef CPUFAMILY_ARM_VORTEX_TEMPEST |
|
#define CPUFAMILY_ARM_VORTEX_TEMPEST 0x07D34B9F |
|
#endif |
|
#ifndef CPUFAMILY_ARM_LIGHTNING_THUNDER |
|
#define CPUFAMILY_ARM_LIGHTNING_THUNDER 0x462504D2 |
|
#endif |
|
#ifndef CPUFAMILY_ARM_FIRESTORM_ICESTORM |
|
#define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1B588BB3 |
|
#endif |
|
#ifndef CPUFAMILY_ARM_AVALANCHE_BLIZZARD |
|
#define CPUFAMILY_ARM_AVALANCHE_BLIZZARD 0xDA33D83D |
|
#endif |
|
|
|
struct cpuinfo_arm_isa cpuinfo_isa = { |
|
.aes = true, |
|
.sha1 = true, |
|
.sha2 = true, |
|
.pmull = true, |
|
.crc32 = true, |
|
}; |
|
|
|
static uint32_t get_sys_info(int type_specifier, const char* name) { |
|
size_t size = 0; |
|
uint32_t result = 0; |
|
int mib[2] = { CTL_HW, type_specifier }; |
|
if (sysctl(mib, 2, NULL, &size, NULL, 0) != 0) { |
|
cpuinfo_log_info("sysctl(\"%s\") failed: %s", name, strerror(errno)); |
|
} else if (size == sizeof(uint32_t)) { |
|
sysctl(mib, 2, &result, &size, NULL, 0); |
|
cpuinfo_log_debug("%s: %"PRIu32 ", size = %lu", name, result, size); |
|
} else { |
|
cpuinfo_log_info("sysctl does not support non-integer lookup for (\"%s\")", name); |
|
} |
|
return result; |
|
} |
|
|
|
static uint32_t get_sys_info_by_name(const char* type_specifier) { |
|
size_t size = 0; |
|
uint32_t result = 0; |
|
if (sysctlbyname(type_specifier, NULL, &size, NULL, 0) != 0) { |
|
cpuinfo_log_info("sysctlbyname(\"%s\") failed: %s", type_specifier, strerror(errno)); |
|
} else if (size == sizeof(uint32_t)) { |
|
sysctlbyname(type_specifier, &result, &size, NULL, 0); |
|
cpuinfo_log_debug("%s: %"PRIu32 ", size = %lu", type_specifier, result, size); |
|
} else { |
|
cpuinfo_log_info("sysctl does not support non-integer lookup for (\"%s\")", type_specifier); |
|
} |
|
return result; |
|
} |
|
|
|
static enum cpuinfo_uarch decode_uarch(uint32_t cpu_family, uint32_t core_index, uint32_t core_count) { |
|
switch (cpu_family) { |
|
case CPUFAMILY_ARM_CYCLONE: |
|
return cpuinfo_uarch_cyclone; |
|
case CPUFAMILY_ARM_TYPHOON: |
|
return cpuinfo_uarch_typhoon; |
|
case CPUFAMILY_ARM_TWISTER: |
|
return cpuinfo_uarch_twister; |
|
case CPUFAMILY_ARM_HURRICANE: |
|
return cpuinfo_uarch_hurricane; |
|
case CPUFAMILY_ARM_MONSOON_MISTRAL: |
|
|
|
return core_index < 2 ? cpuinfo_uarch_monsoon : cpuinfo_uarch_mistral; |
|
case CPUFAMILY_ARM_VORTEX_TEMPEST: |
|
|
|
return core_index + 4 < core_count ? cpuinfo_uarch_vortex : cpuinfo_uarch_tempest; |
|
case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
|
|
|
return core_index + 4 < core_count ? cpuinfo_uarch_lightning : cpuinfo_uarch_thunder; |
|
case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
|
|
|
return core_index + 4 < core_count ? cpuinfo_uarch_firestorm : cpuinfo_uarch_icestorm; |
|
case CPUFAMILY_ARM_AVALANCHE_BLIZZARD: |
|
|
|
return core_index + 4 < core_count ? cpuinfo_uarch_avalanche : cpuinfo_uarch_blizzard; |
|
default: |
|
|
|
break; |
|
} |
|
|
|
return cpuinfo_uarch_unknown; |
|
} |
|
|
|
static void decode_package_name(char* package_name) { |
|
size_t size; |
|
if (sysctlbyname("hw.machine", NULL, &size, NULL, 0) != 0) { |
|
cpuinfo_log_warning("sysctlbyname(\"hw.machine\") failed: %s", strerror(errno)); |
|
return; |
|
} |
|
|
|
char *machine_name = alloca(size); |
|
if (sysctlbyname("hw.machine", machine_name, &size, NULL, 0) != 0) { |
|
cpuinfo_log_warning("sysctlbyname(\"hw.machine\") failed: %s", strerror(errno)); |
|
return; |
|
} |
|
cpuinfo_log_debug("hw.machine: %s", machine_name); |
|
|
|
char name[10]; |
|
uint32_t major = 0, minor = 0; |
|
if (sscanf(machine_name, "%9[^,0123456789]%"SCNu32",%"SCNu32, name, &major, &minor) != 3) { |
|
cpuinfo_log_warning("parsing \"hw.machine\" failed: %s", strerror(errno)); |
|
return; |
|
} |
|
|
|
uint32_t chip_model = 0; |
|
char suffix = '\0'; |
|
if (strcmp(name, "iPhone") == 0) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chip_model = major + 1; |
|
} else if (strcmp(name, "iPad") == 0) { |
|
switch (major) { |
|
|
|
case 2: |
|
|
|
|
|
|
|
|
|
chip_model = major + 3; |
|
break; |
|
case 3: |
|
|
|
|
|
|
|
|
|
chip_model = (minor <= 3) ? 5 : 6; |
|
suffix = 'X'; |
|
break; |
|
case 4: |
|
|
|
|
|
|
|
|
|
|
|
chip_model = major + 3; |
|
break; |
|
case 5: |
|
|
|
|
|
|
|
|
|
chip_model = major + 3; |
|
suffix = (minor <= 2) ? '\0' : 'X'; |
|
break; |
|
case 6: |
|
|
|
|
|
|
|
|
|
|
|
chip_model = major + 3; |
|
suffix = minor <= 8 ? 'X' : '\0'; |
|
break; |
|
case 7: |
|
|
|
|
|
|
|
|
|
|
|
chip_model = major + 3; |
|
suffix = minor <= 4 ? 'X' : '\0'; |
|
break; |
|
default: |
|
cpuinfo_log_info("unknown iPad: %s", machine_name); |
|
break; |
|
} |
|
} else if (strcmp(name, "iPod") == 0) { |
|
switch (major) { |
|
case 5: |
|
chip_model = 5; |
|
break; |
|
|
|
case 7: |
|
|
|
chip_model = 8; |
|
break; |
|
default: |
|
cpuinfo_log_info("unknown iPod: %s", machine_name); |
|
break; |
|
} |
|
} else { |
|
cpuinfo_log_info("unknown device: %s", machine_name); |
|
} |
|
if (chip_model != 0) { |
|
snprintf(package_name, CPUINFO_PACKAGE_NAME_MAX, "Apple A%"PRIu32"%c", chip_model, suffix); |
|
} |
|
} |
|
|
|
void cpuinfo_arm_mach_init(void) { |
|
struct cpuinfo_processor* processors = NULL; |
|
struct cpuinfo_core* cores = NULL; |
|
struct cpuinfo_cluster* clusters = NULL; |
|
struct cpuinfo_package* packages = NULL; |
|
struct cpuinfo_uarch_info* uarchs = NULL; |
|
struct cpuinfo_cache* l1i = NULL; |
|
struct cpuinfo_cache* l1d = NULL; |
|
struct cpuinfo_cache* l2 = NULL; |
|
struct cpuinfo_cache* l3 = NULL; |
|
|
|
struct cpuinfo_mach_topology mach_topology = cpuinfo_mach_detect_topology(); |
|
processors = calloc(mach_topology.threads, sizeof(struct cpuinfo_processor)); |
|
if (processors == NULL) { |
|
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %"PRIu32" logical processors", |
|
mach_topology.threads * sizeof(struct cpuinfo_processor), mach_topology.threads); |
|
goto cleanup; |
|
} |
|
cores = calloc(mach_topology.cores, sizeof(struct cpuinfo_core)); |
|
if (cores == NULL) { |
|
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %"PRIu32" cores", |
|
mach_topology.cores * sizeof(struct cpuinfo_core), mach_topology.cores); |
|
goto cleanup; |
|
} |
|
packages = calloc(mach_topology.packages, sizeof(struct cpuinfo_package)); |
|
if (packages == NULL) { |
|
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %"PRIu32" packages", |
|
mach_topology.packages * sizeof(struct cpuinfo_package), mach_topology.packages); |
|
goto cleanup; |
|
} |
|
|
|
const uint32_t threads_per_core = mach_topology.threads / mach_topology.cores; |
|
const uint32_t threads_per_package = mach_topology.threads / mach_topology.packages; |
|
const uint32_t cores_per_package = mach_topology.cores / mach_topology.packages; |
|
|
|
for (uint32_t i = 0; i < mach_topology.packages; i++) { |
|
packages[i] = (struct cpuinfo_package) { |
|
.processor_start = i * threads_per_package, |
|
.processor_count = threads_per_package, |
|
.core_start = i * cores_per_package, |
|
.core_count = cores_per_package, |
|
}; |
|
decode_package_name(packages[i].name); |
|
} |
|
|
|
|
|
const uint32_t cpu_family = get_sys_info_by_name("hw.cpufamily"); |
|
|
|
|
|
|
|
|
|
|
|
const uint32_t has_feat_lse = get_sys_info_by_name("hw.optional.arm.FEAT_LSE"); |
|
if (has_feat_lse != 0) { |
|
cpuinfo_isa.atomics = true; |
|
} else { |
|
|
|
switch (cpu_family) { |
|
case CPUFAMILY_ARM_MONSOON_MISTRAL: |
|
case CPUFAMILY_ARM_VORTEX_TEMPEST: |
|
case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
|
case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
|
cpuinfo_isa.atomics = true; |
|
} |
|
} |
|
|
|
const uint32_t has_feat_rdm = get_sys_info_by_name("hw.optional.arm.FEAT_RDM"); |
|
if (has_feat_rdm != 0) { |
|
cpuinfo_isa.rdm = true; |
|
} else { |
|
|
|
|
|
switch (cpu_family) { |
|
case CPUFAMILY_ARM_MONSOON_MISTRAL: |
|
case CPUFAMILY_ARM_VORTEX_TEMPEST: |
|
case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
|
case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
|
cpuinfo_isa.rdm = true; |
|
} |
|
} |
|
|
|
const uint32_t has_feat_fp16 = get_sys_info_by_name("hw.optional.arm.FEAT_FP16"); |
|
if (has_feat_fp16 != 0) { |
|
cpuinfo_isa.fp16arith = true; |
|
} else { |
|
|
|
|
|
switch (cpu_family) { |
|
case CPUFAMILY_ARM_MONSOON_MISTRAL: |
|
case CPUFAMILY_ARM_VORTEX_TEMPEST: |
|
case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
|
case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
|
cpuinfo_isa.fp16arith = true; |
|
} |
|
} |
|
|
|
const uint32_t has_feat_fhm = get_sys_info_by_name("hw.optional.arm.FEAT_FHM"); |
|
if (has_feat_fhm != 0) { |
|
cpuinfo_isa.fhm = true; |
|
} else { |
|
|
|
const uint32_t has_feat_fhm_legacy = get_sys_info_by_name("hw.optional.armv8_2_fhm"); |
|
if (has_feat_fhm_legacy != 0) { |
|
cpuinfo_isa.fhm = true; |
|
} else { |
|
|
|
|
|
switch (cpu_family) { |
|
case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
|
case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
|
cpuinfo_isa.fhm = true; |
|
} |
|
} |
|
} |
|
|
|
const uint32_t has_feat_bf16 = get_sys_info_by_name("hw.optional.arm.FEAT_BF16"); |
|
if (has_feat_bf16 != 0) { |
|
cpuinfo_isa.bf16 = true; |
|
} |
|
|
|
const uint32_t has_feat_fcma = get_sys_info_by_name("hw.optional.arm.FEAT_FCMA"); |
|
if (has_feat_fcma != 0) { |
|
cpuinfo_isa.fcma = true; |
|
} else { |
|
|
|
switch (cpu_family) { |
|
case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
|
case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
|
cpuinfo_isa.fcma = true; |
|
} |
|
} |
|
|
|
const uint32_t has_feat_jscvt = get_sys_info_by_name("hw.optional.arm.FEAT_JSCVT"); |
|
if (has_feat_jscvt != 0) { |
|
cpuinfo_isa.jscvt = true; |
|
} else { |
|
|
|
switch (cpu_family) { |
|
case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
|
case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
|
cpuinfo_isa.jscvt = true; |
|
} |
|
} |
|
|
|
const uint32_t has_feat_dotprod = get_sys_info_by_name("hw.optional.arm.FEAT_DotProd"); |
|
if (has_feat_dotprod != 0) { |
|
cpuinfo_isa.dot = true; |
|
} else { |
|
|
|
switch (cpu_family) { |
|
case CPUFAMILY_ARM_LIGHTNING_THUNDER: |
|
case CPUFAMILY_ARM_FIRESTORM_ICESTORM: |
|
cpuinfo_isa.dot = true; |
|
} |
|
} |
|
|
|
const uint32_t has_feat_i8mm = get_sys_info_by_name("hw.optional.arm.FEAT_I8MM"); |
|
if (has_feat_i8mm != 0) { |
|
cpuinfo_isa.i8mm = true; |
|
} |
|
|
|
uint32_t num_clusters = 1; |
|
for (uint32_t i = 0; i < mach_topology.cores; i++) { |
|
cores[i] = (struct cpuinfo_core) { |
|
.processor_start = i * threads_per_core, |
|
.processor_count = threads_per_core, |
|
.core_id = i % cores_per_package, |
|
.package = packages + i / cores_per_package, |
|
.vendor = cpuinfo_vendor_apple, |
|
.uarch = decode_uarch(cpu_family, i, mach_topology.cores), |
|
}; |
|
if (i != 0 && cores[i].uarch != cores[i - 1].uarch) { |
|
num_clusters++; |
|
} |
|
} |
|
for (uint32_t i = 0; i < mach_topology.threads; i++) { |
|
const uint32_t smt_id = i % threads_per_core; |
|
const uint32_t core_id = i / threads_per_core; |
|
const uint32_t package_id = i / threads_per_package; |
|
|
|
processors[i].smt_id = smt_id; |
|
processors[i].core = &cores[core_id]; |
|
processors[i].package = &packages[package_id]; |
|
} |
|
|
|
clusters = calloc(num_clusters, sizeof(struct cpuinfo_cluster)); |
|
if (clusters == NULL) { |
|
cpuinfo_log_error( |
|
"failed to allocate %zu bytes for descriptions of %"PRIu32" clusters", |
|
num_clusters * sizeof(struct cpuinfo_cluster), num_clusters); |
|
goto cleanup; |
|
} |
|
uarchs = calloc(num_clusters, sizeof(struct cpuinfo_uarch_info)); |
|
if (uarchs == NULL) { |
|
cpuinfo_log_error( |
|
"failed to allocate %zu bytes for descriptions of %"PRIu32" uarchs", |
|
num_clusters * sizeof(enum cpuinfo_uarch), num_clusters); |
|
goto cleanup; |
|
} |
|
uint32_t cluster_idx = UINT32_MAX; |
|
for (uint32_t i = 0; i < mach_topology.cores; i++) { |
|
if (i == 0 || cores[i].uarch != cores[i - 1].uarch) { |
|
cluster_idx++; |
|
uarchs[cluster_idx] = (struct cpuinfo_uarch_info) { |
|
.uarch = cores[i].uarch, |
|
.processor_count = 1, |
|
.core_count = 1, |
|
}; |
|
clusters[cluster_idx] = (struct cpuinfo_cluster) { |
|
.processor_start = i * threads_per_core, |
|
.processor_count = 1, |
|
.core_start = i, |
|
.core_count = 1, |
|
.cluster_id = cluster_idx, |
|
.package = cores[i].package, |
|
.vendor = cores[i].vendor, |
|
.uarch = cores[i].uarch, |
|
}; |
|
} else { |
|
uarchs[cluster_idx].processor_count++; |
|
uarchs[cluster_idx].core_count++; |
|
clusters[cluster_idx].processor_count++; |
|
clusters[cluster_idx].core_count++; |
|
} |
|
cores[i].cluster = &clusters[cluster_idx]; |
|
} |
|
|
|
for (uint32_t i = 0; i < mach_topology.threads; i++) { |
|
const uint32_t core_id = i / threads_per_core; |
|
processors[i].cluster = cores[core_id].cluster; |
|
} |
|
|
|
for (uint32_t i = 0; i < mach_topology.packages; i++) { |
|
packages[i].cluster_start = 0; |
|
packages[i].cluster_count = num_clusters; |
|
} |
|
|
|
const uint32_t cacheline_size = get_sys_info(HW_CACHELINE, "HW_CACHELINE"); |
|
const uint32_t l1d_cache_size = get_sys_info(HW_L1DCACHESIZE, "HW_L1DCACHESIZE"); |
|
const uint32_t l1i_cache_size = get_sys_info(HW_L1ICACHESIZE, "HW_L1ICACHESIZE"); |
|
const uint32_t l2_cache_size = get_sys_info(HW_L2CACHESIZE, "HW_L2CACHESIZE"); |
|
const uint32_t l3_cache_size = get_sys_info(HW_L3CACHESIZE, "HW_L3CACHESIZE"); |
|
const uint32_t l1_cache_associativity = 4; |
|
const uint32_t l2_cache_associativity = 8; |
|
const uint32_t l3_cache_associativity = 16; |
|
const uint32_t cache_partitions = 1; |
|
const uint32_t cache_flags = 0; |
|
|
|
uint32_t threads_per_l1 = 0, l1_count = 0; |
|
if (l1i_cache_size != 0 || l1d_cache_size != 0) { |
|
|
|
threads_per_l1 = 1; |
|
l1_count = mach_topology.threads / threads_per_l1; |
|
cpuinfo_log_debug("detected %"PRIu32" L1 caches", l1_count); |
|
} |
|
|
|
uint32_t threads_per_l2 = 0, l2_count = 0; |
|
if (l2_cache_size != 0) { |
|
|
|
threads_per_l2 = mach_topology.cores; |
|
l2_count = 1; |
|
cpuinfo_log_debug("detected %"PRIu32" L2 caches", l2_count); |
|
} |
|
|
|
uint32_t threads_per_l3 = 0, l3_count = 0; |
|
if (l3_cache_size != 0) { |
|
|
|
threads_per_l3 = mach_topology.cores; |
|
l3_count = 1; |
|
cpuinfo_log_debug("detected %"PRIu32" L3 caches", l3_count); |
|
} |
|
|
|
if (l1i_cache_size != 0) { |
|
l1i = calloc(l1_count, sizeof(struct cpuinfo_cache)); |
|
if (l1i == NULL) { |
|
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %"PRIu32" L1I caches", |
|
l1_count * sizeof(struct cpuinfo_cache), l1_count); |
|
goto cleanup; |
|
} |
|
for (uint32_t c = 0; c < l1_count; c++) { |
|
l1i[c] = (struct cpuinfo_cache) { |
|
.size = l1i_cache_size, |
|
.associativity = l1_cache_associativity, |
|
.sets = l1i_cache_size / (l1_cache_associativity * cacheline_size), |
|
.partitions = cache_partitions, |
|
.line_size = cacheline_size, |
|
.flags = cache_flags, |
|
.processor_start = c * threads_per_l1, |
|
.processor_count = threads_per_l1, |
|
}; |
|
} |
|
for (uint32_t t = 0; t < mach_topology.threads; t++) { |
|
processors[t].cache.l1i = &l1i[t / threads_per_l1]; |
|
} |
|
} |
|
|
|
if (l1d_cache_size != 0) { |
|
l1d = calloc(l1_count, sizeof(struct cpuinfo_cache)); |
|
if (l1d == NULL) { |
|
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %"PRIu32" L1D caches", |
|
l1_count * sizeof(struct cpuinfo_cache), l1_count); |
|
goto cleanup; |
|
} |
|
for (uint32_t c = 0; c < l1_count; c++) { |
|
l1d[c] = (struct cpuinfo_cache) { |
|
.size = l1d_cache_size, |
|
.associativity = l1_cache_associativity, |
|
.sets = l1d_cache_size / (l1_cache_associativity * cacheline_size), |
|
.partitions = cache_partitions, |
|
.line_size = cacheline_size, |
|
.flags = cache_flags, |
|
.processor_start = c * threads_per_l1, |
|
.processor_count = threads_per_l1, |
|
}; |
|
} |
|
for (uint32_t t = 0; t < mach_topology.threads; t++) { |
|
processors[t].cache.l1d = &l1d[t / threads_per_l1]; |
|
} |
|
} |
|
|
|
if (l2_count != 0) { |
|
l2 = calloc(l2_count, sizeof(struct cpuinfo_cache)); |
|
if (l2 == NULL) { |
|
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %"PRIu32" L2 caches", |
|
l2_count * sizeof(struct cpuinfo_cache), l2_count); |
|
goto cleanup; |
|
} |
|
for (uint32_t c = 0; c < l2_count; c++) { |
|
l2[c] = (struct cpuinfo_cache) { |
|
.size = l2_cache_size, |
|
.associativity = l2_cache_associativity, |
|
.sets = l2_cache_size / (l2_cache_associativity * cacheline_size), |
|
.partitions = cache_partitions, |
|
.line_size = cacheline_size, |
|
.flags = cache_flags, |
|
.processor_start = c * threads_per_l2, |
|
.processor_count = threads_per_l2, |
|
}; |
|
} |
|
for (uint32_t t = 0; t < mach_topology.threads; t++) { |
|
processors[t].cache.l2 = &l2[0]; |
|
} |
|
} |
|
|
|
if (l3_count != 0) { |
|
l3 = calloc(l3_count, sizeof(struct cpuinfo_cache)); |
|
if (l3 == NULL) { |
|
cpuinfo_log_error("failed to allocate %zu bytes for descriptions of %"PRIu32" L3 caches", |
|
l3_count * sizeof(struct cpuinfo_cache), l3_count); |
|
goto cleanup; |
|
} |
|
for (uint32_t c = 0; c < l3_count; c++) { |
|
l3[c] = (struct cpuinfo_cache) { |
|
.size = l3_cache_size, |
|
.associativity = l3_cache_associativity, |
|
.sets = l3_cache_size / (l3_cache_associativity * cacheline_size), |
|
.partitions = cache_partitions, |
|
.line_size = cacheline_size, |
|
.flags = cache_flags, |
|
.processor_start = c * threads_per_l3, |
|
.processor_count = threads_per_l3, |
|
}; |
|
} |
|
for (uint32_t t = 0; t < mach_topology.threads; t++) { |
|
processors[t].cache.l3 = &l3[0]; |
|
} |
|
} |
|
|
|
|
|
cpuinfo_processors = processors; |
|
cpuinfo_cores = cores; |
|
cpuinfo_clusters = clusters; |
|
cpuinfo_packages = packages; |
|
cpuinfo_uarchs = uarchs; |
|
cpuinfo_cache[cpuinfo_cache_level_1i] = l1i; |
|
cpuinfo_cache[cpuinfo_cache_level_1d] = l1d; |
|
cpuinfo_cache[cpuinfo_cache_level_2] = l2; |
|
cpuinfo_cache[cpuinfo_cache_level_3] = l3; |
|
|
|
cpuinfo_processors_count = mach_topology.threads; |
|
cpuinfo_cores_count = mach_topology.cores; |
|
cpuinfo_clusters_count = num_clusters; |
|
cpuinfo_packages_count = mach_topology.packages; |
|
cpuinfo_uarchs_count = num_clusters; |
|
cpuinfo_cache_count[cpuinfo_cache_level_1i] = l1_count; |
|
cpuinfo_cache_count[cpuinfo_cache_level_1d] = l1_count; |
|
cpuinfo_cache_count[cpuinfo_cache_level_2] = l2_count; |
|
cpuinfo_cache_count[cpuinfo_cache_level_3] = l3_count; |
|
cpuinfo_max_cache_size = cpuinfo_compute_max_cache_size(&processors[0]); |
|
|
|
__sync_synchronize(); |
|
|
|
cpuinfo_is_initialized = true; |
|
|
|
processors = NULL; |
|
cores = NULL; |
|
clusters = NULL; |
|
packages = NULL; |
|
uarchs = NULL; |
|
l1i = l1d = l2 = l3 = NULL; |
|
|
|
cleanup: |
|
free(processors); |
|
free(cores); |
|
free(clusters); |
|
free(packages); |
|
free(uarchs); |
|
free(l1i); |
|
free(l1d); |
|
free(l2); |
|
free(l3); |
|
} |
|
|