diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index 0753399..27132af 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -514,7 +514,6 @@ struct cpuInfo* get_cpu_info(void) { if(cpu->hybrid_flag) cpu->num_cpus = 2; - int32_t *max_freq_pp_vec = NULL; struct cpuInfo* ptr = cpu; for(uint32_t i=0; i < cpu->num_cpus; i++) { int32_t first_core; @@ -547,10 +546,9 @@ struct cpuInfo* get_cpu_info(void) { ptr->feat = get_features_info(ptr); ptr->arch = get_cpu_uarch(ptr); - // If accurate_pp is requested, we need to get the frequency - // after fetching the topology. Otherwise we can do it now. + // If accurate_pp is not requested, get it now. if (!accurate_pp()) - ptr->freq = get_frequency_info(ptr, accurate_pp(), max_freq_pp_vec); + ptr->freq = get_frequency_info(ptr, false, NULL); if (cpu->cpu_name == NULL && ptr == cpu) { // If we couldnt read CPU name from cpuid, infer it now @@ -569,11 +567,19 @@ struct cpuInfo* get_cpu_info(void) { // If topo is NULL, return early, as get_peak_performance // requries non-NULL topology. if(ptr->topo == NULL) return cpu; + } - // If accurate_pp is requested, we need to get the frequency - // after fetching the topology - if (accurate_pp()) - ptr->freq = get_frequency_info(ptr, accurate_pp(), max_freq_pp_vec); + // If accurate_pp is requested, we need to get the frequency + // after fetching the topology for all CPU modules (this information + // is required by get_frequency_info) + if (accurate_pp()) { + int32_t *max_freq_pp_vec = NULL; + ptr = cpu; + + for (uint32_t i=0; i < cpu->num_cpus; i++) { + ptr->freq = get_frequency_info(ptr, accurate_pp(), &max_freq_pp_vec); + ptr = ptr->next_cpu; + } } cpu->peak_performance = get_peak_performance(cpu, accurate_pp()); @@ -941,7 +947,7 @@ struct cache* get_cache_info(struct cpuInfo* cpu) { return cach; } -struct frequency* get_frequency_info(struct cpuInfo* cpu, bool accurate_pp, int32_t *max_freq_pp_vec) { +struct frequency* get_frequency_info(struct cpuInfo* cpu, bool accurate_pp, int32_t **max_freq_pp_vec) { struct frequency* freq = emalloc(sizeof(struct frequency)); freq->measured = false; diff --git a/src/x86/cpuid.h b/src/x86/cpuid.h index 0b57bb6..1c324ec 100644 --- a/src/x86/cpuid.h +++ b/src/x86/cpuid.h @@ -5,7 +5,7 @@ struct cpuInfo* get_cpu_info(void); struct cache* get_cache_info(struct cpuInfo* cpu); -struct frequency* get_frequency_info(struct cpuInfo* cpu, bool accurate_pp, int32_t *max_freq_pp_vec); +struct frequency* get_frequency_info(struct cpuInfo* cpu, bool accurate_pp, int32_t **max_freq_pp_vec); struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, int module); char* get_str_avx(struct cpuInfo* cpu); diff --git a/src/x86/freq/freq.c b/src/x86/freq/freq.c index de57a0a..55ee4ce 100644 --- a/src/x86/freq/freq.c +++ b/src/x86/freq/freq.c @@ -102,7 +102,8 @@ void* measure_freq(void *freq_ptr) { return NULL; } -int64_t measure_frequency(struct cpuInfo* cpu, int32_t *max_freq_pp_vec) { +int32_t measure_frequency(struct cpuInfo* cpu, int32_t **max_freq_pp_vec_ptr) { + int32_t *max_freq_pp_vec = *max_freq_pp_vec_ptr; if (cpu->hybrid_flag && cpu->module_id > 0) { // We have a hybrid architecture and we have already // measured the frequency for this module in a previous @@ -110,7 +111,7 @@ int64_t measure_frequency(struct cpuInfo* cpu, int32_t *max_freq_pp_vec) { return max_freq_pp_vec[cpu->module_id]; } - max_freq_pp_vec = malloc(sizeof(int32_t) * cpu->num_cpus); + *max_freq_pp_vec_ptr = malloc(sizeof(int32_t) * cpu->num_cpus); int ret; int num_spaces; diff --git a/src/x86/freq/freq.h b/src/x86/freq/freq.h index 8d79db3..da30607 100644 --- a/src/x86/freq/freq.h +++ b/src/x86/freq/freq.h @@ -8,6 +8,6 @@ #define MEASURE_TIME_SECONDS 5 #define LOOP_ITERS 100000000 -int64_t measure_frequency(struct cpuInfo* cpu, int32_t *max_freq_pp_vec); +int32_t measure_frequency(struct cpuInfo* cpu, int32_t **max_freq_pp_vec); #endif