From 5737f1ecafbd0386145ee20d6fc4205aa4104ac3 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sat, 7 Aug 2021 10:38:32 +0200 Subject: [PATCH] [v0.98][Refactoring] Do not use hv_present in get_freq_from_file --- src/arm/midr.c | 8 ++++---- src/common/udev.c | 16 ++++++---------- src/common/udev.h | 4 ++-- src/ppc/ppc.c | 4 ++-- src/x86/cpuid.c | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/arm/midr.c b/src/arm/midr.c index c9d32f1..df4fe16 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -31,7 +31,7 @@ struct frequency* get_frequency_info(uint32_t core) { struct frequency* freq = emalloc(sizeof(struct frequency)); freq->base = UNKNOWN_FREQ; - freq->max = get_max_freq_from_file(core, false); + freq->max = get_max_freq_from_file(core); return freq; } @@ -184,7 +184,7 @@ struct cpuInfo* get_cpu_info() { midr_array[i] = midr_array[0]; } - freq_array[i] = get_max_freq_from_file(i, false); + freq_array[i] = get_max_freq_from_file(i); if(freq_array[i] == UNKNOWN_FREQ) { printWarn("Unable to fetch max frequency for core %d. This is probably because the core is offline", i); freq_array[i] = freq_array[0]; @@ -272,7 +272,7 @@ void print_debug(struct cpuInfo* cpu) { for(int i=0; i < ncores; i++) { printf("[Core %d] ", i); - long freq = get_max_freq_from_file(i, false); + long freq = get_max_freq_from_file(i); uint32_t midr = get_midr_from_cpuinfo(i, &success); if(!success) { printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i); @@ -283,7 +283,7 @@ void print_debug(struct cpuInfo* cpu) { } if(freq == UNKNOWN_FREQ) { printWarn("Unable to fetch max frequency for core %d. This is probably because the core is offline", i); - printf("%ld MHz\n", get_max_freq_from_file(0, false)); + printf("%ld MHz\n", get_max_freq_from_file(0)); } else { printf("%ld MHz\n", freq); diff --git a/src/common/udev.c b/src/common/udev.c index bfcf4da..07cb568 100644 --- a/src/common/udev.c +++ b/src/common/udev.c @@ -28,15 +28,11 @@ char* read_file(char* path, int* len) { return buf; } -long get_freq_from_file(char* path, bool hv_present) { +long get_freq_from_file(char* path) { int filelen; char* buf; if((buf = read_file(path, &filelen)) == NULL) { - if(hv_present) - printWarn("Could not open '%s' (HV is present)", path); - else - printWarn("Could not open '%s'", path); - + printWarn("Could not open '%s'", path); return UNKNOWN_FREQ; } @@ -86,16 +82,16 @@ long get_cache_size_from_file(char* path) { return ret * 1024; } -long get_max_freq_from_file(uint32_t core, bool hv_present) { +long get_max_freq_from_file(uint32_t core) { char path[_PATH_FREQUENCY_MAX_LEN]; sprintf(path, "%s%s/cpu%d%s%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_FREQUENCY, _PATH_FREQUENCY_MAX); - return get_freq_from_file(path, hv_present); + return get_freq_from_file(path); } -long get_min_freq_from_file(uint32_t core, bool hv_present) { +long get_min_freq_from_file(uint32_t core) { char path[_PATH_FREQUENCY_MAX_LEN]; sprintf(path, "%s%s/cpu%d%s%s", _PATH_SYS_SYSTEM, _PATH_SYS_CPU, core, _PATH_FREQUENCY, _PATH_FREQUENCY_MIN); - return get_freq_from_file(path, hv_present); + return get_freq_from_file(path); } long get_l1i_cache_size(uint32_t core) { diff --git a/src/common/udev.h b/src/common/udev.h index 76cd6be..bcac44f 100644 --- a/src/common/udev.h +++ b/src/common/udev.h @@ -29,8 +29,8 @@ #define DEFAULT_FILE_SIZE 4096 char* read_file(char* path, int* len); -long get_max_freq_from_file(uint32_t core, bool hv_present); -long get_min_freq_from_file(uint32_t core, bool hv_present); +long get_max_freq_from_file(uint32_t core); +long get_min_freq_from_file(uint32_t core); long get_l1i_cache_size(uint32_t core); long get_l1d_cache_size(uint32_t core); long get_l2_cache_size(uint32_t core); diff --git a/src/ppc/ppc.c b/src/ppc/ppc.c index 3d8a12a..ad5dead 100644 --- a/src/ppc/ppc.c +++ b/src/ppc/ppc.c @@ -126,8 +126,8 @@ struct uarch* get_cpu_uarch(struct cpuInfo* cpu) { struct frequency* get_frequency_info() { struct frequency* freq = emalloc(sizeof(struct frequency)); - freq->max = get_max_freq_from_file(0, false); - freq->base = get_min_freq_from_file(0, false); + freq->max = get_max_freq_from_file(0); + freq->base = get_min_freq_from_file(0); return freq; } diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index 491347f..fa10431 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -659,7 +659,7 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) { #else printWarn("Can't read frequency information from cpuid (needed level is 0x%.8X, max is 0x%.8X). Using udev", 0x00000016, cpu->maxLevels); freq->base = UNKNOWN_FREQ; - freq->max = get_max_freq_from_file(0, cpu->hv->present); + freq->max = get_max_freq_from_file(0); if(freq->max == 0) { printWarn("Read max CPU frequency from udev and got 0 MHz"); @@ -686,7 +686,7 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) { printWarn("Read max CPU frequency from CPUID and got 0 MHz"); #ifdef __linux__ printWarn("Using udev to detect frequency"); - freq->max = get_max_freq_from_file(0, cpu->hv->present); + freq->max = get_max_freq_from_file(0); if(freq->max == 0) { printWarn("Read max CPU frequency from udev and got 0 MHz");