This commit is contained in:
Dr-Noob
2024-09-10 22:03:21 +01:00
parent dc9b111e85
commit 4ccafdc4fa
4 changed files with 31 additions and 35 deletions

View File

@@ -446,6 +446,23 @@ int32_t get_core_type(void) {
}
}
#ifdef __linux__
// Gets the max frequency for estimating the peak performance
// and fills in the passed cpuInfo parameter.
void fill_frequency_info_pp(struct cpuInfo* cpu) {
int32_t unused;
int32_t *max_freq_pp_vec = malloc(sizeof(int32_t) * cpu->num_cpus);
struct cpuInfo* ptr = cpu;
for (uint32_t i=0; i < cpu->num_cpus; i++) {
set_cpu_module(i, cpu->num_cpus, &unused);
cpu->freq->max_pp = measure_frequency(cpu, max_freq_pp_vec);
ptr = ptr->next_cpu;
}
}
#endif
struct cpuInfo* get_cpu_info(void) {
struct cpuInfo* cpu = emalloc(sizeof(struct cpuInfo));
cpu->peak_performance = -1;
@@ -546,9 +563,7 @@ struct cpuInfo* get_cpu_info(void) {
ptr->feat = get_features_info(ptr);
ptr->arch = get_cpu_uarch(ptr);
// If accurate_pp is not requested, get it now.
if (!accurate_pp())
ptr->freq = get_frequency_info(ptr, false, NULL);
ptr->freq = get_frequency_info(ptr);
if (cpu->cpu_name == NULL && ptr == cpu) {
// If we couldnt read CPU name from cpuid, infer it now
@@ -569,21 +584,12 @@ struct cpuInfo* get_cpu_info(void) {
if(ptr->topo == NULL) return cpu;
}
// 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 unused;
int32_t *max_freq_pp_vec = NULL;
ptr = cpu;
for (uint32_t i=0; i < cpu->num_cpus; i++) {
set_cpu_module(i, cpu->num_cpus, &unused);
ptr->freq = get_frequency_info(ptr, accurate_pp(), &max_freq_pp_vec);
ptr = ptr->next_cpu;
}
}
#ifdef __linux__
// If accurate_pp is requested, we need to get the max frequency
// after fetching the topology for all CPU modules, since the topology
// is required by fill_frequency_info_pp
if (accurate_pp()) fill_frequency_info_pp(cpu);
#endif
cpu->peak_performance = get_peak_performance(cpu, accurate_pp());
@@ -950,7 +956,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) {
struct frequency* freq = emalloc(sizeof(struct frequency));
freq->measured = false;
@@ -1021,14 +1027,6 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu, bool accurate_pp, int3
#endif
freq->max_pp = UNKNOWN_DATA;
#ifdef __linux__
if(accurate_pp)
freq->max_pp = measure_frequency(cpu, max_freq_pp_vec);
#else
// Silence compiler warning
(void)(accurate_pp);
#endif
return freq;
}

View File

@@ -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);
struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, int module);
char* get_str_avx(struct cpuInfo* cpu);

View File

@@ -102,23 +102,21 @@ void* measure_freq(void *freq_ptr) {
return NULL;
}
int32_t measure_frequency(struct cpuInfo* cpu, int32_t **max_freq_pp_vec_ptr) {
int32_t measure_frequency(struct cpuInfo* cpu, int32_t *max_freq_pp_vec) {
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
// call to this function, so now just return it.
return (*max_freq_pp_vec_ptr)[cpu->module_id];
return max_freq_pp_vec[cpu->module_id];
}
*max_freq_pp_vec_ptr = malloc(sizeof(int32_t) * cpu->num_cpus);
int ret;
int num_spaces;
struct freq_thread* freq_struct = malloc(sizeof(struct freq_thread));
freq_struct->end = false;
freq_struct->measure = false;
freq_struct->cpu = cpu;
freq_struct->max_pp = *max_freq_pp_vec_ptr;
freq_struct->max_pp = max_freq_pp_vec;
void* (*compute_function)(void*);
@@ -190,5 +188,5 @@ int32_t measure_frequency(struct cpuInfo* cpu, int32_t **max_freq_pp_vec_ptr) {
}
printf("\r%*c", num_spaces, ' ');
return (*max_freq_pp_vec_ptr)[cpu->module_id];
return max_freq_pp_vec[cpu->module_id];
}

View File

@@ -8,6 +8,6 @@
#define MEASURE_TIME_SECONDS 5
#define LOOP_ITERS 100000000
int32_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