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).
Unified · Split
| @@ -16,8 +16,9 @@ · 15 unmodified lines | ||
| 16 | 16 | /* Enable topology flag updates */ |
| 17 | 17 | #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 | 20 | #define arch_scale_thermal_pressure topology_get_thermal_pressure |
| 21 | +#define arch_set_thermal_pressure topology_set_thermal_pressure | |
| 21 | 22 | |
| 22 | 23 | #else |
| 23 | 24 | |
| @@ -34,8 +34,9 @@ void topology_scale_freq_tick(void); · 33 unmodified lines | ||
| 34 | 34 | /* Enable topology flag updates */ |
| 35 | 35 | #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 | 38 | #define arch_scale_thermal_pressure topology_get_thermal_pressure |
| 39 | +#define arch_set_thermal_pressure topology_set_thermal_pressure | |
| 39 | 40 | |
| 40 | 41 | #include <asm-generic/topology.h> |
| 41 | 42 | |
| @@ -54,6 +54,17 @@ void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity) · 53 unmodified lines | ||
| 54 | 54 | per_cpu(cpu_scale, cpu) = capacity; |
| 55 | 55 | } |
| 56 | 56 | |
| 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 | + | |
| 57 | 68 | static ssize_t cpu_capacity_show(struct device *dev, |
| 58 | 69 | struct device_attribute *attr, |
| 59 | 70 | char *buf) |
| @@ -39,8 +39,8 @@ static inline unsigned long topology_get_thermal_pressure(int cpu) · 38 unmodified lines | ||
| 39 | 39 | return per_cpu(thermal_pressure, cpu); |
| 40 | 40 | } |
| 41 | 41 | |
| 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); | |
| 44 | 44 | |
| 45 | 45 | struct cpu_topology { |
| 46 | 46 | int thread_id; |
| @@ -232,6 +232,13 @@ unsigned long arch_scale_thermal_pressure(int cpu) · 231 unmodified lines | ||
| 232 | 232 | } |
| 233 | 233 | #endif |
| 234 | 234 | |
| 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 | + | |
| 235 | 242 | static inline int task_node(const struct task_struct *p) |
| 236 | 243 | { |
| 237 | 244 | return cpu_to_node(task_cpu(p)); |
| @@ -3869,17 +3869,6 @@ unsigned long long task_sched_runtime(struct task_struct *p) · 3868 unmodified lines | ||
| 3869 | 3869 | return ns; |
| 3870 | 3870 | } |
| 3871 | 3871 | |
| 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 | − | |
| 3883 | 3872 | /* |
| 3884 | 3873 | * This function gets called by the timer code, with HZ frequency. |
| 3885 | 3874 | * We call it with interrupts disabled. |