Skip to contentSkip to conversation

Convert bigsmp to use flat physical mode

PATCH In review Ashok Raj 3 participants 6 messages Nov 22, 2005 – Nov 23, 2005

lore
Share & tools
lore

Ashok Raj

author
#0 lore raw

cover Convert bigsmp to use flat physical mode

Hi

This patch converts bigsmp to use flat physical mode instead of logical cluster mode similar to what we use for x86_64. This helps with plugging some race conditions with cpu hotplug (IPI-race) and other things. More details in the respective patches.

Andrew: Please consider for -mm for some exposure

The series has 2 patches.

- Change bigsmp to use flat physical mode instead of logical cluster
- If hotplug is enabled choose bigsmp mode by default.

Both the above are default behaviour for x86_64 builds.

I have tested on some dual core boxes, it will help more testing if people who use bigsmp can give feedback would be great.

Cheers,
ashok

author
#1 lore raw

PATCH 1/2 Convert bigsmp to use flat physical mode

When we bring up a new CPU via INIT/startup IPI messages, the CPU that's coming up sends a xTPR message to the chipset. Intel chipsets (at least) don't provide any architectural guarantee on what the chipset will do with this message. For example, the E850x chipsets uses this xTPR message to interpret the interrupt operating mode of the platform. When the CPU coming online sends this message, it always indicates that it is in logical flat mode. For the CPU hotplug case, the platform may already be functioning in cluster APIC mode at this time, the chipset can get confused and mishandle I/O device and IPI interrupt routing.

The situation eventually gets corrected when the new CPU sends another xTPR update when we switch it to cluster mode, but there's a window during which the chipset may be in an inconsistent state. This patch avoids this problem by using the flat physical interrupt delivery mode instead of cluster mode for bigsmp (>8 cpu) support.

Depends on: pci-changing-msi-to-use-physical-delivery-mode-always.patch

Quoted 1 line

From Gregkh's tree.

---------------------------------------------------------------

 include/asm-i386/mach-bigsmp/mach_apic.h    |   75 ++++++++++++----------------
 include/asm-i386/mach-bigsmp/mach_apicdef.h |    4 -
 2 files changed, 36 insertions(+), 43 deletions(-)
include/asm-i386/mach-bigsmp/mach_apic.h +34 -41
Index: linux-2.6.15-rc1-mm2/include/asm-i386/mach-bigsmp/mach_apic.h
===================================================================
@@ -1,17 +1,10 @@
 #ifndef __ASM_MACH_APIC_H
 #define __ASM_MACH_APIC_H
-#include <asm/smp.h>
 
-#define SEQUENTIAL_APICID
-#ifdef SEQUENTIAL_APICID
-#define xapic_phys_to_log_apicid(phys_apic) ( (1ul << ((phys_apic) & 0x3)) |\
-		((phys_apic<<2) & (~0xf)) )
-#elif CLUSTERED_APICID
-#define xapic_phys_to_log_apicid(phys_apic) ( (1ul << ((phys_apic) & 0x3)) |\
-		((phys_apic) & (~0xf)) )
-#endif
 
-#define NO_BALANCE_IRQ (1)
+extern u8 bios_cpu_apicid[];
+
+#define xapic_phys_to_log_apicid(cpu) (bios_cpu_apicid[cpu])
 #define esr_disable (1)
 
 static inline int apic_id_registered(void)
@@ -19,7 +12,6 @@ static inline int apic_id_registered(voi
 	return (1);
 }
 
-#define APIC_DFR_VALUE	(APIC_DFR_CLUSTER)
 /* Round robin the irqs amoung the online cpus */
 static inline cpumask_t target_cpus(void)
 { 
@@ -32,29 +24,34 @@ static inline cpumask_t target_cpus(void
 	} while (cpu >= NR_CPUS);
 	return cpumask_of_cpu(cpu);
 }
-#define TARGET_CPUS	(target_cpus())
 
-#define INT_DELIVERY_MODE dest_Fixed
-#define INT_DEST_MODE 1     /* logical delivery broadcast to all procs */
+#undef APIC_DEST_LOGICAL
+#define APIC_DEST_LOGICAL 	0
+#define TARGET_CPUS		(target_cpus())
+#define APIC_DFR_VALUE		(APIC_DFR_FLAT)
+#define INT_DELIVERY_MODE	(dest_Fixed)
+#define INT_DEST_MODE		(0)    /* phys delivery to target proc */
+#define NO_BALANCE_IRQ		(0)
+#define WAKE_SECONDARY_VIA_INIT
+
 
 static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid)
 {
-	return 0;
+	return (0);
 }
 
-/* we don't use the phys_cpu_present_map to indicate apicid presence */
-static inline unsigned long check_apicid_present(int bit) 
+static inline unsigned long check_apicid_present(int bit)
 {
-	return 1;
+	return (1);
 }
 
