cpu: distinguish between thermal drivers.

Each cpu arch is likely to have varying behaviours, as added, for
each the behaviour needs to be taken into account.

This is Linux only...
This commit is contained in:
Alastair Poole 2020-10-11 11:26:49 +01:00
parent 42ec39aa6c
commit 856b3acd13
1 changed files with 17 additions and 6 deletions

View File

@ -20,6 +20,12 @@
# 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)
{
@ -315,6 +321,7 @@ system_cpu_n_temperature_get(int n)
#if defined(__linux__)
static int init = 0;
int cpu_count, i;
thermal_drv_t type = THERMAL_UNKNOWN;
if (!init)
{
@ -344,7 +351,10 @@ system_cpu_n_temperature_get(int n)
if (b)
{
if (!strncmp(b, "coretemp", 8))
snprintf(_hwmon_path, sizeof(_hwmon_path), "%s", link);
{
snprintf(_hwmon_path, sizeof(_hwmon_path), "%s", link);
type = THERMAL_INTEL_CORETEMP;
}
free(b);
}
free(link);
@ -359,11 +369,12 @@ system_cpu_n_temperature_get(int n)
if (_core_temps[n][0])
return _cpu_n_temperature_read(n);
cpu_count = system_cpu_count_get();
i = 1 + ((cpu_count + n) / 2) - (cpu_count / 2);
snprintf(_core_temps[n], sizeof(_core_temps[n]), "%s/temp%d_input", _hwmon_path, i);
if (type == THERMAL_INTEL_CORETEMP)
{
cpu_count = system_cpu_count_get();
i = 1 + ((cpu_count + n) / 2) - (cpu_count / 2);
snprintf(_core_temps[n], sizeof(_core_temps[n]), "%s/temp%d_input", _hwmon_path, i);
}
return _cpu_n_temperature_read(n);
#elif defined(__FreeBSD__) || defined(__DragonFly__)
static int init = 0;