Thread (10 messages) 10 messages, 4 authors, 2020-06-20

Re: [PATCH 1/3] thermal/cpu-cooling, sched/core: Cleanup thermal pressure definition

From: Vincent Guittot <vincent.guittot@linaro.org>
Date: 2020-06-18 15:03:41
Also in: linux-pm, lkml

On Sun, 14 Jun 2020 at 03:10, Valentin Schneider
[off-list ref] wrote:
quoted hunk ↗ jump to hunk
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, the public setter, arch_set_thermal_pressure(), is defined
unconditionally in sched/core.c while the public getter,
arch_scale_thermal_pressure(), is hardcoded to return 0 unless it has been
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.

Signed-off-by: Valentin Schneider <redacted>
---
 drivers/base/arch_topology.c      | 11 +++++++++++
 drivers/thermal/cpufreq_cooling.c |  5 +++++
 include/linux/arch_topology.h     |  3 ---
 kernel/sched/core.c               | 11 -----------
 4 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index 4d0a0038b476..d14cab7dfa3c 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -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 arch_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)
diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c
index e297e135c031..a1efd379b683 100644
--- a/drivers/thermal/cpufreq_cooling.c
+++ b/drivers/thermal/cpufreq_cooling.c
@@ -417,6 +417,11 @@ static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
        return 0;
 }

+__weak void
+arch_set_thermal_pressure(const struct cpumask *cpus, unsigned long th_pressure)
+{
+}
Having this weak function declared in cpufreq_cooling is weird. This
means that we will have to do so for each one that wants to use it.

Can't you declare an empty function in a common header file ?
quoted hunk ↗ jump to hunk
+
 /**
  * cpufreq_set_cur_state - callback function to set the current cooling state.
  * @cdev: thermal cooling device pointer.
diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h
index 0566cb3314ef..81bd1c627195 100644
--- a/include/linux/arch_topology.h
+++ b/include/linux/arch_topology.h
@@ -39,9 +39,6 @@ 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;
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 43ba2d4a8eca..7861d21f3c2b 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3628,17 +3628,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.
--
2.27.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help