diff --git a/src/arm/midr.c b/src/arm/midr.c index f7b2117..40c5109 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -13,25 +13,6 @@ #include "uarch.h" #include "soc.h" -void init_cache_struct(struct cache* cach) { - cach->L1i = emalloc(sizeof(struct cach)); - cach->L1d = emalloc(sizeof(struct cach)); - cach->L2 = emalloc(sizeof(struct cach)); - cach->L3 = emalloc(sizeof(struct cach)); - - cach->cach_arr = emalloc(sizeof(struct cach*) * 4); - cach->cach_arr[0] = cach->L1i; - cach->cach_arr[1] = cach->L1d; - cach->cach_arr[2] = cach->L2; - cach->cach_arr[3] = cach->L3; - - cach->max_cache_level = 0; - cach->L1i->exists = false; - cach->L1d->exists = false; - cach->L2->exists = false; - cach->L3->exists = false; -} - struct cache* get_cache_info(struct cpuInfo* cpu) { struct cache* cach = emalloc(sizeof(struct cache)); init_cache_struct(cach); @@ -57,9 +38,7 @@ struct frequency* get_frequency_info(uint32_t core) { struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, uint32_t* midr_array, int socket_idx, int ncores) { struct topology* topo = emalloc(sizeof(struct topology)); - - topo->cach = cach; - topo->total_cores = 0; + init_topology_struct(topo, cach); int sockets_seen = 0; int first_core_idx = 0; diff --git a/src/common/cpu.c b/src/common/cpu.c index 3f37c11..3a6898e 100644 --- a/src/common/cpu.c +++ b/src/common/cpu.c @@ -9,6 +9,7 @@ #ifdef ARCH_X86 #include "../x86/uarch.h" + #include "../x86/apic.h" #elif ARCH_PPC #include "../ppc/uarch.h" #elif ARCH_ARM @@ -150,6 +151,40 @@ char* get_str_freq(struct frequency* freq) { return string; } +void init_topology_struct(struct topology* topo, struct cache* cach) { + topo->total_cores = 0; + topo->cach = cach; +#if defined(ARCH_X86) || defined(ARCH_PPC) + topo->physical_cores = 0; + topo->logical_cores = 0; + topo->smt_supported = 0; + topo->sockets = 0; +#ifdef ARCH_X86 + topo->smt_available = 0; + topo->apic = emalloc(sizeof(struct apic)); +#endif +#endif +} + +void init_cache_struct(struct cache* cach) { + cach->L1i = emalloc(sizeof(struct cach)); + cach->L1d = emalloc(sizeof(struct cach)); + cach->L2 = emalloc(sizeof(struct cach)); + cach->L3 = emalloc(sizeof(struct cach)); + + cach->cach_arr = emalloc(sizeof(struct cach*) * 4); + cach->cach_arr[0] = cach->L1i; + cach->cach_arr[1] = cach->L1d; + cach->cach_arr[2] = cach->L2; + cach->cach_arr[3] = cach->L3; + + cach->max_cache_level = 0; + cach->L1i->exists = false; + cach->L1d->exists = false; + cach->L2->exists = false; + cach->L3->exists = false; +} + void free_cache_struct(struct cache* cach) { for(int i=0; i < 4; i++) free(cach->cach_arr[i]); free(cach->cach_arr); diff --git a/src/common/cpu.h b/src/common/cpu.h index ebb4e03..0b5e9ee 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -162,6 +162,9 @@ char* get_str_l2(struct cache* cach); char* get_str_l3(struct cache* cach); char* get_str_freq(struct frequency* freq); +void init_topology_struct(struct topology* topo, struct cache* cach); +void init_cache_struct(struct cache* cach); + void free_cache_struct(struct cache* cach); void free_freq_struct(struct frequency* freq); void free_cpuinfo_struct(struct cpuInfo* cpu); diff --git a/src/ppc/ppc.c b/src/ppc/ppc.c index 00720fa..242dddd 100644 --- a/src/ppc/ppc.c +++ b/src/ppc/ppc.c @@ -11,34 +11,6 @@ #include "../common/udev.h" #include "../common/global.h" -void init_topology_struct(struct topology* topo, struct cache* cach) { - topo->total_cores = 0; - topo->physical_cores = 0; - topo->logical_cores = 0; - topo->smt_supported = 0; - topo->sockets = 0; - topo->cach = cach; -} - -void init_cache_struct(struct cache* cach) { - cach->L1i = emalloc(sizeof(struct cach)); - cach->L1d = emalloc(sizeof(struct cach)); - cach->L2 = emalloc(sizeof(struct cach)); - cach->L3 = emalloc(sizeof(struct cach)); - - cach->cach_arr = emalloc(sizeof(struct cach*) * 4); - cach->cach_arr[0] = cach->L1i; - cach->cach_arr[1] = cach->L1d; - cach->cach_arr[2] = cach->L2; - cach->cach_arr[3] = cach->L3; - - cach->max_cache_level = 0; - cach->L1i->exists = false; - cach->L1d->exists = false; - cach->L2->exists = false; - cach->L3->exists = false; -} - struct cache* get_cache_info(struct cpuInfo* cpu) { struct cache* cach = emalloc(sizeof(struct cache)); init_cache_struct(cach); diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index c7d5422..a858c07 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -49,36 +49,6 @@ static char *hv_vendors_name[] = { * cpuid amd: https://www.amd.com/system/files/TechDocs/25481.pdf */ -void init_topology_struct(struct topology* topo, struct cache* cach) { - topo->total_cores = 0; - topo->physical_cores = 0; - topo->logical_cores = 0; - topo->smt_available = 0; - topo->smt_supported = 0; - topo->sockets = 0; - topo->apic = emalloc(sizeof(struct apic)); - topo->cach = cach; -} - -void init_cache_struct(struct cache* cach) { - cach->L1i = emalloc(sizeof(struct cach)); - cach->L1d = emalloc(sizeof(struct cach)); - cach->L2 = emalloc(sizeof(struct cach)); - cach->L3 = emalloc(sizeof(struct cach)); - - cach->cach_arr = emalloc(sizeof(struct cach*) * 4); - cach->cach_arr[0] = cach->L1i; - cach->cach_arr[1] = cach->L1d; - cach->cach_arr[2] = cach->L2; - cach->cach_arr[3] = cach->L3; - - cach->max_cache_level = 0; - cach->L1i->exists = false; - cach->L1d->exists = false; - cach->L2->exists = false; - cach->L3->exists = false; -} - void get_name_cpuid(char* name, uint32_t reg1, uint32_t reg2, uint32_t reg3) { uint32_t c = 0;