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* get_cpu_info(void) {
struct cpuInfo* cpu = emalloc(sizeof(struct cpuInfo)); struct cpuInfo* cpu = emalloc(sizeof(struct cpuInfo));
cpu->peak_performance = -1; cpu->peak_performance = -1;
@@ -546,9 +563,7 @@ struct cpuInfo* get_cpu_info(void) {
ptr->feat = get_features_info(ptr); ptr->feat = get_features_info(ptr);
ptr->arch = get_cpu_uarch(ptr); ptr->arch = get_cpu_uarch(ptr);
// If accurate_pp is not requested, get it now. ptr->freq = get_frequency_info(ptr);
if (!accurate_pp())
ptr->freq = get_frequency_info(ptr, false, NULL);
if (cpu->cpu_name == NULL && ptr == cpu) { if (cpu->cpu_name == NULL && ptr == cpu) {
// If we couldnt read CPU name from cpuid, infer it now // 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(ptr->topo == NULL) return cpu;
} }
// If accurate_pp is requested, we need to get the frequency #ifdef __linux__
// after fetching the topology for all CPU modules (this information // If accurate_pp is requested, we need to get the max frequency
// is required by get_frequency_info) // after fetching the topology for all CPU modules, since the topology
if (accurate_pp()) { // is required by fill_frequency_info_pp
int32_t unused; if (accurate_pp()) fill_frequency_info_pp(cpu);
int32_t *max_freq_pp_vec = NULL; #endif
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;
}
}
cpu->peak_performance = get_peak_performance(cpu, accurate_pp()); cpu->peak_performance = get_peak_performance(cpu, accurate_pp());
@@ -950,7 +956,7 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
return cach; 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)); struct frequency* freq = emalloc(sizeof(struct frequency));
freq->measured = false; freq->measured = false;
@@ -1021,14 +1027,6 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu, bool accurate_pp, int3
#endif #endif
freq->max_pp = UNKNOWN_DATA; 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; return freq;
} }

View File

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

View File

@@ -102,23 +102,21 @@ void* measure_freq(void *freq_ptr) {
return NULL; 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) { if (cpu->hybrid_flag && cpu->module_id > 0) {
// We have a hybrid architecture and we have already // We have a hybrid architecture and we have already
// measured the frequency for this module in a previous // measured the frequency for this module in a previous
// call to this function, so now just return it. // 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 ret;
int num_spaces; int num_spaces;
struct freq_thread* freq_struct = malloc(sizeof(struct freq_thread)); struct freq_thread* freq_struct = malloc(sizeof(struct freq_thread));
freq_struct->end = false; freq_struct->end = false;
freq_struct->measure = false; freq_struct->measure = false;
freq_struct->cpu = cpu; 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*); 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, ' '); 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 MEASURE_TIME_SECONDS 5
#define LOOP_ITERS 100000000 #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 #endif