netstar pushed a commit to branch master.

http://git.enlightenment.org/apps/evisum.git/commit/?id=3ec2144f893ea3c8707adb17ac56f75f4c53e7d6

commit 3ec2144f893ea3c8707adb17ac56f75f4c53e7d6
Author: Alastair Poole <nets...@gmail.com>
Date:   Wed Oct 14 11:32:41 2020 +0100

    coretemp: take topology into account
---
 src/bin/system/machine/cpu.bogox | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/bin/system/machine/cpu.bogox b/src/bin/system/machine/cpu.bogox
index 56d656a..8fcc805 100644
--- a/src/bin/system/machine/cpu.bogox
+++ b/src/bin/system/machine/cpu.bogox
@@ -279,6 +279,9 @@ system_cpu_usage_get(int *ncpu)
    return system_cpu_usage_delayed_get(ncpu, 1000000);
 }
 
+
+static int  _cpu_temp_min = 0;
+static int  _cpu_temp_max = 100;
 static char _core_temps[256][512];
 static char _hwmon_path[256];
 
@@ -315,16 +318,26 @@ _cpu_n_temperature_read(int n)
 typedef struct _thermal_drv {
    const char *name;
    void (*init)(void);
+   char min;
+   char max;
 } thermal_drv;
 
 static void
 _coretemp_init(void)
 {
-   int i, cpu_count = system_cpu_count_get();
+   char buf[4096];
+   int cpu_count = system_cpu_count_get();
+
    for (int j = 0; j < cpu_count; j++)
      {
-        i = 2 + ((cpu_count + j) / 2) - (cpu_count / 2);
-        snprintf(_core_temps[j], sizeof(_core_temps[j]), "%s/temp%d_input", 
_hwmon_path, i);
+        snprintf(buf, sizeof(buf), 
"/sys/devices/system/cpu/cpu%i/topology/core_id", j);
+        char *b = file_contents(buf);
+        if (b)
+          {
+             int core_id = atoi(b);
+             snprintf(_core_temps[j], sizeof(_core_temps[j]), 
"%s/temp%d_input", _hwmon_path, 2 + core_id);
+             free(b);
+          }
      }
 }
 
@@ -346,8 +359,8 @@ system_cpu_n_temperature_get(int n)
    static int init = 0;
 
    thermal_drv drivers[] = {
-      { "coretemp", _coretemp_init },
-      { "k10temp", _k10_init },
+      { "coretemp", _coretemp_init, 0, 100 },
+      { "k10temp", _k10_init, 0, 100 },
    };
 
    if (!init)
@@ -415,8 +428,9 @@ system_cpu_n_temperature_get(int n)
 int
 system_cpu_temperature_min_max_get(int *min, int *max)
 {
-   *min = 20;
-   *max = 100;
+
+   *min = _cpu_temp_min;
+   *max = _cpu_temp_max;
 
    return 0;
 }

-- 


Reply via email to