mirror of
https://github.com/Dr-Noob/cpufetch.git
synced 2026-03-24 23:40:39 +01:00
[v1.00][X86] Show unknown string when the number of cores cannot be retrieved (like #119)
This commit is contained in:
@@ -45,7 +45,7 @@ struct cache* get_cache_info(struct cpuInfo* cpu) {
|
|||||||
struct frequency* get_frequency_info(uint32_t core) {
|
struct frequency* get_frequency_info(uint32_t core) {
|
||||||
struct frequency* freq = emalloc(sizeof(struct frequency));
|
struct frequency* freq = emalloc(sizeof(struct frequency));
|
||||||
|
|
||||||
freq->base = UNKNOWN_FREQ;
|
freq->base = UNKNOWN_DATA;
|
||||||
freq->max = get_max_freq_from_file(core);
|
freq->max = get_max_freq_from_file(core);
|
||||||
|
|
||||||
return freq;
|
return freq;
|
||||||
@@ -81,7 +81,7 @@ int64_t get_peak_performance(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
//First check we have consistent data
|
//First check we have consistent data
|
||||||
for(int i=0; i < cpu->num_cpus; ptr = ptr->next_cpu, i++) {
|
for(int i=0; i < cpu->num_cpus; ptr = ptr->next_cpu, i++) {
|
||||||
if(get_freq(ptr->freq) == UNKNOWN_FREQ) {
|
if(get_freq(ptr->freq) == UNKNOWN_DATA) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ struct cpuInfo* get_cpu_info_linux(struct cpuInfo* cpu) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
freq_array[i] = get_max_freq_from_file(i);
|
freq_array[i] = get_max_freq_from_file(i);
|
||||||
if(freq_array[i] == UNKNOWN_FREQ) {
|
if(freq_array[i] == UNKNOWN_DATA) {
|
||||||
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];
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ void fill_cpu_info_firestorm_icestorm(struct cpuInfo* cpu) {
|
|||||||
ice->topo->cach = ice->cach;
|
ice->topo->cach = ice->cach;
|
||||||
ice->topo->total_cores = 4;
|
ice->topo->total_cores = 4;
|
||||||
ice->freq = malloc(sizeof(struct frequency));
|
ice->freq = malloc(sizeof(struct frequency));
|
||||||
ice->freq->base = UNKNOWN_FREQ;
|
ice->freq->base = UNKNOWN_DATA;
|
||||||
ice->freq->max = 2064;
|
ice->freq->max = 2064;
|
||||||
ice->hv = malloc(sizeof(struct hypervisor));
|
ice->hv = malloc(sizeof(struct hypervisor));
|
||||||
ice->hv->present = false;
|
ice->hv->present = false;
|
||||||
@@ -272,7 +272,7 @@ void fill_cpu_info_firestorm_icestorm(struct cpuInfo* cpu) {
|
|||||||
fire->topo->cach = fire->cach;
|
fire->topo->cach = fire->cach;
|
||||||
fire->topo->total_cores = 4;
|
fire->topo->total_cores = 4;
|
||||||
fire->freq = malloc(sizeof(struct frequency));
|
fire->freq = malloc(sizeof(struct frequency));
|
||||||
fire->freq->base = UNKNOWN_FREQ;
|
fire->freq->base = UNKNOWN_DATA;
|
||||||
fire->freq->max = 3200;
|
fire->freq->max = 3200;
|
||||||
fire->hv = malloc(sizeof(struct hypervisor));
|
fire->hv = malloc(sizeof(struct hypervisor));
|
||||||
fire->hv->present = false;
|
fire->hv->present = false;
|
||||||
@@ -368,7 +368,7 @@ void print_debug(struct cpuInfo* cpu) {
|
|||||||
else {
|
else {
|
||||||
printf("0x%.8X ", midr);
|
printf("0x%.8X ", midr);
|
||||||
}
|
}
|
||||||
if(freq == UNKNOWN_FREQ) {
|
if(freq == UNKNOWN_DATA) {
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ char* get_str_freq(struct frequency* freq) {
|
|||||||
char* string = emalloc(sizeof(char)*size);
|
char* string = emalloc(sizeof(char)*size);
|
||||||
memset(string, 0, sizeof(char)*size);
|
memset(string, 0, sizeof(char)*size);
|
||||||
|
|
||||||
if(freq->max == UNKNOWN_FREQ || freq->max < 0)
|
if(freq->max == UNKNOWN_DATA || freq->max < 0)
|
||||||
snprintf(string,strlen(STRING_UNKNOWN)+1,STRING_UNKNOWN);
|
snprintf(string,strlen(STRING_UNKNOWN)+1,STRING_UNKNOWN);
|
||||||
else if(freq->max >= 1000)
|
else if(freq->max >= 1000)
|
||||||
snprintf(string,size,"%.3f "STRING_GIGAHERZ,(float)(freq->max)/1000);
|
snprintf(string,size,"%.3f "STRING_GIGAHERZ,(float)(freq->max)/1000);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ enum {
|
|||||||
HV_VENDOR_INVALID
|
HV_VENDOR_INVALID
|
||||||
};
|
};
|
||||||
|
|
||||||
#define UNKNOWN_FREQ -1
|
#define UNKNOWN_DATA -1
|
||||||
#define CPU_NAME_MAX_LENGTH 64
|
#define CPU_NAME_MAX_LENGTH 64
|
||||||
|
|
||||||
typedef int32_t VENDOR;
|
typedef int32_t VENDOR;
|
||||||
@@ -71,8 +71,8 @@ struct topology {
|
|||||||
int32_t total_cores;
|
int32_t total_cores;
|
||||||
struct cache* cach;
|
struct cache* cach;
|
||||||
#if defined(ARCH_X86) || defined(ARCH_PPC)
|
#if defined(ARCH_X86) || defined(ARCH_PPC)
|
||||||
uint32_t physical_cores;
|
int32_t physical_cores;
|
||||||
uint32_t logical_cores;
|
int32_t logical_cores;
|
||||||
uint32_t sockets;
|
uint32_t sockets;
|
||||||
uint32_t smt_supported; // Number of SMT that CPU supports (equal to smt_available if SMT is enabled)
|
uint32_t smt_supported; // Number of SMT that CPU supports (equal to smt_available if SMT is enabled)
|
||||||
#ifdef ARCH_X86
|
#ifdef ARCH_X86
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ long get_freq_from_file(char* path) {
|
|||||||
char* buf;
|
char* buf;
|
||||||
if((buf = read_file(path, &filelen)) == NULL) {
|
if((buf = read_file(path, &filelen)) == NULL) {
|
||||||
printWarn("Could not open '%s'", path);
|
printWarn("Could not open '%s'", path);
|
||||||
return UNKNOWN_FREQ;
|
return UNKNOWN_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* end;
|
char* end;
|
||||||
@@ -42,7 +42,7 @@ long get_freq_from_file(char* path) {
|
|||||||
if(errno != 0) {
|
if(errno != 0) {
|
||||||
printBug("strtol: %s", strerror(errno));
|
printBug("strtol: %s", strerror(errno));
|
||||||
free(buf);
|
free(buf);
|
||||||
return UNKNOWN_FREQ;
|
return UNKNOWN_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We will be getting the frequency in KHz
|
// We will be getting the frequency in KHz
|
||||||
@@ -50,7 +50,7 @@ long get_freq_from_file(char* path) {
|
|||||||
// greater than 10 GHz or less than 100 MHz
|
// greater than 10 GHz or less than 100 MHz
|
||||||
if(ret > 10000 * 1000 || ret < 100 * 1000) {
|
if(ret > 10000 * 1000 || ret < 100 * 1000) {
|
||||||
printBug("Invalid data was read from file '%s': %ld\n", path, ret);
|
printBug("Invalid data was read from file '%s': %ld\n", path, ret);
|
||||||
return UNKNOWN_FREQ;
|
return UNKNOWN_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ int64_t get_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
//First check we have consistent data
|
//First check we have consistent data
|
||||||
if(freq == UNKNOWN_FREQ) {
|
if(freq == UNKNOWN_DATA) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ bool fill_apic_ids(uint32_t* apic_ids, int n, bool x2apic_id) {
|
|||||||
|
|
||||||
for(int i=0; i < n; i++) {
|
for(int i=0; i < n; i++) {
|
||||||
if(!bind_to_cpu(i)) {
|
if(!bind_to_cpu(i)) {
|
||||||
printErr("Failed binding to CPU %d", i);
|
printErr("Failed binding the process to CPU %d", i);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
apic_ids[i] = get_apic_id(x2apic_id);
|
apic_ids[i] = get_apic_id(x2apic_id);
|
||||||
@@ -385,8 +385,13 @@ bool get_topology_from_apic(struct cpuInfo* cpu, struct topology* topo) {
|
|||||||
|
|
||||||
get_cache_topology_from_apic(topo);
|
get_cache_topology_from_apic(topo);
|
||||||
|
|
||||||
if(!fill_apic_ids(apic_ids, topo->total_cores, x2apic_id))
|
if(!fill_apic_ids(apic_ids, topo->total_cores, x2apic_id)) {
|
||||||
|
topo->logical_cores = UNKNOWN_DATA;
|
||||||
|
topo->physical_cores = UNKNOWN_DATA;
|
||||||
|
topo->smt_available = 1;
|
||||||
|
topo->smt_supported = 1;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i=0; i < topo->total_cores; i++) {
|
for(int i=0; i < topo->total_cores; i++) {
|
||||||
apic_id = apic_ids[i];
|
apic_id = apic_ids[i];
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ int64_t get_peak_performance(struct cpuInfo* cpu, struct topology* topo, int64_t
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//First, check we have consistent data
|
//First, check we have consistent data
|
||||||
if(freq == UNKNOWN_FREQ) {
|
if(freq == UNKNOWN_DATA || topo->logical_cores == UNKNOWN_DATA) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,16 +710,16 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
|||||||
if(cpu->maxLevels < 0x00000016) {
|
if(cpu->maxLevels < 0x00000016) {
|
||||||
#if defined (_WIN32) || defined (__APPLE__)
|
#if defined (_WIN32) || defined (__APPLE__)
|
||||||
printWarn("Can't read frequency information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x00000016, cpu->maxLevels);
|
printWarn("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_DATA;
|
||||||
freq->max = UNKNOWN_FREQ;
|
freq->max = UNKNOWN_DATA;
|
||||||
#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_DATA;
|
||||||
freq->max = get_max_freq_from_file(0);
|
freq->max = get_max_freq_from_file(0);
|
||||||
|
|
||||||
if(freq->max == 0) {
|
if(freq->max == 0) {
|
||||||
printWarn("Read max CPU frequency from udev and got 0 MHz");
|
printWarn("Read max CPU frequency from udev and got 0 MHz");
|
||||||
freq->max = UNKNOWN_FREQ;
|
freq->max = UNKNOWN_DATA;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -736,7 +736,7 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
if(freq->base == 0) {
|
if(freq->base == 0) {
|
||||||
printWarn("Read base CPU frequency from CPUID and got 0 MHz");
|
printWarn("Read base CPU frequency from CPUID and got 0 MHz");
|
||||||
freq->base = UNKNOWN_FREQ;
|
freq->base = UNKNOWN_DATA;
|
||||||
}
|
}
|
||||||
if(freq->max == 0) {
|
if(freq->max == 0) {
|
||||||
printWarn("Read max CPU frequency from CPUID and got 0 MHz");
|
printWarn("Read max CPU frequency from CPUID and got 0 MHz");
|
||||||
@@ -746,10 +746,10 @@ struct frequency* get_frequency_info(struct cpuInfo* cpu) {
|
|||||||
|
|
||||||
if(freq->max == 0) {
|
if(freq->max == 0) {
|
||||||
printWarn("Read max CPU frequency from udev and got 0 MHz");
|
printWarn("Read max CPU frequency from udev and got 0 MHz");
|
||||||
freq->max = UNKNOWN_FREQ;
|
freq->max = UNKNOWN_DATA;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
freq->max = UNKNOWN_FREQ;
|
freq->max = UNKNOWN_DATA;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -771,7 +771,11 @@ char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_soc
|
|||||||
int topo_sockets = dual_socket ? topo->sockets : 1;
|
int topo_sockets = dual_socket ? topo->sockets : 1;
|
||||||
char* string;
|
char* string;
|
||||||
|
|
||||||
if(topo->smt_supported > 1) {
|
if(topo->logical_cores == UNKNOWN_DATA) {
|
||||||
|
string = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1));
|
||||||
|
strcpy(string, STRING_UNKNOWN);
|
||||||
|
}
|
||||||
|
else if(topo->smt_supported > 1) {
|
||||||
// 4 for digits, 21 for ' cores (SMT disabled)' which is the longest possible output
|
// 4 for digits, 21 for ' cores (SMT disabled)' which is the longest possible output
|
||||||
uint32_t max_size = 4+21+1;
|
uint32_t max_size = 4+21+1;
|
||||||
string = emalloc(sizeof(char) * max_size);
|
string = emalloc(sizeof(char) * max_size);
|
||||||
|
|||||||
Reference in New Issue
Block a user