
From: Anton Blanchard <anton@samba.org>

Add cpus and NUMA memory nodes to sysfs. Also add cpu physical id.


---

 arch/ppc64/kernel/smp.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++++
 arch/ppc64/mm/numa.c    |    4 ++
 2 files changed, 73 insertions(+), 1 deletion(-)

diff -puN arch/ppc64/kernel/smp.c~ppc64-cpus-in-sysfs arch/ppc64/kernel/smp.c
--- 25/arch/ppc64/kernel/smp.c~ppc64-cpus-in-sysfs	2004-02-22 15:14:55.000000000 -0800
+++ 25-akpm/arch/ppc64/kernel/smp.c	2004-02-22 15:14:55.000000000 -0800
@@ -28,6 +28,8 @@
 #include <linux/spinlock.h>
 #include <linux/cache.h>
 #include <linux/err.h>
+#include <linux/sysdev.h>
+#include <linux/cpu.h>
 
 #include <asm/ptrace.h>
 #include <asm/atomic.h>
@@ -726,3 +728,71 @@ void __init smp_cpus_done(unsigned int m
 
 	set_cpus_allowed(current, old_mask);
 }
+
+#ifdef CONFIG_NUMA
+static struct node node_devices[MAX_NUMNODES];
+
+static void register_nodes(void)
+{
+	int i;
+	int ret;
+
+	for (i = 0; i < MAX_NUMNODES; i++) {
+		if (node_online(i)) {
+			int p_node = parent_node(i);
+			struct node *parent = NULL;
+
+			if (p_node != i)
+				parent = &node_devices[p_node];
+
+			ret = register_node(&node_devices[i], i, parent);
+			if (ret)
+				printk(KERN_WARNING "register_nodes: "
+				       "register_node %d failed (%d)", i, ret);
+		}
+	}
+}
+#else
+static void register_nodes(void)
+{
+	return 0;
+}
+#endif
+
+/* Only valid if CPU is online. */
+static ssize_t show_physical_id(struct sys_device *dev, char *buf)
+{
+	struct cpu *cpu = container_of(dev, struct cpu, sysdev);
+
+	return sprintf(buf, "%u\n", get_hard_smp_processor_id(cpu->sysdev.id));
+}
+static SYSDEV_ATTR(physical_id, 0444, show_physical_id, NULL);
+
+static DEFINE_PER_CPU(struct cpu, cpu_devices);
+
+static int __init topology_init(void)
+{
+	int cpu;
+	struct node *parent = NULL;
+	int ret;
+
+	register_nodes();
+
+	for_each_cpu(cpu) {
+#ifdef CONFIG_NUMA
+		parent = &node_devices[cpu_to_node(cpu)];
+#endif
+		ret = register_cpu(&per_cpu(cpu_devices, cpu), cpu, parent);
+		if (ret)
+			printk(KERN_WARNING "topology_init: register_cpu %d "
+			       "failed (%d)\n", cpu, ret);
+
+		ret = sysdev_create_file(&per_cpu(cpu_devices, cpu).sysdev,
+					 &attr_physical_id);
+		if (ret)
+			printk(KERN_WARNING "toplogy_init: sysdev_create_file "
+			       "%d failed (%d)\n", cpu, ret);
+	}
+	return 0;
+}
+__initcall(topology_init);
diff -puN arch/ppc64/mm/numa.c~ppc64-cpus-in-sysfs arch/ppc64/mm/numa.c
--- 25/arch/ppc64/mm/numa.c~ppc64-cpus-in-sysfs	2004-02-22 15:14:55.000000000 -0800
+++ 25-akpm/arch/ppc64/mm/numa.c	2004-02-22 15:14:55.000000000 -0800
@@ -100,6 +100,8 @@ static int __init parse_numa_properties(
 		if (numa_domain >= MAX_NUMNODES)
 			BUG();
 
+		node_set_online(numa_domain);
+
 		if (max_domain < numa_domain)
 			max_domain = numa_domain;
 
@@ -201,7 +203,7 @@ err:
 	return -1;
 }
 
-void setup_nonnuma(void)
+static void __init setup_nonnuma(void)
 {
 	unsigned long i;
 

_
