Compare commits

..

3 Commits
i255 ... i253

7 changed files with 69 additions and 140 deletions

View File

@@ -175,7 +175,6 @@ Thanks to the fellow contributors and interested people in the project. Special
- [mdoksa76](https://github.com/mdoksa76) and [exkc](https://github.com/exkc): Excellent ideas and feedback for supporting Allwinner SoCs. - [mdoksa76](https://github.com/mdoksa76) and [exkc](https://github.com/exkc): Excellent ideas and feedback for supporting Allwinner SoCs.
- [Sakura286](https://github.com/Sakura286), [exkc](https://github.com/exkc) and [Patola](https://github.com/Patola): Helped with RISC-V port with ssh access, ideas, testing, etc. - [Sakura286](https://github.com/Sakura286), [exkc](https://github.com/exkc) and [Patola](https://github.com/Patola): Helped with RISC-V port with ssh access, ideas, testing, etc.
- [ThomasKaiser](https://github.com/ThomasKaiser): Very valuable feedback on improving ARM SoC detection (Apple, Allwinner, Rockchip). - [ThomasKaiser](https://github.com/ThomasKaiser): Very valuable feedback on improving ARM SoC detection (Apple, Allwinner, Rockchip).
- [zerkerX](https://github.com/zerkerX): Helped with feedback for supporting old (e.g., Pentium III) Intel CPUs.
## 8. cpufetch for GPUs (gpufetch) ## 8. cpufetch for GPUs (gpufetch)
See [gpufetch](https://github.com/Dr-Noob/gpufetch) project! See [gpufetch](https://github.com/Dr-Noob/gpufetch) project!

View File

@@ -45,9 +45,8 @@ enum {
}; };
enum { enum {
CORE_TYPE_PERFORMANCE,
CORE_TYPE_EFFICIENCY, CORE_TYPE_EFFICIENCY,
CORE_TYPE_LP_EFFICIENCY, CORE_TYPE_PERFORMANCE,
CORE_TYPE_UNKNOWN CORE_TYPE_UNKNOWN
}; };

View File

@@ -614,9 +614,8 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct
} }
if(hybrid_architecture) { if(hybrid_architecture) {
if (ptr->core_type == CORE_TYPE_PERFORMANCE) sprintf(cpu_num, "P-cores:"); if(ptr->core_type == CORE_TYPE_EFFICIENCY) sprintf(cpu_num, "E-cores:");
else if (ptr->core_type == CORE_TYPE_EFFICIENCY) sprintf(cpu_num, "E-cores:"); else if(ptr->core_type == CORE_TYPE_PERFORMANCE) sprintf(cpu_num, "P-cores:");
else if (ptr->core_type == CORE_TYPE_LP_EFFICIENCY) sprintf(cpu_num, "LP-E-cores:");
else printBug("Found invalid core type!\n"); else printBug("Found invalid core type!\n");
setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num); setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num);

View File

@@ -91,7 +91,6 @@ int get_total_cores_module(int total_cores, int module) {
while(!end) { while(!end) {
if(!bind_to_cpu(i)) { if(!bind_to_cpu(i)) {
printBug("get_total_cores_module: Cannot bind to core %d", i);
return -1; return -1;
} }
uint32_t eax = 0x0000001A; uint32_t eax = 0x0000001A;
@@ -100,17 +99,6 @@ int get_total_cores_module(int total_cores, int module) {
uint32_t edx = 0; uint32_t edx = 0;
cpuid(&eax, &ebx, &ecx, &edx); cpuid(&eax, &ebx, &ecx, &edx);
int32_t core_type = eax >> 24 & 0xFF; int32_t core_type = eax >> 24 & 0xFF;
// Here we artificially create a new core type for
// LP-E cores. In case the core has no L3 (on a hybrid)
// architecture, then we now it's an LP-E core.
eax = 0x4;
ebx = 0;
ecx = 0x3;
edx = 0;
cpuid(&eax, &ebx, &ecx, &edx);
core_type += eax == 0;
bool found = false; bool found = false;
for(int j=0; j < total_modules && !found; j++) { for(int j=0; j < total_modules && !found; j++) {

View File

@@ -137,31 +137,39 @@ bool abbreviate_intel_cpu_name(char** name) {
char* new_name_ptr = new_name; char* new_name_ptr = new_name;
char* aux_ptr = NULL; char* aux_ptr = NULL;
// 1. Find "Intel(R)" // 1. Remove "(R)"
old_name_ptr = strstr(old_name_ptr, "Intel(R)"); old_name_ptr = strstr(old_name_ptr, "Intel(R)");
if(old_name_ptr == NULL) return false; if(old_name_ptr == NULL) return false;
strcpy(new_name_ptr, "Intel");
new_name_ptr += strlen("Intel");
old_name_ptr += strlen("Intel(R)");
// 2. Search for "@" // 2. Remove "(R)" or "(TM)"
aux_ptr = strstr(old_name_ptr, "(");
if(aux_ptr == NULL) return false;
strncpy(new_name_ptr, old_name_ptr, aux_ptr-old_name_ptr);
new_name_ptr += aux_ptr-old_name_ptr;
strcpy(new_name_ptr, " ");
new_name_ptr++;
old_name_ptr = strstr(aux_ptr, ")");
if(old_name_ptr == NULL) return false;
old_name_ptr++;
while(*old_name_ptr == ' ') old_name_ptr++;
// 3. Copy the CPU name
aux_ptr = strstr(old_name_ptr, "@"); aux_ptr = strstr(old_name_ptr, "@");
if(aux_ptr == NULL) { if(aux_ptr == NULL) return false;
// New CPUs, copy end ptr is end of string strncpy(new_name_ptr, old_name_ptr, (aux_ptr-1)-old_name_ptr);
aux_ptr = old_name + strlen(old_name);
strncpy(new_name_ptr, old_name_ptr, (aux_ptr)-old_name_ptr);
}
else {
// Copy end ptr is "@"
strncpy(new_name_ptr, old_name_ptr, (aux_ptr-1)-old_name_ptr);
}
// 3. Remove dummy strings in Intel CPU names // 4. Remove dummy strings in Intel CPU names
strremove(new_name, "(R)");
strremove(new_name, "(TM)");
strremove(new_name, " CPU"); strremove(new_name, " CPU");
strremove(new_name, " Dual"); strremove(new_name, " Dual");
strremove(new_name, " 0"); strremove(new_name, " 0");
free(old_name); free(old_name);
*name = new_name; *name = new_name;
return true; return true;
} }
@@ -389,17 +397,6 @@ bool set_cpu_module(int m, int total_modules, int32_t* first_core) {
uint32_t edx = 0; uint32_t edx = 0;
cpuid(&eax, &ebx, &ecx, &edx); cpuid(&eax, &ebx, &ecx, &edx);
int32_t core_type = eax >> 24 & 0xFF; int32_t core_type = eax >> 24 & 0xFF;
// Here we artificially create a new core type for
// LP-E cores. In case the core has no L3 (on a hybrid)
// architecture, then we now it's an LP-E core.
eax = 0x4;
ebx = 0;
ecx = 0x3;
edx = 0;
cpuid(&eax, &ebx, &ecx, &edx);
core_type += eax == 0;
bool found = false; bool found = false;
for(int j=0; j < total_modules && !found; j++) { for(int j=0; j < total_modules && !found; j++) {
@@ -426,19 +423,13 @@ bool set_cpu_module(int m, int total_modules, int32_t* first_core) {
#endif #endif
} }
else { else {
// This is a non-hybrid architecture // This is a normal architecture
*first_core = 0; *first_core = 0;
} }
return true; return true;
} }
// Difference between E and LP-E cores:
// According to Intel Core Ultra Processor Datasheet Volume 1 of 2
// (https://www.intel.com/content/www/us/en/content-details/792044/intel-core-ultra-processor-datasheet-volume-1-of-2.html),
// LP-E cores do not have L3 cache. This seems to be the only way of differentiating them.
// - https://community.intel.com/t5/Processors/Detecting-LP-E-Cores-on-Meteor-Lake-in-software/m-p/1584555/highlight/true#M70732
// - https://x.com/InstLatX64/status/1741416428538941718
int32_t get_core_type(void) { int32_t get_core_type(void) {
uint32_t eax = 0x0000001A; uint32_t eax = 0x0000001A;
uint32_t ebx = 0; uint32_t ebx = 0;
@@ -449,26 +440,8 @@ int32_t get_core_type(void) {
cpuid(&eax, &ebx, &ecx, &edx); cpuid(&eax, &ebx, &ecx, &edx);
int32_t type = eax >> 24 & 0xFF; int32_t type = eax >> 24 & 0xFF;
if (type == 0x40) return CORE_TYPE_PERFORMANCE; if(type == 0x20) return CORE_TYPE_EFFICIENCY;
else if (type == 0x20) { else if(type == 0x40) return CORE_TYPE_PERFORMANCE;
// get_core_type is only called iff hybrid_flag is true, which can only
// happen if CPUID maxLevel >= 0x7 so we can assume the CPU supports
// CPUID leaf 0x4
eax = 0x4;
ebx = 0;
ecx = 0x3;
edx = 0;
cpuid(&eax, &ebx, &ecx, &edx);
if (eax == 0) {
// No L3 access, this is LP-E
return CORE_TYPE_LP_EFFICIENCY;
}
else {
return CORE_TYPE_EFFICIENCY;
}
}
else { else {
printErr("Found invalid core type: 0x%.8X\n", type); printErr("Found invalid core type: 0x%.8X\n", type);
return CORE_TYPE_UNKNOWN; return CORE_TYPE_UNKNOWN;
@@ -483,6 +456,7 @@ struct cpuInfo* get_cpu_info(void) {
cpu->cach = NULL; cpu->cach = NULL;
cpu->feat = NULL; cpu->feat = NULL;
cpu->num_cpus = 1;
uint32_t eax = 0; uint32_t eax = 0;
uint32_t ebx = 0; uint32_t ebx = 0;
uint32_t ecx = 0; uint32_t ecx = 0;
@@ -540,13 +514,7 @@ struct cpuInfo* get_cpu_info(void) {
cpu->hybrid_flag = (edx >> 15) & 0x1; cpu->hybrid_flag = (edx >> 15) & 0x1;
} }
if(cpu->hybrid_flag) { if(cpu->hybrid_flag) cpu->num_cpus = 2;
struct uarch* tmp = get_cpu_uarch(cpu);
cpu->num_cpus = get_hybrid_num_cpus(tmp);
}
else {
cpu->num_cpus = 1;
}
struct cpuInfo* ptr = cpu; struct cpuInfo* ptr = cpu;
for(uint32_t i=0; i < cpu->num_cpus; i++) { for(uint32_t i=0; i < cpu->num_cpus; i++) {
@@ -561,9 +529,8 @@ struct cpuInfo* get_cpu_info(void) {
ptr->topo = NULL; ptr->topo = NULL;
ptr->cach = NULL; ptr->cach = NULL;
ptr->feat = NULL; ptr->feat = NULL;
// We assume that this core has the // We assume that this cores have the
// same cpuid capabilities as the core in the // same cpuid capabilities
// first module
ptr->cpu_vendor = cpu->cpu_vendor; ptr->cpu_vendor = cpu->cpu_vendor;
ptr->maxLevels = cpu->maxLevels; ptr->maxLevels = cpu->maxLevels;
ptr->maxExtendedLevels = cpu->maxExtendedLevels; ptr->maxExtendedLevels = cpu->maxExtendedLevels;
@@ -689,15 +656,10 @@ bool get_cache_topology_amd(struct cpuInfo* cpu, struct topology* topo) {
void get_topology_from_udev(struct topology* topo) { void get_topology_from_udev(struct topology* topo) {
topo->total_cores = get_ncores_from_cpuinfo(); topo->total_cores = get_ncores_from_cpuinfo();
// TODO: To be improved in the future // TODO: To be improved in the future
if (topo->total_cores == 1) { // Conservative setting as we only know the total
// We can assume it's a single core CPU // number of cores.
topo->logical_cores = topo->total_cores; topo->logical_cores = UNKNOWN_DATA;
topo->physical_cores = topo->total_cores; topo->physical_cores = UNKNOWN_DATA;
}
else {
topo->logical_cores = UNKNOWN_DATA;
topo->physical_cores = UNKNOWN_DATA;
}
topo->smt_available = 1; topo->smt_available = 1;
topo->smt_supported = 1; topo->smt_supported = 1;
topo->sockets = 1; topo->sockets = 1;
@@ -733,8 +695,6 @@ struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, int
if(cpu->hybrid_flag) { if(cpu->hybrid_flag) {
#ifdef __linux__ #ifdef __linux__
topo->total_cores_module = get_total_cores_module(topo->total_cores, module); topo->total_cores_module = get_total_cores_module(topo->total_cores, module);
printBug("get_total_cores_module: Failed to get number of cores in module");
return NULL;
#else #else
UNUSED(module); UNUSED(module);
topo->total_cores_module = topo->total_cores; topo->total_cores_module = topo->total_cores;
@@ -746,25 +706,27 @@ struct topology* get_topology_info(struct cpuInfo* cpu, struct cache* cach, int
switch(cpu->cpu_vendor) { switch(cpu->cpu_vendor) {
case CPU_VENDOR_INTEL: case CPU_VENDOR_INTEL:
bool toporet = false;
if (cpu->maxLevels >= 0x00000004) { if (cpu->maxLevels >= 0x00000004) {
toporet = get_topology_from_apic(cpu, topo); bool toporet = get_topology_from_apic(cpu, topo);
if(!toporet) {
#ifdef __linux__
printWarn("Failed to retrieve topology from APIC, using udev...\n");
get_topology_from_udev(topo);
#else
printErr("Failed to retrieve topology from APIC, assumming default values...\n");
topo->logical_cores = UNKNOWN_DATA;
topo->physical_cores = UNKNOWN_DATA;
topo->smt_available = 1;
topo->smt_supported = 1;
#endif
}
} }
else { else {
printWarn("Can't read topology information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x00000004, cpu->maxLevels); printWarn("Can't read topology information from cpuid (needed level is 0x%.8X, max is 0x%.8X)", 0x00000001, cpu->maxLevels);
} topo->physical_cores = UNKNOWN_DATA;
if(!toporet) { topo->logical_cores = UNKNOWN_DATA;
#ifdef __linux__ topo->smt_available = 1;
printWarn("Failed to retrieve topology from APIC, using udev..."); topo->smt_supported = 1;
get_topology_from_udev(topo);
#else
if (cpu->maxLevels >= 0x00000004)
printErr("Failed to retrieve topology from APIC, assumming default values...");
topo->logical_cores = UNKNOWN_DATA;
topo->physical_cores = UNKNOWN_DATA;
topo->smt_available = 1;
topo->smt_supported = 1;
#endif
} }
break; break;
case CPU_VENDOR_AMD: case CPU_VENDOR_AMD:
@@ -1044,34 +1006,25 @@ char* get_str_topology(struct cpuInfo* cpu, struct topology* topo, bool dual_soc
string = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1)); string = emalloc(sizeof(char) * (strlen(STRING_UNKNOWN) + 1));
strcpy(string, STRING_UNKNOWN); strcpy(string, STRING_UNKNOWN);
} }
else { else if(topo->smt_supported > 1) {
char cores_str[6]; // 4 for digits, 21 for ' cores (SMT disabled)' which is the longest possible output
memset(cores_str, 0, sizeof(char) * 6); uint32_t max_size = 4+21+1;
if (topo->physical_cores * topo_sockets > 1) string = emalloc(sizeof(char) * max_size);
strcpy(cores_str, "cores");
else
strcpy(cores_str, "core");
if(topo->smt_supported > 1) { if(topo->smt_available > 1)
// 4 for digits, 21 for ' cores (SMT disabled)' which is the longest possible output snprintf(string, max_size, "%d cores (%d threads)", topo->physical_cores * topo_sockets, topo->logical_cores * topo_sockets);
uint32_t max_size = 4+21+1;
string = emalloc(sizeof(char) * max_size);
if(topo->smt_available > 1)
snprintf(string, max_size, "%d %s (%d threads)", topo->physical_cores * topo_sockets, cores_str, topo->logical_cores * topo_sockets);
else {
if(cpu->cpu_vendor == CPU_VENDOR_AMD)
snprintf(string, max_size, "%d %s (SMT disabled)", topo->physical_cores * topo_sockets, cores_str);
else
snprintf(string, max_size, "%d %s (HT disabled)", topo->physical_cores * topo_sockets, cores_str);
}
}
else { else {
uint32_t max_size = 4+7+1; if(cpu->cpu_vendor == CPU_VENDOR_AMD)
string = emalloc(sizeof(char) * max_size); snprintf(string, max_size, "%d cores (SMT disabled)", topo->physical_cores * topo_sockets);
snprintf(string, max_size, "%d %s",topo->physical_cores * topo_sockets, cores_str); else
snprintf(string, max_size, "%d cores (HT disabled)", topo->physical_cores * topo_sockets);
} }
} }
else {
uint32_t max_size = 4+7+1;
string = emalloc(sizeof(char) * max_size);
snprintf(string, max_size, "%d cores",topo->physical_cores * topo_sockets);
}
return string; return string;
} }

View File

@@ -94,7 +94,6 @@ enum {
UARCH_TIGER_LAKE, UARCH_TIGER_LAKE,
UARCH_ALDER_LAKE, UARCH_ALDER_LAKE,
UARCH_RAPTOR_LAKE, UARCH_RAPTOR_LAKE,
UARCH_METEOR_LAKE,
// AMD // // AMD //
UARCH_AM486, UARCH_AM486,
UARCH_AM5X86, UARCH_AM5X86,
@@ -249,7 +248,6 @@ struct uarch* get_uarch_from_cpuid_intel(uint32_t ef, uint32_t f, uint32_t em, u
CHECK_UARCH(arch, 0, 6, 10, 5, NA, "Comet Lake", UARCH_COMET_LAKE, 14) // wikichip CHECK_UARCH(arch, 0, 6, 10, 5, NA, "Comet Lake", UARCH_COMET_LAKE, 14) // wikichip
CHECK_UARCH(arch, 0, 6, 10, 6, NA, "Comet Lake", UARCH_COMET_LAKE, 14) // instlatx64.atw.hu (i7-10710U) CHECK_UARCH(arch, 0, 6, 10, 6, NA, "Comet Lake", UARCH_COMET_LAKE, 14) // instlatx64.atw.hu (i7-10710U)
CHECK_UARCH(arch, 0, 6, 10, 7, NA, "Rocket Lake", UARCH_ROCKET_LAKE, 14) // instlatx64.atw.hu (i7-11700K) CHECK_UARCH(arch, 0, 6, 10, 7, NA, "Rocket Lake", UARCH_ROCKET_LAKE, 14) // instlatx64.atw.hu (i7-11700K)
CHECK_UARCH(arch, 0, 6, 10, 10, NA, "Meteor Lake", UARCH_METEOR_LAKE, 7) // instlatx64.atw.hu (Ultra 7 155H)
CHECK_UARCH(arch, 0, 6, 11, 7, NA, "Raptor Lake", UARCH_RAPTOR_LAKE, 10) // instlatx64.atw.hu (i5-13600K) CHECK_UARCH(arch, 0, 6, 11, 7, NA, "Raptor Lake", UARCH_RAPTOR_LAKE, 10) // instlatx64.atw.hu (i5-13600K)
CHECK_UARCH(arch, 0, 6, 11, 10, NA, "Raptor Lake", UARCH_RAPTOR_LAKE, 10) // instlatx64.atw.hu (i7-1370P) CHECK_UARCH(arch, 0, 6, 11, 10, NA, "Raptor Lake", UARCH_RAPTOR_LAKE, 10) // instlatx64.atw.hu (i7-1370P)
CHECK_UARCH(arch, 0, 6, 11, 14, NA, "Alder Lake", UARCH_ALDER_LAKE, 10) // instlatx64.atw.hu (Alder Lake-N) CHECK_UARCH(arch, 0, 6, 11, 14, NA, "Alder Lake", UARCH_ALDER_LAKE, 10) // instlatx64.atw.hu (Alder Lake-N)
@@ -538,7 +536,6 @@ int get_number_of_vpus(struct cpuInfo* cpu) {
case UARCH_TIGER_LAKE: case UARCH_TIGER_LAKE:
case UARCH_ALDER_LAKE: case UARCH_ALDER_LAKE:
case UARCH_RAPTOR_LAKE: case UARCH_RAPTOR_LAKE:
case UARCH_METEOR_LAKE:
// AMD // AMD
case UARCH_ZEN2: case UARCH_ZEN2:
@@ -552,11 +549,6 @@ int get_number_of_vpus(struct cpuInfo* cpu) {
} }
} }
uint32_t get_hybrid_num_cpus(struct uarch* arch) {
if (arch->uarch == UARCH_METEOR_LAKE) return 3;
else return 2;
}
bool choose_new_intel_logo_uarch(struct cpuInfo* cpu) { bool choose_new_intel_logo_uarch(struct cpuInfo* cpu) {
switch(cpu->arch->uarch) { switch(cpu->arch->uarch) {
case UARCH_ALDER_LAKE: case UARCH_ALDER_LAKE:

View File

@@ -12,7 +12,6 @@ char* infer_cpu_name_from_uarch(struct uarch* arch);
bool vpus_are_AVX512(struct cpuInfo* cpu); bool vpus_are_AVX512(struct cpuInfo* cpu);
bool is_knights_landing(struct cpuInfo* cpu); bool is_knights_landing(struct cpuInfo* cpu);
int get_number_of_vpus(struct cpuInfo* cpu); int get_number_of_vpus(struct cpuInfo* cpu);
uint32_t get_hybrid_num_cpus(struct uarch* arch);
bool choose_new_intel_logo_uarch(struct cpuInfo* cpu); bool choose_new_intel_logo_uarch(struct cpuInfo* cpu);
char* get_str_uarch(struct cpuInfo* cpu); char* get_str_uarch(struct cpuInfo* cpu);
char* get_str_process(struct cpuInfo* cpu); char* get_str_process(struct cpuInfo* cpu);