mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
Looks good but need to fix bug first
This commit is contained in:
@@ -21,8 +21,11 @@
|
|||||||
#define FREQ_VECTOR_SIZE 1<<16
|
#define FREQ_VECTOR_SIZE 1<<16
|
||||||
|
|
||||||
struct freq_thread {
|
struct freq_thread {
|
||||||
|
// Inputs
|
||||||
|
struct cpuInfo* cpu;
|
||||||
bool end;
|
bool end;
|
||||||
bool measure;
|
bool measure;
|
||||||
|
// Output
|
||||||
double freq;
|
double freq;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,6 +51,7 @@ void* measure_freq(void *freq_ptr) {
|
|||||||
char* line = NULL;
|
char* line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ssize_t read;
|
ssize_t read;
|
||||||
|
struct cpuInfo* cpu = freq->cpu;
|
||||||
|
|
||||||
int v = 0;
|
int v = 0;
|
||||||
double* freq_vector = malloc(sizeof(double) * FREQ_VECTOR_SIZE);
|
double* freq_vector = malloc(sizeof(double) * FREQ_VECTOR_SIZE);
|
||||||
@@ -76,18 +80,46 @@ void* measure_freq(void *freq_ptr) {
|
|||||||
sleep_ms(500);
|
sleep_ms(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
freq->freq = vector_average_harmonic(freq_vector, v);
|
if (cpu->hybrid_flag) {
|
||||||
printWarn("AVX2 measured freq=%f\n", freq->freq);
|
// We have an heterogeneous architecture. After measuring the
|
||||||
|
// frequency for all cores, we now need to compute the average
|
||||||
|
// independently for each CPU module.
|
||||||
|
struct cpuInfo* ptr = cpu;
|
||||||
|
double* freq_vector_ptr = freq_vector;
|
||||||
|
|
||||||
|
for (int i=0; i < cpu->num_cpus; ptr = ptr->next_cpu, i++) {
|
||||||
|
double average_freq = vector_average_harmonic(freq_vector_ptr, ptr->topo->total_cores_module);
|
||||||
|
|
||||||
|
ptr->freq->max = (int32_t) average_freq;
|
||||||
|
printWarn("AVX2 measured freq=%d (module %d)", ptr->freq->max, i);
|
||||||
|
|
||||||
|
freq_vector_ptr = freq_vector_ptr + ptr->topo->total_cores_module;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
double average_freq = vector_average_harmonic(freq_vector, v);
|
||||||
|
|
||||||
|
cpu->freq->max = (int32_t) average_freq;
|
||||||
|
printWarn("AVX2 measured freq=%d\n", cpu->freq->max);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t measure_frequency(struct cpuInfo* cpu) {
|
int64_t measure_frequency(struct cpuInfo* cpu) {
|
||||||
|
if (cpu->hybrid_flag && cpu->first_core_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 get_freq(cpu->freq);
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
void* (*compute_function)(void*);
|
void* (*compute_function)(void*);
|
||||||
|
|
||||||
@@ -159,5 +191,5 @@ int64_t measure_frequency(struct cpuInfo* cpu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("\r%*c", num_spaces, ' ');
|
printf("\r%*c", num_spaces, ' ');
|
||||||
return freq_struct->freq;
|
return cpu->freq->max;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user