-#define apicid_cluster(apicid) (apicid & 0xF0)
-
-static inline unsigned long calculate_ldr(unsigned long old)
+static inline unsigned long calculate_ldr(int cpu)
 {
-	unsigned long id;
-	id = xapic_phys_to_log_apicid(hard_smp_processor_id());
-	return ((old & ~APIC_LDR_MASK) | SET_APIC_LOGICAL_ID(id));
+	unsigned long val, id;
+	val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
+	id = xapic_phys_to_log_apicid(cpu);
+	val |= SET_APIC_LOGICAL_ID(id);
+	return val;
 }
 
 /*
@@ -67,37 +64,35 @@ static inline unsigned long calculate_ld
 static inline void init_apic_ldr(void)
 {
 	unsigned long val;
+	int cpu = smp_processor_id();
 
 	apic_write_around(APIC_DFR, APIC_DFR_VALUE);
-	val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
-	val = calculate_ldr(val);
+	val = calculate_ldr(cpu);
 	apic_write_around(APIC_LDR, val);
 }
 
 static inline void clustered_apic_check(void)
 {
 	printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
-		"Cluster", nr_ioapics);
+		"Physflat", nr_ioapics);
 }
 
 static inline int multi_timer_check(int apic, int irq)
 {
-	return 0;
+	return (0);
 }
 
 static inline int apicid_to_node(int logical_apicid)
 {
-	return 0;
+	return (0);
 }
 
-extern u8 bios_cpu_apicid[];
-
 static inline int cpu_present_to_apicid(int mps_cpu)
 {
 	if (mps_cpu < NR_CPUS)
-		return (int)bios_cpu_apicid[mps_cpu];
-	else
-		return BAD_APICID;
+		return (int) bios_cpu_apicid[mps_cpu];
+
+	return BAD_APICID;
 }
 
 static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
@@ -109,10 +104,10 @@ extern u8 cpu_2_logical_apicid[];
 /* Mapping from cpu number to logical apicid */
 static inline int cpu_to_logical_apicid(int cpu)
 {
-       if (cpu >= NR_CPUS)
-	       return BAD_APICID;
-       return (int)cpu_2_logical_apicid[cpu];
- }
+	if (cpu >= NR_CPUS)
+		return BAD_APICID;
+	return cpu_physical_id(cpu);
+}
 
 static inline int mpc_apic_id(struct mpc_config_processor *m,
 			struct mpc_config_translation *translation_record)
