]> www.infradead.org Git - users/willy/xarray.git/commitdiff
drivers/base/arch_topology: Add infrastructure to store and update instantaneous...
authorThara Gopinath <thara.gopinath@linaro.org>
Sat, 22 Feb 2020 00:52:07 +0000 (19:52 -0500)
committerIngo Molnar <mingo@kernel.org>
Fri, 6 Mar 2020 11:57:18 +0000 (12:57 +0100)
Add architecture specific APIs to update and track thermal pressure on a
per CPU basis. A per CPU variable thermal_pressure is introduced to keep
track of instantaneous per CPU thermal pressure. Thermal pressure is the
delta between maximum capacity and capped capacity due to a thermal event.

topology_get_thermal_pressure can be hooked into the scheduler specified
arch_scale_thermal_pressure to retrieve instantaneous thermal pressure of
a CPU.

arch_set_thermal_pressure can be used to update the thermal pressure.

Considering topology_get_thermal_pressure reads thermal_pressure and
arch_set_thermal_pressure writes into thermal_pressure, one can argue for
some sort of locking mechanism to avoid a stale value.  But considering
topology_get_thermal_pressure can be called from a system critical path
like scheduler tick function, a locking mechanism is not ideal. This means
that it is possible the thermal_pressure value used to calculate average
thermal pressure for a CPU can be stale for up to 1 tick period.

Signed-off-by: Thara Gopinath <thara.gopinath@linaro.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lkml.kernel.org/r/20200222005213.3873-4-thara.gopinath@linaro.org
drivers/base/arch_topology.c
include/linux/arch_topology.h

index 6119e11a9f95a9625ab390bb7e7d6d9ab041aab9..68dfa49d3b63cb4d0287f4c89e371c36f9322da8 100644 (file)
@@ -42,6 +42,17 @@ void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
        per_cpu(cpu_scale, cpu) = capacity;
 }
 
+DEFINE_PER_CPU(unsigned long, thermal_pressure);
+
+void arch_set_thermal_pressure(struct cpumask *cpus,
+                              unsigned long th_pressure)
+{
+       int cpu;
+
+       for_each_cpu(cpu, cpus)
+               WRITE_ONCE(per_cpu(thermal_pressure, cpu), th_pressure);
+}
+
 static ssize_t cpu_capacity_show(struct device *dev,
                                 struct device_attribute *attr,
                                 char *buf)
index 3015ecbb90b131691fe3bcda3f59351f93694589..88a115e81f2769b5e9f411bbcaf646799eaa5f08 100644 (file)
@@ -33,6 +33,16 @@ unsigned long topology_get_freq_scale(int cpu)
        return per_cpu(freq_scale, cpu);
 }
 
+DECLARE_PER_CPU(unsigned long, thermal_pressure);
+
+static inline unsigned long topology_get_thermal_pressure(int cpu)
+{
+       return per_cpu(thermal_pressure, cpu);
+}
+
+void arch_set_thermal_pressure(struct cpumask *cpus,
+                              unsigned long th_pressure);
+
 struct cpu_topology {
        int thread_id;
        int core_id;