From b2aa8194c63b4ec1a81d5b7c251e262c4590d56e Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Fri, 2 Dec 2022 21:25:30 +0000 Subject: [PATCH] [v1.02][x86] Detect and print core type in ADL --- src/common/cpu.h | 8 ++++++++ src/common/printer.c | 5 ++++- src/x86/cpuid.c | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/common/cpu.h b/src/common/cpu.h index b386d7c..ed08fc7 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -35,6 +35,12 @@ enum { HV_VENDOR_INVALID }; +enum { + CORE_TYPE_EFFICIENCY, + CORE_TYPE_PERFORMANCE, + CORE_TYPE_UNKNOWN +}; + #define UNKNOWN_DATA -1 #define CPU_NAME_MAX_LENGTH 64 @@ -134,6 +140,8 @@ struct cpuInfo { bool topology_extensions; // Hybrid Flag (Intel only) bool hybrid_flag; + // Core Type (P/E) + uint32_t core_type; #elif ARCH_PPC uint32_t pvr; #elif ARCH_ARM diff --git a/src/common/printer.c b/src/common/printer.c index d69538a..b0b8a0d 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -565,7 +565,10 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct color** cs, struct } if(hybrid_architecture) { - sprintf(cpu_num, "CPU %d:", i+1); + 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 printBug("Found invalid core type!\n"); + setAttribute(art, ATTRIBUTE_CPU_NUM, cpu_num); } setAttribute(art, ATTRIBUTE_FREQUENCY, max_frequency); diff --git a/src/x86/cpuid.c b/src/x86/cpuid.c index 73c1b42..bdc397d 100644 --- a/src/x86/cpuid.c +++ b/src/x86/cpuid.c @@ -402,6 +402,24 @@ bool set_cpu_module(int m, int total_modules, int32_t* first_core) { return true; } +int32_t get_core_type() { + uint32_t eax = 0x0000001A; + uint32_t ebx = 0; + uint32_t ecx = 0; + uint32_t edx = 0; + + eax = 0x0000001A; + cpuid(&eax, &ebx, &ecx, &edx); + + int32_t type = eax >> 24 & 0xFF; + if(type == 0x20) return CORE_TYPE_EFFICIENCY; + else if(type == 0x40) return CORE_TYPE_PERFORMANCE; + else { + printErr("Found invalid core type: 0x%.8X\n", type); + return CORE_TYPE_UNKNOWN; + } +} + struct cpuInfo* get_cpu_info() { struct cpuInfo* cpu = emalloc(sizeof(struct cpuInfo)); cpu->peak_performance = -1; @@ -490,6 +508,12 @@ struct cpuInfo* get_cpu_info() { ptr->hybrid_flag = cpu->hybrid_flag; } + if(cpu->hybrid_flag) { + // Detect core type + eax = 0x0000001A; + cpuid(&eax, &ebx, &ecx, &edx); + ptr->core_type = get_core_type(); + } ptr->first_core_id = first_core; ptr->feat = get_features_info(ptr);