[aarch64] Getting temperature from the Generic Thermal Management

This commit is contained in:
CyrIng
2025-07-07 16:39:47 +02:00
parent 35f9a9c384
commit a9bd15efe3
5 changed files with 113 additions and 5 deletions

View File

@@ -4,7 +4,7 @@
COREFREQ_MAJOR = 2
COREFREQ_MINOR = 0
COREFREQ_REV = 7
COREFREQ_REV = 8
HW = $(shell uname -m)
CC ?= cc
WARNING ?= -Wall -Wfatal-errors

View File

@@ -126,6 +126,51 @@ static void (*ComputeThermal_None_Matrix[4])( struct FLIP_FLOP*,
[FORMULA_SCOPE_PKG ] = ComputeThermal_None_PerPkg
};
static void ComputeThermal_Celsius( struct FLIP_FLOP *CFlip,
RO(SHM_STRUCT) *RO(Shm),
unsigned int cpu )
{
COMPUTE_THERMAL(CELSIUS,
CFlip->Thermal.Temp,
CFlip->Thermal.Param,
CFlip->Thermal.Sensor);
Core_ComputeThermalLimits(&RO(Shm)->Cpu[cpu], CFlip);
}
#define ComputeThermal_Celsius_PerSMT ComputeThermal_Celsius
static void ComputeThermal_Celsius_PerCore( struct FLIP_FLOP *CFlip,
RO(SHM_STRUCT) *RO(Shm),
unsigned int cpu )
{
if ((RO(Shm)->Cpu[cpu].Topology.ThreadID == 0)
|| (RO(Shm)->Cpu[cpu].Topology.ThreadID == -1))
{
ComputeThermal_Celsius(CFlip, RO(Shm), cpu);
}
}
static void ComputeThermal_Celsius_PerPkg( struct FLIP_FLOP *CFlip,
RO(SHM_STRUCT) *RO(Shm),
unsigned int cpu )
{
if (cpu == RO(Shm)->Proc.Service.Core)
{
ComputeThermal_Celsius(CFlip, RO(Shm), cpu);
}
}
static void (*ComputeThermal_Celsius_Matrix[4])(struct FLIP_FLOP*,
RO(SHM_STRUCT)*,
unsigned int ) = \
{
[FORMULA_SCOPE_NONE] = ComputeThermal_None,
[FORMULA_SCOPE_SMT ] = ComputeThermal_Celsius_PerSMT,
[FORMULA_SCOPE_CORE] = ComputeThermal_Celsius_PerCore,
[FORMULA_SCOPE_PKG ] = ComputeThermal_Celsius_PerPkg
};
void Core_ComputeVoltageLimits(CPU_STRUCT *Cpu, struct FLIP_FLOP *CFlip)
{ /* Per Core, computes the Min CPU voltage. */
TEST_AND_SET_SENSOR( VOLTAGE, LOWEST, CFlip->Voltage.Vcore,
@@ -282,6 +327,9 @@ static void *Core_Cycle(void *arg)
unsigned int );
switch (KIND_OF_FORMULA(RO(Shm)->Proc.thermalFormula)) {
case THERMAL_KIND_CELSIUS:
ComputeThermalFormula = ComputeThermal_Celsius_Matrix;
break;
case THERMAL_KIND_NONE:
default:
ComputeThermalFormula = ComputeThermal_None_Matrix;

View File

@@ -48,6 +48,7 @@
#ifdef CONFIG_ACPI_CPPC_LIB
#include <acpi/cppc_acpi.h>
#endif
#include <linux/thermal.h>
#ifdef CONFIG_HAVE_NMI
enum {
@@ -3252,6 +3253,25 @@ static void PerCore_Reset(CORE_RO *Core)
BITWISECLR(LOCKLESS, Core->ThermalPoint.State);
}
static void PerCore_ThermalZone(CORE_RO *Core)
{
struct thermal_zone_device *tz = NULL;
switch (Core->T.Cluster.Hybrid_ID) {
case Hybrid_Secondary:
tz = thermal_zone_get_zone_by_name("littlecore-thermal");
break;
case Hybrid_Primary:
if (Core->T.CoreID & 1) {
tz = thermal_zone_get_zone_by_name("bigcore1-thermal");
} else {
tz = thermal_zone_get_zone_by_name("bigcore0-thermal");
}
break;
}
PRIVATE(OF(Core, AT(Core->Bind)))->ThermalZone = tz;
}
static void PerCore_GenericMachine(void *arg)
{
volatile PMUSERENR pmuser;
@@ -3299,6 +3319,8 @@ static void PerCore_GenericMachine(void *arg)
SystemRegisters(Core);
PerCore_ThermalZone(Core);
BITSET_CC(BUS_LOCK, PUBLIC(RO(Proc))->SPEC_CTRL_Mask, Core->Bind);
}
@@ -3969,6 +3991,18 @@ static COF_ST Compute_COF_From_PMU_Counter( unsigned long long deltaCounter,
return ratio;
}
static void Core_Thermal_Temp(CORE_RO *Core)
{
if (!IS_ERR(PRIVATE(OF(Core, AT(Core->Bind)))->ThermalZone)) {
int mcelsius;
if (thermal_zone_get_temp(PRIVATE(OF(Core, AT(Core->Bind)))->ThermalZone,
&mcelsius) == 0)
{
Core->PowerThermal.Sensor = mcelsius;
}
}
}
static enum hrtimer_restart Cycle_GenericMachine(struct hrtimer *pTimer)
{
CORE_RO *Core;
@@ -3992,6 +4026,12 @@ static enum hrtimer_restart Cycle_GenericMachine(struct hrtimer *pTimer)
{
PKG_Counters_Generic(Core, 1);
switch (SCOPE_OF_FORMULA(PUBLIC(RO(Proc))->thermalFormula)) {
case FORMULA_SCOPE_PKG:
Core_Thermal_Temp(Core);
break;
}
Delta_PTSC_OVH(PUBLIC(RO(Proc)), Core);
Save_PTSC(PUBLIC(RO(Proc)));
@@ -3999,6 +4039,19 @@ static enum hrtimer_restart Cycle_GenericMachine(struct hrtimer *pTimer)
Sys_Tick(PUBLIC(RO(Proc)));
}
switch (SCOPE_OF_FORMULA(PUBLIC(RO(Proc))->thermalFormula)) {
case FORMULA_SCOPE_CORE:
if ((Core->T.ThreadID == 0) || (Core->T.ThreadID == -1))
{
Core_Thermal_Temp(Core);
break;
}
fallthrough;
case FORMULA_SCOPE_SMT:
Core_Thermal_Temp(Core);
break;
}
Delta_INST(Core);
Delta_C0(Core);

View File

@@ -424,6 +424,7 @@ typedef struct
#ifdef CONFIG_CPU_FREQ
struct cpufreq_policy FreqPolicy;
#endif /* CONFIG_CPU_FREQ */
struct thermal_zone_device *ThermalZone;
#ifdef CONFIG_PM_OPP
struct {
signed int VID;
@@ -948,7 +949,7 @@ static ARCH Arch[ARCHITECTURES] = {
.BaseClock = BaseClock_GenericMachine,
.ClockMod = NULL,
.TurboClock = NULL,
.thermalFormula = THERMAL_FORMULA_NONE,
.thermalFormula = THERMAL_FORMULA_CELSIUS,
#ifdef CONFIG_PM_OPP
.voltageFormula = VOLTAGE_FORMULA_OPP,
#else
@@ -1284,7 +1285,7 @@ static ARCH Arch[ARCHITECTURES] = {
.BaseClock = BaseClock_GenericMachine,
.ClockMod = NULL,
.TurboClock = NULL,
.thermalFormula = THERMAL_FORMULA_NONE,
.thermalFormula = THERMAL_FORMULA_CELSIUS,
#ifdef CONFIG_PM_OPP
.voltageFormula = VOLTAGE_FORMULA_OPP,
#else

View File

@@ -603,11 +603,13 @@ enum FORMULA_SCOPE {
};
enum THERMAL_KIND {
THERMAL_KIND_NONE = 0b000000000000000000000000
THERMAL_KIND_NONE = 0b000000000000000000000000,
THERMAL_KIND_CELSIUS = 0b000000000000000000000001
};
enum THERMAL_FORMULAS {
THERMAL_FORMULA_NONE = (THERMAL_KIND_NONE << 8) | FORMULA_SCOPE_NONE
THERMAL_FORMULA_NONE = (THERMAL_KIND_NONE << 8) | FORMULA_SCOPE_NONE,
THERMAL_FORMULA_CELSIUS=(THERMAL_KIND_CELSIUS << 8) | FORMULA_SCOPE_PKG
};
enum VOLTAGE_KIND {
@@ -690,6 +692,10 @@ enum POWER_FORMULAS {
} \
})
#define COMPUTE_THERMAL_CELSIUS(Temp, Param, Sensor) \
UNUSED(Param); \
(Temp = Sensor / 1000)
#define COMPUTE_THERMAL(_ARCH_, Temp, Param, Sensor) \
COMPUTE_THERMAL_##_ARCH_(Temp, Param, Sensor)