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
1616 /* Enable topology flag updates */
1717 #define arch_update_cpu_topology topology_update_cpu_topology
1818
19−/* Replace task scheduler's default thermal pressure retrieve API */
19+/* Replace task scheduler's default thermal pressure API */
2020 #define arch_scale_thermal_pressure topology_get_thermal_pressure
21+#define arch_set_thermal_pressure topology_set_thermal_pressure
2122
2223 #else
2324
arch/arm64/include/asm/topology.h+2−1
@@ -34,8 +34,9 @@ void topology_scale_freq_tick(void); · 33 unmodified lines
3434 /* Enable topology flag updates */
3535 #define arch_update_cpu_topology topology_update_cpu_topology
3636
37−/* Replace task scheduler's default thermal pressure retrieve API */
37+/* Replace task scheduler's default thermal pressure API */
3838 #define arch_scale_thermal_pressure topology_get_thermal_pressure
39+#define arch_set_thermal_pressure topology_set_thermal_pressure
3940
4041 #include <asm-generic/topology.h>
4142
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
5454 per_cpu(cpu_scale, cpu) = capacity;
5555 }
5656
57+DEFINE_PER_CPU(unsigned long, thermal_pressure);
58+
59+void 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+
5768 static ssize_t cpu_capacity_show(struct device *dev,
5869 struct device_attribute *attr,
5970 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
3939 return per_cpu(thermal_pressure, cpu);
4040 }
4141
42−void arch_set_thermal_pressure(struct cpumask *cpus,
43− unsigned long th_pressure);
42+void topology_set_thermal_pressure(const struct cpumask *cpus,
43+ unsigned long th_pressure);
4444
4545 struct cpu_topology {
4646 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
232232 }
233233 #endif
234234
235+#ifndef arch_set_thermal_pressure
236+static __always_inline
237+void arch_set_thermal_pressure(const struct cpumask *cpus,
238+ unsigned long th_pressure)
239+{ }
240+#endif
241+
235242 static inline int task_node(const struct task_struct *p)
236243 {
237244 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
38693869 return ns;
38703870 }
38713871
3872−DEFINE_PER_CPU(unsigned long, thermal_pressure);
3873−
3874−void 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−
38833872 /*
38843873 * This function gets called by the timer code, with HZ frequency.
38853874 * We call it with interrupts disabled.