Skip to content

Commit 6504a83

Browse files
committed
arch_topology: Make register_cpu_capacity_sysctl() tolerant to late CPUs
JIRA: https://issues.redhat.com/browse/RHEL-112493 commit c72bbf2 Author: James Morse <james.morse@arm.com> Date: Tue Nov 21 13:43:54 2023 +0000 arch_topology: Make register_cpu_capacity_sysctl() tolerant to late CPUs register_cpu_capacity_sysctl() adds a property to sysfs that describes the CPUs capacity. This is done from a subsys_initcall() that assumes all possible CPUs are registered. With CPU hotplug, possible CPUs aren't registered until they become present, (or for arm64 enabled). This leads to messages during boot: | register_cpu_capacity_sysctl: too early to get CPU1 device! and once these CPUs are added to the system, the file is missing. Move this to a cpuhp callback, so that the file is created once CPUs are brought online. This covers CPUs that are added late by mechanisms like hotplug. One observable difference is the file is now missing for offline CPUs. Signed-off-by: James Morse <james.morse@arm.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Signed-off-by: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/E1r5R2g-00CsyV-Ss@rmk-PC.armlinux.org.uk Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: David Arcari <darcari@redhat.com>
1 parent e1b5a25 commit 6504a83

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

drivers/base/arch_topology.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,34 @@ static DECLARE_WORK(update_topology_flags_work, update_topology_flags_workfn);
219219

220220
static DEVICE_ATTR_RO(cpu_capacity);
221221

222-
static int register_cpu_capacity_sysctl(void)
222+
static int cpu_capacity_sysctl_add(unsigned int cpu)
223223
{
224-
int i;
225-
struct device *cpu;
224+
struct device *cpu_dev = get_cpu_device(cpu);
226225

227-
for_each_possible_cpu(i) {
228-
cpu = get_cpu_device(i);
229-
if (!cpu) {
230-
pr_err("%s: too early to get CPU%d device!\n",
231-
__func__, i);
232-
continue;
233-
}
234-
device_create_file(cpu, &dev_attr_cpu_capacity);
235-
}
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);
236250

237251
return 0;
238252
}

0 commit comments

Comments
 (0)