From 0e0482d54fc39967cb746c981d9ff6514915ac23 Mon Sep 17 00:00:00 2001 From: a Date: Wed, 21 Sep 2016 08:45:16 +0200 Subject: [PATCH] get_cpu_info now handles newer Intel cpus --- README.md | 2 +- src/cpu.c | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9ca624c..1d362c0 100644 --- a/README.md +++ b/README.md @@ -640,7 +640,7 @@ With the help from the gcc documentation, this wish list option has been solved. GPU temperature, voltage, fan(s) and used RAM: hard, but not impossible. -It would be nice to have decent gpu temperature, voltage, fan(s) speed and used RAM detection regarding SLI, single and dual gpu cards that doesn't require X and/or MESA. +It would be nice to have decent gpu temperature, voltage, fan(s) speed and used RAM detection regarding SLI, single and dual gpu cards that doesn't require X, MESA and **/sys/kernel/debug/dri** Using assembly is strongly no-go. diff --git a/src/cpu.c b/src/cpu.c index 6e42b5c..575f25f 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -287,7 +287,8 @@ void get_cpu_info(char *str1) { char buffer[VLA], vend_id[13], vend_chars[17]; char *all = buffer; - uint_fast16_t vend = 0, x = 0, z = 0, corez = 0, bitz[2]; + bool got_leafB = false; + uint_fast16_t vend = 0, x = 0, z = 0, corez = 0, bitz[2], leafB = 0; uint_fast16_t eax = 0, ecx = 0, edx = 0, ebx = 0, eax_old = 0; uint_fast16_t line_size = 0, regz = 0, clflu6 = 0, caches[3]; @@ -331,6 +332,22 @@ get_cpu_info(char *str1) { CPU_STR2(0x80000005, eax, ebx, ecx, edx); /* movl $0x80000005, %eax */ caches[0] = SHFT2(ecx >> (3 * 8)); /* movl %ecx, 24 */ } + CPU_STR2(1, eax, ebx, ecx, edx); /* movl $0x00000001, %eax */ + corez = SHFT2(ebx >> (2 * 8)); /* movl %ebx, 16 */ + } + + if (vend == InteL) { + CPU_FEATURE(0x0000000B, eax); /* movl $0x0000000B, %eax */ + if (0x0000000B <= eax) { + CPU_STR2(0x0000000B, eax, ebx, ecx, edx); + corez = SHFT2(ebx); /* movl %ebx, 0 */ + leafB = SHFT2(edx); /* movl %edx, 0 */ + got_leafB = true; + + } else { + CPU_STR2(4, eax, ebx, ecx, edx); /* movl $0x00000004, %eax */ + corez = SHFT2(eax >> 26); /* movl %eax, 26 */ + } } if (0x80000006 <= regz) { @@ -350,9 +367,6 @@ get_cpu_info(char *str1) { CPU_STR2(1, eax, ebx, ecx, edx); /* movl $0x00000001, %eax */ clflu6 = SHFT2(ebx >> 8); /* movl %ebx, 8 */ - /* Newer intel cpu's rely on 0B */ - corez = SHFT2(ebx >> (2 * 8)); /* movl %ebx, 16 */ - FILL_ARR(str1, UFINT "x %s ID %s " "CLFLUSH/Line size " UFINT " " UFINT @@ -367,7 +381,7 @@ get_cpu_info(char *str1) { SHFT(eax_old), (SHFT(eax_old >> 8) + SHFT2(eax_old >> 20)), (SHFT(eax_old >> 4) | ((eax_old >> 12) & 0xf0)), bitz[0], bitz[1], - SHFT2(ebx >> 24) + (true == got_leafB) ? leafB : SHFT2(ebx >> 24) ); } } -- 2.11.0