All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC][PATCH] AMD CPU core topology detection
@ 2011-01-06 16:47 Wei Huang
  2011-01-07  8:56 ` Jan Beulich
  0 siblings, 1 reply; 9+ messages in thread
From: Wei Huang @ 2011-01-06 16:47 UTC (permalink / raw)
  To: 'xen-devel@lists.xensource.com', keir, Jan Beulich

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

Hi Keir and Jan,

This patch is to support the new core pair topology introduced by AMD 
new CPUs, which introduces a new concept of core/compute unit/node. 
There is a new feature bit for topology extension in CPUID:0x80000001. 
Also a new CPUID (0x8000001E) is introduced for CPU topology 
enumeration. This patch collects the sibling information from a new 
CPUID and the info will be stored into the sibling map in Xen.

Please help review it. Comments are welcome.

Signed-off-by: Wei Huang <wei.huang2@amd.com>

[-- Attachment #2: xen_amd_core_topology.txt --]
[-- Type: text/plain, Size: 3172 bytes --]

diff -r 94c5d7ee424a -r f8e36046ee17 xen/arch/x86/cpu/amd.c
--- a/xen/arch/x86/cpu/amd.c	Wed Jan 05 13:58:21 2011 -0600
+++ b/xen/arch/x86/cpu/amd.c	Wed Jan 05 16:48:01 2011 -0600
@@ -337,6 +337,56 @@
 		on_each_cpu(disable_c1e, NULL, 1);
 }
 
+#ifdef CONFIG_X86_HT
+/* This function detects system CPU topology */
+static void amd_detect_topology(struct cpuinfo_x86 *c)
+{
+	u32 eax, ebx, ecx, edx;
+	int cpu = smp_processor_id();
+
+	if (c->x86_max_cores <= 1)
+		return;
+
+	if (cpu_has(c, X86_FEATURE_TOPO_EXT)) {
+		/* AMD new CPUs introduce a new term called compute unit. But 
+		 * we still keep the names of existing variables for the 
+		 * purpose of consistency. Keep in mind that cpu_core_id here 
+		 * represents the computer unit ID; and we use the node ID as 
+                 * the processor ID because it is unique across the whole 
+		 * system. 
+		 */
+		cpuid(0x8000001e, &eax, &ebx, &ecx, &edx);
+		cpu_core_id[cpu] = ebx & 0xFF;
+		phys_proc_id[cpu] = ecx & 0xFF;
+
+		c->x86_num_siblings = ((ebx >> 8) & 0x3) + 1;
+
+		if (opt_cpu_info)
+			printk("CPU %d(%d) -> Compute Unit %d, Node %d\n",
+			       cpu, c->x86_max_cores, cpu_core_id[cpu],
+			       phys_proc_id[cpu]);
+	} else {
+		/* On a AMD multi core setup the lower bits of the APIC id
+		 * distingush the cores.
+		 */
+		unsigned bits = (cpuid_ecx(0x80000008) >> 12) & 0xf;
+
+		if (bits == 0) {
+			while ((1 << bits) < c->x86_max_cores)
+				bits++;
+		}
+		cpu_core_id[cpu] = phys_proc_id[cpu] & ((1<<bits)-1);
+		phys_proc_id[cpu] >>= bits;
+
+		if (opt_cpu_info)
+			printk("CPU %d(%d) -> Core %d\n",
+			       cpu, c->x86_max_cores, cpu_core_id[cpu]);
+	}
+}
+#else
+#define amd_detect_topology(struct cpuinfo_x86 *c) (void(0))
+#endif
+
 static void __devinit init_amd(struct cpuinfo_x86 *c)
 {
 	u32 l, h;
@@ -574,26 +624,7 @@
 		}
 	}
 
-#ifdef CONFIG_X86_HT
-	/*
-	 * On a AMD multi core setup the lower bits of the APIC id
-	 * distingush the cores.
-	 */
-	if (c->x86_max_cores > 1) {
-		int cpu = smp_processor_id();
-		unsigned bits = (cpuid_ecx(0x80000008) >> 12) & 0xf;
-
-		if (bits == 0) {
-			while ((1 << bits) < c->x86_max_cores)
-				bits++;
-		}
-		cpu_core_id[cpu] = phys_proc_id[cpu] & ((1<<bits)-1);
-		phys_proc_id[cpu] >>= bits;
-		if (opt_cpu_info)
-			printk("CPU %d(%d) -> Core %d\n",
-			       cpu, c->x86_max_cores, cpu_core_id[cpu]);
-	}
-#endif
+	amd_detect_topology(c);
 
 	/* Pointless to use MWAIT on Family10 as it does not deep sleep. */
 	if (c->x86 >= 0x10 && !force_mwait)
diff -r 94c5d7ee424a -r f8e36046ee17 xen/include/asm-x86/cpufeature.h
--- a/xen/include/asm-x86/cpufeature.h	Wed Jan 05 13:58:21 2011 -0600
+++ b/xen/include/asm-x86/cpufeature.h	Wed Jan 05 16:48:01 2011 -0600
@@ -132,6 +132,7 @@
 #define X86_FEATURE_SSE5	(6*32+ 11) /* AMD Streaming SIMD Extensions-5 */
 #define X86_FEATURE_SKINIT	(6*32+ 12) /* SKINIT, STGI/CLGI, DEV */
 #define X86_FEATURE_WDT		(6*32+ 13) /* Watchdog Timer */
+#define X86_FEATURE_TOPO_EXT    (6*32+ 22) /* Topology Extension Support */
 
 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
 #define X86_FEATURE_FSGSBASE	(7*32+ 0) /* {RD,WR}{FS,GS}BASE instructions */

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-01-11 17:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-06 16:47 [RFC][PATCH] AMD CPU core topology detection Wei Huang
2011-01-07  8:56 ` Jan Beulich
2011-01-07 15:52   ` Huang2, Wei
2011-01-07 22:56     ` Huang2, Wei
2011-01-10  8:20       ` Jan Beulich
2011-01-11 10:58     ` George Dunlap
2011-01-11 11:12       ` George Dunlap
2011-01-11 17:05         ` Wei Huang
2011-01-11 15:38       ` Huang2, Wei

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.