diff --git a/src/arm/midr.c b/src/arm/midr.c index 7a82ac2..f4edbd2 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -12,16 +12,6 @@ #define STRING_UNKNOWN "Unknown" -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->cach = cach; -} - void init_cache_struct(struct cache* cach) { cach->L1i = malloc(sizeof(struct cach)); cach->L1d = malloc(sizeof(struct cach)); @@ -64,17 +54,30 @@ struct frequency* get_frequency_info(uint32_t core) { return freq; } -struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach) { +struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, uint32_t* midr_array, int socket_idx, int ncores) { struct topology* topo = malloc(sizeof(struct topology)); - init_topology_struct(topo, cach); - - topo->total_cores = get_ncores_from_cpuinfo(); - topo->physical_cores = topo->total_cores; - topo->logical_cores = topo->total_cores; - topo->smt_available = 1; - topo->smt_supported = 0; - topo->sockets = 1; + topo->cach = cach; + topo->total_cores = 0; + + int sockets_seen = 0; + int first_core_idx = 0; + int currrent_core_idx = 0; + int cores_in_socket = 0; + + while(socket_idx + 1 > sockets_seen) { + if(midr_array[first_core_idx] == midr_array[currrent_core_idx] && currrent_core_idx < ncores) { + currrent_core_idx++; + cores_in_socket++; + } + else { + topo->total_cores = cores_in_socket; + cores_in_socket = 0; + first_core_idx = currrent_core_idx; + sockets_seen++; + } + } + return topo; } @@ -155,9 +158,9 @@ struct cpuInfo* get_cpu_info() { ptr->midr = midr_array[midr_idx]; ptr->arch = get_uarch_from_midr(ptr->midr, ptr); - ptr->freq = get_frequency_info(i); // TODO: wrong! + ptr->freq = get_frequency_info(midr_idx); ptr->cach = get_cache_info(ptr); - ptr->topo = get_topology_info(ptr, ptr->cach); + ptr->topo = get_topology_info(ptr, ptr->cach, midr_array, i, ncores); } cpu->num_cpus = sockets; @@ -171,7 +174,7 @@ struct cpuInfo* get_cpu_info() { char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket) { uint32_t size = 3+7+1; char* string = malloc(sizeof(char)*size); - snprintf(string, size, "%d cores", topo->physical_cores); + snprintf(string, size, "%d cores", topo->total_cores); return string; } diff --git a/src/arm/midr.h b/src/arm/midr.h index 75af86a..edbd2aa 100644 --- a/src/arm/midr.h +++ b/src/arm/midr.h @@ -4,9 +4,6 @@ #include "../common/cpu.h" struct cpuInfo* get_cpu_info(); -struct cache* get_cache_info(struct cpuInfo* cpu); -struct frequency* get_frequency_info(uint32_t core); -struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach); uint32_t get_nsockets(struct topology* topo); char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_socket); diff --git a/src/common/cpu.c b/src/common/cpu.c index 7e417fb..03caccf 100755 --- a/src/common/cpu.c +++ b/src/common/cpu.c @@ -26,14 +26,15 @@ VENDOR get_cpu_vendor(struct cpuInfo* cpu) { return cpu->cpu_vendor; } -uint32_t get_nsockets(struct topology* topo) { - return topo->sockets; -} - int64_t get_freq(struct frequency* freq) { return freq->max; } +#ifdef ARCH_X86 +char* get_str_cpu_name(struct cpuInfo* cpu) { + return cpu->cpu_name; +} + char* get_str_sockets(struct topology* topo) { char* string = malloc(sizeof(char) * 2); int32_t sanity_ret = snprintf(string, 2, "%d", topo->sockets); @@ -44,9 +45,8 @@ char* get_str_sockets(struct topology* topo) { return string; } -#ifdef ARCH_X86 -char* get_str_cpu_name(struct cpuInfo* cpu) { - return cpu->cpu_name; +uint32_t get_nsockets(struct topology* topo) { + return topo->sockets; } #endif diff --git a/src/common/cpu.h b/src/common/cpu.h index 6f8f942..037d148 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -74,14 +74,14 @@ struct cache { }; struct topology { - int64_t total_cores; - uint32_t physical_cores; + int32_t total_cores; + struct cache* cach; +#ifdef ARCH_X86 + uint32_t physical_cores; uint32_t logical_cores; uint32_t smt_available; // Number of SMT that is currently enabled uint32_t smt_supported; // Number of SMT that CPU supports (equal to smt_available if SMT is enabled) uint32_t sockets; - struct cache* cach; -#ifdef ARCH_X86 struct apic* apic; #endif }; @@ -135,13 +135,13 @@ struct cpuInfo { #ifdef ARCH_X86 char* get_str_cpu_name(struct cpuInfo* cpu); +char* get_str_sockets(struct topology* topo); +uint32_t get_nsockets(struct topology* topo); #endif VENDOR get_cpu_vendor(struct cpuInfo* cpu); -uint32_t get_nsockets(struct topology* topo); int64_t get_freq(struct frequency* freq); -char* get_str_sockets(struct topology* topo); char* get_str_aes(struct cpuInfo* cpu); char* get_str_sha(struct cpuInfo* cpu); char* get_str_l1i(struct cache* cach); diff --git a/src/common/main.c b/src/common/main.c index 82617ff..22481de 100644 --- a/src/common/main.c +++ b/src/common/main.c @@ -13,7 +13,7 @@ #include "../arm/midr.h" #endif -static const char* VERSION = "0.89"; +static const char* VERSION = "0.90"; void print_help(char *argv[]) { printf("Usage: %s [--version] [--help] [--debug] [--style \"fancy\"|\"retro\"|\"legacy\"] [--color \"intel\"|\"amd\"|'R,G,B:R,G,B:R,G,B:R,G,B']\n\n", argv[0]);