Skip to content

Commit 25980c7

Browse files
Valentin SchneiderPeter Zijlstra
authored andcommitted
arch_topology, sched/core: Cleanup thermal pressure definition
The following commit: 14533a1 ("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 <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 2705937 commit 25980c7

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

arch/arm/include/asm/topology.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ void topology_scale_freq_tick(void);
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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ static inline unsigned long topology_get_thermal_pressure(int cpu)
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,13 @@ unsigned long arch_scale_thermal_pressure(int cpu)
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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,17 +3869,6 @@ unsigned long long task_sched_runtime(struct task_struct *p)
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.

0 commit comments

Comments
 (0)