@@ -128,11 +123,9 @@ static inline int mpc_apic_id(struct mpc
 static inline physid_mask_t ioapic_phys_id_map(physid_mask_t phys_map)
 {
 	/* For clustered we don't have a good way to do this yet - hack */
-	return physids_promote(0xFUL);
+	return physids_promote(0xFFL);
 }
 
-#define WAKE_SECONDARY_VIA_INIT
-
 static inline void setup_portio_remap(void)
 {
 }
include/asm-i386/mach-bigsmp/mach_apicdef.h +2 -2
Index: linux-2.6.15-rc1-mm2/include/asm-i386/mach-bigsmp/mach_apicdef.h
===================================================================
@@ -1,11 +1,11 @@
 #ifndef __ASM_MACH_APICDEF_H
 #define __ASM_MACH_APICDEF_H
 
-#define		APIC_ID_MASK		(0x0F<<24)
+#define		APIC_ID_MASK		(0xFF<<24)
 
 static inline unsigned get_apic_id(unsigned long x) 
 { 
-	return (((x)>>24)&0x0F);
+	return (((x)>>24)&0xFF);
 } 
 
 #define		GET_APIC_ID(x)	get_apic_id(x)

--

author
#2 lore raw

PATCH 2/2 Convert bigsmp to use flat physical mode

In reply to Ashok Raj

If we are using hotplug enabled kernel, then make bigsmp the default mode.

-------------------------------------------------------

 arch/i386/kernel/mpparse.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
arch/i386/kernel/mpparse.c +10 -3
Index: linux-2.6.15-rc1-mm2/arch/i386/kernel/mpparse.c
===================================================================
@@ -38,6 +38,12 @@
 int smp_found_config;
 unsigned int __initdata maxcpus = NR_CPUS;
 
+#ifdef CONFIG_HOTPLUG_CPU
+#define CPU_HOTPLUG_ENABLED	(1)
+#else
+#define CPU_HOTPLUG_ENABLED	(0)
+#endif
+
 /*
  * Various Linux-internal data structures created from the
  * MP-table.
@@ -219,9 +225,10 @@ static void __devinit MP_processor_info 
 	cpu_set(num_processors, cpu_possible_map);
 	num_processors++;
 
-	if ((num_processors > 8) &&
-	    APIC_XAPIC(ver) &&
-	    (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL))
+	if (APIC_XAPIC(ver) &&
+		(CPU_HOTPLUG_ENABLED ||
+		((num_processors > 8) &&
+	    		(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL))))
 		def_to_bigsmp = 1;
 	else
 		def_to_bigsmp = 0;

--

author
#3 lore raw
Quoted 10 lines · Ashok Raj

- if ((num_processors > 8) &&
- APIC_XAPIC(ver) &&
- (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL))
+ if (APIC_XAPIC(ver) &&
+ (CPU_HOTPLUG_ENABLED ||
+ ((num_processors > 8) &&
+ (boot_cpu_data.x86_vendor ==
X86_VENDOR_INTEL))))

                   def_to_bigsmp = 1;

Noticed that Andi send one more patch do enable bigsmp for AMD (i386), and the APIC_XAPIC() check was not properly placed to factor this in. This updated patch should work for AMD as well, and switch to bigsmp when we have hotplug enabled.

Signature · 56 lines
Cheers,
Ashok Raj
- Open Source Technology Center


If we are using hotplug enabled kernel, then make bigsmp the default mode.


Signed-off-by: Ashok Raj <[email protected]>
Signed-off-by: Venkatesh Pallipadi <[email protected]>
-------------------------------------------------------
 arch/i386/kernel/mpparse.c |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

Index: linux-2.6.15-rc1-mm2/arch/i386/kernel/mpparse.c
===================================================================
--- linux-2.6.15-rc1-mm2.orig/arch/i386/kernel/mpparse.c
+++ linux-2.6.15-rc1-mm2/arch/i386/kernel/mpparse.c
@@ -38,6 +38,12 @@
 int smp_found_config;
 unsigned int __initdata maxcpus = NR_CPUS;
 
+#ifdef CONFIG_HOTPLUG_CPU
+#define CPU_HOTPLUG_ENABLED	(1)
+#else
+#define CPU_HOTPLUG_ENABLED	(0)
+#endif
+
 /*
  * Various Linux-internal data structures created from the
  * MP-table.
@@ -219,13 +225,18 @@ static void __devinit MP_processor_info 
 	cpu_set(num_processors, cpu_possible_map);
 	num_processors++;
 
-	if ((num_processors > 8) &&
-	    APIC_XAPIC(ver) &&
-	    (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL))
-		def_to_bigsmp = 1;
-	else
-		def_to_bigsmp = 0;
-
+	if (CPU_HOTPLUG_ENABLED || (num_processors > 8)) {
+		switch (boot_cpu_data.x86_vendor) {
+			case X86_VENDOR_INTEL:
+				if (!APIC_XAPIC(ver)) {
+					def_to_bigsmp = 0;
+					break;
+				}
+				/* If P4 and above fall through */
+			case X86_VENDOR_AMD:
+				def_to_bigsmp = 1;
+		}
+	}
 	bios_cpu_apicid[num_processors - 1] = m->mpc_apicid;
 }
#4 lore raw
Quoted 12 lines · Ashok Raj
Quoted 10 lines · Ashok Raj

- if ((num_processors > 8) &&
- APIC_XAPIC(ver) &&
- (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL))
+ if (APIC_XAPIC(ver) &&
+ (CPU_HOTPLUG_ENABLED ||
+ ((num_processors > 8) &&
+ (boot_cpu_data.x86_vendor ==
X86_VENDOR_INTEL))))

                   def_to_bigsmp = 1;
Quoted 4 lines

Noticed that Andi send one more patch do enable bigsmp for AMD (i386), and the APIC_XAPIC() check was not properly placed to factor this in. This updated patch should work for AMD as well, and switch to bigsmp when we have hotplug enabled.

Looks good thanks.

-Andi

#5 lore raw
In reply to Ashok Raj
Quoted 15 lines · Ashok Raj
(quoted diff) +0 -0
@@ -219,13 +225,18 @@ static void __devinit MP_processor_info 
  	cpu_set(num_processors, cpu_possible_map);
  	num_processors++;
 
 -	if ((num_processors > 8) &&
 -	    APIC_XAPIC(ver) &&
 -	    (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL))
 -		def_to_bigsmp = 1;
 -	else
 -		def_to_bigsmp = 0;
 -
 +	if (CPU_HOTPLUG_ENABLED || (num_processors > 8)) {
 +		switch (boot_cpu_data.x86_vendor) {
 +			case X86_VENDOR_INTEL:

Review static void __devinit MP_processor_info

Quoted 10 lines
(quoted diff) +0 -0
 +				if (!APIC_XAPIC(ver)) {
 +					def_to_bigsmp = 0;
 +					break;
 +				}
 +				/* If P4 and above fall through */
 +			case X86_VENDOR_AMD:
 +				def_to_bigsmp = 1;
 +		}
 +	}
  	bios_cpu_apicid[num_processors - 1] = m->mpc_apicid;

The code you're patching here is changed:

	if ((num_processors > 8) &&
	    ((APIC_XAPIC(ver) &&
	     (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)) ||
	     (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)))
		def_to_bigsmp = 1;

But the fixup was obvious.

While I was there I unindented the body of the switch statement by one tab stop, as we usually do.

Please avoid sending multiple patches with the same Subject:, thanks.