Skip to content

Commit 6bceea7

Browse files
ricardonrafaeljw
authored andcommitted
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 <[email protected]> Tested-by: Christian Loehle <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 4854649 commit 6bceea7

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
@@ -154,14 +154,6 @@ void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq,
154154
per_cpu(arch_freq_scale, i) = scale;
155155
}
156156

157-
DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE;
158-
EXPORT_PER_CPU_SYMBOL_GPL(cpu_scale);
159-
160-
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
161-
{
162-
per_cpu(cpu_scale, cpu) = capacity;
163-
}
164-
165157
DEFINE_PER_CPU(unsigned long, hw_pressure);
166158

167159
/**
@@ -207,53 +199,9 @@ void topology_update_hw_pressure(const struct cpumask *cpus,
207199
}
208200
EXPORT_SYMBOL_GPL(topology_update_hw_pressure);
209201

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

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

259207
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
@@ -332,4 +332,13 @@ sched_numa_hop_mask(unsigned int node, unsigned int hops)
332332
!IS_ERR_OR_NULL(mask); \
333333
__hops++)
334334

335+
DECLARE_PER_CPU(unsigned long, cpu_scale);
336+
337+
static inline unsigned long topology_get_cpu_scale(int cpu)
338+
{
339+
return per_cpu(cpu_scale, cpu);
340+
}
341+
342+
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
343+
335344
#endif /* _LINUX_TOPOLOGY_H */

0 commit comments

Comments
 (0)