Skip to content

Commit 06d3ad0

Browse files
committed
arch_topology: Relocate cpu_scale to topology.[h|c]
JIRA: https://issues.redhat.com/browse/RHEL-112493 commit 6bceea7 Author: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Date: Fri Apr 18 19:55:03 2025 -0700 arch_topology: Relocate cpu_scale to topology.[h|c] arch_topology.c provides functionality to parse and scale CPU capacity. It also provides a corresponding sysfs interface. Some architectures parse and scale CPU capacity differently as per their own needs. On Intel processors, for instance, it is responsibility of the Intel P-state driver. Relocate the implementation of that interface to a common location in topology.c. Architectures can use the interface and populate it using their own mechanisms. An alternative approach would be to compile arch_topology.c even if not needed only to get this interface. This approach would create duplicated and conflicting functionality and data structures. Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Tested-by: Christian Loehle <christian.loehle@arm.com> Link: https://patch.msgid.link/20250419025504.9760-2-ricardo.neri-calderon@linux.intel.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent 6504a83 commit 06d3ad0

File tree

4 files changed

+61
-60
lines changed

4 files changed

+61
-60
lines changed

drivers/base/arch_topology.c

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,6 @@ void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq,
152152
per_cpu(arch_freq_scale, i) = scale;
153153
}
154154

155-
DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE;
156-
EXPORT_PER_CPU_SYMBOL_GPL(cpu_scale);
157-
158-
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
159-
{
160-
per_cpu(cpu_scale, cpu) = capacity;
161-
}
162-
163155
DEFINE_PER_CPU(unsigned long, hw_pressure);
164156

165157
/**
@@ -205,53 +197,9 @@ void topology_update_hw_pressure(const struct cpumask *cpus,
205197
}
206198
EXPORT_SYMBOL_GPL(topology_update_hw_pressure);
207199

208-
static ssize_t cpu_capacity_show(struct device *dev,
209-
struct device_attribute *attr,
210-
char *buf)
211-
{
212-
struct cpu *cpu = container_of(dev, struct cpu, dev);
213-
214-
return sysfs_emit(buf, "%lu\n", topology_get_cpu_scale(cpu->dev.id));
215-
}
216-
217200
static void update_topology_flags_workfn(struct work_struct *work);
218201
static DECLARE_WORK(update_topology_flags_work, update_topology_flags_workfn);
219202

220-
static DEVICE_ATTR_RO(cpu_capacity);
221-
222-
static int cpu_capacity_sysctl_add(unsigned int cpu)
223-
{
224-
struct device *cpu_dev = get_cpu_device(cpu);
225-
226-
if (!cpu_dev)
227-
return -ENOENT;
228-
229-
device_create_file(cpu_dev, &dev_attr_cpu_capacity);
230-
231-
return 0;
232-
}
233-
234-
static int cpu_capacity_sysctl_remove(unsigned int cpu)
235-
{
236-
struct device *cpu_dev = get_cpu_device(cpu);
237-
238-
if (!cpu_dev)
239-
return -ENOENT;
240-
241-
device_remove_file(cpu_dev, &dev_attr_cpu_capacity);
242-
243-
return 0;
244-
}
245-
246-
static int register_cpu_capacity_sysctl(void)
247-
{
248-
cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity",
249-
cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove);
250-
251-
return 0;
252-
}
253-
subsys_initcall(register_cpu_capacity_sysctl);
254-
255203
static int update_topology;
256204

257205
int topology_update_cpu_topology(void)

drivers/base/topology.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,55 @@ static int __init topology_sysfs_init(void)
208208
}
209209

210210
device_initcall(topology_sysfs_init);
211+
212+
DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE;
213+
EXPORT_PER_CPU_SYMBOL_GPL(cpu_scale);
214+
215+
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
216+
{
217+
per_cpu(cpu_scale, cpu) = capacity;
218+
}
219+
220+
static ssize_t cpu_capacity_show(struct device *dev,
221+
struct device_attribute *attr,
222+
char *buf)
223+
{
224+
struct cpu *cpu = container_of(dev, struct cpu, dev);
225+
226+
return sysfs_emit(buf, "%lu\n", topology_get_cpu_scale(cpu->dev.id));
227+
}
228+
229+
static DEVICE_ATTR_RO(cpu_capacity);
230+
231+
static int cpu_capacity_sysctl_add(unsigned int cpu)
232+
{
233+
struct device *cpu_dev = get_cpu_device(cpu);
234+
235+
if (!cpu_dev)
236+
return -ENOENT;
237+
238+
device_create_file(cpu_dev, &dev_attr_cpu_capacity);
239+
240+
return 0;
241+
}
242+
243+
static int cpu_capacity_sysctl_remove(unsigned int cpu)
244+
{
245+
struct device *cpu_dev = get_cpu_device(cpu);
246+
247+
if (!cpu_dev)
248+
return -ENOENT;
249+
250+
device_remove_file(cpu_dev, &dev_attr_cpu_capacity);
251+
252+
return 0;
253+
}
254+
255+
static int register_cpu_capacity_sysctl(void)
256+
{
257+
cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity",
258+
cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove);
259+
260+
return 0;
261+
}
262+
subsys_initcall(register_cpu_capacity_sysctl);

include/linux/arch_topology.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ int topology_update_cpu_topology(void);
1414
struct device_node;
1515
bool topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu);
1616

17-
DECLARE_PER_CPU(unsigned long, cpu_scale);
18-
19-
static inline unsigned long topology_get_cpu_scale(int cpu)
20-
{
21-
return per_cpu(cpu_scale, cpu);
22-
}
23-
24-
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
2517

2618
DECLARE_PER_CPU(unsigned long, capacity_freq_ref);
2719

include/linux/topology.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,13 @@ sched_numa_hop_mask(unsigned int node, unsigned int hops)
279279
!IS_ERR_OR_NULL(mask); \
280280
__hops++)
281281

282+
DECLARE_PER_CPU(unsigned long, cpu_scale);
283+
284+
static inline unsigned long topology_get_cpu_scale(int cpu)
285+
{
286+
return per_cpu(cpu_scale, cpu);
287+
}
288+
289+
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
290+
282291
#endif /* _LINUX_TOPOLOGY_H */

0 commit comments

Comments
 (0)