From: KAMEZAWA Hiroyuki With Goto-san's patch, we can add new pgdat/node at runtime. I'm now considering node-hot-add with cpu + memory on ACPI. I found acpi container, which describes node, could evaluate cpu before memory. This means cpu-hot-add occurs before memory hot add. In most part, cpu-hot-add doesn't depend on node hot add. But register_cpu(), which creates symbolic link from node to cpu, requires that node should be onlined before register_cpu(). When a node is onlined, its pgdat should be there. This patch-set holds off creating symbolic link from node to cpu until node is onlined. [1/3] modifies register_cpu [2/3] changes caller of register cpu [3/3] changes register_node. create symbolic link fron node to cpu. With these patched, (cpu + memory) node hot add will succeed. (cpu-only)/(IO-only) node hot add will need more fixes. (But we need this ?) This patch: This removes node arguments from register_cpu(). Now, register_cpu() requires 'struct node' as its argument. But the array of struct node is now unified in driver/base/node.c now (By Goto's node hotplug patch). We can get struct node in generic way. So, this argument is not necessary now. This patch also guarantees add cpu under node only when node is onlined. It is necessary for node-hot-add vs. cpu-hot-add patch following this. Moreover, register_cpu calculates cpu->node_id by cpu_to_node() without regard to its 'struct node *root' argument. This patch removes it. Patches for fixing the caller of register_cpu() for each arch will follow this. Signed-off-by: KAMEZAWA Hiroyuki Cc: Yasunori Goto Cc: Ashok Raj Cc: Dave Hansen Signed-off-by: Andrew Morton --- drivers/base/cpu.c | 18 ++++++++---------- drivers/base/node.c | 29 +++++++++++++++++++++++++++++ include/linux/cpu.h | 4 ++-- include/linux/node.h | 13 +++++++++++++ 4 files changed, 52 insertions(+), 12 deletions(-) diff -puN drivers/base/cpu.c~node-hotplug-register-cpu-remove-node-struct drivers/base/cpu.c --- 25/drivers/base/cpu.c~node-hotplug-register-cpu-remove-node-struct Fri May 26 16:03:04 2006 +++ 25-akpm/drivers/base/cpu.c Fri May 26 16:03:04 2006 @@ -8,6 +8,7 @@ #include #include #include +#include #include "base.h" @@ -57,13 +58,12 @@ static void __devinit register_cpu_contr { sysdev_create_file(&cpu->sysdev, &attr_online); } -void unregister_cpu(struct cpu *cpu, struct node *root) +void unregister_cpu(struct cpu *cpu) { int logical_cpu = cpu->sysdev.id; - if (root) - sysfs_remove_link(&root->sysdev.kobj, - kobject_name(&cpu->sysdev.kobj)); + unregister_cpu_under_node(logical_cpu, cpu_to_node(logical_cpu)); + sysdev_remove_file(&cpu->sysdev, &attr_online); sysdev_unregister(&cpu->sysdev); @@ -109,23 +109,21 @@ static SYSDEV_ATTR(crash_notes, 0400, sh * * Initialize and register the CPU device. */ -int __devinit register_cpu(struct cpu *cpu, int num, struct node *root) +int __devinit register_cpu(struct cpu *cpu, int num) { int error; - cpu->node_id = cpu_to_node(num); cpu->sysdev.id = num; cpu->sysdev.cls = &cpu_sysdev_class; error = sysdev_register(&cpu->sysdev); - if (!error && root) - error = sysfs_create_link(&root->sysdev.kobj, - &cpu->sysdev.kobj, - kobject_name(&cpu->sysdev.kobj)); + if (!error && !cpu->no_control) register_cpu_control(cpu); if (!error) cpu_sys_devices[num] = &cpu->sysdev; + if (!error) + register_cpu_under_node(num, cpu_to_node(num)); #ifdef CONFIG_KEXEC if (!error) diff -puN drivers/base/node.c~node-hotplug-register-cpu-remove-node-struct drivers/base/node.c --- 25/drivers/base/node.c~node-hotplug-register-cpu-remove-node-struct Fri May 26 16:03:04 2006 +++ 25-akpm/drivers/base/node.c Fri May 26 16:03:06 2006 @@ -11,6 +11,7 @@ #include #include #include +#include static struct sysdev_class node_class = { set_kset_name("node"), @@ -192,6 +193,34 @@ void unregister_node(struct node *node) struct node node_devices[MAX_NUMNODES]; +/* + * register cpu under node + */ +int register_cpu_under_node(unsigned int cpu, unsigned int nid) +{ + if (node_online(nid)) { + struct sys_device *obj = get_cpu_sysdev(cpu); + if (!obj) + return 0; + return sysfs_create_link(&node_devices[nid].sysdev.kobj, + &obj->kobj, + kobject_name(&obj->kobj)); + } + + return 0; +} + +int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) +{ + if (node_online(nid)) { + struct sys_device *obj = get_cpu_sysdev(cpu); + if (obj) + sysfs_remove_link(&node_devices[nid].sysdev.kobj, + kobject_name(&obj->kobj)); + } + return 0; +} + int register_one_node(int nid) { int error = 0; diff -puN include/linux/cpu.h~node-hotplug-register-cpu-remove-node-struct include/linux/cpu.h --- 25/include/linux/cpu.h~node-hotplug-register-cpu-remove-node-struct Fri May 26 16:03:04 2006 +++ 25-akpm/include/linux/cpu.h Fri May 26 16:03:05 2006 @@ -31,10 +31,10 @@ struct cpu { struct sys_device sysdev; }; -extern int register_cpu(struct cpu *, int, struct node *); +extern int register_cpu(struct cpu *cpu, int num); extern struct sys_device *get_cpu_sysdev(unsigned cpu); #ifdef CONFIG_HOTPLUG_CPU -extern void unregister_cpu(struct cpu *, struct node *); +extern void unregister_cpu(struct cpu *cpu); #endif struct notifier_block; diff -puN include/linux/node.h~node-hotplug-register-cpu-remove-node-struct include/linux/node.h --- 25/include/linux/node.h~node-hotplug-register-cpu-remove-node-struct Fri May 26 16:03:04 2006 +++ 25-akpm/include/linux/node.h Fri May 26 16:03:04 2006 @@ -32,6 +32,19 @@ extern int register_node(struct node *, extern void unregister_node(struct node *node); extern int register_one_node(int nid); extern void unregister_one_node(int nid); +#ifdef CONFIG_NUMA +extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); +extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); +#else +static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid) +{ + return 0; +} +static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) +{ + return 0; +} +#endif #define to_node(sys_device) container_of(sys_device, struct node, sysdev) _