diff --git a/src/bin/system/machine/cpu.bogox b/src/bin/system/machine/cpu.bogox index b4d2ca8..56d656a 100644 --- a/src/bin/system/machine/cpu.bogox +++ b/src/bin/system/machine/cpu.bogox @@ -20,12 +20,6 @@ # define CPU_STATES 5 #endif -typedef enum { - THERMAL_UNKNOWN = 0, - THERMAL_INTEL_CORETEMP = 1, - THERMAL_AMD_AMDTEMP = 2, -} thermal_drv_t; - static int cpu_count(void) { @@ -316,13 +310,45 @@ _cpu_n_temperature_read(int n) return temp; } +#if defined(__linux__) + +typedef struct _thermal_drv { + const char *name; + void (*init)(void); +} thermal_drv; + +static void +_coretemp_init(void) +{ + int i, 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); + } +} + +static void +_k10_init(void) +{ + int i, cpu_count = system_cpu_count_get(); + + for (i = 0; i < cpu_count; i++) + snprintf(_core_temps[i], sizeof(_core_temps[i]), "%s/temp1_input", _hwmon_path); +} + +#endif + int system_cpu_n_temperature_get(int n) { #if defined(__linux__) static int init = 0; - int cpu_count, i; - thermal_drv_t type = THERMAL_UNKNOWN; + + thermal_drv drivers[] = { + { "coretemp", _coretemp_init }, + { "k10temp", _k10_init }, + }; if (!init) { @@ -351,14 +377,18 @@ system_cpu_n_temperature_get(int n) char *b = file_contents(buf); if (b) { - if (!strncmp(b, "coretemp", 8)) + for (int i = 0; i < sizeof(drivers) / sizeof(thermal_drv); i++) { - snprintf(_hwmon_path, sizeof(_hwmon_path), "%s", link); - type = THERMAL_INTEL_CORETEMP; + if (!strncmp(b, drivers[i].name, strlen(drivers[i].name))) + { + snprintf(_hwmon_path, sizeof(_hwmon_path), "%s", link); + drivers[i].init(); + } } free(b); } free(link); + if (_hwmon_path[0]) break; } closedir(dir); @@ -367,18 +397,6 @@ system_cpu_n_temperature_get(int n) if (!_hwmon_path[0]) return -1; - if (_core_temps[n][0]) - return _cpu_n_temperature_read(n); - - if (type == THERMAL_INTEL_CORETEMP) - { - 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); - } - } return _cpu_n_temperature_read(n); #elif defined(__FreeBSD__) || defined(__DragonFly__) static int init = 0;