Skip to contentSkip to conversation

x86: use hard_smp_processor_id to get apic id in identify_cpu

PATCH New Yinghai Lu 2 participants 10 messages Aug 25, 2009 – Sep 4, 2009 x86

lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

PATCH 1/1 x86: use hard_smp_processor_id to get apic id in identify_cpu

and leave phys_proc_id to use initial apic id.

otherwise, system with apci id lifting will have wrong apicid in /proc/cpuinfo

for 2.6.31 ?

---
 arch/x86/kernel/cpu/common.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/common.c +2 -2
Index: linux-2.6/arch/x86/kernel/cpu/common.c
===================================================================
@@ -715,7 +715,7 @@ static void __cpuinit generic_identify(s
 		c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;
 #ifdef CONFIG_X86_32
 # ifdef CONFIG_X86_HT
-		c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
+		c->apicid = hard_smp_processor_id();
 # else
 		c->apicid = c->initial_apicid;
 # endif
@@ -772,7 +772,7 @@ static void __cpuinit identify_cpu(struc
 	}
 
 #ifdef CONFIG_X86_64
-	c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
+	c->apicid = hard_smp_processor_id();
 #endif
 
 	/*
author
#1 lore raw

PATCH 1/1 x86: use c->apicid directly in srat_detect_node

need applied after
| [PATCH] x86: use hard_smp_processor_id to get apic id in identify_cpu

don't need to read it again, just use stored value.

---
 arch/x86/kernel/cpu/amd.c   |    2 +-
 arch/x86/kernel/cpu/intel.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/cpu/amd.c +1 -1
Index: linux-2.6/arch/x86/kernel/cpu/amd.c
===================================================================
@@ -277,7 +277,7 @@ static void __cpuinit srat_detect_node(s
 #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
 	int cpu = smp_processor_id();
 	int node;
-	unsigned apicid = cpu_has_apic ? hard_smp_processor_id() : c->apicid;
+	unsigned apicid = c->apicid;
 
 	node = c->phys_proc_id;
 	if (apicid_to_node[apicid] != NUMA_NO_NODE)
arch/x86/kernel/cpu/intel.c +1 -1
Index: linux-2.6/arch/x86/kernel/cpu/intel.c
===================================================================
@@ -258,7 +258,7 @@ static void __cpuinit srat_detect_node(s
 #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
 	unsigned node;
 	int cpu = smp_processor_id();
-	int apicid = cpu_has_apic ? hard_smp_processor_id() : c->apicid;
+	int apicid = c->apicid;
 
 	/* Don't do the funky fallback heuristics the AMD version employs
 	   for now. */
author
#2 lore raw

PATCH 1/1 x86: use hard_smp_processor_id to get apic id in identify_cpu -v2

In reply to Yinghai Lu

and leave phys_proc_id to use initial apic id.

otherwise, system with apci id lifting will have wrong apicid in /proc/cpuinfo

-v2: update the one in detect_extended_topology too.

---
 arch/x86/kernel/cpu/addon_cpuid_features.c |    4 ++--
 arch/x86/kernel/cpu/common.c               |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/common.c +2 -2
Index: linux-2.6/arch/x86/kernel/cpu/common.c
===================================================================
@@ -715,7 +715,7 @@ static void __cpuinit generic_identify(s
 		c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;
 #ifdef CONFIG_X86_32
 # ifdef CONFIG_X86_HT
-		c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
+		c->apicid = hard_smp_processor_id();
 # else
 		c->apicid = c->initial_apicid;
 # endif
@@ -772,7 +772,7 @@ static void __cpuinit identify_cpu(struc
 	}
 
 #ifdef CONFIG_X86_64
-	c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
+	c->apicid = hard_smp_processor_id();
 #endif
 
 	/*
arch/x86/kernel/cpu/addon_cpuid_features.c +2 -2
Index: linux-2.6/arch/x86/kernel/cpu/addon_cpuid_features.c
===================================================================
@@ -121,9 +121,9 @@ void __cpuinit detect_extended_topology(
 						 & core_select_mask;
 	c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, core_plus_mask_width);
 	/*
-	 * Reinit the apicid, now that we have extended initial_apicid.
+	 * Reinit the apicid, now that we have extended apicid ?
 	 */
-	c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
+	c->apicid = hard_smp_processor_id();
 
 	c->x86_max_cores = (core_level_siblings / smp_num_siblings);
 
#3 lore raw

Re: [PATCH] x86: use hard_smp_processor_id to get apic id in identify_cpu -v2

Quoted 2 lines · Yinghai Lu

and leave phys_proc_id to use initial apic id.

No. We need to be consistent for both phys_proc_id and apicid computations.

i.e., if the bios changes the apic id's and those updated apic id's are not reflected in the initial apic id, then we need to use hard_smp_processor_id() for both phys_proc_id and apicid computations.

On the other platforms (default option) we need to use initial apic id (returned by cpuid).

Quoted 1 line

-v2: update the one in detect_extended_topology too.

This is not required. On these platforms, initial_apicid will be updated (along with the physical apicid) if there are any bios modifications.

Instead of this patch, what we need to do is: Just like the vsmp change, we need to override the phys_pkg_id routine for the platforms where the bios will modify apic id's and where cpuid doesn't reflect the bios modification (for example IBM x445 system etc)

thanks,
suresh

author
#4 lore raw

Re: [PATCH] x86: use hard_smp_processor_id to get apic id in identify_cpu -v2

Quoted 9 lines · Suresh Siddha
Quoted 1 line · Yinghai Lu

and leave phys_proc_id to use initial apic id.

No. We need to be consistent for both phys_proc_id and apicid computations.

i.e., if the bios changes the apic id's and those updated apic id's are not reflected in the initial apic id, then we need to use hard_smp_processor_id() for both phys_proc_id and apicid computations.

then you may get wrong phys_proc_id for amd system with apic id lifting.

Quoted 6 lines

On the other platforms (default option) we need to use initial apic id (returned by cpuid).

Quoted 1 line

-v2: update the one in detect_extended_topology too.

Quoted 7 lines

This is not required. On these platforms, initial_apicid will be updated (along with the physical apicid) if there are any bios modifications.

Instead of this patch, what we need to do is: Just like the vsmp change, we need to override the phys_pkg_id routine for the platforms where the bios will modify apic id's and where cpuid doesn't reflect the bios modification (for example IBM x445 system etc)

A: phys_pkg_id:
Default option:
use cpu id to get initial apic id, and then use initial apic id to get phys_pkg_id.

exception:
vsmp: need to use apic id to get phys_pkg_id, and apic id and initial apic id is not consistent.

for AMD system with apic id lifting, initial apic id and apic is not consistent. but we should use initial apic id to get phys_pkg_id. and that is consistent to Default option.

B: c->apicid for real apic id?
we already have c->initial_apicid, and c->apicid.
1. for amd system with apicid lifting, should use hard_smp_processor_id to get c->apicid.
2. for intel system (other than vsmp, and x445), c->apicid c->initial_apicid is the same, so could use hard_smp_processor_id
3. for vsmp, and x445, do you want to have c->apicid to have real apic id or the same as initial apic_id?

this patch is trying to make c->apicid to have real apic_id.

YH

#5 lore raw

Re: [PATCH] x86: use hard_smp_processor_id to get apic id in identify_cpu -v2

Quoted 4 lines · Yinghai Lu
Quoted 3 lines · Suresh Siddha
Quoted 1 line · Yinghai Lu

and leave phys_proc_id to use initial apic id.

Quoted 8 lines
Quoted 6 lines

No. We need to be consistent for both phys_proc_id and apicid computations.

i.e., if the bios changes the apic id's and those updated apic id's are not reflected in the initial apic id, then we need to use hard_smp_processor_id() for both phys_proc_id and apicid computations.

then you may get wrong phys_proc_id for amd system with apic id lifting.

Then we should add an exception for AMD systems too. And not change generic code.

Quoted 7 lines

A: phys_pkg_id:
Default option:
use cpu id to get initial apic id, and then use initial apic id to get phys_pkg_id.

exception:
vsmp: need to use apic id to get phys_pkg_id, and apic id and initial apic id is not consistent.

Quoted 7 lines

for AMD system with apic id lifting, initial apic id and apic is not consistent. but we should use initial apic id to get phys_pkg_id. and that is consistent to Default option.

B: c->apicid for real apic id?
we already have c->initial_apicid, and c->apicid.
1. for amd system with apicid lifting, should use hard_smp_processor_id to get c->apicid.
2. for intel system (other than vsmp, and x445), c->apicid c->initial_apicid is the same, so could use hard_smp_processor_id

On the platforms which don't support cpuid leaf 0xb, apicid and initial apicid might be potentially different if the bios changes the apicid. And we don't want to depend on the bios to get the things correct. So where it is not needed, we don't want to depend on the hard_smp_processor_id() for topology detection.

In short, on all the platforms we want to use initial apic id for apicid and phys_proc_id. And only on the required platforms like x445, vsmp, some AMD platforms, we can have their own mechanisms.

Quoted 1 line

3. for vsmp, and x445, do you want to have c->apicid to have real apic id or the same as initial apic_id?

On these platforms, c->apicid should be based on their real apic id.

Quoted 2 lines

this patch is trying to make c->apicid to have real apic_id.

Can you please modify the patch so that we can have exceptions for needed platforms only?

thanks,
suresh

author
#6 lore raw

Re: [PATCH] x86: use hard_smp_processor_id to get apic id in identify_cpu -v2

Quoted 5 lines · Suresh Siddha

In short, on all the platforms we want to use initial apic id for apicid and phys_proc_id. And only on the required platforms like x445, vsmp, some AMD platforms, we can have their own mechanisms.

Quoted 9 lines
Quoted 1 line

3. for vsmp, and x445, do you want to have c->apicid to have real apic id or the same as initial apic_id?

On these platforms, c->apicid should be based on their real apic id.

Quoted 1 line

this patch is trying to make c->apicid to have real apic_id.

Can you please modify the patch so that we can have exceptions for needed platforms only?

please check this one

[PATCH] x86: use hard_smp_processor_id to get apic id for amd k8 cpus

otherwise, system with apci id lifting will have wrong apicid in /proc/cpuinfo

and use that in srat_detect_node

---
 arch/x86/kernel/cpu/amd.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/amd.c +4 -1
Index: linux-2.6/arch/x86/kernel/cpu/amd.c
===================================================================
@@ -277,7 +277,7 @@ static void __cpuinit srat_detect_node(s
 #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
 	int cpu = smp_processor_id();
 	int node;
-	unsigned apicid = cpu_has_apic ? hard_smp_processor_id() : c->apicid;
+	unsigned apicid = c->apicid;
 
 	node = c->phys_proc_id;
 	if (apicid_to_node[apicid] != NUMA_NO_NODE)
@@ -437,6 +437,9 @@ static void __cpuinit init_amd(struct cp
 	}
 	if (c->x86 == 0x10 || c->x86 == 0x11)
 		set_cpu_cap(c, X86_FEATURE_REP_GOOD);
+
+	/* get apicid instead of initial apic id from cpuid */
+	c->apicid = hard_smp_processor_id();
 #else
 
 	/*
#7 lore raw

Re: [PATCH] x86: use hard_smp_processor_id to get apic id in identify_cpu -v2

Quoted 18 lines · Yinghai Lu
Quoted 5 lines · Suresh Siddha

In short, on all the platforms we want to use initial apic id for apicid and phys_proc_id. And only on the required platforms like x445, vsmp, some AMD platforms, we can have their own mechanisms.

Quoted 9 lines
Quoted 1 line

3. for vsmp, and x445, do you want to have c->apicid to have real apic id or the same as initial apic_id?

On these platforms, c->apicid should be based on their real apic id.

Quoted 1 line

this patch is trying to make c->apicid to have real apic_id.

Can you please modify the patch so that we can have exceptions for needed platforms only?

please check this one

Quoted 9 lines

[PATCH] x86: use hard_smp_processor_id to get apic id for amd k8 cpus

otherwise, system with apci id lifting will have wrong apicid in /proc/cpuinfo

and use that in srat_detect_node

Looks better.

author
#8 lore raw

PATCH 1/1 x86: use hard_smp_processor_id to get apic id for amd k8 cpus

otherwise, system with apci id lifting will have wrong apicid in /proc/cpuinfo

and use that in srat_detect_node

---
 arch/x86/kernel/cpu/amd.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/amd.c +4 -1
Index: linux-2.6/arch/x86/kernel/cpu/amd.c
===================================================================
@@ -277,7 +277,7 @@ static void __cpuinit srat_detect_node(s
 #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
 	int cpu = smp_processor_id();
 	int node;
-	unsigned apicid = cpu_has_apic ? hard_smp_processor_id() : c->apicid;
+	unsigned apicid = c->apicid;
 
 	node = c->phys_proc_id;
 	if (apicid_to_node[apicid] != NUMA_NO_NODE)
@@ -437,6 +437,9 @@ static void __cpuinit init_amd(struct cp
 	}
 	if (c->x86 == 0x10 || c->x86 == 0x11)
 		set_cpu_cap(c, X86_FEATURE_REP_GOOD);
+
+	/* get apicid instead of initial apic id from cpuid */
+	c->apicid = hard_smp_processor_id();
 #else
 
 	/*
#9 lore raw

[tip:x86/cpu] x86: Use hard_smp_processor_id() to get apic id for AMD K8 cpus

Commit-ID:  0d96b9ff748b5f57d6f1d6d21209f5745245aadc
Gitweb:     http://git.kernel.org/tip/0d96b9ff748b5f57d6f1d6d21209f5745245aadc
Author:     Yinghai Lu <[email protected]>
AuthorDate: Sat, 29 Aug 2009 13:17:14 -0700
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 4 Sep 2009 09:55:29 +0200

x86: Use hard_smp_processor_id() to get apic id for AMD K8 cpus

Otherwise, system with apci id lifting will have wrong apicid in /proc/cpuinfo.

and use that in srat_detect_node().

Cc Andreas Herrmann <[email protected]>
Cc Suresh Siddha <[email protected]>
Cc Cyrill Gorcunov <[email protected]>

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/cpu/amd.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/amd.c +4 -1
index a76d2c1..e1600c7 100644
@@ -336,7 +336,7 @@ static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c)
 #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
 	int cpu = smp_processor_id();
 	int node;
-	unsigned apicid = cpu_has_apic ? hard_smp_processor_id() : c->apicid;
+	unsigned apicid = c->apicid;
 
 	node = per_cpu(cpu_llc_id, cpu);
 
@@ -481,6 +481,9 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c)
 	}
 	if (c->x86 == 0x10 || c->x86 == 0x11)
 		set_cpu_cap(c, X86_FEATURE_REP_GOOD);
+
+	/* get apicid instead of initial apic id from cpuid */
+	c->apicid = hard_smp_processor_id();
 #else
 
 	/*