x86/AMD: Fix cpu_llc_id for AMD Fam17h systems
Subsystems (2)
PATCH v2 1/2 x86/AMD: Fix cpu_llc_id for AMD Fam17h systems
The current Fam17h cpu_llc_id derivation has an underflow bug when extracting the socket_id value. The socket_id value starts from 0, so subtracting 1 will result in an underflow. This breaks scheduling topology later on since the cpu_llc_id will be incorrect.
The apicid decoding is fixed for bits 3 and above, which give the core complex, node and socket IDs. The LLC is at the core complex level so we can find a unique cpu_llc_id by right shifting the apicid by 3.
We can fix the underflow bug and simplify the code by replacing the current cpu_llc_id derivation with a right shift.
--- arch/x86/kernel/cpu/amd.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/kernel/cpu/amd.c +1 -5
@@ -347,7 +347,6 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)#ifdef CONFIG_SMP unsigned bits;int cpu =smp_processor_id (); -unsigned int socket_id, core_complex_id; bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */
@@ -365,10 +364,7 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)if (c->x86 !=0x17 || !cpuid_edx (0x80000006 ))return ; - socket_id = (c->apicid >> bits) -1 ; - core_complex_id = (c->apicid & ((1 << bits) -1 )) >>3 ; - -per_cpu (cpu_llc_id, cpu) = (socket_id <<3 ) | core_complex_id; +per_cpu (cpu_llc_id, cpu) = c->apicid >>3 ;#endif }
Signature · 1 line
1.9.1
PATCH v2 2/2 x86/AMD: Group cpu_llc_id assignment by topology feature and family
Currently, we assume that a system has multiple last level caches only if there are multiple nodes, and that the cpu_llc_id is equal to the node_id. This no longer applies since Fam17h can have multiple last level caches within a node.
So group the cpu_llc_id assignment by topology feature and family.
The NODEID_MSR feature only applies to Fam10h in which case the llc is at the node level.
The TOPOEXT feature is used on families 15h, 16h and 17h. So far we only see multiple last level caches if L3 caches are available. Otherwise, the cpu_llc_id will default to be the phys_proc_id. We have L3 caches only on families 15h and 17h. On Fam15h, the llc is at the node level. On Fam17h, the llc is at the core complex level and can be found by right shifting the apicid. Also, keep the family checks explicit so that new families will fall back to the default.
Single node systems in families 10h and 15h will have a Node ID of 0 which will be the same as the phys_proc_id, so we don't need to check for multiple nodes before using the node_id.
--- arch/x86/kernel/cpu/amd.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/amd.c +20 -12
@@ -314,11 +314,31 @@ static void amd_get_topology(struct cpuinfo_x86 *c) smp_num_siblings = ((ebx >>8 ) &3 ) +1 ; c->x86_max_cores /= smp_num_siblings; c->cpu_core_id = ebx &0xff ; + +/* +* We may have multiple LLCs if L3 caches exist, so check if we +* have an L3 cache by looking at the L3 cache cpuid leaf. +*/ +if (cpuid_edx (0x80000006 )) { +if (c->x86 ==0x15 ) { +/* LLC is at the node level. */ +per_cpu (cpu_llc_id, cpu) = node_id; + + }else if (c->x86 ==0x17 ) { +/* +* LLC is at the core complex level. +* Core complex id is ApicId[3]. +*/ +per_cpu (cpu_llc_id, cpu) = c->apicid >>3 ; + } + } }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {u64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); node_id = value &7 ; + +per_cpu (cpu_llc_id, cpu) = node_id; }else return ;
@@ -329,9 +349,6 @@ static void amd_get_topology(struct cpuinfo_x86 *c)set_cpu_cap (c,X86_FEATURE_AMD_DCM ); cus_per_node = c->x86_max_cores / nodes_per_socket; -/* store NodeID, use llc_shared_map to store sibling info */ -per_cpu (cpu_llc_id, cpu) = node_id; -/* core id has to be in the [0 .. cores_per_node - 1] range */ c->cpu_core_id %= cus_per_node; }
@@ -356,15 +373,6 @@ static void amd_detect_cmp(struct cpuinfo_x86 *c)/* use socket ID also for last level cache */ per_cpu (cpu_llc_id, cpu) = c->phys_proc_id;amd_get_topology (c); - -/* -* Fix percpu cpu_llc_id here as LLC topology is different -* for Fam17h systems. -*/ -if (c->x86 !=0x17 || !cpuid_edx (0x80000006 )) -return ; - -per_cpu (cpu_llc_id, cpu) = c->apicid >>3 ;#endif }
Signature · 1 line
1.9.1
Re: [PATCH v2 2/2] x86/AMD: Group cpu_llc_id assignment by topology feature and family
Quoted 6 lines · Yazen Ghannam
Currently, we assume that a system has multiple last level caches only if there are multiple nodes, and that the
cpu_llc_idis equal to thenode_id. This no longer applies since Fam17h can have multiple last level caches within a node.So group the
cpu_llc_idassignment by topology feature and family.
That's a very nice intro, good.
Quoted 1 line
The
NODEID_MSRfeature only applies to Fam10h in which case the llc is at
s/llc/LLC (Last Level Cache/
Let's try to have abbreviations written out in their first mention in the text.
Quoted 6 lines
the node level.
The TOPOEXT feature is used on families 15h, 16h and 17h. So far we only see multiple last level caches if L3 caches are available. Otherwise, the
cpu_llc_idwill default to be thephys_proc_id. We have L3 caches only on families 15h and 17h. On Fam15h, the llc is at the node level. On Fam17h,
s/llc/LLC/g
Quoted 1 line
the llc is at the core complex level and can be found by right shifting the
^^^
LLC
Quoted 17 lines
apicid. Also, keep the family checks explicit so that new families will fall back to the default.
Single node systems in families 10h and 15h will have a Node ID of 0 which will be the same as the
phys_proc_id, so we don't need to check for multiple nodes before using thenode_id.Signed-off-by Yazen Ghannam <[email protected]>--- arch/x86/kernel/cpu/amd.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)arch/x86/kernel/cpu/amd.c +0
-0
arch/x86/kernel/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 320
Quoted 7 lines
arch/x86/kernel/cpu/amd.c +4
-0@@ -314,11 +314,31 @@ static void amd_get_topology(struct cpuinfo_x86 *c) smp_num_siblings = ((ebx >>8 ) &3 ) +1 ; c->x86_max_cores /= smp_num_siblings; c->cpu_core_id = ebx &0xff ; + +/* +* We may have multiple LLCs if L3 caches exist, so check if we +* have an L3 cache by looking at the L3 cache cpuid leaf.
x86 instructions in caps please: CPUID
arch/x86/kernel/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 327
Quoted 7 lines
arch/x86/kernel/cpu/amd.c +7
-0+*/ +if (cpuid_edx (0x80000006 )) { +if (c->x86 ==0x15 ) { +/* LLC is at the node level. */ +per_cpu (cpu_llc_id, cpu) = node_id; + + }else if (c->x86 ==0x17 ) {
How about >= ?
Quoted 6 lines
arch/x86/kernel/cpu/amd.c +6
-0+/* +* LLC is at the core complex level. +* Core complex id is ApicId[3]. +*/ +per_cpu (cpu_llc_id, cpu) = c->apicid >>3 ; + }
arch/x86/kernel/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 343
Quoted 10 lines
arch/x86/kernel/cpu/amd.c +3
-0+ } }else if (cpu_has (c,X86_FEATURE_NODEID_MSR )) {u64 value;rdmsrl (MSR_FAM10H_NODE_ID , value); node_id = value &7 ; + +per_cpu (cpu_llc_id, cpu) = node_id; }else return ;
Btw, please add for your next submission:
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- Re: [PATCH v2 2/2] x86/AMD: Group cpu_llc_id assignment by topology feature and family
Quoted 7 lines
Quoted 2 lines
The
NODEID_MSRfeature only applies to Fam10h in which case the llc is ats/llc/LLC (Last Level Cache/
Let's try to have abbreviations written out in their first mention in the text.
Okay.
Quoted 9 lines
Quoted 6 lines
the node level.
The TOPOEXT feature is used on families 15h, 16h and 17h. So far we only see multiple last level caches if L3 caches are available. Otherwise, the
cpu_llc_idwill default to be thephys_proc_id. We have L3 caches only on families 15h and 17h. On Fam15h, the llc is at the node level. On Fam17h,s/llc/LLC/g
Ack.
Quoted 5 lines
Quoted 1 line
the llc is at the core complex level and can be found by right shifting the
^^^LLC
Ack.
Quoted 7 lines
arch/x86/kernel/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 320
Quoted 4 lines
arch/x86/kernel/cpu/amd.c +4
-0+ +/* +* We may have multiple LLCs if L3 caches exist, so check if we +* have an L3 cache by looking at the L3 cache cpuid leaf. x86 instructions in caps please: CPUID
Ack.
Quoted 10 lines
arch/x86/kernel/cpu/amd.c static void amd_get_topology(struct cpuinfo_x86 *c) · line 327
Quoted 7 lines
arch/x86/kernel/cpu/amd.c +7
-0+*/ +if (cpuid_edx (0x80000006 )) { +if (c->x86 ==0x15 ) { +/* LLC is at the node level. */ +per_cpu (cpu_llc_id, cpu) = node_id; + + }else if (c->x86 ==0x17 ) {How about >= ?
This APICID format is only valid for Fam17h. What I'm going for is that we fall back to a sensible default if we don't have a better assignment for a new family. At first I thought that phys_proc_id would be good but now I think node_id is better as a sensible default. I'll make this change in the V3 set.
Quoted 5 lines
Btw, please add for your next submission:
Tested-by Borislav Petkov <[email protected]>
For both patches?
Thanks,
Yazen
Re: [PATCH v2 2/2] x86/AMD: Group cpu_llc_id assignment by topology feature and family
Quoted 1 line · Yazen Ghannam
For both patches?
Yap, I ran them both. But since you're going to change stuff again, I'll run v3 too so don't add the tag yet.
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- Quoted 1 line · Yazen Ghannam
The current Fam17h
cpu_llc_idderivation has an underflow bug when
^ (Last Level Cache ID)
Let's write it out the first time.
Quoted 5 lines
extracting the
socket_idvalue. Thesocket_idvalue starts from 0, so subtracting 1 will result in an underflow. This breaks scheduling topology later on since thecpu_llc_idwill be incorrect.The apicid decoding is fixed for bits 3 and above,
^
"is fixed ... in register... "
Quoted 3 lines
which give the core
complex, node and socket IDs. The LLC is at the core complex level so we can find a uniquecpu_llc_idby right shifting the apicid by 3.
"... because then the LSBit will be the Core Complex ID."
Quoted 7 lines
We can fix the underflow bug and simplify the code by replacing the current
cpu_llc_idderivation with a right shift.Signed-off-by Yazen Ghannam <[email protected]>Cc <[email protected]> # v4.4..Fixes 3849e91f571d ("x86/AMD: Fix last level cache topology for AMD Fam17h systems")---
I'll run it soon.
Signature · 5 lines
Regards/Gruss,
Boris.
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- Quoted 6 lines
Quoted 1 line
The current Fam17h
cpu_llc_idderivation has an underflow bug when^ (Last Level Cache ID)Let's write it out the first time.
Ack.
Quoted 5 lines
Quoted 2 lines
The apicid decoding is fixed for bits 3 and above,
^"is fixed ... in register... "
Ack.
Quoted 6 lines
Quoted 3 lines
which give the core
complex, node and socket IDs. The LLC is at the core complex level so we can find a uniquecpu_llc_idby right shifting the apicid by 3."... because then the LSBit will be the Core Complex ID."
Ack.
Quoted 10 lines
Quoted 7 lines
We can fix the underflow bug and simplify the code by replacing the current
cpu_llc_idderivation with a right shift.Signed-off-by Yazen Ghannam <[email protected]>Cc <[email protected]> # v4.4..Fixes 3849e91f571d ("x86/AMD: Fix last level cache topology for AMD Fam17h systems")---
I'll run it soon.
Thanks,
Yazen