arch_topology, sched/core: Cleanup thermal pressure definition
authorValentin Schneider <valentin.schneider@arm.com>
Sun, 12 Jul 2020 16:59:15 +0000 (17:59 +0100)
committerPeter Zijlstra <peterz@infradead.org>
Wed, 22 Jul 2020 08:22:05 +0000 (10:22 +0200)
The following commit:

  14533a16c46d ("thermal/cpu-cooling, sched/core: Move the arch_set_thermal_pressure() API to generic scheduler code")

moved the definition of arch_set_thermal_pressure() to sched/core.c, but
kept its declaration in linux/arch_topology.h. When building e.g. an x86
kernel with CONFIG_SCHED_THERMAL_PRESSURE=y, cpufreq_cooling.c ends up
getting the declaration of arch_set_thermal_pressure() from
include/linux/arch_topology.h, which is somewhat awkward.

On top of this, sched/core.c unconditionally defines
o The thermal_pressure percpu variable
o arch_set_thermal_pressure()

while arch_scale_thermal_pressure() does nothing unless redefined by the
architecture.

arch_*() functions are meant to be defined by architectures, so revert the
aforementioned commit and re-implement it in a way that keeps
arch_set_thermal_pressure() architecture-definable, and doesn't define the
thermal pressure percpu variable for kernels that don't need
it (CONFIG_SCHED_THERMAL_PRESSURE=n).

Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200712165917.9168-2-valentin.schneider@arm.com
arch/arm/include/asm/topology.h
arch/arm64/include/asm/topology.h
drivers/base/arch_topology.c
include/linux/arch_topology.h
include/linux/sched/topology.h
kernel/sched/core.c

index 435aba289fc55c84a88c3a6cd9208fd7a1942c77..e0593cf095d05a68bfd784f260c6859548320b7d 100644 (file)
@@ -16,8 +16,9 @@
 /* Enable topology flag updates */
 #define arch_update_cpu_topology topology_update_cpu_topology
 
-/* Replace task scheduler's default thermal pressure retrieve API */
+/* Replace task scheduler's default thermal pressure API */
 #define arch_scale_thermal_pressure topology_get_thermal_pressure
+#define arch_set_thermal_pressure   topology_set_thermal_pressure
 
 #else
 
index 0cc835ddfcd14bbeafdf0336777f4342a96a9515..e042f6527981e8cef88e69a6fb66315e9d89bc59 100644 (file)
@@ -34,8 +34,9 @@ void topology_scale_freq_tick(void);
 /* Enable topology flag updates */
 #define arch_update_cpu_topology topology_update_cpu_topology
 
-/* Replace task scheduler's default thermal pressure retrieve API */
+/* Replace task scheduler's default thermal pressure API */
 #define arch_scale_thermal_pressure topology_get_thermal_pressure
+#define arch_set_thermal_pressure   topology_set_thermal_pressure
 
 #include <asm-generic/topology.h>
 
index 4d0a0038b476e4a6d12ff980f5f882b8cb8e4d03..75f72d684294174565fcdfb2e50f84a348ba2fbc 100644 (file)
@@ -54,6 +54,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 topology_set_thermal_pressure(const 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 0566cb3314ef428aa0170842bfbd7a6cf091e684..69b1dabe39dc33e693f2e7a0f9fecc24241848ff 100644 (file)
@@ -39,8 +39,8 @@ 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);
+void topology_set_thermal_pressure(const struct cpumask *cpus,
+                                  unsigned long th_pressure);
 
 struct cpu_topology {
        int thread_id;
index fb11091129b3133ee8be0698abf11e8e688cb9d8..764222d637b75879e7fb911d9c16dfa27a2dfd21 100644 (file)
@@ -232,6 +232,13 @@ unsigned long arch_scale_thermal_pressure(int cpu)
 }
 #endif
 
+#ifndef arch_set_thermal_pressure
+static __always_inline
+void arch_set_thermal_pressure(const struct cpumask *cpus,
+                              unsigned long th_pressure)
+{ }
+#endif
+
 static inline int task_node(const struct task_struct *p)
 {
        return cpu_to_node(task_cpu(p));
index 12db8fbd9c97a84b6e60c31b72fe654f15cb8fde..bd8e5211d31f75a31f07280443ec9ffbfe8fd9cc 100644 (file)
@@ -3869,17 +3869,6 @@ unsigned long long task_sched_runtime(struct task_struct *p)
        return ns;
 }
 
-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);
-}
-
 /*
  * This function gets called by the timer code, with HZ frequency.
  * We call it with interrupts disabled.