[v0.98][Refactoring] Do not use hv_present in get_freq_from_file

This commit is contained in:
Dr-Noob
2021-08-07 10:38:32 +02:00
parent fba69daee0
commit 5737f1ecaf
5 changed files with 16 additions and 20 deletions

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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");