History

arch_topology, sched/core: Cleanup thermal pressure definition

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).

Valentin Schneider committed 6 years ago

Commit 25980c71 parent 27059376 files · +24 −15Browse files

Unified · Split

6 files
  1. arch/arm/include/asm/topology.h +2 −1
  2. arch/arm64/include/asm/topology.h +2 −1
  3. drivers/base/arch_topology.c +11 −0
  4. include/linux/arch_topology.h +2 −2
  5. include/linux/sched/topology.h +7 −0
  6. kernel/sched/core.c +0 −11
arch/arm/include/asm/topology.h+2−1
@@ -16,8 +16,9 @@ · 15 unmodified lines
16/* Enable topology flag updates */16/* Enable topology flag updates */
17#define arch_update_cpu_topology topology_update_cpu_topology17#define arch_update_cpu_topology topology_update_cpu_topology
18 18
19/* Replace task scheduler's default thermal pressure retrieve API */19/* Replace task scheduler's default thermal pressure API */
20#define arch_scale_thermal_pressure topology_get_thermal_pressure20#define arch_scale_thermal_pressure topology_get_thermal_pressure
21#define arch_set_thermal_pressure topology_set_thermal_pressure
21 22
22#else23#else
23 24
arch/arm64/include/asm/topology.h+2−1
@@ -34,8 +34,9 @@ void topology_scale_freq_tick(void); · 33 unmodified lines
34/* Enable topology flag updates */34/* Enable topology flag updates */
35#define arch_update_cpu_topology topology_update_cpu_topology35#define arch_update_cpu_topology topology_update_cpu_topology
36 36
37/* Replace task scheduler's default thermal pressure retrieve API */37/* Replace task scheduler's default thermal pressure API */
38#define arch_scale_thermal_pressure topology_get_thermal_pressure38#define arch_scale_thermal_pressure topology_get_thermal_pressure
39#define arch_set_thermal_pressure topology_set_thermal_pressure
39 40
40#include <asm-generic/topology.h>41#include <asm-generic/topology.h>
41 42
drivers/base/arch_topology.c+11−0
@@ -54,6 +54,17 @@ void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity) · 53 unmodified lines
54 per_cpu(cpu_scale, cpu) = capacity;54 per_cpu(cpu_scale, cpu) = capacity;
55}55}
56 56
57DEFINE_PER_CPU(unsigned long, thermal_pressure);
58
59void topology_set_thermal_pressure(const struct cpumask *cpus,
60 unsigned long th_pressure)
61{
62 int cpu;
63
64 for_each_cpu(cpu, cpus)
65 WRITE_ONCE(per_cpu(thermal_pressure, cpu), th_pressure);
66}
67
57static ssize_t cpu_capacity_show(struct device *dev,68static ssize_t cpu_capacity_show(struct device *dev,
58 struct device_attribute *attr,69 struct device_attribute *attr,
59 char *buf)70 char *buf)
include/linux/arch_topology.h+2−2
@@ -39,8 +39,8 @@ static inline unsigned long topology_get_thermal_pressure(int cpu) · 38 unmodified lines
39 return per_cpu(thermal_pressure, cpu);39 return per_cpu(thermal_pressure, cpu);
40}40}
41 41
42void arch_set_thermal_pressure(struct cpumask *cpus,42void topology_set_thermal_pressure(const struct cpumask *cpus,
43 unsigned long th_pressure);43 unsigned long th_pressure);
44 44
45struct cpu_topology {45struct cpu_topology {
46 int thread_id;46 int thread_id;
include/linux/sched/topology.h+7−0
@@ -232,6 +232,13 @@ unsigned long arch_scale_thermal_pressure(int cpu) · 231 unmodified lines
232}232}
233#endif233#endif
234 234
235#ifndef arch_set_thermal_pressure
236static __always_inline
237void arch_set_thermal_pressure(const struct cpumask *cpus,
238 unsigned long th_pressure)
239{ }
240#endif
241
235static inline int task_node(const struct task_struct *p)242static inline int task_node(const struct task_struct *p)
236{243{
237 return cpu_to_node(task_cpu(p));244 return cpu_to_node(task_cpu(p));
kernel/sched/core.c+0−11
@@ -3869,17 +3869,6 @@ unsigned long long task_sched_runtime(struct task_struct *p) · 3868 unmodified lines
3869 return ns;3869 return ns;
3870}3870}
3871 3871
3872DEFINE_PER_CPU(unsigned long, thermal_pressure);
3873
3874void arch_set_thermal_pressure(struct cpumask *cpus,
3875 unsigned long th_pressure)
3876{
3877 int cpu;
3878
3879 for_each_cpu(cpu, cpus)
3880 WRITE_ONCE(per_cpu(thermal_pressure, cpu), th_pressure);
3881}
3882
3883/*3872/*
3884 * This function gets called by the timer code, with HZ frequency.3873 * This function gets called by the timer code, with HZ frequency.
3885 * We call it with interrupts disabled.3874 * We call it with interrupts disabled.