aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/cpu.c
diff options
context:
space:
mode:
authorYasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>2013-04-29 18:08:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 18:54:39 -0400
commit346404682434ad0e31b71f9f37fb6c45a46fe208 (patch)
tree4e8b106849fa983d2fff4f191694739dc4527fc3 /drivers/base/cpu.c
parent349daa0f93177958c4618542a61926674169a698 (diff)
numa, cpu hotplug: change links of CPU and node when changing node number by onlining CPU
When booting x86 system contains memoryless node, node numbers of CPUs on memoryless node were changed to nearest online node number by init_cpu_to_node() because the node is not online. In my system, node numbers of cpu#30-44 and 75-89 were changed from 2 to 0 as follows: $ numactl --hardware available: 2 nodes (0-1) node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 node 0 size: 32394 MB node 0 free: 27898 MB node 1 cpus: 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 node 1 size: 32768 MB node 1 free: 30335 MB If we hot add memory to memoryless node and offine/online all CPUs on the node, node numbers of these CPUs are changed to correct node numbers by srat_detect_node() because the node become online. In this case, node numbers of cpu#30-44 and 75-89 were changed from 0 to 2 in my system as follows: $ numactl --hardware available: 3 nodes (0-2) node 0 cpus: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 node 0 size: 32394 MB node 0 free: 27218 MB node 1 cpus: 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 node 1 size: 32768 MB node 1 free: 30014 MB node 2 cpus: 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 node 2 size: 16384 MB node 2 free: 16384 MB But "cpu to node" and "node to cpu" links were not changed as follows: $ ls /sys/devices/system/cpu/cpu30/|grep node node0 $ ls /sys/devices/system/node/node0/|grep cpu30 cpu30 "numactl --hardware" shows that cpu30 belongs to node 2. But sysfs links does not change. This patch changes "cpu to node" and "node to cpu" links when node number changed by onlining CPU. Signed-off-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: "Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com> Cc: Greg KH <greg@kroah.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/base/cpu.c')
-rw-r--r--drivers/base/cpu.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index d8c7f3ee6e19..3d48fc887ef4 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -25,6 +25,15 @@ EXPORT_SYMBOL_GPL(cpu_subsys);
25static DEFINE_PER_CPU(struct device *, cpu_sys_devices); 25static DEFINE_PER_CPU(struct device *, cpu_sys_devices);
26 26
27#ifdef CONFIG_HOTPLUG_CPU 27#ifdef CONFIG_HOTPLUG_CPU
28static void change_cpu_under_node(struct cpu *cpu,
29 unsigned int from_nid, unsigned int to_nid)
30{
31 int cpuid = cpu->dev.id;
32 unregister_cpu_under_node(cpuid, from_nid);
33 register_cpu_under_node(cpuid, to_nid);
34 cpu->node_id = to_nid;
35}
36
28static ssize_t show_online(struct device *dev, 37static ssize_t show_online(struct device *dev,
29 struct device_attribute *attr, 38 struct device_attribute *attr,
30 char *buf) 39 char *buf)
@@ -39,17 +48,29 @@ static ssize_t __ref store_online(struct device *dev,
39 const char *buf, size_t count) 48 const char *buf, size_t count)
40{ 49{
41 struct cpu *cpu = container_of(dev, struct cpu, dev); 50 struct cpu *cpu = container_of(dev, struct cpu, dev);
51 int cpuid = cpu->dev.id;
52 int from_nid, to_nid;
42 ssize_t ret; 53 ssize_t ret;
43 54
44 cpu_hotplug_driver_lock(); 55 cpu_hotplug_driver_lock();
45 switch (buf[0]) { 56 switch (buf[0]) {
46 case '0': 57 case '0':
47 ret = cpu_down(cpu->dev.id); 58 ret = cpu_down(cpuid);
48 if (!ret) 59 if (!ret)
49 kobject_uevent(&dev->kobj, KOBJ_OFFLINE); 60 kobject_uevent(&dev->kobj, KOBJ_OFFLINE);
50 break; 61 break;
51 case '1': 62 case '1':
52 ret = cpu_up(cpu->dev.id); 63 from_nid = cpu_to_node(cpuid);
64 ret = cpu_up(cpuid);
65
66 /*
67 * When hot adding memory to memoryless node and enabling a cpu
68 * on the node, node number of the cpu may internally change.
69 */
70 to_nid = cpu_to_node(cpuid);
71 if (from_nid != to_nid)
72 change_cpu_under_node(cpu, from_nid, to_nid);
73
53 if (!ret) 74 if (!ret)
54 kobject_uevent(&dev->kobj, KOBJ_ONLINE); 75 kobject_uevent(&dev->kobj, KOBJ_ONLINE);
55 break; 76 break;