mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-25 07:50:40 +01:00
[v0.94][x86] Consider missing frequency file in x86_64 as a bug if no hypervisor is present. Took this idea from issue #37. Add if hypervisor is present to debug mode to prevent more confusions in the future
This commit is contained in:
@@ -52,7 +52,7 @@ struct frequency* get_frequency_info(uint32_t core) {
|
|||||||
struct frequency* freq = malloc(sizeof(struct frequency));
|
struct frequency* freq = malloc(sizeof(struct frequency));
|
||||||
|
|
||||||
freq->base = UNKNOWN_FREQ;
|
freq->base = UNKNOWN_FREQ;
|
||||||
freq->max = get_max_freq_from_file(core);
|
freq->max = get_max_freq_from_file(core, false);
|
||||||
|
|
||||||
return freq;
|
return freq;
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ struct cpuInfo* get_cpu_info() {
|
|||||||
midr_array[i] = midr_array[0];
|
midr_array[i] = midr_array[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
freq_array[i] = get_max_freq_from_file(i);
|
freq_array[i] = get_max_freq_from_file(i, false);
|
||||||
if(freq_array[i] == UNKNOWN_FREQ) {
|
if(freq_array[i] == UNKNOWN_FREQ) {
|
||||||
printWarn("Unable to fetch max frequency for core %d. This is probably because the core is offline", i);
|
printWarn("Unable to fetch max frequency for core %d. This is probably because the core is offline", i);
|
||||||
freq_array[i] = freq_array[0];
|
freq_array[i] = freq_array[0];
|
||||||
@@ -306,7 +306,7 @@ void print_debug(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
for(int i=0; i < ncores; i++) {
|
for(int i=0; i < ncores; i++) {
|
||||||
printf("[Core %d] ", i);
|
printf("[Core %d] ", i);
|
||||||
long freq = get_max_freq_from_file(i);
|
long freq = get_max_freq_from_file(i, false);
|
||||||
uint32_t midr = get_midr_from_cpuinfo(i, &success);
|
uint32_t midr = get_midr_from_cpuinfo(i, &success);
|
||||||
if(!success) {
|
if(!success) {
|
||||||
printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i);
|
printWarn("Unable to fetch MIDR for core %d. This is probably because the core is offline", i);
|
||||||
@@ -317,7 +317,7 @@ void print_debug(struct cpuInfo* cpu) {
|
|||||||
}
|
}
|
||||||
if(freq == UNKNOWN_FREQ) {
|
if(freq == UNKNOWN_FREQ) {
|
||||||
printWarn("Unable to fetch max frequency for core %d. This is probably because the core is offline", i);
|
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));
|
printf("%ld MHz\n", get_max_freq_from_file(0, false));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printf("%ld MHz\n", freq);
|
printf("%ld MHz\n", freq);
|
||||||
|
|||||||
@@ -28,11 +28,21 @@ char* read_file(char* path, int* len) {
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
long get_freq_from_file(char* path) {
|
long get_freq_from_file(char* path, bool hv_present) {
|
||||||
int filelen;
|
int filelen;
|
||||||
char* buf;
|
char* buf;
|
||||||
if((buf = read_file(path, &filelen)) == NULL) {
|
if((buf = read_file(path, &filelen)) == NULL) {
|
||||||
|
#ifdef ARCH_X86
|
||||||
|
if(hv_present) {
|
||||||
printWarn("Could not open '%s'", path);
|
printWarn("Could not open '%s'", path);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
perror("open");
|
||||||
|
printBug("Could not open '%s'", path);
|
||||||
|
}
|
||||||
|
#elif ARCH_ARM
|
||||||
|
printWarn("Could not open '%s'", path);
|
||||||
|
#endif
|
||||||
return UNKNOWN_FREQ;
|
return UNKNOWN_FREQ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,14 +69,14 @@ long get_freq_from_file(char* path) {
|
|||||||
return ret/1000;
|
return ret/1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
long get_max_freq_from_file(uint32_t core) {
|
long get_max_freq_from_file(uint32_t core, bool hv_present) {
|
||||||
char path[_PATH_FREQUENCY_MAX_LEN];
|
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);
|
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);
|
return get_freq_from_file(path, hv_present);
|
||||||
}
|
}
|
||||||
|
|
||||||
long get_min_freq_from_file(uint32_t core) {
|
long get_min_freq_from_file(uint32_t core, bool hv_present) {
|
||||||
char path[_PATH_FREQUENCY_MAX_LEN];
|
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);
|
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);
|
return get_freq_from_file(path, hv_present);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "cpu.h"
|
||||||
|
|
||||||
#define _PATH_SYS_SYSTEM "/sys/devices/system"
|
#define _PATH_SYS_SYSTEM "/sys/devices/system"
|
||||||
#define _PATH_SYS_CPU "/cpu"
|
#define _PATH_SYS_CPU "/cpu"
|
||||||
#define _PATH_FREQUENCY "/cpufreq"
|
#define _PATH_FREQUENCY "/cpufreq"
|
||||||
@@ -20,7 +22,7 @@
|
|||||||
#define DEFAULT_FILE_SIZE 4096
|
#define DEFAULT_FILE_SIZE 4096
|
||||||
|
|
||||||
char* read_file(char* path, int* len);
|
char* read_file(char* path, int* len);
|
||||||
long get_max_freq_from_file(uint32_t core);
|
long get_max_freq_from_file(uint32_t core, bool hv_present);
|
||||||
long get_min_freq_from_file(uint32_t core);
|
long get_min_freq_from_file(uint32_t core, bool hv_present);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -661,13 +661,28 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
if(cpu->maxLevels < 0x00000016) {
|
if(cpu->maxLevels < 0x00000016) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
if(cpu->hv->present) {
|
||||||
|
printWarn("Can't read frequency information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x00000016, cpu->maxLevels);
|
||||||
|
}
|
||||||
|
else {
|
||||||
printErr("Can't read frequency information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x00000016, cpu->maxLevels);
|
printErr("Can't read frequency information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x00000016, cpu->maxLevels);
|
||||||
|
}
|
||||||
freq->base = UNKNOWN_FREQ;
|
freq->base = UNKNOWN_FREQ;
|
||||||
freq->max = UNKNOWN_FREQ;
|
freq->max = UNKNOWN_FREQ;
|
||||||
#else
|
#else
|
||||||
printWarn("Can't read frequency information from cpuid (needed level is 0x%.8X, max is 0x%.8X). Using udev", 0x00000016, cpu->maxLevels);
|
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->base = UNKNOWN_FREQ;
|
||||||
freq->max = get_max_freq_from_file(0);
|
freq->max = get_max_freq_from_file(0, cpu->hv->present);
|
||||||
|
|
||||||
|
if(freq->max == 0) {
|
||||||
|
if(cpu->hv->present) {
|
||||||
|
printWarn("Read max CPU frequency and got 0 MHz");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printBug("Read max CPU frequency and got 0 MHz");
|
||||||
|
}
|
||||||
|
freq->max = UNKNOWN_FREQ;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -682,11 +697,21 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
|||||||
freq->max = ebx;
|
freq->max = ebx;
|
||||||
|
|
||||||
if(freq->base == 0) {
|
if(freq->base == 0) {
|
||||||
|
if(cpu->hv->present) {
|
||||||
printWarn("Read base CPU frequency and got 0 MHz");
|
printWarn("Read base CPU frequency and got 0 MHz");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printBug("Read base CPU frequency and got 0 MHz");
|
||||||
|
}
|
||||||
freq->base = UNKNOWN_FREQ;
|
freq->base = UNKNOWN_FREQ;
|
||||||
}
|
}
|
||||||
if(freq->max == 0) {
|
if(freq->max == 0) {
|
||||||
|
if(cpu->hv->present) {
|
||||||
printWarn("Read max CPU frequency and got 0 MHz");
|
printWarn("Read max CPU frequency and got 0 MHz");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printBug("Read max CPU frequency and got 0 MHz");
|
||||||
|
}
|
||||||
freq->max = UNKNOWN_FREQ;
|
freq->max = UNKNOWN_FREQ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -870,6 +895,7 @@ char* get_str_fma(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
void print_debug(struct cpuInfo* cpu) {
|
void print_debug(struct cpuInfo* cpu) {
|
||||||
printf("%s\n", cpu->cpu_name);
|
printf("%s\n", cpu->cpu_name);
|
||||||
|
if(cpu->hv->present) printf("- Hypervisor: %s\n", cpu->hv->hv_name);
|
||||||
printf("- Max standard level: 0x%.8X\n", cpu->maxLevels);
|
printf("- Max standard level: 0x%.8X\n", cpu->maxLevels);
|
||||||
printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels);
|
printf("- Max extended level: 0x%.8X\n", cpu->maxExtendedLevels);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user