MCE, AMD: Select SMP explicitly
Subsystems (6)
Borislav Petkov
maintainerPATCH 1/1 MCE, AMD: Select SMP explicitly
Randy Dunlap reported that building randconfigs which do not select CONFIG_SMP cause the following link error:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Fix it.
--- arch/x86/Kconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/Kconfig +1 -1
@@ -897,7 +897,7 @@ config X86_MCE_INTEL config X86_MCE_AMD def_bool y prompt "AMD MCE features" - depends on X86_MCE && X86_LOCAL_APIC + depends on X86_MCE && X86_LOCAL_APIC && SMP ---help--- Additional support for AMD specific MCE features such as the DRAM Error Threshold.
Signature · 1 line
1.7.9
Hi,
Quoted 10 lines · Borislav Petkov
Randy Dunlap reported that building randconfigs which do not select
CONFIG_SMPcause the following link error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Fix it.
[...]
arch/x86/Kconfig config X86_MCE_INTEL · line 900
Quoted 5 lines
config
X86_MCE_AMDarch/x86/Kconfig +1
-1def_bool y prompt "AMD MCE features" - depends on X86_MCE && X86_LOCAL_APIC + depends on X86_MCE && X86_LOCAL_APIC && SMP
Is this feature truly irrelevant on UP systems? I ask because I've always enabled this option on my UP AMD systems in the past...
Cheers,
Signature · 1 line
Nick Bowler, Elliptic Technologies (http://www.elliptictech.com/)
Borislav Petkov
maintainerQuoted 14 lines · Nick Bowler
Hi,
Quoted 10 lines · Borislav Petkov
Randy Dunlap reported that building randconfigs which do not select
CONFIG_SMPcause the following link error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Fix it.
[...]
Quoted 8 lines
arch/x86/Kconfig config X86_MCE_INTEL · line 900
Quoted 5 lines
config
X86_MCE_AMDarch/x86/Kconfig +1
-1def_bool y prompt "AMD MCE features" - depends on X86_MCE && X86_LOCAL_APIC + depends on X86_MCE && X86_LOCAL_APIC && SMPIs this feature truly irrelevant on UP systems? I ask because I've always enabled this option on my UP AMD systems in the past...
No, you're right. Thanks for the suggestion. Scratch that version, I'll think of a better fix.
Thanks.
Signature · 2 lines
Regards/Gruss, Boris.
Borislav Petkov
maintainerMCE, AMD: Hide smp-only code around CONFIG_SMP
Quoted 5 lines · Borislav Petkov
Quoted 2 lines
Is this feature truly irrelevant on UP systems? I ask because I've always enabled this option on my UP AMD systems in the past...
No, you're right. Thanks for the suggestion. Scratch that version, I'll think of a better fix.
Ok, I think I got it, pls take a look and scream if something's amiss.
@Randy: it builds fine with your randconfig and with mine default one; I'd appreciate if you could run it too, just in case.
Thanks.
--
From: Borislav Petkov <[email protected]>
Date: Fri, 3 Feb 2012 18:07:54 +0100
Subject: [PATCH] MCE, AMD: Hide smp-only code around CONFIG_SMP
141168c36cde ("x86: Simplify code by removing a !SMP #ifdefs from 'struct cpuinfo_x86'") removed a bunch of CONFIG_SMP ifdefs around code touching struct cpuinfo_x86 members but also caused the following build error with Randy's randconfigs:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Restore the #ifdef in threshold_create_bank() which creates symlinks on the non-BSP CPUs.
--- arch/x86/kernel/cpu/mcheck/mce_amd.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/mcheck/mce_amd.c +2 -0
@@ -528,6 +528,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)sprintf (name,"threshold_bank%i" , bank); +#ifdef CONFIG_SMP if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ i =cpumask_first (cpu_llc_shared_mask (cpu));
@@ -553,6 +554,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) goto out; } +#endif b =kzalloc (sizeof (struct threshold_bank ),GFP_KERNEL );if (!b) {
Signature · 6 lines
1.7.9 -- Regards/Gruss, Boris.
Randy Dunlap
Acked-byRe: MCE, AMD: Hide smp-only code around CONFIG_SMP
Quoted 11 lines · Borislav Petkov
Quoted 5 lines · Borislav Petkov
Quoted 2 lines
Is this feature truly irrelevant on UP systems? I ask because I've always enabled this option on my UP AMD systems in the past...
No, you're right. Thanks for the suggestion. Scratch that version, I'll think of a better fix.
Ok, I think I got it, pls take a look and scream if something's amiss.
@Randy: it builds fine with your randconfig and with mine default one; I'd appreciate if you could run it too, just in case.
Yes, it's fine for me also.
Thanks.
Quoted 46 lines
Thanks.
--
From: Borislav Petkov <[email protected]>
Date: Fri, 3 Feb 2012 18:07:54 +0100
Subject: [PATCH] MCE, AMD: Hide smp-only code aroundCONFIG_SMP
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") removed a bunch ofCONFIG_SMPifdefs around code touching structcpuinfo_x86members but also caused the following build error with Randy's randconfigs:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Restore the #ifdef in
threshold_create_bank()which creates symlinks on the non-BSP CPUs.Cc Kevin Winchester <[email protected]>Cc Ingo Molnar <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Borislav Petkov <[email protected]>--- arch/x86/kernel/cpu/mcheck/mce_amd.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)arch/x86/kernel/cpu/mcheck/mce_amd.c +2
-0@@ -528,6 +528,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)sprintf (name,"threshold_bank%i" , bank); +#ifdef CONFIG_SMP if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ i =cpumask_first (cpu_llc_shared_mask (cpu));@@ -553,6 +554,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) goto out; } +#endif b =kzalloc (sizeof (struct threshold_bank ),GFP_KERNEL );if (!b) {
Signature · 2 lines
~Randy *** Remember to use Documentation/SubmitChecklist when testing your code ***
Re: MCE, AMD: Hide smp-only code around CONFIG_SMP
In reply to Borislav PetkovQuoted 43 lines · Borislav Petkov
Quoted 5 lines · Borislav Petkov
Quoted 2 lines
Is this feature truly irrelevant on UP systems? I ask because I've always enabled this option on my UP AMD systems in the past...
No, you're right. Thanks for the suggestion. Scratch that version, I'll think of a better fix.
Ok, I think I got it, pls take a look and scream if something's amiss.
@Randy: it builds fine with your randconfig and with mine default one; I'd appreciate if you could run it too, just in case.
Thanks.
--
From: Borislav Petkov <[email protected]>
Date: Fri, 3 Feb 2012 18:07:54 +0100
Subject: [PATCH] MCE, AMD: Hide smp-only code aroundCONFIG_SMP
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") removed a bunch ofCONFIG_SMPifdefs around code touching structcpuinfo_x86members but also caused the following build error with Randy's randconfigs:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Restore the #ifdef in
threshold_create_bank()which creates symlinks on the non-BSP CPUs.Cc Kevin Winchester <[email protected]>Cc Ingo Molnar <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Borislav Petkov <[email protected]>--- arch/x86/kernel/cpu/mcheck/mce_amd.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)arch/x86/kernel/cpu/mcheck/mce_amd.c +0
-0
arch/x86/kernel/cpu/mcheck/mce_amd.c static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) · line 533
Quoted 6 lines
arch/x86/kernel/cpu/mcheck/mce_amd.c +1
-0@@ -528,6 +528,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)sprintf (name,"threshold_bank%i" , bank); +#ifdef CONFIG_SMP if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ i =cpumask_first (cpu_llc_shared_mask (cpu));
Could we please just define an obvious cpu_llc_shared_mask on UP (one bit long and set to 1) and not reintroduce the ugly #ifdef CONFIG_SMP?
Thanks,
Ingo
Re: MCE, AMD: Hide smp-only code around CONFIG_SMP
Quoted 29 lines · Ingo Molnar
Quoted 26 lines · Borislav Petkov
Quoted 5 lines · Borislav Petkov
Quoted 2 lines
Is this feature truly irrelevant on UP systems? I ask because I've always enabled this option on my UP AMD systems in the past...
No, you're right. Thanks for the suggestion. Scratch that version, I'll think of a better fix.
Ok, I think I got it, pls take a look and scream if something's amiss.
@Randy: it builds fine with your randconfig and with mine default one; I'd appreciate if you could run it too, just in case.
Thanks.
--
From: Borislav Petkov <[email protected]>
Date: Fri, 3 Feb 2012 18:07:54 +0100
Subject: [PATCH] MCE, AMD: Hide smp-only code aroundCONFIG_SMP
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") removed a bunch ofCONFIG_SMPifdefs around code touching structcpuinfo_x86members but also caused the following build error with Randy's randconfigs:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Quoted 8 lines
Quoted 3 lines
Restore the #ifdef in
threshold_create_bank()which creates symlinks on the non-BSP CPUs.Could we please just define an obvious
cpu_llc_shared_maskon UP (one bit long and set to 1) and not reintroduce the ugly #ifdefCONFIG_SMP?
I ran into this when I was working on the original patch, and I thought I had solved all of the issues like this. Unfortunately not.
The problem is that there doesn't seem to be a great place to define this (along with a few other functions like this) on UP. We have <linux/smp.h> including <asm/smp.h> in the CONFIG_SMP case, but no arch-specific defs for UP. Would it be crazy to have <linux/smp.h> include a new <asm/up.h> for !CONFIG_SMP?
I am willing to prepare the patch, if someone can tell me where to define cpu_llc_shared_mask for UP?
Thanks,
Signature · 1 line
Kevin Winchester
Borislav Petkov
maintainerRe: MCE, AMD: Hide smp-only code around CONFIG_SMP
In reply to Ingo MolnarQuoted 3 lines · Ingo Molnar
Could we please just define an obvious
cpu_llc_shared_maskon UP (one bit long and set to 1) and not reintroduce the ugly #ifdefCONFIG_SMP?
Ok, here's a tentative proposed solution where I was trying not to fatfinger the cpumask magic. Let me know if this is similar to what you had in mind. The call to cpu_llc_shared_mask(int cpu) on UP might cause a problem if the cpu arg is not 0 but it should not happen anyway and there should be other problems with the caller side anyway.
Thanks.
--
From: Borislav Petkov <[email protected]>
Date: Tue, 7 Feb 2012 21:40:22 +0100
Subject: [PATCH] MCE, AMD: Fix !CONFIG_SMP build
141168c36cde ("x86: Simplify code by removing a !SMP #ifdefs from 'struct cpuinfo_x86'") removed a bunch of CONFIG_SMP ifdefs around code touching struct cpuinfo_x86 members but also caused the following build error with Randy's randconfigs:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Fix that by adding a UP version of the cpu_llc_shared_map, as Ingo suggested.
--- arch/x86/include/asm/smp.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
arch/x86/include/asm/smp.h +8 -1
@@ -33,8 +33,15 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ + +#ifdef CONFIG_SMP +/* CPUs sharing the last level cache: */ DECLARE_PER_CPU (cpumask_var_t, cpu_llc_shared_map); +#else +static DECLARE_BITMAP(cpu_llc_shared_bits, NR_CPUS) __read_mostly = { [0] = 1UL }; +static struct cpumask *const cpu_llc_shared_map =to_cpumask (cpu_llc_shared_bits); +#endif +DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);
Signature · 5 lines
1.7.9 -- Regards/Gruss, Boris.
Re: MCE, AMD: Hide smp-only code around CONFIG_SMP
Quoted 59 lines · Borislav Petkov
Quoted 3 lines · Ingo Molnar
Could we please just define an obvious
cpu_llc_shared_maskon UP (one bit long and set to 1) and not reintroduce the ugly #ifdefCONFIG_SMP?Ok, here's a tentative proposed solution where I was trying not to fatfinger the cpumask magic. Let me know if this is similar to what you had in mind. The call to
cpu_llc_shared_mask(int cpu)on UP might cause a problem if the cpu arg is not 0 but it should not happen anyway and there should be other problems with the caller side anyway.Thanks.
--
From: Borislav Petkov <[email protected]>
Date: Tue, 7 Feb 2012 21:40:22 +0100
Subject: [PATCH] MCE, AMD: Fix !CONFIG_SMP build
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") removed a bunch ofCONFIG_SMPifdefs around code touching structcpuinfo_x86members but also caused the following build error with Randy's randconfigs:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Fix that by adding a UP version of the
cpu_llc_shared_map, as Ingo suggested.Cc Kevin Winchester <[email protected]>Cc Ingo Molnar <[email protected]>Cc Randy Dunlap <[email protected]>Signed-off-by Borislav Petkov <[email protected]>---
arch/x86/include/asm/smp.h | 9 ++++++++-1 files changed, 8 insertions(+), 1 deletions(-)arch/x86/include/asm/smp.h +8
-2@@ -33,8 +33,15 @@ static inline bool cpu_has_ht_siblings(void) DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map); DECLARE_PER_CPU(cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ + +#ifdef CONFIG_SMP +/* CPUs sharing the last level cache: */ DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map); +#else +static DECLARE_BITMAP(cpu_llc_shared_bits, NR_CPUS) __read_mostly = { [0] = 1UL }; +static struct cpumask *const cpu_llc_shared_map =to_cpumask (cpu_llc_shared_bits); +#endif + DECLARE_PER_CPU(u16, cpu_llc_id); DECLARE_PER_CPU(int, cpu_number); --
Quoted 2 lines
1.7.9
Does this work? arch/x86/kernel/cpu/mcheck/mce_amd.c includes <linux/smp.h> rather than <asm/smp.h> directly. And <linux/smp.h> only includes <asm/smp.h> for the CONFIG_SMP case. Or perhaps one of the other includes in mce_amd.c includes <asm/smp.h>?
Signature · 1 line
Kevin Winchester
Borislav Petkov
maintainerRe: MCE, AMD: Hide smp-only code around CONFIG_SMP
Quoted 4 lines · Kevin Winchester
Does this work?
arch/x86/kernel/cpu/mcheck/mce_amd.cincludes <linux/smp.h> rather than <asm/smp.h> directly. And <linux/smp.h> only includes <asm/smp.h> for theCONFIG_SMPcase. Or perhaps one of the other includes inmce_amd.cincludes <asm/smp.h>?
It looks like it:
$ make arch/x86/kernel/cpu/mcheck/mce_amd.i $ grep 'asm/smp.h' arch/x86/kernel/cpu/mcheck/mce_amd.i # 1 "/home/boris/kernel/linux-2.6/arch/x86/include/asm/smp.h" 1 # 13 "/home/boris/kernel/linux-2.6/arch/x86/include/asm/smp.h" # 14 "/home/boris/kernel/linux-2.6/arch/x86/include/asm/smp.h" 2 # 16 "/home/boris/kernel/linux-2.6/arch/x86/include/asm/smp.h" 2
and this one pulls in the cpu_llc* crap.
# 183 "/home/boris/kernel/linux-2.6/arch/x86/include/asm/smp.h" # 225 "/home/boris/kernel/linux-2.6/arch/x86/include/asm/smp.h" # 236 "/home/boris/kernel/linux-2.6/arch/x86/include/asm/smp.h"
So some other headers seem to pull in asm/smp.h.
HTH.
Signature · 2 lines
Regards/Gruss, Boris.
Re: MCE, AMD: Hide smp-only code around CONFIG_SMP
In reply to Borislav PetkovQuoted 4 lines · Borislav Petkov
+++
b/arch/x86/include/asm/smp.harch/x86/include/asm/smp.h +0
-0@@ -33,8 +33,15 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);
arch/x86/include/asm/smp.h static inline bool cpu_has_ht_siblings(void) · line 43
Quoted 10 lines
arch/x86/include/asm/smp.h +7
-1DECLARE_PER_CPU (cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ + +#ifdef CONFIG_SMP +/* CPUs sharing the last level cache: */ DECLARE_PER_CPU (cpumask_var_t, cpu_llc_shared_map); +#else +static DECLARE_BITMAP(cpu_llc_shared_bits, NR_CPUS) __read_mostly = { [0] = 1UL }; +static struct cpumask *const cpu_llc_shared_map =to_cpumask (cpu_llc_shared_bits); +#endif
Why not just expose it like on SMP?
We want to *reduce* the specialness of UP, not increase it - one more word of .data and .text does not matter much - UP is becoming more and more an oddball, rarely tested config. By the time these changes hit any real boxes it will be even more oddball.
Thanks,
Ingo
Re: MCE, AMD: Hide smp-only code around CONFIG_SMP
Quoted 20 lines · Ingo Molnar
Quoted 4 lines · Borislav Petkov
+++
b/arch/x86/include/asm/smp.harch/x86/include/asm/smp.h +0
-0@@ -33,8 +33,15 @@ static inline bool cpu_has_ht_siblings(void) DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);arch/x86/include/asm/smp.h static inline bool cpu_has_ht_siblings(void) · line 43
Quoted 10 lines
arch/x86/include/asm/smp.h +7
-1DECLARE_PER_CPU(cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ + +#ifdef CONFIG_SMP +/* CPUs sharing the last level cache: */ DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map); +#else +static DECLARE_BITMAP(cpu_llc_shared_bits, NR_CPUS) __read_mostly = { [0] = 1UL }; +static struct cpumask *const cpu_llc_shared_map =to_cpumask (cpu_llc_shared_bits); +#endif Why not just expose it like on SMP?
Quoted 6 lines
We want to *reduce* the specialness of UP, not increase it - one more word of .data and .text does not matter much - UP is becoming more and more an oddball, rarely tested config. By the time these changes hit any real boxes it will be even more oddball.
It seems that cpu_llc_shared_map is actually defined in arch/x86/kernel/smpboot.c, which is not compiled/linked for UP builds.
Is there an equivalent file for UP that could be used instead, or
could the:
DEFINE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
be moved to some other file?
Generally, it sounds like you might approve of an eventual merging of the boot paths for SMP and UP. Is that true? I wonder how much work that would be. That would really reduce the specialness of UP.
Signature · 1 line
Kevin Winchester
Re: MCE, AMD: Hide smp-only code around CONFIG_SMP
Quoted 34 lines · Kevin Winchester
Quoted 20 lines · Ingo Molnar
Quoted 4 lines · Borislav Petkov
+++
b/arch/x86/include/asm/smp.harch/x86/include/asm/smp.h +0
-0@@ -33,8 +33,15 @@ static inline bool cpu_has_ht_siblings(void) DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);arch/x86/include/asm/smp.h static inline bool cpu_has_ht_siblings(void) · line 43
Quoted 10 lines
arch/x86/include/asm/smp.h +7
-1DECLARE_PER_CPU(cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ + +#ifdef CONFIG_SMP +/* CPUs sharing the last level cache: */ DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map); +#else +static DECLARE_BITMAP(cpu_llc_shared_bits, NR_CPUS) __read_mostly = { [0] = 1UL }; +static struct cpumask *const cpu_llc_shared_map =to_cpumask (cpu_llc_shared_bits); +#endif Why not just expose it like on SMP?
Quoted 6 lines
We want to *reduce* the specialness of UP, not increase it - one more word of .data and .text does not matter much - UP is becoming more and more an oddball, rarely tested config. By the time these changes hit any real boxes it will be even more oddball.
It seems that
cpu_llc_shared_mapis actually defined inarch/x86/kernel/smpboot.c, which is not compiled/linked for UP builds.
Is there an equivalent file for UP that could be used
instead, or could the:
Quoted 3 lines
DEFINE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);be moved to some other file?
Yes, it should be moved into struct cpuinfo_x86, and thus we'd remove cpu_llc_shared_map altogether, it would be named cpu->llc_shared_map or so - taking up a single bit (or maybe zero bits) on UP.
Quoted 4 lines
Generally, it sounds like you might approve of an eventual merging of the boot paths for SMP and UP. Is that true? I wonder how much work that would be. That would really reduce the specialness of UP.
I generally approve just about any patch that works and reduces complexity! :-) The boot path is rather ambitious, but if you want to try, feel free ...
Thanks,
Ingo
PATCH 1/1 x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Commit 141168c36cde ("x86: Simplify code by removing a !SMP #ifdefs from 'struct cpuinfo_x86'") caused the compilation error:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to 'cpu_llc_shared_map'
by removing an #ifdef CONFIG_SMP around a block containing a reference to cpu_llc_shared_map. Rather than replace the #ifdef, move cpu_llc_shared_map to be a new field llc_shared_map in struct cpuinfo_x86 and adjust all references to cpu_llc_shared_map.
--- arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/smp.h | 6 ------ arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/mcheck/mce_amd.c | 7 ++++--- arch/x86/kernel/smpboot.c | 15 ++++++--------- arch/x86/xen/smp.c | 1 - 6 files changed, 13 insertions(+), 21 deletions(-)
arch/x86/include/asm/processor.h +1 -0
@@ -110,6 +110,7 @@ struct cpuinfo_x86 {/* Index into per_cpu list: */ u16 cpu_index;u32 microcode; +cpumask_var_t llc_shared_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -34,7 +34,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);/* cpus sharing the last level cache: */ -DECLARE_PER_CPU (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);
@@ -48,11 +47,6 @@ static inline struct cpumask *cpu_core_mask(int cpu)return per_cpu (cpu_core_map, cpu); } -static inline struct cpumask *cpu_llc_shared_mask (int cpu) -{ -return per_cpu (cpu_llc_shared_map, cpu); -} -DECLARE_EARLY_PER_CPU (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU (u16, x86_bios_cpu_apicid);#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86_32 )
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -734,11 +734,11 @@ static int __cpuinit cache_shared_amd_cpu_map_setup(unsigned int cpu, int index) ret =0 ;if (index ==3 ) { ret =1 ; -for_each_cpu (i,cpu_llc_shared_mask (cpu)) { +for_each_cpu (i, c->llc_shared_map) {if (!per_cpu (ici_cpuid4_info, i))continue ; this_leaf =CPUID4_INFO_IDX (i, index); -for_each_cpu (sibling,cpu_llc_shared_mask (cpu)) { +for_each_cpu (sibling, c->llc_shared_map) {if (!cpu_online (sibling))continue ;set_bit (sibling, this_leaf->shared_cpu_map);
arch/x86/kernel/cpu/mcheck/mce_amd.c +4 -3
@@ -525,11 +525,12 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)struct threshold_bank *b =NULL ;struct device *dev = mce_device[cpu];char name[32 ]; +struct cpuinfo_x86 *c = &cpu_data (cpu);sprintf (name,"threshold_bank%i" , bank); -if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ - i =cpumask_first (cpu_llc_shared_mask (cpu)); +if (c->cpu_core_id && shared_bank[bank]) {/* symlink */ + i =cpumask_first (c->llc_shared_map);/* first core not up yet */ if (cpu_data (i).cpu_core_id)
@@ -548,7 +549,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)if (err) goto out; -cpumask_copy (b->cpus,cpu_llc_shared_mask (cpu)); +cpumask_copy (b->cpus, c->llc_shared_map);per_cpu (threshold_banks, cpu)[bank] = b; goto out;
arch/x86/kernel/smpboot.c +6 -9
@@ -127,8 +127,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);DEFINE_PER_CPU (cpumask_var_t, cpu_core_map);EXPORT_PER_CPU_SYMBOL (cpu_core_map); -DEFINE_PER_CPU (cpumask_var_t, cpu_llc_shared_map); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
@@ -337,8 +335,8 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2)cpumask_set_cpu (cpu2,cpu_sibling_mask (cpu1));cpumask_set_cpu (cpu1,cpu_core_mask (cpu2));cpumask_set_cpu (cpu2,cpu_core_mask (cpu1)); -cpumask_set_cpu (cpu1,cpu_llc_shared_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_llc_shared_mask (cpu1)); +cpumask_set_cpu (cpu1,cpu_data (cpu2).llc_shared_map); +cpumask_set_cpu (cpu2,cpu_data (cpu1).llc_shared_map); }
@@ -367,7 +365,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu,cpu_sibling_mask (cpu)); } -cpumask_set_cpu (cpu,cpu_llc_shared_mask (cpu)); +cpumask_set_cpu (cpu, c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) {cpumask_copy (cpu_core_mask (cpu),cpu_sibling_mask (cpu));
@@ -378,8 +376,8 @@ void __cpuinit set_cpu_sibling_map(int cpu)for_each_cpu (i, cpu_sibling_setup_mask) {if (per_cpu (cpu_llc_id, cpu) !=BAD_APICID &&per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i)) { -cpumask_set_cpu (i,cpu_llc_shared_mask (cpu)); -cpumask_set_cpu (cpu,cpu_llc_shared_mask (i)); +cpumask_set_cpu (i, c->llc_shared_map); +cpumask_set_cpu (cpu,cpu_data (i).llc_shared_map); }if (c->phys_proc_id ==cpu_data (i).phys_proc_id) {cpumask_set_cpu (i,cpu_core_mask (cpu));
@@ -418,7 +416,7 @@ const struct cpumask *cpu_coregroup_mask(int cpu) !(cpu_has(c, X86_FEATURE_AMD_DCM)))return cpu_core_mask (cpu); else - return cpu_llc_shared_mask(cpu); + return c->llc_shared_map; }static void impress_friends (void )
@@ -1053,7 +1051,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
arch/x86/xen/smp.c +0 -1
@@ -225,7 +225,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
Signature · 1 line
1.7.9
Re: [PATCH] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Quoted 35 lines · Kevin Winchester
Commit
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") caused the compilation error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to '
cpu_llc_shared_map'by removing an #ifdef
CONFIG_SMParound a block containing a reference tocpu_llc_shared_map. Rather than replace the #ifdef, movecpu_llc_shared_mapto be a new fieldllc_shared_mapin structcpuinfo_x86and adjust all references tocpu_llc_shared_map.Signed-off-by Kevin Winchester <[email protected]>---
arch/x86/include/asm/processor.h | 1 +arch/x86/include/asm/smp.h| 6 ------arch/x86/kernel/cpu/intel_cacheinfo.c| 4 ++--arch/x86/kernel/cpu/mcheck/mce_amd.c| 7 ++++---arch/x86/kernel/smpboot.c| 15 ++++++---------arch/x86/xen/smp.c| 1 -6 files changed, 13 insertions(+), 21 deletions(-)static void
impress_friends(void)arch/x86/kernel/smpboot.c +0
-1@@ -1053,7 +1051,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus) for_each_possible_cpu(i) { zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); - zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL); } set_cpu_sibling_map(0);arch/x86/xen/smp.c +0
-0
arch/x86/xen/smp.c static void __init xen_smp_prepare_cpus(unsigned int max_cpus) · line 230
Quoted 7 lines
arch/x86/xen/smp.c +0
-1@@ -225,7 +225,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus) for_each_possible_cpu(i) { zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); - zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL); } set_cpu_sibling_map(0);
I just realized that I took out a couple of allocations here for cpu_llc_shared_map, without replacing them. Am I leaving cpuinfo_x86.llc_shared_map unallocated then, and just writing to whatever address that field happened to get?
Re: [PATCH] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Quoted 40 lines · Kevin Winchester
Quoted 39 lines · Kevin Winchester
Commit
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") caused the compilation error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to '
cpu_llc_shared_map'by removing an #ifdef
CONFIG_SMParound a block containing a reference tocpu_llc_shared_map. Rather than replace the #ifdef, movecpu_llc_shared_mapto be a new fieldllc_shared_mapin structcpuinfo_x86and adjust all references tocpu_llc_shared_map.Signed-off-by Kevin Winchester <[email protected]>---
arch/x86/include/asm/processor.h | 1 +arch/x86/include/asm/smp.h| 6 ------arch/x86/kernel/cpu/intel_cacheinfo.c| 4 ++--arch/x86/kernel/cpu/mcheck/mce_amd.c| 7 ++++---arch/x86/kernel/smpboot.c| 15 ++++++---------arch/x86/xen/smp.c| 1 -6 files changed, 13 insertions(+), 21 deletions(-)static void
impress_friends(void)arch/x86/kernel/smpboot.c +0
-1@@ -1053,7 +1051,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus) for_each_possible_cpu(i) { zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); - zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL); } set_cpu_sibling_map(0);arch/x86/xen/smp.c +0
-1@@ -225,7 +225,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus) for_each_possible_cpu(i) { zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); - zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
Quoted 8 lines
arch/x86/xen/smp.c static void __init xen_smp_prepare_cpus(unsigned int max_cpus) · line 230
Quoted 3 lines
arch/x86/xen/smp.c +0
-0} set_cpu_sibling_map(0);I just realized that I took out a couple of allocations here for
cpu_llc_shared_map, without replacing them. Am I leaving cpuinfo_x86.llc_shared_map unallocated then, and just writing to whatever address that field happened to get?
That will probably crash CONFIG_CPUMASK_OFFSTACK=y kernels.
The simplest approach would be to use a cpumask_t (i.e. not a variable cpumask_var_t one), on the [valid looking] assumption that cpuinfo_x86 gets allocated in sane ways - i.e. never on the kernel stack and such.
The before/after vmlinux 'size' result should be inspected, with NR_CPUs set to 4096 and OFFSTACK activated in the .config, to see how bad the size effect is - but I think it should not be too bad.
Thanks,
Ingo
PATCH v2 1/1 x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Commit 141168c36cde ("x86: Simplify code by removing a !SMP #ifdefs from 'struct cpuinfo_x86'") caused the compilation error:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to 'cpu_llc_shared_map'
by removing an #ifdef CONFIG_SMP around a block containing a reference to cpu_llc_shared_map. Rather than replace the #ifdef, move cpu_llc_shared_map to be a new cpumask_t field llc_shared_map in struct cpuinfo_x86 and adjust all references to cpu_llc_shared_map.
The size effects on various kernels are as follows:
text data bss dec hex filename
5281572 513296 1044480 6839348 685c34 vmlinux.up
5281572 513296 1044480 6839348 685c34 vmlinux.up.patched
5548860 516792 1110016 7175668 6d7df4 vmlinux.smp.2
5548837 516792 1110016 7175645 6d7ddd vmlinux.smp.2.patched
5595965 706840 1310720 7613525 742c55 vmlinux.smp.max
5595876 707880 1310720 7614476 74300c vmlinux.smp.max.patched
It can be seen that this change has no effect on UP, a minor effect for SMP with Max 2 CPUs, and a more substantial but still not overly large effect for MAXSMP.
---
I'm still wondering if I should I give the same treatment to:
cpu_sibling_mapcpu_core_mapcpu_llc_idcpu_number
or is that going too far?
arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/smp.h | 6 ------ arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/mcheck/mce_amd.c | 7 ++++--- arch/x86/kernel/smpboot.c | 15 ++++++--------- arch/x86/xen/smp.c | 1 - 6 files changed, 13 insertions(+), 21 deletions(-)
arch/x86/include/asm/processor.h +1 -0
@@ -110,6 +110,7 @@ struct cpuinfo_x86 {/* Index into per_cpu list: */ u16 cpu_index;u32 microcode; +cpumask_t llc_shared_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -34,7 +34,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);/* cpus sharing the last level cache: */ -DECLARE_PER_CPU (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);
@@ -48,11 +47,6 @@ static inline struct cpumask *cpu_core_mask(int cpu)return per_cpu (cpu_core_map, cpu); } -static inline struct cpumask *cpu_llc_shared_mask (int cpu) -{ -return per_cpu (cpu_llc_shared_map, cpu); -} -DECLARE_EARLY_PER_CPU (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU (u16, x86_bios_cpu_apicid);#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86_32 )
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -734,11 +734,11 @@ static int __cpuinit cache_shared_amd_cpu_map_setup(unsigned int cpu, int index) ret =0 ;if (index ==3 ) { ret =1 ; -for_each_cpu (i,cpu_llc_shared_mask (cpu)) { +for_each_cpu (i, &c->llc_shared_map) {if (!per_cpu (ici_cpuid4_info, i))continue ; this_leaf =CPUID4_INFO_IDX (i, index); -for_each_cpu (sibling,cpu_llc_shared_mask (cpu)) { +for_each_cpu (sibling, &c->llc_shared_map) {if (!cpu_online (sibling))continue ;set_bit (sibling, this_leaf->shared_cpu_map);
arch/x86/kernel/cpu/mcheck/mce_amd.c +4 -3
@@ -525,11 +525,12 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)struct threshold_bank *b =NULL ;struct device *dev = mce_device[cpu];char name[32 ]; +struct cpuinfo_x86 *c = &cpu_data (cpu);sprintf (name,"threshold_bank%i" , bank); -if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ - i =cpumask_first (cpu_llc_shared_mask (cpu)); +if (c->cpu_core_id && shared_bank[bank]) {/* symlink */ + i =cpumask_first (&c->llc_shared_map);/* first core not up yet */ if (cpu_data (i).cpu_core_id)
@@ -548,7 +549,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)if (err) goto out; -cpumask_copy (b->cpus,cpu_llc_shared_mask (cpu)); +cpumask_copy (b->cpus, &c->llc_shared_map);per_cpu (threshold_banks, cpu)[bank] = b; goto out;
arch/x86/kernel/smpboot.c +6 -9
@@ -127,8 +127,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);DEFINE_PER_CPU (cpumask_var_t, cpu_core_map);EXPORT_PER_CPU_SYMBOL (cpu_core_map); -DEFINE_PER_CPU (cpumask_var_t, cpu_llc_shared_map); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
@@ -337,8 +335,8 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2)cpumask_set_cpu (cpu2,cpu_sibling_mask (cpu1));cpumask_set_cpu (cpu1,cpu_core_mask (cpu2));cpumask_set_cpu (cpu2,cpu_core_mask (cpu1)); -cpumask_set_cpu (cpu1,cpu_llc_shared_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_llc_shared_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).llc_shared_map); }
@@ -367,7 +365,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu,cpu_sibling_mask (cpu)); } -cpumask_set_cpu (cpu,cpu_llc_shared_mask (cpu)); +cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) {cpumask_copy (cpu_core_mask (cpu),cpu_sibling_mask (cpu));
@@ -378,8 +376,8 @@ void __cpuinit set_cpu_sibling_map(int cpu)for_each_cpu (i, cpu_sibling_setup_mask) {if (per_cpu (cpu_llc_id, cpu) !=BAD_APICID &&per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i)) { -cpumask_set_cpu (i,cpu_llc_shared_mask (cpu)); -cpumask_set_cpu (cpu,cpu_llc_shared_mask (i)); +cpumask_set_cpu (i, &c->llc_shared_map); +cpumask_set_cpu (cpu, &cpu_data (i).llc_shared_map); }if (c->phys_proc_id ==cpu_data (i).phys_proc_id) {cpumask_set_cpu (i,cpu_core_mask (cpu));
@@ -418,7 +416,7 @@ const struct cpumask *cpu_coregroup_mask(int cpu) !(cpu_has(c, X86_FEATURE_AMD_DCM))) return cpu_core_mask(cpu); else - return cpu_llc_shared_mask(cpu); + return &c->llc_shared_map; }static void impress_friends (void )
@@ -1053,7 +1051,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
arch/x86/xen/smp.c +0 -1
@@ -225,7 +225,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
Signature · 1 line
1.7.9
Re: [PATCH v2] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Quoted 36 lines · Kevin Winchester
Commit
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") caused the compilation error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to '
cpu_llc_shared_map'by removing an #ifdef
CONFIG_SMParound a block containing a reference tocpu_llc_shared_map. Rather than replace the #ifdef, movecpu_llc_shared_mapto be a newcpumask_tfieldllc_shared_mapin structcpuinfo_x86and adjust all references tocpu_llc_shared_map.The size effects on various kernels are as follows:
text data bss dec hex filename
5281572 513296 1044480 6839348 685c34 vmlinux.up
5281572 513296 1044480 6839348 685c34 vmlinux.up.patched
5548860 516792 1110016 7175668 6d7df4 vmlinux.smp.2
5548837 516792 1110016 7175645 6d7ddd vmlinux.smp.2.patched
5595965 706840 1310720 7613525 742c55 vmlinux.smp.max
5595876 707880 1310720 7614476 74300c vmlinux.smp.max.patchedIt can be seen that this change has no effect on UP, a minor effect for SMP with Max 2 CPUs, and a more substantial but still not overly large effect for MAXSMP.
Signed-off-by Kevin Winchester <[email protected]>---
I'm still wondering if I should I give the same treatment to:
cpu_sibling_mapcpu_core_mapcpu_llc_idcpu_numberor is that going too far?
Quoted 7 lines
arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/smp.h | 6 ------ arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/mcheck/mce_amd.c | 7 ++++--- arch/x86/kernel/smpboot.c | 15 ++++++--------- arch/x86/xen/smp.c | 1 - 6 files changed, 13 insertions(+), 21 deletions(-)
Yeah, I'd definitely give them the same treatment.
Would you like to update your series? I'd suggest you keep patch #1 in place, as it's already probably reasonably well tested.
Thanks,
Ingo
Re: [PATCH v2] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Quoted 10 lines · Ingo Molnar
Quoted 9 lines
I'm still wondering if I should I give the same treatment to:
cpu_sibling_mapcpu_core_mapcpu_llc_idcpu_number
Quoted 5 lines
Yeah, I'd definitely give them the same treatment.
Would you like to update your series? I'd suggest you keep patch #1 in place, as it's already probably reasonably well tested.
Sure, I'll leave that patch as #1, and add an additional patch per field. It will take me a week or two to find the time to get it all together, but I'll keep working away at it.
Signature · 1 line
Kevin Winchester
cover x86: Cleanup and simplify cpu-specific data
In reply to Ingo MolnarVarious per-cpu fields are define in arch/x86/kernel/smpboot.c that are basically equivalent to the cpu-specific data in struct cpuinfo_x86. By moving these fields into the structure, a number of codepaths can be simplified since they no longer need to care about those fields not existing on !SMP builds.
The size effects on allno (UP) and allyes (MAX_SMP) kernels are as follows:
text data bss dec hex filename
1586721 304864 506208 2397793 249661 vmlinux.allno
1588517 304928 505920 2399365 249c85 vmlinux.allno.after
84706053 13212311 42434560 140352924 85d9d9c vmlinux.allyes
84705333 13213799 42434560 140353692 85da09c vmlinux.allyes.afte
As can be seen, the kernels get slighly larger, but the code reduction/ simplification should be enough to compensate for it.
Kevin Winchester (5):
x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
x86: Move per cpu cpu_llc_id to a field in struct cpuinfo_x86
x86: Move per cpu cpu_sibling_map to a field in struct cpuinfo_x86
x86: Move per cpu cpu_core_map to a field in struct cpuinfo_x86
x86: Remove #ifdef CONFIG_SMP sections by moving smp_num_siblings
into common.c
arch/x86/include/asm/perf_event_p4.h | 9 +-- arch/x86/include/asm/processor.h | 7 +++ arch/x86/include/asm/smp.h | 26 +--------- arch/x86/include/asm/topology.h | 10 ++-- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 18 ++----- arch/x86/kernel/cpu/common.c | 7 ++- arch/x86/kernel/cpu/intel_cacheinfo.c | 19 ++----- arch/x86/kernel/cpu/mcheck/mce_amd.c | 7 ++- arch/x86/kernel/cpu/proc.c | 8 +-- arch/x86/kernel/cpu/topology.c | 2 - arch/x86/kernel/process.c | 3 +- arch/x86/kernel/smpboot.c | 95 +++++++++++++-------------------- arch/x86/oprofile/nmi_int.c | 6 -- arch/x86/oprofile/op_model_p4.c | 11 +---- arch/x86/xen/smp.c | 6 -- drivers/cpufreq/acpi-cpufreq.c | 2 +- drivers/cpufreq/p4-clockmod.c | 4 +- drivers/cpufreq/powernow-k8.c | 13 +---- drivers/cpufreq/speedstep-ich.c | 6 +- drivers/hwmon/coretemp.c | 6 +-- 21 files changed, 86 insertions(+), 181 deletions(-)
Signature · 1 line
1.7.9
PATCH 1/5 x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Commit 141168c36cde ("x86: Simplify code by removing a !SMP #ifdefs from 'struct cpuinfo_x86'") caused the compilation error:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to 'cpu_llc_shared_map'
by removing an #ifdef CONFIG_SMP around a block containing a reference to cpu_llc_shared_map. Rather than replace the #ifdef, move cpu_llc_shared_map to be a new cpumask_t field llc_shared_map in struct cpuinfo_x86 and adjust all references to cpu_llc_shared_map.
The size effects on various kernels are as follows:
text data bss dec hex filename
5281572 513296 1044480 6839348 685c34 vmlinux.up
5281572 513296 1044480 6839348 685c34 vmlinux.up.patched
5548860 516792 1110016 7175668 6d7df4 vmlinux.smp.2
5548837 516792 1110016 7175645 6d7ddd vmlinux.smp.2.patched
5595965 706840 1310720 7613525 742c55 vmlinux.smp.max
5595876 707880 1310720 7614476 74300c vmlinux.smp.max.patched
It can be seen that this change has no effect on UP, a minor effect for SMP with Max 2 CPUs, and a more substantial but still not overly large effect for MAXSMP.
--- arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/smp.h | 6 ------ arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/mcheck/mce_amd.c | 7 ++++--- arch/x86/kernel/smpboot.c | 15 ++++++--------- arch/x86/xen/smp.c | 1 - 6 files changed, 13 insertions(+), 21 deletions(-)
arch/x86/include/asm/processor.h +1 -0
@@ -110,6 +110,7 @@ struct cpuinfo_x86 {/* Index into per_cpu list: */ u16 cpu_index;u32 microcode; +cpumask_t llc_shared_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -34,7 +34,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);/* cpus sharing the last level cache: */ -DECLARE_PER_CPU (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);
@@ -48,11 +47,6 @@ static inline struct cpumask *cpu_core_mask(int cpu)return per_cpu (cpu_core_map, cpu); } -static inline struct cpumask *cpu_llc_shared_mask (int cpu) -{ -return per_cpu (cpu_llc_shared_map, cpu); -} -DECLARE_EARLY_PER_CPU (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU (u16, x86_bios_cpu_apicid);#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86_32 )
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -734,11 +734,11 @@ static int __cpuinit cache_shared_amd_cpu_map_setup(unsigned int cpu, int index) ret =0 ;if (index ==3 ) { ret =1 ; -for_each_cpu (i,cpu_llc_shared_mask (cpu)) { +for_each_cpu (i, &c->llc_shared_map) {if (!per_cpu (ici_cpuid4_info, i))continue ; this_leaf =CPUID4_INFO_IDX (i, index); -for_each_cpu (sibling,cpu_llc_shared_mask (cpu)) { +for_each_cpu (sibling, &c->llc_shared_map) {if (!cpu_online (sibling))continue ;set_bit (sibling, this_leaf->shared_cpu_map);
arch/x86/kernel/cpu/mcheck/mce_amd.c +4 -3
@@ -525,11 +525,12 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)struct threshold_bank *b =NULL ;struct device *dev = mce_device[cpu];char name[32 ]; +struct cpuinfo_x86 *c = &cpu_data (cpu);sprintf (name,"threshold_bank%i" , bank); -if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ - i =cpumask_first (cpu_llc_shared_mask (cpu)); +if (c->cpu_core_id && shared_bank[bank]) {/* symlink */ + i =cpumask_first (&c->llc_shared_map);/* first core not up yet */ if (cpu_data (i).cpu_core_id)
@@ -548,7 +549,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)if (err) goto out; -cpumask_copy (b->cpus,cpu_llc_shared_mask (cpu)); +cpumask_copy (b->cpus, &c->llc_shared_map);per_cpu (threshold_banks, cpu)[bank] = b; goto out;
arch/x86/kernel/smpboot.c +6 -9
@@ -127,8 +127,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);DEFINE_PER_CPU (cpumask_var_t, cpu_core_map);EXPORT_PER_CPU_SYMBOL (cpu_core_map); -DEFINE_PER_CPU (cpumask_var_t, cpu_llc_shared_map); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
@@ -337,8 +335,8 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2)cpumask_set_cpu (cpu2,cpu_sibling_mask (cpu1));cpumask_set_cpu (cpu1,cpu_core_mask (cpu2));cpumask_set_cpu (cpu2,cpu_core_mask (cpu1)); -cpumask_set_cpu (cpu1,cpu_llc_shared_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_llc_shared_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).llc_shared_map); }
@@ -367,7 +365,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu,cpu_sibling_mask (cpu)); } -cpumask_set_cpu (cpu,cpu_llc_shared_mask (cpu)); +cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) {cpumask_copy (cpu_core_mask (cpu),cpu_sibling_mask (cpu));
@@ -378,8 +376,8 @@ void __cpuinit set_cpu_sibling_map(int cpu)for_each_cpu (i, cpu_sibling_setup_mask) {if (per_cpu (cpu_llc_id, cpu) !=BAD_APICID &&per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i)) { -cpumask_set_cpu (i,cpu_llc_shared_mask (cpu)); -cpumask_set_cpu (cpu,cpu_llc_shared_mask (i)); +cpumask_set_cpu (i, &c->llc_shared_map); +cpumask_set_cpu (cpu, &cpu_data (i).llc_shared_map); }if (c->phys_proc_id ==cpu_data (i).phys_proc_id) {cpumask_set_cpu (i,cpu_core_mask (cpu));
@@ -418,7 +416,7 @@ const struct cpumask *cpu_coregroup_mask(int cpu) !(cpu_has(c, X86_FEATURE_AMD_DCM))) return cpu_core_mask(cpu); else - return cpu_llc_shared_mask(cpu); + return &c->llc_shared_map; }static void impress_friends (void )
@@ -1054,7 +1052,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
arch/x86/xen/smp.c +0 -1
@@ -225,7 +225,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
Signature · 1 line
1.7.9
Borislav Petkov
maintainerRe: [PATCH 1/5] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Quoted 51 lines · Kevin Winchester
Commit
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") caused the compilation error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to '
cpu_llc_shared_map'by removing an #ifdef
CONFIG_SMParound a block containing a reference tocpu_llc_shared_map. Rather than replace the #ifdef, movecpu_llc_shared_mapto be a newcpumask_tfieldllc_shared_mapin structcpuinfo_x86and adjust all references tocpu_llc_shared_map.The size effects on various kernels are as follows:
text data bss dec hex filename
5281572 513296 1044480 6839348 685c34 vmlinux.up
5281572 513296 1044480 6839348 685c34 vmlinux.up.patched
5548860 516792 1110016 7175668 6d7df4 vmlinux.smp.2
5548837 516792 1110016 7175645 6d7ddd vmlinux.smp.2.patched
5595965 706840 1310720 7613525 742c55 vmlinux.smp.max
5595876 707880 1310720 7614476 74300c vmlinux.smp.max.patchedIt can be seen that this change has no effect on UP, a minor effect for SMP with Max 2 CPUs, and a more substantial but still not overly large effect for MAXSMP.
Signed-off-by Kevin Winchester <[email protected]>--- arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/smp.h | 6 ------ arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/mcheck/mce_amd.c | 7 ++++--- arch/x86/kernel/smpboot.c | 15 ++++++--------- arch/x86/xen/smp.c | 1 - 6 files changed, 13 insertions(+), 21 deletions(-)arch/x86/include/asm/processor.h +1
-0@@ -110,6 +110,7 @@ struct cpuinfo_x86 {/* Index into per_cpu list: */ u16 cpu_index;u32 microcode; +cpumask_t llc_shared_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0arch/x86/include/asm/smp.h +0
-0
arch/x86/include/asm/smp.h static inline bool cpu_has_ht_siblings(void) · line 36
Quoted 3 lines
arch/x86/include/asm/smp.h +0
-0@@ -34,7 +34,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);/* cpus sharing the last level cache: */
You'd need to pull up that comment along with the llc_shared_map definition above in the struct cpuinfo_x86 so that we know what kind of map it is.
Thanks.
Signature · 2 lines
Regards/Gruss, Boris.
PATCH 2/5 x86: Move per cpu cpu_llc_id to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 2 -- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 14 ++++---------- arch/x86/kernel/cpu/common.c | 1 + arch/x86/kernel/cpu/intel_cacheinfo.c | 11 ++--------- arch/x86/kernel/smpboot.c | 18 ++++++++---------- 7 files changed, 18 insertions(+), 32 deletions(-)
arch/x86/include/asm/processor.h +2 -0
@@ -111,6 +111,8 @@ struct cpuinfo_x86 {u16 cpu_index;u32 microcode;cpumask_t llc_shared_map; +/* cpus sharing the last level cache: */ +u16 llc_id; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -2
@@ -33,8 +33,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ -DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);static inline struct cpumask *cpu_sibling_mask (int cpu)
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -202,7 +202,7 @@ static void __init map_csrs(void)static void fixup_cpu_id (struct cpuinfo_x86 *c,int node) { c->phys_proc_id = node; -per_cpu (cpu_llc_id,smp_processor_id ()) = node; + c->llc_id = node; }static int __init numachip_system_init (void )
arch/x86/kernel/cpu/amd.c +4 -10
@@ -268,7 +268,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) {u32 nodes, cores_per_cu =1 ;u8 node_id; -int cpu =smp_processor_id ();/* get information required for multi-node processors */ if (cpu_has (c,X86_FEATURE_TOPOEXT )) {
@@ -301,7 +300,7 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) cus_per_node = cores_per_node / cores_per_cu;/* store NodeID, use llc_shared_map to store sibling info */ -per_cpu (cpu_llc_id, cpu) = node_id; + c->llc_id = node_id;/* core id has to be in the [0 .. cores_per_node - 1] range */ c->cpu_core_id %= cores_per_node;
@@ -318,7 +317,6 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c) {#ifdef CONFIG_X86_HT unsigned bits; -int cpu =smp_processor_id (); bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */
@@ -326,18 +324,14 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)/* Convert the initial APIC ID into the socket ID */ c->phys_proc_id = c->initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->phys_proc_id; + c->llc_id = c->phys_proc_id;amd_get_topology (c);#endif }int amd_get_nb_id (int cpu) { -int id =0 ; -#ifdef CONFIG_SMP - id =per_cpu (cpu_llc_id, cpu); -#endif -return id; +return cpu_data (cpu).llc_id; }EXPORT_SYMBOL_GPL (amd_get_nb_id);
@@ -350,7 +344,7 @@ static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c) node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE ) - node =per_cpu (cpu_llc_id, cpu); + node = c->llc_id;/* * If core numbers are inconsistent, it's likely a multi-fabric platform,
arch/x86/kernel/cpu/common.c +1 -0
@@ -787,6 +787,7 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) c->x86_model_id[0 ] ='\0' ;/* Unset */ c->x86_max_cores =1 ; c->x86_coreid_bits =0 ; + c->llc_id =BAD_APICID ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -9
@@ -579,9 +579,6 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)unsigned int new_l1d =0 , new_l1i =0 ;/* Cache sizes from cpuid(4) */ unsigned int new_l2 =0 , new_l3 =0 , i;/* Cache sizes from cpuid(4) */ unsigned int l2_id =0 , l3_id =0 , num_threads_sharing, index_msb; -#ifdef CONFIG_X86_HT -unsigned int cpu = c->cpu_index; -#endif if (c->cpuid_level >3 ) {static int is_initialized;
@@ -700,16 +697,12 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)if (new_l2) { l2 = new_l2; -#ifdef CONFIG_X86_HT -per_cpu (cpu_llc_id, cpu) = l2_id; -#endif + c->llc_id = l2_id; }if (new_l3) { l3 = new_l3; -#ifdef CONFIG_X86_HT -per_cpu (cpu_llc_id, cpu) = l3_id; -#endif + c->llc_id = l3_id; } c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
arch/x86/kernel/smpboot.c +8 -10
@@ -116,9 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* Last level cache ID of each logical CPU */ -DEFINE_PER_CPU (u16, cpu_llc_id) =BAD_APICID ; -/* representing HT siblings of each logical CPU */ DEFINE_PER_CPU (cpumask_var_t, cpu_sibling_map);EXPORT_PER_CPU_SYMBOL (cpu_sibling_map);
@@ -353,7 +350,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)if (cpu_has (c,X86_FEATURE_TOPOEXT )) {if (c->phys_proc_id == o->phys_proc_id && -per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i) && + c->llc_id == o->llc_id && c->compute_unit_id == o->compute_unit_id)link_thread_siblings (cpu, i); } else if (c->phys_proc_id == o->phys_proc_id &&
@@ -374,12 +371,13 @@ void __cpuinit set_cpu_sibling_map(int cpu) }for_each_cpu (i, cpu_sibling_setup_mask) { -if (per_cpu (cpu_llc_id, cpu) !=BAD_APICID && -per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i)) { +struct cpuinfo_x86 *o = &cpu_data (i); + +if (c->llc_id !=BAD_APICID && c->llc_id == o->llc_id) {cpumask_set_cpu (i, &c->llc_shared_map); -cpumask_set_cpu (cpu, &cpu_data (i).llc_shared_map); +cpumask_set_cpu (cpu, &o->llc_shared_map); } -if (c->phys_proc_id ==cpu_data (i).phys_proc_id) { +if (c->phys_proc_id == o->phys_proc_id) {cpumask_set_cpu (i,cpu_core_mask (cpu));cpumask_set_cpu (cpu,cpu_core_mask (i));/*
@@ -397,9 +395,9 @@ void __cpuinit set_cpu_sibling_map(int cpu)* the other cpus in this package */ if (i != cpu) -cpu_data (i).booted_cores++; + o->booted_cores++; }else if (i != cpu && !c->booted_cores) - c->booted_cores =cpu_data (i).booted_cores; + c->booted_cores = o->booted_cores; } } }
Signature · 1 line
1.7.9
Re: [PATCH 2/5] x86: Move per cpu cpu_llc_id to a field in struct cpuinfo_x86
Quoted 4 lines · Kevin Winchester
This simplifies the various code paths using this field as it groups the per-cpu data together.
Signed-off-by Kevin Winchester <[email protected]>
Quoted 9 lines
--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 2 -- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 14 ++++---------- arch/x86/kernel/cpu/common.c | 1 + arch/x86/kernel/cpu/intel_cacheinfo.c | 11 ++--------- arch/x86/kernel/smpboot.c | 18 ++++++++---------- 7 files changed, 18 insertions(+), 32 deletions(-)
This actually makes the code even a bit easier on the eyes.
Signature · 2 lines
Regards/Gruss, Boris.
Borislav Petkov
maintainerRe: [PATCH 2/5] x86: Move per cpu cpu_llc_id to a field in struct cpuinfo_x86
In reply to Kevin WinchesterQuoted 19 lines · Kevin Winchester
This simplifies the various code paths using this field as it groups the per-cpu data together.
Signed-off-by Kevin Winchester <[email protected]>--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 2 -- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 14 ++++---------- arch/x86/kernel/cpu/common.c | 1 + arch/x86/kernel/cpu/intel_cacheinfo.c | 11 ++--------- arch/x86/kernel/smpboot.c | 18 ++++++++---------- 7 files changed, 18 insertions(+), 32 deletions(-)arch/x86/include/asm/processor.h +0
-0
arch/x86/include/asm/processor.h struct cpuinfo_x86 { · line 114
Quoted 4 lines
arch/x86/include/asm/processor.h +1
-0@@ -111,6 +111,8 @@ struct cpuinfo_x86 {u16 cpu_index;u32 microcode;cpumask_t llc_shared_map; +/* cpus sharing the last level cache: */
Just a minor nitpick which I forgot: we spell "CPUs" in the comments as in the next patch you're adding a comment about the sibling_map.
Thanks.
Signature · 2 lines
Regards/Gruss, Boris.
PATCH 3/5 x86: Move per cpu cpu_sibling_map to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/perf_event_p4.h | 2 +- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 6 ------ arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/smpboot.c | 27 +++++++++++---------------- arch/x86/oprofile/op_model_p4.c | 5 +---- arch/x86/xen/smp.c | 1 - drivers/cpufreq/p4-clockmod.c | 4 +--- drivers/cpufreq/speedstep-ich.c | 6 +++--- drivers/hwmon/coretemp.c | 6 +----- 11 files changed, 23 insertions(+), 42 deletions(-)
arch/x86/include/asm/perf_event_p4.h +1 -1
@@ -189,7 +189,7 @@ static inline int p4_ht_thread(int cpu) {#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) -return cpu !=cpumask_first (__get_cpu_var (cpu_sibling_map)); + return cpu != cpumask_first(&cpu_data(cpu).sibling_map));#endif return 0 ; }
arch/x86/include/asm/processor.h +2 -0
@@ -113,6 +113,8 @@ struct cpuinfo_x86 {cpumask_t llc_shared_map;/* cpus sharing the last level cache: */ u16 llc_id; +/* representing HT siblings of each logical CPU */ +cpumask_t sibling_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -31,15 +31,9 @@ static inline bool cpu_has_ht_siblings(void)return has_siblings; } -DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);DECLARE_PER_CPU (int, cpu_number); -static inline struct cpumask *cpu_sibling_mask (int cpu) -{ -return per_cpu (cpu_sibling_map, cpu); -} -static inline struct cpumask *cpu_core_mask (int cpu) {return per_cpu (cpu_core_map, cpu);
arch/x86/include/asm/topology.h +1 -1
@@ -161,7 +161,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);#define topology_physical_package_id (cpu) (cpu_data(cpu).phys_proc_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id)#define topology_core_cpumask (cpu) (per_cpu(cpu_core_map, cpu)) -#define topology_thread_cpumask (cpu) (per_cpu(cpu_sibling_map, cpu)) +#define topology_thread_cpumask (cpu) (&cpu_data(cpu).sibling_map)/* indicates that pointers to the topology cpumask_t maps are valid */ #define arch_provides_topology_pointers yes
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -739,11 +739,11 @@ static int __cpuinit cache_shared_amd_cpu_map_setup(unsigned int cpu, int index) } }else if ((c->x86 ==0x15 ) && ((index ==1 ) || (index ==2 ))) { ret =1 ; -for_each_cpu (i,cpu_sibling_mask (cpu)) { +for_each_cpu (i, &c->sibling_map) {if (!per_cpu (ici_cpuid4_info, i))continue ; this_leaf =CPUID4_INFO_IDX (i, index); -for_each_cpu (sibling,cpu_sibling_mask (cpu)) { +for_each_cpu (sibling, &c->sibling_map) {if (!cpu_online (sibling))continue ;set_bit (sibling, this_leaf->shared_cpu_map);
arch/x86/kernel/smpboot.c +11 -16
@@ -116,10 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* representing HT siblings of each logical CPU */ -DEFINE_PER_CPU (cpumask_var_t, cpu_sibling_map); -EXPORT_PER_CPU_SYMBOL (cpu_sibling_map); -/* representing HT and core siblings of each logical CPU */ DEFINE_PER_CPU (cpumask_var_t, cpu_core_map);EXPORT_PER_CPU_SYMBOL (cpu_core_map);
@@ -328,8 +324,8 @@ void __cpuinit smp_store_cpu_info(int id)static void __cpuinit link_thread_siblings (int cpu1,int cpu2) { -cpumask_set_cpu (cpu1,cpu_sibling_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_sibling_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).sibling_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).sibling_map);cpumask_set_cpu (cpu1,cpu_core_mask (cpu2));cpumask_set_cpu (cpu2,cpu_core_mask (cpu1));cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map);
@@ -359,13 +355,13 @@ void __cpuinit set_cpu_sibling_map(int cpu) } } }else { -cpumask_set_cpu (cpu,cpu_sibling_mask (cpu)); +cpumask_set_cpu (cpu, &c->sibling_map); }cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) { -cpumask_copy (cpu_core_mask (cpu),cpu_sibling_mask (cpu)); +cpumask_copy (cpu_core_mask (cpu), &c->sibling_map); c->booted_cores =1 ;return ; }
@@ -383,12 +379,12 @@ void __cpuinit set_cpu_sibling_map(int cpu)/* * Does this new cpu bringup a new core? */ -if (cpumask_weight (cpu_sibling_mask (cpu)) ==1 ) { +if (cpumask_weight (&c->sibling_map) ==1 ) {/* * for each core in package, increment * the booted_cores for this new cpu */ -if (cpumask_first (cpu_sibling_mask (i)) == i) +if (cpumask_first (&o->sibling_map) == i) c->booted_cores++;/* * increment the core count for all
@@ -910,7 +906,7 @@ static __init void disable_smp(void)physid_set_mask_of_physid (boot_cpu_physical_apicid, &phys_cpu_present_map); else physid_set_mask_of_physid(0, &phys_cpu_present_map); -cpumask_set_cpu (0 ,cpu_sibling_mask (0 )); +cpumask_set_cpu (0 , &cpu_data (0 ).sibling_map);cpumask_set_cpu (0 ,cpu_core_mask (0 )); }
@@ -1048,7 +1044,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)current_thread_info ()->cpu =0 ;/* needed? */ for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
@@ -1243,13 +1238,13 @@ static void remove_siblinginfo(int cpu)/*/ * last thread sibling in this cpu core going down */ -if (cpumask_weight (cpu_sibling_mask (cpu)) ==1 ) +if (cpumask_weight (&c->sibling_map) ==1 )cpu_data (sibling).booted_cores--; } -for_each_cpu (sibling,cpu_sibling_mask (cpu)) -cpumask_clear_cpu (cpu,cpu_sibling_mask (sibling)); -cpumask_clear (cpu_sibling_mask (cpu)); +for_each_cpu (sibling, &c->sibling_map) +cpumask_clear_cpu (cpu, &c->sibling_map); +cpumask_clear (&c->sibling_map);cpumask_clear (cpu_core_mask (cpu)); c->phys_proc_id =0 ; c->cpu_core_id =0 ;
arch/x86/oprofile/op_model_p4.c +1 -4
@@ -370,11 +370,8 @@ static struct p4_event_binding p4_events[NUM_EVENTS] = {or "odd" part of all the divided resources. */ static unsigned int get_stagger (void ) { -#ifdef CONFIG_SMP int cpu =smp_processor_id (); -return cpu !=cpumask_first (__get_cpu_var (cpu_sibling_map)); -#endif -return 0 ; +return cpu !=cpumask_first (&cpu_data (cpu).sibling_map); }
arch/x86/xen/smp.c +0 -1
@@ -223,7 +223,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)cpu_data (0 ).x86_max_cores =1 ;for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
drivers/cpufreq/p4-clockmod.c +1 -3
@@ -203,9 +203,7 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)int cpuid =0 ;unsigned int i; -#ifdef CONFIG_SMP -cpumask_copy (policy->cpus,cpu_sibling_mask (policy->cpu)); -#endif +cpumask_copy (policy->cpus, &c->sibling_map);/* Errata workaround */ cpuid = (c->x86 <<8 ) | (c->x86_model <<4 ) | c->x86_mask;
drivers/cpufreq/speedstep-ich.c +3 -3
@@ -326,14 +326,14 @@ static void get_freqs_on_cpu(void *_get_freqs)static int speedstep_cpu_init (struct cpufreq_policy *policy) { +struct cpuinfo_x86 *c = &cpu_data (policy->cpu);int result;unsigned int policy_cpu, speed;struct get_freqs gf;/* only run on CPU to be set, or on its sibling */ -#ifdef CONFIG_SMP -cpumask_copy (policy->cpus,cpu_sibling_mask (policy->cpu)); -#endif +cpumask_copy (policy->cpus, c->sibling_map); + policy_cpu =cpumask_any_and (policy->cpus, cpu_online_mask);/* detect low and high frequency and transition latency */
drivers/hwmon/coretemp.c +1 -5
@@ -61,11 +61,7 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");#define TO_CORE_ID (cpu) cpu_data(cpu).cpu_core_id#define TO_ATTR_NO (cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO) -#ifdef CONFIG_SMP -#define for_each_sibling (i, cpu) for_each_cpu(i, cpu_sibling_mask(cpu)) -#else -#define for_each_sibling (i, cpu) for (i = 0; false; ) -#endif +#define for_each_sibling (i, cpu) for_each_cpu(i, &cpu_data(cpu).sibling_map)/* * Per-Core Temperature Data
Signature · 1 line
1.7.9
Re: [PATCH 3/5] x86: Move per cpu cpu_sibling_map to a field in struct cpuinfo_x86
Quoted 4 lines · Kevin Winchester
This simplifies the various code paths using this field as it groups the per-cpu data together.
Signed-off-by Kevin Winchester <[email protected]>
Signature · 2 lines
Regards/Gruss, Boris.
PATCH 4/5 x86: Move per cpu cpu_core_map to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 6 ------ arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/proc.c | 3 +-- arch/x86/kernel/smpboot.c | 35 ++++++++++++++--------------------- arch/x86/xen/smp.c | 4 ---- drivers/cpufreq/acpi-cpufreq.c | 2 +- drivers/cpufreq/powernow-k8.c | 13 +++---------- 8 files changed, 23 insertions(+), 46 deletions(-)
arch/x86/include/asm/processor.h +2 -0
@@ -115,6 +115,8 @@ struct cpuinfo_x86 {u16 llc_id;/* representing HT siblings of each logical CPU */ cpumask_t sibling_map; +/* representing HT and core siblings of each logical CPU */ +cpumask_t core_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -31,14 +31,8 @@ static inline bool cpu_has_ht_siblings(void)return has_siblings; } -DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);DECLARE_PER_CPU (int, cpu_number); -static inline struct cpumask *cpu_core_mask (int cpu) -{ -return per_cpu (cpu_core_map, cpu); -} -DECLARE_EARLY_PER_CPU (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU (u16, x86_bios_cpu_apicid);#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86_32 )
arch/x86/include/asm/topology.h +2 -2
@@ -160,7 +160,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);#ifdef ENABLE_TOPO_DEFINES #define topology_physical_package_id (cpu) (cpu_data(cpu).phys_proc_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id) -#define topology_core_cpumask (cpu) (per_cpu(cpu_core_map, cpu)) +#define topology_core_cpumask (cpu) (&cpu_data(cpu).core_map)#define topology_thread_cpumask (cpu) (&cpu_data(cpu).sibling_map)/* indicates that pointers to the topology cpumask_t maps are valid */
@@ -176,7 +176,7 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources);#ifdef CONFIG_SMP #define mc_capable () ((boot_cpu_data.x86_max_cores > 1) && \ - (cpumask_weight(cpu_core_mask(0)) != nr_cpu_ids)) + (cpumask_weight(&boot_cpu_data.core_map) != nr_cpu_ids))#define smt_capable () (smp_num_siblings > 1)#endif
arch/x86/kernel/cpu/proc.c +1 -2
@@ -13,8 +13,7 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,#ifdef CONFIG_SMP if (c->x86_max_cores * smp_num_siblings >1 ) {seq_printf (m,"physical id\t: %d\n" , c->phys_proc_id); -seq_printf (m,"siblings\t: %d\n" , -cpumask_weight (cpu_core_mask (cpu))); +seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (&c->core_map));seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id);seq_printf (m,"cpu cores\t: %d\n" , c->booted_cores);seq_printf (m,"apicid\t\t: %d\n" , c->apicid);
arch/x86/kernel/smpboot.c +14 -21
@@ -116,10 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* representing HT and core siblings of each logical CPU */ -DEFINE_PER_CPU (cpumask_var_t, cpu_core_map); -EXPORT_PER_CPU_SYMBOL (cpu_core_map); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
@@ -326,8 +322,8 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2) {cpumask_set_cpu (cpu1, &cpu_data (cpu2).sibling_map);cpumask_set_cpu (cpu2, &cpu_data (cpu1).sibling_map); -cpumask_set_cpu (cpu1,cpu_core_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_core_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).core_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).core_map);cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map);cpumask_set_cpu (cpu2, &cpu_data (cpu1).llc_shared_map); }
@@ -361,7 +357,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) { -cpumask_copy (cpu_core_mask (cpu), &c->sibling_map); +cpumask_copy (&c->core_map, &c->sibling_map); c->booted_cores =1 ;return ; }
@@ -374,8 +370,8 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu, &o->llc_shared_map); }if (c->phys_proc_id == o->phys_proc_id) { -cpumask_set_cpu (i,cpu_core_mask (cpu)); -cpumask_set_cpu (cpu,cpu_core_mask (i)); +cpumask_set_cpu (i, &c->core_map); +cpumask_set_cpu (cpu, &o->core_map);/* * Does this new cpu bringup a new core? */
@@ -404,11 +400,11 @@ const struct cpumask *cpu_coregroup_mask(int cpu)struct cpuinfo_x86 *c = &cpu_data (cpu);/* * For perf, we return last level cache shared map. -* And for power savings, we return cpu_core_map +* And for power savings, we return core map. */ if ((sched_mc_power_savings || sched_smt_power_savings) && !(cpu_has (c,X86_FEATURE_AMD_DCM ))) -return cpu_core_mask (cpu); +return &c->core_map;else return &c->llc_shared_map; }
@@ -907,7 +903,7 @@ static __init void disable_smp(void)else physid_set_mask_of_physid (0 , &phys_cpu_present_map);cpumask_set_cpu (0 , &cpu_data (0 ).sibling_map); -cpumask_set_cpu (0 ,cpu_core_mask (0 )); +cpumask_set_cpu (0 , &cpu_data (0 ).core_map); }/*
@@ -1030,8 +1026,6 @@ static void __init smp_cpu_index_default(void)*/ void __init native_smp_prepare_cpus (unsigned int max_cpus) { -unsigned int i; -preempt_disable ();smp_cpu_index_default ();
@@ -1043,9 +1037,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)mb ();current_thread_info ()->cpu =0 ;/* needed? */ -for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); - }set_cpu_sibling_map (0 );
@@ -1233,19 +1224,21 @@ static void remove_siblinginfo(int cpu)int sibling;struct cpuinfo_x86 *c = &cpu_data (cpu); -for_each_cpu (sibling,cpu_core_mask (cpu)) { -cpumask_clear_cpu (cpu,cpu_core_mask (sibling)); +for_each_cpu (sibling, &c->core_map) { +struct cpuinfo_x86 *o = &cpu_data (sibling); + +cpumask_clear_cpu (cpu, &o->core_map);/*/ * last thread sibling in this cpu core going down */ if (cpumask_weight (&c->sibling_map) ==1 ) -cpu_data (sibling).booted_cores--; + o->booted_cores--; }for_each_cpu (sibling, &c->sibling_map)cpumask_clear_cpu (cpu, &c->sibling_map);cpumask_clear (&c->sibling_map); -cpumask_clear (cpu_core_mask (cpu)); +cpumask_clear (&c->core_map); c->phys_proc_id =0 ; c->cpu_core_id =0 ;cpumask_clear_cpu (cpu, cpu_sibling_setup_mask);
arch/x86/xen/smp.c +0 -4
@@ -206,7 +206,6 @@ static void __init xen_smp_prepare_boot_cpu(void)static void __init xen_smp_prepare_cpus (unsigned int max_cpus) {unsigned cpu; -unsigned int i;if (skip_ioapic_setup) { char *m = (max_cpus == 0) ?
@@ -222,9 +221,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)smp_store_cpu_info (0 );cpu_data (0 ).x86_max_cores =1 ; -for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); - }set_cpu_sibling_map (0 );if (xen_smp_intr_init (0 ))
drivers/cpufreq/acpi-cpufreq.c +1 -1
@@ -557,7 +557,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)dmi_check_system (sw_any_bug_dmi_table);if (bios_with_sw_any_bug &&cpumask_weight (policy->cpus) ==1 ) { policy->shared_type =CPUFREQ_SHARED_TYPE_ALL ; -cpumask_copy (policy->cpus,cpu_core_mask (cpu)); +cpumask_copy (policy->cpus, &c->core_map); }#endif
drivers/cpufreq/powernow-k8.c +3 -10
@@ -66,13 +66,6 @@ static struct msr __percpu *msrs;static struct cpufreq_driver cpufreq_amd64_driver; -#ifndef CONFIG_SMP -static inline const struct cpumask *cpu_core_mask (int cpu) -{ -return cpumask_of (0 ); -} -#endif -/* Return a frequency in MHz, given an input fid */ static u32 find_freq_from_fid (u32 fid) {
@@ -715,7 +708,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,pr_debug ("cfid 0x%x, cvid 0x%x\n" , data->currfid, data->currvid); data->powernow_table = powernow_table; -if (cpumask_first (cpu_core_mask (data->cpu)) == data->cpu) +if (cpumask_first (&cpu_data (data->cpu).core_map) == data->cpu)print_basics (data);for (j =0 ; j < data->numps; j++)
@@ -884,7 +877,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) powernow_table[data->acpi_data.state_count].index =0 ; data->powernow_table = powernow_table; -if (cpumask_first (cpu_core_mask (data->cpu)) == data->cpu) +if (cpumask_first (&cpu_data (data->cpu).core_map) == data->cpu)print_basics (data);/* notify BIOS that we exist */
@@ -1326,7 +1319,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)if (cpu_family ==CPU_HW_PSTATE )cpumask_copy (pol->cpus,cpumask_of (pol->cpu));else -cpumask_copy (pol->cpus,cpu_core_mask (pol->cpu)); +cpumask_copy (pol->cpus, &c->core_map); data->available_cores = pol->cpus;if (cpu_family ==CPU_HW_PSTATE )
Signature · 1 line
1.7.9
Re: [PATCH 4/5] x86: Move per cpu cpu_core_map to a field in struct cpuinfo_x86
Quoted 20 lines · Kevin Winchester
This simplifies the various code paths using this field as it groups the per-cpu data together.
Signed-off-by Kevin Winchester <[email protected]>--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 6 ------ arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/proc.c | 3 +-- arch/x86/kernel/smpboot.c | 35 ++++++++++++++--------------------- arch/x86/xen/smp.c | 4 ---- drivers/cpufreq/acpi-cpufreq.c | 2 +- drivers/cpufreq/powernow-k8.c | 13 +++---------- 8 files changed, 23 insertions(+), 46 deletions(-)arch/x86/include/asm/processor.h +0
-0
arch/x86/include/asm/processor.h struct cpuinfo_x86 { · line 118
Quoted 4 lines
arch/x86/include/asm/processor.h +1
-0@@ -115,6 +115,8 @@ struct cpuinfo_x86 {u16 llc_id;/* representing HT siblings of each logical CPU */ cpumask_t sibling_map; +/* representing HT and core siblings of each logical CPU */
Let's change that to be more clear:
"representing all execution threads on a logical CPU, i.e. per physical socket"
or if someone has an even better formulation...
other than that:
Signature · 2 lines
Regards/Gruss, Boris.
PATCH 5/5 x86: Remove #ifdef CONFIG_SMP sections by moving smp_num_siblings into common.c
In reply to Kevin Winchestersmp_num_siblings was defined in arch/x86/kernel/smpboot.c, making it necessary to wrap any UP relevant code referencing it with #ifdef CONFIG_SMP.
Instead, move the definition to arch/x86/kernel/cpu/common.c, thus making it available always.
--- arch/x86/include/asm/perf_event_p4.h | 9 +++------ arch/x86/include/asm/smp.h | 6 +----- arch/x86/include/asm/topology.h | 4 +--- arch/x86/kernel/cpu/amd.c | 4 ---- arch/x86/kernel/cpu/common.c | 6 ++++-- arch/x86/kernel/cpu/proc.c | 5 ++--- arch/x86/kernel/cpu/topology.c | 2 -- arch/x86/kernel/process.c | 3 +-- arch/x86/kernel/smpboot.c | 4 ---- arch/x86/oprofile/nmi_int.c | 6 ------ arch/x86/oprofile/op_model_p4.c | 6 ------ 11 files changed, 12 insertions(+), 43 deletions(-)
arch/x86/include/asm/perf_event_p4.h +3 -6
@@ -8,6 +8,8 @@#include <linux/cpu.h> #include <linux/bitops.h> +#include <asm/smp.h> +/* * NetBurst has performance MSRs shared between * threads if HT is turned on, ie for both logical
@@ -179,18 +181,13 @@ static inline u64 p4_clear_ht_bit(u64 config)static inline int p4_ht_active (void ) { -#ifdef CONFIG_SMP return smp_num_siblings >1 ; -#endif -return 0 ; }static inline int p4_ht_thread (int cpu) { -#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) - return cpu != cpumask_first(&cpu_data(cpu).sibling_map)); -#endif +return cpu !=cpumask_first (&cpu_data (cpu).sibling_map);return 0 ; }
arch/x86/include/asm/smp.h +1 -5
@@ -24,11 +24,7 @@ extern unsigned int num_processors;static inline bool cpu_has_ht_siblings (void ) { -bool has_siblings = false; -#ifdef CONFIG_SMP - has_siblings = cpu_has_ht && smp_num_siblings >1 ; -#endif -return has_siblings; +return cpu_has_ht && smp_num_siblings >1 ; }DECLARE_PER_CPU (int, cpu_number);
arch/x86/include/asm/topology.h +1 -3
@@ -174,11 +174,9 @@ static inline void arch_fix_phys_package_id(int num, u32 slot)struct pci_bus ;void x86_pci_root_bus_resources (int bus,struct list_head *resources); -#ifdef CONFIG_SMP #define mc_capable () ((boot_cpu_data.x86_max_cores > 1) && \ (cpumask_weight(&boot_cpu_data.core_map) != nr_cpu_ids)) -#define smt_capable () (smp_num_siblings > 1) -#endif +#define smt_capable () (smp_num_siblings > 1)#ifdef CONFIG_NUMA extern int get_mp_bus_to_node (int busnum);
arch/x86/kernel/cpu/amd.c +0 -4
@@ -263,7 +263,6 @@ static int __cpuinit nearby_node(int apicid)* Assumption: Number of cores in each internal node is the same. * (2) AMD processors supporting compute units */ -#ifdef CONFIG_X86_HT static void __cpuinit amd_get_topology (struct cpuinfo_x86 *c) {u32 nodes, cores_per_cu =1 ;
@@ -307,7 +306,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) c->compute_unit_id %= cus_per_node; } } -#endif /* * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
@@ -315,7 +313,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c)*/ static void __cpuinit amd_detect_cmp (struct cpuinfo_x86 *c) { -#ifdef CONFIG_X86_HT unsigned bits; bits = c->x86_coreid_bits;
@@ -326,7 +323,6 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)/* use socket ID also for last level cache */ c->llc_id = c->phys_proc_id;amd_get_topology (c); -#endif }int amd_get_nb_id (int cpu)
arch/x86/kernel/cpu/common.c +4 -2
@@ -47,6 +47,10 @@ cpumask_var_t cpu_initialized_mask;cpumask_var_t cpu_callout_mask;cpumask_var_t cpu_callin_mask; +/* Number of siblings per CPU package */ +int smp_num_siblings =1 ; +EXPORT_SYMBOL (smp_num_siblings); +/* representing cpus for which sibling maps can be computed */ cpumask_var_t cpu_sibling_setup_mask;
@@ -452,7 +456,6 @@ void __cpuinit cpu_detect_cache_sizes(struct cpuinfo_x86 *c)void __cpuinit detect_ht (struct cpuinfo_x86 *c) { -#ifdef CONFIG_X86_HT u32 eax, ebx, ecx, edx;int index_msb, core_bits;static bool printed;
@@ -498,7 +501,6 @@ out: c->cpu_core_id); printed =1 ; } -#endif }static void __cpuinit get_cpu_vendor (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/proc.c +2 -3
@@ -1,16 +1,16 @@ -#include <linux/smp.h> #include <linux/timex.h> #include <linux/string.h> #include <linux/seq_file.h> #include <linux/cpufreq.h> +#include <asm/smp.h> +/* * Get CPU information for use by the procfs. */ static void show_cpuinfo_core (struct seq_file *m,struct cpuinfo_x86 *c,unsigned int cpu) { -#ifdef CONFIG_SMP if (c->x86_max_cores * smp_num_siblings >1 ) {seq_printf (m,"physical id\t: %d\n" , c->phys_proc_id);seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (&c->core_map));
@@ -19,7 +19,6 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,seq_printf (m,"apicid\t\t: %d\n" , c->apicid);seq_printf (m,"initial apicid\t: %d\n" , c->initial_apicid); } -#endif }#ifdef CONFIG_X86_32
arch/x86/kernel/cpu/topology.c +0 -2
@@ -28,7 +28,6 @@*/ void __cpuinit detect_extended_topology (struct cpuinfo_x86 *c) { -#ifdef CONFIG_SMP unsigned int eax, ebx, ecx, edx, sub_index;unsigned int ht_mask_width, core_plus_mask_width;unsigned int core_select_mask, core_level_siblings;
@@ -95,5 +94,4 @@ void __cpuinit detect_extended_topology(struct cpuinfo_x86 *c) printed =1 ; }return ; -#endif }
arch/x86/kernel/process.c +1 -2
@@ -586,12 +586,11 @@ static void amd_e400_idle(void)void __cpuinit select_idle_routine (const struct cpuinfo_x86 *c) { -#ifdef CONFIG_SMP if (pm_idle == poll_idle && smp_num_siblings >1 ) {printk_once (KERN_WARNING "WARNING: polling idle and HT enabled," " performance may degrade.\n" ); } -#endif +if (pm_idle)return ;
arch/x86/kernel/smpboot.c +0 -4
@@ -112,10 +112,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;#define set_idle_for_cpu (x, p) (idle_thread_array[(x)] = (p))#endif -/* Number of siblings per CPU package */ -int smp_num_siblings =1 ; -EXPORT_SYMBOL (smp_num_siblings); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
arch/x86/oprofile/nmi_int.c +0 -6
@@ -572,11 +572,6 @@ static int __init p4_init(char **cpu_type)if (cpu_model >6 || cpu_model ==5 )return 0 ; -#ifndef CONFIG_SMP - *cpu_type ="i386/p4" ; - model = &op_p4_spec; -return 1 ; -#else switch (smp_num_siblings) {case 1 : *cpu_type ="i386/p4" ;
@@ -588,7 +583,6 @@ static int __init p4_init(char **cpu_type) model = &op_p4_ht2_spec;return 1 ; } -#endif printk (KERN_INFO "oprofile: P4 HyperThreading detected with > 2 threads\n" );printk (KERN_INFO "oprofile: Reverting to timer mode.\n" );
arch/x86/oprofile/op_model_p4.c +0 -6
@@ -42,21 +42,15 @@ static unsigned int num_controls = NUM_CONTROLS_NON_HT;kernel boot-time. */ static inline void setup_num_counters (void ) { -#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) { num_counters =NUM_COUNTERS_HT2 ; num_controls =NUM_CONTROLS_HT2 ; } -#endif }static inline int addr_increment (void ) { -#ifdef CONFIG_SMP return smp_num_siblings ==2 ?2 :1 ; -#else -return 1 ; -#endif }
Signature · 1 line
1.7.9
Borislav Petkov
maintainerRe: [PATCH 5/5] x86: Remove #ifdef CONFIG_SMP sections by moving smp_num_siblings into common.c
Quoted 36 lines · Kevin Winchester
smp_num_siblingswas defined inarch/x86/kernel/smpboot.c, making it necessary to wrap any UP relevant code referencing it with #ifdefCONFIG_SMP.Instead, move the definition to
arch/x86/kernel/cpu/common.c, thus making it available always.Signed-off-by Kevin Winchester <[email protected]>--- arch/x86/include/asm/perf_event_p4.h | 9 +++------ arch/x86/include/asm/smp.h | 6 +----- arch/x86/include/asm/topology.h | 4 +--- arch/x86/kernel/cpu/amd.c | 4 ---- arch/x86/kernel/cpu/common.c | 6 ++++-- arch/x86/kernel/cpu/proc.c | 5 ++--- arch/x86/kernel/cpu/topology.c | 2 -- arch/x86/kernel/process.c | 3 +-- arch/x86/kernel/smpboot.c | 4 ---- arch/x86/oprofile/nmi_int.c | 6 ------ arch/x86/oprofile/op_model_p4.c | 6 ------ 11 files changed, 12 insertions(+), 43 deletions(-)arch/x86/include/asm/perf_event_p4.h +2
-0@@ -8,6 +8,8 @@#include <linux/cpu.h> #include <linux/bitops.h> +#include <asm/smp.h> +/* * NetBurst has performance MSRs shared between * threads if HT is turned on, ie for both logical
arch/x86/include/asm/perf_event_p4.h static inline u64 p4_clear_ht_bit(u64 config) · line 185
Quoted 8 lines
arch/x86/include/asm/perf_event_p4.h +0
-3@@ -179,18 +181,13 @@ static inline u64 p4_clear_ht_bit(u64 config)static inline int p4_ht_active (void ) { -#ifdef CONFIG_SMP return smp_num_siblings >1 ; -#endif -return 0 ; }
You could drop this function completely now and use the equal smt_capable() macro below.
Quoted 58 lines
arch/x86/include/asm/perf_event_p4.h +1
-3static inline int p4_ht_thread (int cpu) { -#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) - return cpu != cpumask_first(&cpu_data(cpu).sibling_map)); -#endif +return cpu !=cpumask_first (&cpu_data (cpu).sibling_map);return 0 ; }arch/x86/include/asm/smp.h +1
-5@@ -24,11 +24,7 @@ extern unsigned int num_processors;static inline bool cpu_has_ht_siblings (void ) { -bool has_siblings = false; -#ifdef CONFIG_SMP - has_siblings = cpu_has_ht && smp_num_siblings >1 ; -#endif -return has_siblings; +return cpu_has_ht && smp_num_siblings >1 ; }DECLARE_PER_CPU (int, cpu_number);arch/x86/include/asm/topology.h +1
-3@@ -174,11 +174,9 @@ static inline void arch_fix_phys_package_id(int num, u32 slot)struct pci_bus ;void x86_pci_root_bus_resources (int bus,struct list_head *resources); -#ifdef CONFIG_SMP #define mc_capable () ((boot_cpu_data.x86_max_cores > 1) && \ (cpumask_weight(&boot_cpu_data.core_map) != nr_cpu_ids)) -#define smt_capable () (smp_num_siblings > 1) -#endif +#define smt_capable () (smp_num_siblings > 1)#ifdef CONFIG_NUMA extern int get_mp_bus_to_node (int busnum);arch/x86/kernel/cpu/amd.c +0
-1@@ -263,7 +263,6 @@ static int __cpuinit nearby_node(int apicid)* Assumption: Number of cores in each internal node is the same. * (2) AMD processors supporting compute units */ -#ifdef CONFIG_X86_HT static void __cpuinit amd_get_topology (struct cpuinfo_x86 *c) {u32 nodes, cores_per_cu =1 ;
arch/x86/kernel/cpu/amd.c static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) · line 310
Quoted 4 lines
arch/x86/kernel/cpu/amd.c +0
-1@@ -307,7 +306,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) c->compute_unit_id %= cus_per_node; } } -#endif
I'm assuming all those X86_HT changes have been built and boot-tested also with CONFIG_X86_HT unset?
Thanks.
Signature · 2 lines
Regards/Gruss, Boris.
Re: [PATCH 5/5] x86: Remove #ifdef CONFIG_SMP sections by moving smp_num_siblings into common.c
Quoted 106 lines · Borislav Petkov
Quoted 36 lines · Kevin Winchester
smp_num_siblingswas defined inarch/x86/kernel/smpboot.c, making it necessary to wrap any UP relevant code referencing it with #ifdefCONFIG_SMP.Instead, move the definition to
arch/x86/kernel/cpu/common.c, thus making it available always.Signed-off-by Kevin Winchester <[email protected]>---
arch/x86/include/asm/perf_event_p4.h | 9 +++------arch/x86/include/asm/smp.h| 6 +-----arch/x86/include/asm/topology.h| 4 +---arch/x86/kernel/cpu/amd.c| 4 ----arch/x86/kernel/cpu/common.c| 6 ++++--arch/x86/kernel/cpu/proc.c| 5 ++---arch/x86/kernel/cpu/topology.c| 2 --arch/x86/kernel/process.c| 3 +--arch/x86/kernel/smpboot.c| 4 ----arch/x86/oprofile/nmi_int.c| 6 ------arch/x86/oprofile/op_model_p4.c| 6 ------11 files changed, 12 insertions(+), 43 deletions(-)arch/x86/include/asm/perf_event_p4.h +2
-0@@ -8,6 +8,8 @@ #include <linux/cpu.h> #include <linux/bitops.h> +#include <asm/smp.h> + /** NetBurst has performance MSRs shared between * threads if HT is turned on, ie for both logical arch/x86/include/asm/perf_event_p4.h static inline u64 p4_clear_ht_bit(u64 config) · line 185
Quoted 8 lines
arch/x86/include/asm/perf_event_p4.h +0
-3@@ -179,18 +181,13 @@ static inline u64 p4_clear_ht_bit(u64 config) static inline int p4_ht_active(void) { -#ifdef CONFIG_SMP return smp_num_siblings > 1; -#endif - return 0; }You could drop this function completely now and use the equal
smt_capable()macro below.Quoted 57 lines
arch/x86/include/asm/perf_event_p4.h +1
-3static inline int p4_ht_thread(int cpu) { -#ifdef CONFIG_SMP if (smp_num_siblings == 2) - return cpu != cpumask_first(&cpu_data(cpu).sibling_map)); -#endif + return cpu != cpumask_first(&cpu_data(cpu).sibling_map); return 0; }arch/x86/include/asm/smp.h +1
-5@@ -24,11 +24,7 @@ extern unsigned int num_processors; static inline bool cpu_has_ht_siblings(void) { - bool has_siblings = false; -#ifdef CONFIG_SMP - has_siblings = cpu_has_ht && smp_num_siblings > 1; -#endif - return has_siblings; + return cpu_has_ht && smp_num_siblings > 1; } DECLARE_PER_CPU(int, cpu_number);arch/x86/include/asm/topology.h +1
-3@@ -174,11 +174,9 @@ static inline void arch_fix_phys_package_id(int num, u32 slot) struct pci_bus; void x86_pci_root_bus_resources(int bus, struct list_head *resources); -#ifdef CONFIG_SMP #define mc_capable() ((boot_cpu_data.x86_max_cores > 1) && \ (cpumask_weight(&boot_cpu_data.core_map) != nr_cpu_ids)) -#define smt_capable () (smp_num_siblings > 1) -#endif +#define smt_capable () (smp_num_siblings > 1) #ifdef CONFIG_NUMA extern int get_mp_bus_to_node(int busnum);arch/x86/kernel/cpu/amd.c +0
-1@@ -263,7 +263,6 @@ static int __cpuinit nearby_node(int apicid)* Assumption: Number of cores in each internal node is the same. * (2) AMD processors supporting compute units */ -#ifdef CONFIG_X86_HT static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) { u32 nodes, cores_per_cu = 1;
Quoted 9 lines
arch/x86/kernel/cpu/amd.c static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) · line 310
Quoted 5 lines
arch/x86/kernel/cpu/amd.c +0
-1@@ -307,7 +306,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) c->compute_unit_id %= cus_per_node; } } -#endif I'm assuming all those
X86_HTchanges have been built and boot-tested also withCONFIG_X86_HTunset?
Yes, I am running a !CONFIG_SMP build with these patches applied right now.
New version of the patchset coming in a few minutes with all requested changes.
Signature · 1 line
Kevin Winchester
v2 cover x86: Cleanup and simplify cpu-specific data
In reply to Borislav PetkovVarious per-cpu fields are define in arch/x86/kernel/smpboot.c that are basically equivalent to the cpu-specific data in struct cpuinfo_x86. By moving these fields into the structure, a number of codepaths can be simplified since they no longer need to care about those fields not existing on !SMP builds.
The size effects on allno (UP) and allyes (MAX_SMP) kernels are as follows:
text data bss dec hex filename
1586721 304864 506208 2397793 249661 vmlinux.allno
1588517 304928 505920 2399365 249c85 vmlinux.allno.after
84706053 13212311 42434560 140352924 85d9d9c vmlinux.allyes
84705333 13213799 42434560 140353692 85da09c vmlinux.allyes.afte
As can be seen, the kernels get slighly larger, but the code reduction/ simplification should be enough to compensate for it.
Kevin Winchester (5):
x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
x86: Move per cpu cpu_llc_id to a field in struct cpuinfo_x86
x86: Move per cpu cpu_sibling_map to a field in struct cpuinfo_x86
x86: Move per cpu cpu_core_map to a field in struct cpuinfo_x86
x86: Remove #ifdef CONFIG_SMP sections by moving smp_num_siblings
into common.c
arch/x86/include/asm/perf_event_p4.h | 14 +---- arch/x86/include/asm/processor.h | 10 ++++ arch/x86/include/asm/smp.h | 26 +--------- arch/x86/include/asm/topology.h | 10 ++-- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 18 ++----- arch/x86/kernel/cpu/common.c | 7 ++- arch/x86/kernel/cpu/intel_cacheinfo.c | 19 ++----- arch/x86/kernel/cpu/mcheck/mce_amd.c | 7 ++- arch/x86/kernel/cpu/perf_event_p4.c | 4 +- arch/x86/kernel/cpu/proc.c | 8 +-- arch/x86/kernel/cpu/topology.c | 2 - arch/x86/kernel/process.c | 3 +- arch/x86/kernel/smpboot.c | 95 +++++++++++++-------------------- arch/x86/oprofile/nmi_int.c | 6 -- arch/x86/oprofile/op_model_p4.c | 11 +---- arch/x86/xen/smp.c | 6 -- drivers/cpufreq/acpi-cpufreq.c | 2 +- drivers/cpufreq/p4-clockmod.c | 4 +- drivers/cpufreq/powernow-k8.c | 13 +---- drivers/cpufreq/speedstep-ich.c | 6 +- drivers/hwmon/coretemp.c | 6 +-- 22 files changed, 91 insertions(+), 188 deletions(-)
Signature · 1 line
1.7.9
PATCH v2 1/5 x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Commit 141168c36cde ("x86: Simplify code by removing a !SMP #ifdefs from 'struct cpuinfo_x86'") caused the compilation error:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to 'cpu_llc_shared_map'
by removing an #ifdef CONFIG_SMP around a block containing a reference to cpu_llc_shared_map. Rather than replace the #ifdef, move cpu_llc_shared_map to be a new cpumask_t field llc_shared_map in struct cpuinfo_x86 and adjust all references to cpu_llc_shared_map.
The size effects on various kernels are as follows:
text data bss dec hex filename
5281572 513296 1044480 6839348 685c34 vmlinux.up
5281572 513296 1044480 6839348 685c34 vmlinux.up.patched
5548860 516792 1110016 7175668 6d7df4 vmlinux.smp.2
5548837 516792 1110016 7175645 6d7ddd vmlinux.smp.2.patched
5595965 706840 1310720 7613525 742c55 vmlinux.smp.max
5595876 707880 1310720 7614476 74300c vmlinux.smp.max.patched
It can be seen that this change has no effect on UP, a minor effect for SMP with Max 2 CPUs, and a more substantial but still not overly large effect for MAXSMP.
--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 7 ------- arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/mcheck/mce_amd.c | 7 ++++--- arch/x86/kernel/smpboot.c | 15 ++++++--------- arch/x86/xen/smp.c | 1 - 6 files changed, 14 insertions(+), 22 deletions(-)
arch/x86/include/asm/processor.h +2 -0
@@ -110,6 +110,8 @@ struct cpuinfo_x86 {/* Index into per_cpu list: */ u16 cpu_index;u32 microcode; +/* CPUs sharing the last level cache: */ +cpumask_t llc_shared_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -7
@@ -33,8 +33,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ -DECLARE_PER_CPU (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);
@@ -48,11 +46,6 @@ static inline struct cpumask *cpu_core_mask(int cpu)return per_cpu (cpu_core_map, cpu); } -static inline struct cpumask *cpu_llc_shared_mask (int cpu) -{ -return per_cpu (cpu_llc_shared_map, cpu); -} -DECLARE_EARLY_PER_CPU (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU (u16, x86_bios_cpu_apicid);#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86_32 )
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -734,11 +734,11 @@ static int __cpuinit cache_shared_amd_cpu_map_setup(unsigned int cpu, int index) ret =0 ;if (index ==3 ) { ret =1 ; -for_each_cpu (i,cpu_llc_shared_mask (cpu)) { +for_each_cpu (i, &c->llc_shared_map) {if (!per_cpu (ici_cpuid4_info, i))continue ; this_leaf =CPUID4_INFO_IDX (i, index); -for_each_cpu (sibling,cpu_llc_shared_mask (cpu)) { +for_each_cpu (sibling, &c->llc_shared_map) {if (!cpu_online (sibling))continue ;set_bit (sibling, this_leaf->shared_cpu_map);
arch/x86/kernel/cpu/mcheck/mce_amd.c +4 -3
@@ -525,11 +525,12 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)struct threshold_bank *b =NULL ;struct device *dev = mce_device[cpu];char name[32 ]; +struct cpuinfo_x86 *c = &cpu_data (cpu);sprintf (name,"threshold_bank%i" , bank); -if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ - i =cpumask_first (cpu_llc_shared_mask (cpu)); +if (c->cpu_core_id && shared_bank[bank]) {/* symlink */ + i =cpumask_first (&c->llc_shared_map);/* first core not up yet */ if (cpu_data (i).cpu_core_id)
@@ -548,7 +549,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)if (err) goto out; -cpumask_copy (b->cpus,cpu_llc_shared_mask (cpu)); +cpumask_copy (b->cpus, &c->llc_shared_map);per_cpu (threshold_banks, cpu)[bank] = b; goto out;
arch/x86/kernel/smpboot.c +6 -9
@@ -127,8 +127,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);DEFINE_PER_CPU (cpumask_var_t, cpu_core_map);EXPORT_PER_CPU_SYMBOL (cpu_core_map); -DEFINE_PER_CPU (cpumask_var_t, cpu_llc_shared_map); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
@@ -337,8 +335,8 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2)cpumask_set_cpu (cpu2,cpu_sibling_mask (cpu1));cpumask_set_cpu (cpu1,cpu_core_mask (cpu2));cpumask_set_cpu (cpu2,cpu_core_mask (cpu1)); -cpumask_set_cpu (cpu1,cpu_llc_shared_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_llc_shared_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).llc_shared_map); }
@@ -367,7 +365,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu,cpu_sibling_mask (cpu)); } -cpumask_set_cpu (cpu,cpu_llc_shared_mask (cpu)); +cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) {cpumask_copy (cpu_core_mask (cpu),cpu_sibling_mask (cpu));
@@ -378,8 +376,8 @@ void __cpuinit set_cpu_sibling_map(int cpu)for_each_cpu (i, cpu_sibling_setup_mask) {if (per_cpu (cpu_llc_id, cpu) !=BAD_APICID &&per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i)) { -cpumask_set_cpu (i,cpu_llc_shared_mask (cpu)); -cpumask_set_cpu (cpu,cpu_llc_shared_mask (i)); +cpumask_set_cpu (i, &c->llc_shared_map); +cpumask_set_cpu (cpu, &cpu_data (i).llc_shared_map); }if (c->phys_proc_id ==cpu_data (i).phys_proc_id) {cpumask_set_cpu (i,cpu_core_mask (cpu));
@@ -418,7 +416,7 @@ const struct cpumask *cpu_coregroup_mask(int cpu) !(cpu_has(c, X86_FEATURE_AMD_DCM))) return cpu_core_mask(cpu); else - return cpu_llc_shared_mask(cpu); + return &c->llc_shared_map; }static void impress_friends (void )
@@ -1054,7 +1052,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
arch/x86/xen/smp.c +0 -1
@@ -225,7 +225,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
Signature · 1 line
1.7.9
H. Peter Anvin
reviewerRe: [PATCH v2 1/5] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Quoted 10 lines · Kevin Winchester
Commit
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") caused the compilation error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to '
cpu_llc_shared_map'by removing an #ifdef
CONFIG_SMParound a block containing a reference tocpu_llc_shared_map. Rather than replace the #ifdef, movecpu_llc_shared_mapto be a newcpumask_tfieldllc_shared_mapin structcpuinfo_x86and adjust all references tocpu_llc_shared_map.
I'm not comfortable with a patch this large after we are already at -rc4. Please send a minimal patch to fix the failure for v3.3, and then a patch on top of that which we can queue up with the rest of the patchset to for v3.4.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Re: [PATCH v2 1/5] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Quoted 13 lines · H. Peter Anvin
Quoted 11 lines · Kevin Winchester
Commit
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") caused the compilation error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to '
cpu_llc_shared_map'by removing an #ifdef
CONFIG_SMParound a block containing a reference tocpu_llc_shared_map. Rather than replace the #ifdef, movecpu_llc_shared_mapto be a newcpumask_tfieldllc_shared_mapin structcpuinfo_x86and adjust all references tocpu_llc_shared_map.
Quoted 4 lines
I'm not comfortable with a patch this large after we are already at -rc4. Please send a minimal patch to fix the failure for v3.3, and then a patch on top of that which we can queue up with the rest of the patchset to for v3.4.
I forgot about the v3.3 aspect of the series - yes, you are right, doing it like that would be preferred.
It can all be in the same series, we'll sort apart the v3.3 and v3.4 bits.
Thanks,
Ingo
Re: [PATCH v2 1/5] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Quoted 21 lines · Ingo Molnar
Quoted 13 lines · H. Peter Anvin
Quoted 11 lines · Kevin Winchester
Commit
141168c36cde("x86: Simplify code by removing a !SMP #ifdefs from 'structcpuinfo_x86'") caused the compilation error:mce_amd.c:(.cpuinit.text+0x4723): undefined reference to '
cpu_llc_shared_map'by removing an #ifdef
CONFIG_SMParound a block containing a reference tocpu_llc_shared_map. Rather than replace the #ifdef, movecpu_llc_shared_mapto be a newcpumask_tfieldllc_shared_mapin structcpuinfo_x86and adjust all references tocpu_llc_shared_map.Quoted 4 lines
I'm not comfortable with a patch this large after we are already at -rc4. Please send a minimal patch to fix the failure for v3.3, and then a patch on top of that which we can queue up with the rest of the patchset to for v3.4.
Quoted 6 lines
I forgot about the v3.3 aspect of the series - yes, you are right, doing it like that would be preferred.
It can all be in the same series, we'll sort apart the v3.3 and v3.4 bits.
That seems quite reasonable, I was not really thinking about v3.3 or v3.4 at all when working on this. Can I suggest, then, that you apply Borislav's original patch:
https://lkml.org/lkml/2012/2/3/331
for now, and then I will rebase on top of that and remove the #ifdefs as part of my first patch?
Signature · 1 line
Kevin Winchester
v3 cover x86: Cleanup and simplify cpu-specific data
In reply to Ingo MolnarVarious per-cpu fields are define in arch/x86/kernel/smpboot.c that are basically equivalent to the cpu-specific data in struct cpuinfo_x86. By moving these fields into the structure, a number of codepaths can be simplified since they no longer need to care about those fields not existing on !SMP builds.
The size effects on allno (UP) and allyes (MAX_SMP) kernels are as follows:
text data bss dec hex filename
1586721 304864 506208 2397793 249661 vmlinux.allno
1588517 304928 505920 2399365 249c85 vmlinux.allno.after
84706053 13212311 42434560 140352924 85d9d9c vmlinux.allyes
84705333 13213799 42434560 140353692 85da09c vmlinux.allyes.afte
As can be seen, the kernels get slighly larger, but the code reduction/ simplification should be enough to compensate for it.
Kevin Winchester (5):
x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
x86: Move per cpu cpu_llc_id to a field in struct cpuinfo_x86
x86: Move per cpu cpu_sibling_map to a field in struct cpuinfo_x86
x86: Move per cpu cpu_core_map to a field in struct cpuinfo_x86
x86: Remove #ifdef CONFIG_SMP sections by moving smp_num_siblings
into common.c
arch/x86/include/asm/perf_event_p4.h | 14 +---- arch/x86/include/asm/processor.h | 10 ++++ arch/x86/include/asm/smp.h | 26 +--------- arch/x86/include/asm/topology.h | 10 ++-- arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 18 ++----- arch/x86/kernel/cpu/common.c | 7 ++- arch/x86/kernel/cpu/intel_cacheinfo.c | 19 ++----- arch/x86/kernel/cpu/mcheck/mce_amd.c | 9 ++-- arch/x86/kernel/cpu/perf_event_p4.c | 4 +- arch/x86/kernel/cpu/proc.c | 8 +-- arch/x86/kernel/cpu/topology.c | 2 - arch/x86/kernel/process.c | 3 +- arch/x86/kernel/smpboot.c | 95 +++++++++++++-------------------- arch/x86/oprofile/nmi_int.c | 6 -- arch/x86/oprofile/op_model_p4.c | 11 +---- arch/x86/xen/smp.c | 6 -- drivers/cpufreq/acpi-cpufreq.c | 2 +- drivers/cpufreq/p4-clockmod.c | 4 +- drivers/cpufreq/powernow-k8.c | 13 +---- drivers/cpufreq/speedstep-ich.c | 6 +- drivers/hwmon/coretemp.c | 6 +-- 22 files changed, 91 insertions(+), 190 deletions(-)
Signature · 1 line
1.7.9
PATCH v3 1/5 x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
Commit 141168c36cde ("x86: Simplify code by removing a !SMP #ifdefs from 'struct cpuinfo_x86'") caused the compilation error:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to 'cpu_llc_shared_map'
by removing an #ifdef CONFIG_SMP around a block containing a reference to cpu_llc_shared_map. Rather than replace the #ifdef, move cpu_llc_shared_map to be a new cpumask_t field llc_shared_map in struct cpuinfo_x86 and adjust all references to cpu_llc_shared_map.
The size effects on various kernels are as follows:
text data bss dec hex filename
5281572 513296 1044480 6839348 685c34 vmlinux.up
5281572 513296 1044480 6839348 685c34 vmlinux.up.patched
5548860 516792 1110016 7175668 6d7df4 vmlinux.smp.2
5548837 516792 1110016 7175645 6d7ddd vmlinux.smp.2.patched
5595965 706840 1310720 7613525 742c55 vmlinux.smp.max
5595876 707880 1310720 7614476 74300c vmlinux.smp.max.patched
It can be seen that this change has no effect on UP, a minor effect for SMP with Max 2 CPUs, and a more substantial but still not overly large effect for MAXSMP.
--- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 7 ------- arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/cpu/mcheck/mce_amd.c | 9 ++++----- arch/x86/kernel/smpboot.c | 15 ++++++--------- arch/x86/xen/smp.c | 1 - 6 files changed, 14 insertions(+), 24 deletions(-)
arch/x86/include/asm/processor.h +2 -0
@@ -110,6 +110,8 @@ struct cpuinfo_x86 {/* Index into per_cpu list: */ u16 cpu_index;u32 microcode; +/* CPUs sharing the last level cache: */ +cpumask_t llc_shared_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -7
@@ -33,8 +33,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ -DECLARE_PER_CPU (cpumask_var_t, cpu_llc_shared_map);DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);
@@ -48,11 +46,6 @@ static inline struct cpumask *cpu_core_mask(int cpu)return per_cpu (cpu_core_map, cpu); } -static inline struct cpumask *cpu_llc_shared_mask (int cpu) -{ -return per_cpu (cpu_llc_shared_map, cpu); -} -DECLARE_EARLY_PER_CPU (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU (u16, x86_bios_cpu_apicid);#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86_32 )
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -734,11 +734,11 @@ static int __cpuinit cache_shared_amd_cpu_map_setup(unsigned int cpu, int index) ret =0 ;if (index ==3 ) { ret =1 ; -for_each_cpu (i,cpu_llc_shared_mask (cpu)) { +for_each_cpu (i, &c->llc_shared_map) {if (!per_cpu (ici_cpuid4_info, i))continue ; this_leaf =CPUID4_INFO_IDX (i, index); -for_each_cpu (sibling,cpu_llc_shared_mask (cpu)) { +for_each_cpu (sibling, &c->llc_shared_map) {if (!cpu_online (sibling))continue ;set_bit (sibling, this_leaf->shared_cpu_map);
arch/x86/kernel/cpu/mcheck/mce_amd.c +4 -5
@@ -525,12 +525,12 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)struct threshold_bank *b =NULL ;struct device *dev = mce_device[cpu];char name[32 ]; +struct cpuinfo_x86 *c = &cpu_data (cpu);sprintf (name,"threshold_bank%i" , bank); -#ifdef CONFIG_SMP -if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ - i =cpumask_first (cpu_llc_shared_mask (cpu)); +if (c->cpu_core_id && shared_bank[bank]) {/* symlink */ + i =cpumask_first (&c->llc_shared_map);/* first core not up yet */ if (cpu_data (i).cpu_core_id)
@@ -549,12 +549,11 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)if (err) goto out; -cpumask_copy (b->cpus,cpu_llc_shared_mask (cpu)); +cpumask_copy (b->cpus, &c->llc_shared_map);per_cpu (threshold_banks, cpu)[bank] = b; goto out; } -#endif b =kzalloc (sizeof (struct threshold_bank ),GFP_KERNEL );if (!b) {
arch/x86/kernel/smpboot.c +6 -9
@@ -127,8 +127,6 @@ EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);DEFINE_PER_CPU (cpumask_var_t, cpu_core_map);EXPORT_PER_CPU_SYMBOL (cpu_core_map); -DEFINE_PER_CPU (cpumask_var_t, cpu_llc_shared_map); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
@@ -337,8 +335,8 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2)cpumask_set_cpu (cpu2,cpu_sibling_mask (cpu1));cpumask_set_cpu (cpu1,cpu_core_mask (cpu2));cpumask_set_cpu (cpu2,cpu_core_mask (cpu1)); -cpumask_set_cpu (cpu1,cpu_llc_shared_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_llc_shared_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).llc_shared_map); }
@@ -367,7 +365,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu,cpu_sibling_mask (cpu)); } -cpumask_set_cpu (cpu,cpu_llc_shared_mask (cpu)); +cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) {cpumask_copy (cpu_core_mask (cpu),cpu_sibling_mask (cpu));
@@ -378,8 +376,8 @@ void __cpuinit set_cpu_sibling_map(int cpu)for_each_cpu (i, cpu_sibling_setup_mask) {if (per_cpu (cpu_llc_id, cpu) !=BAD_APICID &&per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i)) { -cpumask_set_cpu (i,cpu_llc_shared_mask (cpu)); -cpumask_set_cpu (cpu,cpu_llc_shared_mask (i)); +cpumask_set_cpu (i, &c->llc_shared_map); +cpumask_set_cpu (cpu, &cpu_data (i).llc_shared_map); }if (c->phys_proc_id ==cpu_data (i).phys_proc_id) {cpumask_set_cpu (i,cpu_core_mask (cpu));
@@ -418,7 +416,7 @@ const struct cpumask *cpu_coregroup_mask(int cpu) !(cpu_has(c, X86_FEATURE_AMD_DCM))) return cpu_core_mask(cpu); else - return cpu_llc_shared_mask(cpu); + return &c->llc_shared_map; }static void impress_friends (void )
@@ -1052,7 +1050,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
arch/x86/xen/smp.c +0 -1
@@ -225,7 +225,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)for_each_possible_cpu (i) {zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); -zalloc_cpumask_var (&per_cpu (cpu_llc_shared_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
Signature · 1 line
1.7.9
PATCH v3 2/5 x86: Move per cpu cpu_llc_id to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/smp.h | 1 - arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 14 ++++---------- arch/x86/kernel/cpu/common.c | 1 + arch/x86/kernel/cpu/intel_cacheinfo.c | 11 ++--------- arch/x86/kernel/smpboot.c | 18 ++++++++---------- 7 files changed, 17 insertions(+), 31 deletions(-)
arch/x86/include/asm/processor.h +1 -0
@@ -112,6 +112,7 @@ struct cpuinfo_x86 {u32 microcode;/* CPUs sharing the last level cache: */ cpumask_t llc_shared_map; +u16 llc_id; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -1
@@ -33,7 +33,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map); -DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);static inline struct cpumask *cpu_sibling_mask (int cpu)
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -202,7 +202,7 @@ static void __init map_csrs(void)static void fixup_cpu_id (struct cpuinfo_x86 *c,int node) { c->phys_proc_id = node; -per_cpu (cpu_llc_id,smp_processor_id ()) = node; + c->llc_id = node; }static int __init numachip_system_init (void )
arch/x86/kernel/cpu/amd.c +4 -10
@@ -268,7 +268,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) {u32 nodes, cores_per_cu =1 ;u8 node_id; -int cpu =smp_processor_id ();/* get information required for multi-node processors */ if (cpu_has (c,X86_FEATURE_TOPOEXT )) {
@@ -301,7 +300,7 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) cus_per_node = cores_per_node / cores_per_cu;/* store NodeID, use llc_shared_map to store sibling info */ -per_cpu (cpu_llc_id, cpu) = node_id; + c->llc_id = node_id;/* core id has to be in the [0 .. cores_per_node - 1] range */ c->cpu_core_id %= cores_per_node;
@@ -318,7 +317,6 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c) {#ifdef CONFIG_X86_HT unsigned bits; -int cpu =smp_processor_id (); bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */
@@ -326,18 +324,14 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)/* Convert the initial APIC ID into the socket ID */ c->phys_proc_id = c->initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->phys_proc_id; + c->llc_id = c->phys_proc_id;amd_get_topology (c);#endif }int amd_get_nb_id (int cpu) { -int id =0 ; -#ifdef CONFIG_SMP - id =per_cpu (cpu_llc_id, cpu); -#endif -return id; +return cpu_data (cpu).llc_id; }EXPORT_SYMBOL_GPL (amd_get_nb_id);
@@ -350,7 +344,7 @@ static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c) node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE ) - node =per_cpu (cpu_llc_id, cpu); + node = c->llc_id;/* * If core numbers are inconsistent, it's likely a multi-fabric platform,
arch/x86/kernel/cpu/common.c +1 -0
@@ -788,6 +788,7 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) c->x86_model_id[0 ] ='\0' ;/* Unset */ c->x86_max_cores =1 ; c->x86_coreid_bits =0 ; + c->llc_id =BAD_APICID ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -9
@@ -579,9 +579,6 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)unsigned int new_l1d =0 , new_l1i =0 ;/* Cache sizes from cpuid(4) */ unsigned int new_l2 =0 , new_l3 =0 , i;/* Cache sizes from cpuid(4) */ unsigned int l2_id =0 , l3_id =0 , num_threads_sharing, index_msb; -#ifdef CONFIG_X86_HT -unsigned int cpu = c->cpu_index; -#endif if (c->cpuid_level >3 ) {static int is_initialized;
@@ -700,16 +697,12 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)if (new_l2) { l2 = new_l2; -#ifdef CONFIG_X86_HT -per_cpu (cpu_llc_id, cpu) = l2_id; -#endif + c->llc_id = l2_id; }if (new_l3) { l3 = new_l3; -#ifdef CONFIG_X86_HT -per_cpu (cpu_llc_id, cpu) = l3_id; -#endif + c->llc_id = l3_id; } c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
arch/x86/kernel/smpboot.c +8 -10
@@ -116,9 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* Last level cache ID of each logical CPU */ -DEFINE_PER_CPU (u16, cpu_llc_id) =BAD_APICID ; -/* representing HT siblings of each logical CPU */ DEFINE_PER_CPU (cpumask_var_t, cpu_sibling_map);EXPORT_PER_CPU_SYMBOL (cpu_sibling_map);
@@ -353,7 +350,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)if (cpu_has (c,X86_FEATURE_TOPOEXT )) {if (c->phys_proc_id == o->phys_proc_id && -per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i) && + c->llc_id == o->llc_id && c->compute_unit_id == o->compute_unit_id)link_thread_siblings (cpu, i); } else if (c->phys_proc_id == o->phys_proc_id &&
@@ -374,12 +371,13 @@ void __cpuinit set_cpu_sibling_map(int cpu) }for_each_cpu (i, cpu_sibling_setup_mask) { -if (per_cpu (cpu_llc_id, cpu) !=BAD_APICID && -per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i)) { +struct cpuinfo_x86 *o = &cpu_data (i); + +if (c->llc_id !=BAD_APICID && c->llc_id == o->llc_id) {cpumask_set_cpu (i, &c->llc_shared_map); -cpumask_set_cpu (cpu, &cpu_data (i).llc_shared_map); +cpumask_set_cpu (cpu, &o->llc_shared_map); } -if (c->phys_proc_id ==cpu_data (i).phys_proc_id) { +if (c->phys_proc_id == o->phys_proc_id) {cpumask_set_cpu (i,cpu_core_mask (cpu));cpumask_set_cpu (cpu,cpu_core_mask (i));/*
@@ -397,9 +395,9 @@ void __cpuinit set_cpu_sibling_map(int cpu)* the other cpus in this package */ if (i != cpu) -cpu_data (i).booted_cores++; + o->booted_cores++; }else if (i != cpu && !c->booted_cores) - c->booted_cores =cpu_data (i).booted_cores; + c->booted_cores = o->booted_cores; } } }
Signature · 1 line
1.7.9
PATCH v3 3/5 x86: Move per cpu cpu_sibling_map to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/perf_event_p4.h | 2 +- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 6 ------ arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/smpboot.c | 27 +++++++++++---------------- arch/x86/oprofile/op_model_p4.c | 5 +---- arch/x86/xen/smp.c | 1 - drivers/cpufreq/p4-clockmod.c | 4 +--- drivers/cpufreq/speedstep-ich.c | 6 +++--- drivers/hwmon/coretemp.c | 6 +----- 11 files changed, 23 insertions(+), 42 deletions(-)
arch/x86/include/asm/perf_event_p4.h +1 -1
@@ -189,7 +189,7 @@ static inline int p4_ht_thread(int cpu) {#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) -return cpu !=cpumask_first (__get_cpu_var (cpu_sibling_map)); + return cpu != cpumask_first(&cpu_data(cpu).sibling_map));#endif return 0 ; }
arch/x86/include/asm/processor.h +2 -0
@@ -113,6 +113,8 @@ struct cpuinfo_x86 {/* CPUs sharing the last level cache: */ cpumask_t llc_shared_map;u16 llc_id; +/* representing HT siblings of each logical CPU */ +cpumask_t sibling_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -31,15 +31,9 @@ static inline bool cpu_has_ht_siblings(void)return has_siblings; } -DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);DECLARE_PER_CPU (int, cpu_number); -static inline struct cpumask *cpu_sibling_mask (int cpu) -{ -return per_cpu (cpu_sibling_map, cpu); -} -static inline struct cpumask *cpu_core_mask (int cpu) {return per_cpu (cpu_core_map, cpu);
arch/x86/include/asm/topology.h +1 -1
@@ -161,7 +161,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);#define topology_physical_package_id (cpu) (cpu_data(cpu).phys_proc_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id)#define topology_core_cpumask (cpu) (per_cpu(cpu_core_map, cpu)) -#define topology_thread_cpumask (cpu) (per_cpu(cpu_sibling_map, cpu)) +#define topology_thread_cpumask (cpu) (&cpu_data(cpu).sibling_map)/* indicates that pointers to the topology cpumask_t maps are valid */ #define arch_provides_topology_pointers yes
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -739,11 +739,11 @@ static int __cpuinit cache_shared_amd_cpu_map_setup(unsigned int cpu, int index) } }else if ((c->x86 ==0x15 ) && ((index ==1 ) || (index ==2 ))) { ret =1 ; -for_each_cpu (i,cpu_sibling_mask (cpu)) { +for_each_cpu (i, &c->sibling_map) {if (!per_cpu (ici_cpuid4_info, i))continue ; this_leaf =CPUID4_INFO_IDX (i, index); -for_each_cpu (sibling,cpu_sibling_mask (cpu)) { +for_each_cpu (sibling, &c->sibling_map) {if (!cpu_online (sibling))continue ;set_bit (sibling, this_leaf->shared_cpu_map);
arch/x86/kernel/smpboot.c +11 -16
@@ -116,10 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* representing HT siblings of each logical CPU */ -DEFINE_PER_CPU (cpumask_var_t, cpu_sibling_map); -EXPORT_PER_CPU_SYMBOL (cpu_sibling_map); -/* representing HT and core siblings of each logical CPU */ DEFINE_PER_CPU (cpumask_var_t, cpu_core_map);EXPORT_PER_CPU_SYMBOL (cpu_core_map);
@@ -328,8 +324,8 @@ void __cpuinit smp_store_cpu_info(int id)static void __cpuinit link_thread_siblings (int cpu1,int cpu2) { -cpumask_set_cpu (cpu1,cpu_sibling_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_sibling_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).sibling_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).sibling_map);cpumask_set_cpu (cpu1,cpu_core_mask (cpu2));cpumask_set_cpu (cpu2,cpu_core_mask (cpu1));cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map);
@@ -359,13 +355,13 @@ void __cpuinit set_cpu_sibling_map(int cpu) } } }else { -cpumask_set_cpu (cpu,cpu_sibling_mask (cpu)); +cpumask_set_cpu (cpu, &c->sibling_map); }cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) { -cpumask_copy (cpu_core_mask (cpu),cpu_sibling_mask (cpu)); +cpumask_copy (cpu_core_mask (cpu), &c->sibling_map); c->booted_cores =1 ;return ; }
@@ -383,12 +379,12 @@ void __cpuinit set_cpu_sibling_map(int cpu)/* * Does this new cpu bringup a new core? */ -if (cpumask_weight (cpu_sibling_mask (cpu)) ==1 ) { +if (cpumask_weight (&c->sibling_map) ==1 ) {/* * for each core in package, increment * the booted_cores for this new cpu */ -if (cpumask_first (cpu_sibling_mask (i)) == i) +if (cpumask_first (&o->sibling_map) == i) c->booted_cores++;/* * increment the core count for all
@@ -908,7 +904,7 @@ static __init void disable_smp(void)physid_set_mask_of_physid (boot_cpu_physical_apicid, &phys_cpu_present_map); else physid_set_mask_of_physid(0, &phys_cpu_present_map); -cpumask_set_cpu (0 ,cpu_sibling_mask (0 )); +cpumask_set_cpu (0 , &cpu_data (0 ).sibling_map);cpumask_set_cpu (0 ,cpu_core_mask (0 )); }
@@ -1046,7 +1042,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)current_thread_info ()->cpu =0 ;/* needed? */ for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
@@ -1241,13 +1236,13 @@ static void remove_siblinginfo(int cpu)/*/ * last thread sibling in this cpu core going down */ -if (cpumask_weight (cpu_sibling_mask (cpu)) ==1 ) +if (cpumask_weight (&c->sibling_map) ==1 )cpu_data (sibling).booted_cores--; } -for_each_cpu (sibling,cpu_sibling_mask (cpu)) -cpumask_clear_cpu (cpu,cpu_sibling_mask (sibling)); -cpumask_clear (cpu_sibling_mask (cpu)); +for_each_cpu (sibling, &c->sibling_map) +cpumask_clear_cpu (cpu, &c->sibling_map); +cpumask_clear (&c->sibling_map);cpumask_clear (cpu_core_mask (cpu)); c->phys_proc_id =0 ; c->cpu_core_id =0 ;
arch/x86/oprofile/op_model_p4.c +1 -4
@@ -370,11 +370,8 @@ static struct p4_event_binding p4_events[NUM_EVENTS] = {or "odd" part of all the divided resources. */ static unsigned int get_stagger (void ) { -#ifdef CONFIG_SMP int cpu =smp_processor_id (); -return cpu !=cpumask_first (__get_cpu_var (cpu_sibling_map)); -#endif -return 0 ; +return cpu !=cpumask_first (&cpu_data (cpu).sibling_map); }
arch/x86/xen/smp.c +0 -1
@@ -223,7 +223,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)cpu_data (0 ).x86_max_cores =1 ;for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
drivers/cpufreq/p4-clockmod.c +1 -3
@@ -203,9 +203,7 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)int cpuid =0 ;unsigned int i; -#ifdef CONFIG_SMP -cpumask_copy (policy->cpus,cpu_sibling_mask (policy->cpu)); -#endif +cpumask_copy (policy->cpus, &c->sibling_map);/* Errata workaround */ cpuid = (c->x86 <<8 ) | (c->x86_model <<4 ) | c->x86_mask;
drivers/cpufreq/speedstep-ich.c +3 -3
@@ -326,14 +326,14 @@ static void get_freqs_on_cpu(void *_get_freqs)static int speedstep_cpu_init (struct cpufreq_policy *policy) { +struct cpuinfo_x86 *c = &cpu_data (policy->cpu);int result;unsigned int policy_cpu, speed;struct get_freqs gf;/* only run on CPU to be set, or on its sibling */ -#ifdef CONFIG_SMP -cpumask_copy (policy->cpus,cpu_sibling_mask (policy->cpu)); -#endif +cpumask_copy (policy->cpus, c->sibling_map); + policy_cpu =cpumask_any_and (policy->cpus, cpu_online_mask);/* detect low and high frequency and transition latency */
drivers/hwmon/coretemp.c +1 -5
@@ -61,11 +61,7 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");#define TO_CORE_ID (cpu) cpu_data(cpu).cpu_core_id#define TO_ATTR_NO (cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO) -#ifdef CONFIG_SMP -#define for_each_sibling (i, cpu) for_each_cpu(i, cpu_sibling_mask(cpu)) -#else -#define for_each_sibling (i, cpu) for (i = 0; false; ) -#endif +#define for_each_sibling (i, cpu) for_each_cpu(i, &cpu_data(cpu).sibling_map)/* * Per-Core Temperature Data
Signature · 1 line
1.7.9
PATCH v3 4/5 x86: Move per cpu cpu_core_map to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/processor.h | 5 +++++ arch/x86/include/asm/smp.h | 6 ------ arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/proc.c | 3 +-- arch/x86/kernel/smpboot.c | 35 ++++++++++++++--------------------- arch/x86/xen/smp.c | 4 ---- drivers/cpufreq/acpi-cpufreq.c | 2 +- drivers/cpufreq/powernow-k8.c | 13 +++---------- 8 files changed, 26 insertions(+), 46 deletions(-)
arch/x86/include/asm/processor.h +5 -0
@@ -115,6 +115,11 @@ struct cpuinfo_x86 {u16 llc_id;/* representing HT siblings of each logical CPU */ cpumask_t sibling_map; +/* +* representing all execution threads on a logical CPU, i.e. per +* physical socket +*/ +cpumask_t core_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -31,14 +31,8 @@ static inline bool cpu_has_ht_siblings(void)return has_siblings; } -DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);DECLARE_PER_CPU (int, cpu_number); -static inline struct cpumask *cpu_core_mask (int cpu) -{ -return per_cpu (cpu_core_map, cpu); -} -DECLARE_EARLY_PER_CPU (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU (u16, x86_bios_cpu_apicid);#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86_32 )
arch/x86/include/asm/topology.h +2 -2
@@ -160,7 +160,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);#ifdef ENABLE_TOPO_DEFINES #define topology_physical_package_id (cpu) (cpu_data(cpu).phys_proc_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id) -#define topology_core_cpumask (cpu) (per_cpu(cpu_core_map, cpu)) +#define topology_core_cpumask (cpu) (&cpu_data(cpu).core_map)#define topology_thread_cpumask (cpu) (&cpu_data(cpu).sibling_map)/* indicates that pointers to the topology cpumask_t maps are valid */
@@ -176,7 +176,7 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources);#ifdef CONFIG_SMP #define mc_capable () ((boot_cpu_data.x86_max_cores > 1) && \ - (cpumask_weight(cpu_core_mask(0)) != nr_cpu_ids)) + (cpumask_weight(&boot_cpu_data.core_map) != nr_cpu_ids))#define smt_capable () (smp_num_siblings > 1)#endif
arch/x86/kernel/cpu/proc.c +1 -2
@@ -13,8 +13,7 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,#ifdef CONFIG_SMP if (c->x86_max_cores * smp_num_siblings >1 ) {seq_printf (m,"physical id\t: %d\n" , c->phys_proc_id); -seq_printf (m,"siblings\t: %d\n" , -cpumask_weight (cpu_core_mask (cpu))); +seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (&c->core_map));seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id);seq_printf (m,"cpu cores\t: %d\n" , c->booted_cores);seq_printf (m,"apicid\t\t: %d\n" , c->apicid);
arch/x86/kernel/smpboot.c +14 -21
@@ -116,10 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* representing HT and core siblings of each logical CPU */ -DEFINE_PER_CPU (cpumask_var_t, cpu_core_map); -EXPORT_PER_CPU_SYMBOL (cpu_core_map); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
@@ -326,8 +322,8 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2) {cpumask_set_cpu (cpu1, &cpu_data (cpu2).sibling_map);cpumask_set_cpu (cpu2, &cpu_data (cpu1).sibling_map); -cpumask_set_cpu (cpu1,cpu_core_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_core_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).core_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).core_map);cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map);cpumask_set_cpu (cpu2, &cpu_data (cpu1).llc_shared_map); }
@@ -361,7 +357,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) { -cpumask_copy (cpu_core_mask (cpu), &c->sibling_map); +cpumask_copy (&c->core_map, &c->sibling_map); c->booted_cores =1 ;return ; }
@@ -374,8 +370,8 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu, &o->llc_shared_map); }if (c->phys_proc_id == o->phys_proc_id) { -cpumask_set_cpu (i,cpu_core_mask (cpu)); -cpumask_set_cpu (cpu,cpu_core_mask (i)); +cpumask_set_cpu (i, &c->core_map); +cpumask_set_cpu (cpu, &o->core_map);/* * Does this new cpu bringup a new core? */
@@ -404,11 +400,11 @@ const struct cpumask *cpu_coregroup_mask(int cpu)struct cpuinfo_x86 *c = &cpu_data (cpu);/* * For perf, we return last level cache shared map. -* And for power savings, we return cpu_core_map +* And for power savings, we return core map. */ if ((sched_mc_power_savings || sched_smt_power_savings) && !(cpu_has (c,X86_FEATURE_AMD_DCM ))) -return cpu_core_mask (cpu); +return &c->core_map;else return &c->llc_shared_map; }
@@ -905,7 +901,7 @@ static __init void disable_smp(void)else physid_set_mask_of_physid (0 , &phys_cpu_present_map);cpumask_set_cpu (0 , &cpu_data (0 ).sibling_map); -cpumask_set_cpu (0 ,cpu_core_mask (0 )); +cpumask_set_cpu (0 , &cpu_data (0 ).core_map); }/*
@@ -1028,8 +1024,6 @@ static void __init smp_cpu_index_default(void)*/ void __init native_smp_prepare_cpus (unsigned int max_cpus) { -unsigned int i; -preempt_disable ();smp_cpu_index_default ();
@@ -1041,9 +1035,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)mb ();current_thread_info ()->cpu =0 ;/* needed? */ -for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); - }set_cpu_sibling_map (0 );
@@ -1231,19 +1222,21 @@ static void remove_siblinginfo(int cpu)int sibling;struct cpuinfo_x86 *c = &cpu_data (cpu); -for_each_cpu (sibling,cpu_core_mask (cpu)) { -cpumask_clear_cpu (cpu,cpu_core_mask (sibling)); +for_each_cpu (sibling, &c->core_map) { +struct cpuinfo_x86 *o = &cpu_data (sibling); + +cpumask_clear_cpu (cpu, &o->core_map);/*/ * last thread sibling in this cpu core going down */ if (cpumask_weight (&c->sibling_map) ==1 ) -cpu_data (sibling).booted_cores--; + o->booted_cores--; }for_each_cpu (sibling, &c->sibling_map)cpumask_clear_cpu (cpu, &c->sibling_map);cpumask_clear (&c->sibling_map); -cpumask_clear (cpu_core_mask (cpu)); +cpumask_clear (&c->core_map); c->phys_proc_id =0 ; c->cpu_core_id =0 ;cpumask_clear_cpu (cpu, cpu_sibling_setup_mask);
arch/x86/xen/smp.c +0 -4
@@ -206,7 +206,6 @@ static void __init xen_smp_prepare_boot_cpu(void)static void __init xen_smp_prepare_cpus (unsigned int max_cpus) {unsigned cpu; -unsigned int i;if (skip_ioapic_setup) { char *m = (max_cpus == 0) ?
@@ -222,9 +221,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)smp_store_cpu_info (0 );cpu_data (0 ).x86_max_cores =1 ; -for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); - }set_cpu_sibling_map (0 );if (xen_smp_intr_init (0 ))
drivers/cpufreq/acpi-cpufreq.c +1 -1
@@ -557,7 +557,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)dmi_check_system (sw_any_bug_dmi_table);if (bios_with_sw_any_bug &&cpumask_weight (policy->cpus) ==1 ) { policy->shared_type =CPUFREQ_SHARED_TYPE_ALL ; -cpumask_copy (policy->cpus,cpu_core_mask (cpu)); +cpumask_copy (policy->cpus, &c->core_map); }#endif
drivers/cpufreq/powernow-k8.c +3 -10
@@ -66,13 +66,6 @@ static struct msr __percpu *msrs;static struct cpufreq_driver cpufreq_amd64_driver; -#ifndef CONFIG_SMP -static inline const struct cpumask *cpu_core_mask (int cpu) -{ -return cpumask_of (0 ); -} -#endif -/* Return a frequency in MHz, given an input fid */ static u32 find_freq_from_fid (u32 fid) {
@@ -715,7 +708,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,pr_debug ("cfid 0x%x, cvid 0x%x\n" , data->currfid, data->currvid); data->powernow_table = powernow_table; -if (cpumask_first (cpu_core_mask (data->cpu)) == data->cpu) +if (cpumask_first (&cpu_data (data->cpu).core_map) == data->cpu)print_basics (data);for (j =0 ; j < data->numps; j++)
@@ -884,7 +877,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) powernow_table[data->acpi_data.state_count].index =0 ; data->powernow_table = powernow_table; -if (cpumask_first (cpu_core_mask (data->cpu)) == data->cpu) +if (cpumask_first (&cpu_data (data->cpu).core_map) == data->cpu)print_basics (data);/* notify BIOS that we exist */
@@ -1326,7 +1319,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)if (cpu_family ==CPU_HW_PSTATE )cpumask_copy (pol->cpus,cpumask_of (pol->cpu));else -cpumask_copy (pol->cpus,cpu_core_mask (pol->cpu)); +cpumask_copy (pol->cpus, &c->core_map); data->available_cores = pol->cpus;if (cpu_family ==CPU_HW_PSTATE )
Signature · 1 line
1.7.9
PATCH v3 5/5 x86: Remove #ifdef CONFIG_SMP sections by moving smp_num_siblings into common.c
In reply to Kevin Winchestersmp_num_siblings was defined in arch/x86/kernel/smpboot.c, making it necessary to wrap any UP relevant code referencing it with #ifdef CONFIG_SMP.
Instead, move the definition to arch/x86/kernel/cpu/common.c, thus making it available always.
--- arch/x86/include/asm/perf_event_p4.h | 14 +++----------- arch/x86/include/asm/smp.h | 6 +----- arch/x86/include/asm/topology.h | 4 +--- arch/x86/kernel/cpu/amd.c | 4 ---- arch/x86/kernel/cpu/common.c | 6 ++++-- arch/x86/kernel/cpu/perf_event_p4.c | 4 ++-- arch/x86/kernel/cpu/proc.c | 5 ++--- arch/x86/kernel/cpu/topology.c | 2 -- arch/x86/kernel/process.c | 3 +-- arch/x86/kernel/smpboot.c | 4 ---- arch/x86/oprofile/nmi_int.c | 6 ------ arch/x86/oprofile/op_model_p4.c | 6 ------ 12 files changed, 14 insertions(+), 50 deletions(-)
arch/x86/include/asm/perf_event_p4.h +3 -11
@@ -8,6 +8,8 @@#include <linux/cpu.h> #include <linux/bitops.h> +#include <asm/smp.h> +/* * NetBurst has performance MSRs shared between * threads if HT is turned on, ie for both logical
@@ -177,20 +179,10 @@ static inline u64 p4_clear_ht_bit(u64 config)return config & ~P4_CONFIG_HT ; } -static inline int p4_ht_active (void ) -{ -#ifdef CONFIG_SMP -return smp_num_siblings >1 ; -#endif -return 0 ; -} -static inline int p4_ht_thread (int cpu) { -#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) - return cpu != cpumask_first(&cpu_data(cpu).sibling_map)); -#endif +return cpu !=cpumask_first (&cpu_data (cpu).sibling_map);return 0 ; }
arch/x86/include/asm/smp.h +1 -5
@@ -24,11 +24,7 @@ extern unsigned int num_processors;static inline bool cpu_has_ht_siblings (void ) { -bool has_siblings = false; -#ifdef CONFIG_SMP - has_siblings = cpu_has_ht && smp_num_siblings >1 ; -#endif -return has_siblings; +return cpu_has_ht && smp_num_siblings >1 ; }DECLARE_PER_CPU (int, cpu_number);
arch/x86/include/asm/topology.h +1 -3
@@ -174,11 +174,9 @@ static inline void arch_fix_phys_package_id(int num, u32 slot)struct pci_bus ;void x86_pci_root_bus_resources (int bus,struct list_head *resources); -#ifdef CONFIG_SMP #define mc_capable () ((boot_cpu_data.x86_max_cores > 1) && \ (cpumask_weight(&boot_cpu_data.core_map) != nr_cpu_ids)) -#define smt_capable () (smp_num_siblings > 1) -#endif +#define smt_capable () (smp_num_siblings > 1)#ifdef CONFIG_NUMA extern int get_mp_bus_to_node (int busnum);
arch/x86/kernel/cpu/amd.c +0 -4
@@ -263,7 +263,6 @@ static int __cpuinit nearby_node(int apicid)* Assumption: Number of cores in each internal node is the same. * (2) AMD processors supporting compute units */ -#ifdef CONFIG_X86_HT static void __cpuinit amd_get_topology (struct cpuinfo_x86 *c) {u32 nodes, cores_per_cu =1 ;
@@ -307,7 +306,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) c->compute_unit_id %= cus_per_node; } } -#endif /* * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
@@ -315,7 +313,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c)*/ static void __cpuinit amd_detect_cmp (struct cpuinfo_x86 *c) { -#ifdef CONFIG_X86_HT unsigned bits; bits = c->x86_coreid_bits;
@@ -326,7 +323,6 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)/* use socket ID also for last level cache */ c->llc_id = c->phys_proc_id;amd_get_topology (c); -#endif }int amd_get_nb_id (int cpu)
arch/x86/kernel/cpu/common.c +4 -2
@@ -48,6 +48,10 @@ cpumask_var_t cpu_initialized_mask;cpumask_var_t cpu_callout_mask;cpumask_var_t cpu_callin_mask; +/* Number of siblings per CPU package */ +int smp_num_siblings =1 ; +EXPORT_SYMBOL (smp_num_siblings); +/* representing cpus for which sibling maps can be computed */ cpumask_var_t cpu_sibling_setup_mask;
@@ -453,7 +457,6 @@ void __cpuinit cpu_detect_cache_sizes(struct cpuinfo_x86 *c)void __cpuinit detect_ht (struct cpuinfo_x86 *c) { -#ifdef CONFIG_X86_HT u32 eax, ebx, ecx, edx;int index_msb, core_bits;static bool printed;
@@ -499,7 +502,6 @@ out: c->cpu_core_id); printed =1 ; } -#endif }static void __cpuinit get_cpu_vendor (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/perf_event_p4.c +2 -2
@@ -775,7 +775,7 @@ static int p4_validate_raw_event(struct perf_event *event)* if an event is shared across the logical threads * the user needs special permissions to be able to use it */ -if (p4_ht_active () && p4_event_bind_map[v].shared) { +if (smt_capable () && p4_event_bind_map[v].shared) {if (perf_paranoid_cpu () && !capable (CAP_SYS_ADMIN ))return -EACCES ; }
@@ -816,7 +816,7 @@ static int p4_hw_config(struct perf_event *event) event->hw.config =p4_config_pack_escr (escr) |p4_config_pack_cccr (cccr); -if (p4_ht_active () &&p4_ht_thread (cpu)) +if (smt_capable () &&p4_ht_thread (cpu)) event->hw.config =p4_set_ht_bit (event->hw.config);if (event->attr.type ==PERF_TYPE_RAW ) {
arch/x86/kernel/cpu/proc.c +2 -3
@@ -1,16 +1,16 @@ -#include <linux/smp.h> #include <linux/timex.h> #include <linux/string.h> #include <linux/seq_file.h> #include <linux/cpufreq.h> +#include <asm/smp.h> +/* * Get CPU information for use by the procfs. */ static void show_cpuinfo_core (struct seq_file *m,struct cpuinfo_x86 *c,unsigned int cpu) { -#ifdef CONFIG_SMP if (c->x86_max_cores * smp_num_siblings >1 ) {seq_printf (m,"physical id\t: %d\n" , c->phys_proc_id);seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (&c->core_map));
@@ -19,7 +19,6 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,seq_printf (m,"apicid\t\t: %d\n" , c->apicid);seq_printf (m,"initial apicid\t: %d\n" , c->initial_apicid); } -#endif }#ifdef CONFIG_X86_32
arch/x86/kernel/cpu/topology.c +0 -2
@@ -28,7 +28,6 @@*/ void __cpuinit detect_extended_topology (struct cpuinfo_x86 *c) { -#ifdef CONFIG_SMP unsigned int eax, ebx, ecx, edx, sub_index;unsigned int ht_mask_width, core_plus_mask_width;unsigned int core_select_mask, core_level_siblings;
@@ -95,5 +94,4 @@ void __cpuinit detect_extended_topology(struct cpuinfo_x86 *c) printed =1 ; }return ; -#endif }
arch/x86/kernel/process.c +1 -2
@@ -587,12 +587,11 @@ static void amd_e400_idle(void)void __cpuinit select_idle_routine (const struct cpuinfo_x86 *c) { -#ifdef CONFIG_SMP if (pm_idle == poll_idle && smp_num_siblings >1 ) {printk_once (KERN_WARNING "WARNING: polling idle and HT enabled," " performance may degrade.\n" ); } -#endif +if (pm_idle)return ;
arch/x86/kernel/smpboot.c +0 -4
@@ -112,10 +112,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;#define set_idle_for_cpu (x, p) (idle_thread_array[(x)] = (p))#endif -/* Number of siblings per CPU package */ -int smp_num_siblings =1 ; -EXPORT_SYMBOL (smp_num_siblings); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
arch/x86/oprofile/nmi_int.c +0 -6
@@ -572,11 +572,6 @@ static int __init p4_init(char **cpu_type)if (cpu_model >6 || cpu_model ==5 )return 0 ; -#ifndef CONFIG_SMP - *cpu_type ="i386/p4" ; - model = &op_p4_spec; -return 1 ; -#else switch (smp_num_siblings) {case 1 : *cpu_type ="i386/p4" ;
@@ -588,7 +583,6 @@ static int __init p4_init(char **cpu_type) model = &op_p4_ht2_spec;return 1 ; } -#endif printk (KERN_INFO "oprofile: P4 HyperThreading detected with > 2 threads\n" );printk (KERN_INFO "oprofile: Reverting to timer mode.\n" );
arch/x86/oprofile/op_model_p4.c +0 -6
@@ -42,21 +42,15 @@ static unsigned int num_controls = NUM_CONTROLS_NON_HT;kernel boot-time. */ static inline void setup_num_counters (void ) { -#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) { num_counters =NUM_COUNTERS_HT2 ; num_controls =NUM_CONTROLS_HT2 ; } -#endif }static inline int addr_increment (void ) { -#ifdef CONFIG_SMP return smp_num_siblings ==2 ?2 :1 ; -#else -return 1 ; -#endif }
Signature · 1 line
1.7.9
Re: [PATCH v3 0/5] x86: Cleanup and simplify cpu-specific data
In reply to Kevin WinchesterQuoted 25 lines · Kevin Winchester
Kevin Winchester (5):
x86: Move per cpucpu_llc_shared_mapto a field in structcpuinfo_x86
x86: Move per cpucpu_llc_idto a field in structcpuinfo_x86
x86: Move per cpucpu_sibling_mapto a field in structcpuinfo_x86
x86: Move per cpucpu_core_mapto a field in structcpuinfo_x86
x86: Remove #ifdefCONFIG_SMPsections by movingsmp_num_siblingsintocommon.carch/x86/include/asm/perf_event_p4.h | 14 +----
arch/x86/include/asm/processor.h| 10 ++++arch/x86/include/asm/smp.h| 26 +---------arch/x86/include/asm/topology.h| 10 ++--arch/x86/kernel/apic/apic_numachip.c| 2 +-arch/x86/kernel/cpu/amd.c| 18 ++-----arch/x86/kernel/cpu/common.c| 7 ++-arch/x86/kernel/cpu/intel_cacheinfo.c| 19 ++-----arch/x86/kernel/cpu/mcheck/mce_amd.c| 9 ++--arch/x86/kernel/cpu/perf_event_p4.c| 4 +-arch/x86/kernel/cpu/proc.c| 8 +--arch/x86/kernel/cpu/topology.c| 2 -arch/x86/kernel/process.c| 3 +-arch/x86/kernel/smpboot.c| 95 +++++++++++++--------------------arch/x86/oprofile/nmi_int.c| 6 --arch/x86/oprofile/op_model_p4.c| 11 +----arch/x86/xen/smp.c| 6 --
Quoted 7 lines
drivers/cpufreq/acpi-cpufreq.c | 2 +- drivers/cpufreq/p4-clockmod.c | 4 +- drivers/cpufreq/powernow-k8.c | 13 +---- drivers/cpufreq/speedstep-ich.c | 6 +- drivers/hwmon/coretemp.c | 6 +-- 22 files changed, 91 insertions(+), 190 deletions(-)
Please ignore this posting, I rushed it and did not build all combinations. It looks like a new user of cpu_core_mask appeared in tip since my last rebase.
I'll send the series out again once I have confirmed that everything is correct.
Signature · 1 line
Kevin Winchester
Re: [PATCH v3 0/5] x86: Cleanup and simplify cpu-specific data
In reply to Kevin WinchesterQuoted 1 line · Kevin Winchester
22 files changed, 91 insertions(+), 190 deletions(-)
Btw., the diffstat is very nice - the individual patches only hinted at the simplification effect - the combined diffstat shows that we saved a hundred lines of often rather complex code and made this code quite a bit more hackable.
Thanks,
Ingo
PATCH v2 2/5 x86: Move per cpu cpu_llc_id to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/processor.h | 1 + arch/x86/include/asm/smp.h | 1 - arch/x86/kernel/apic/apic_numachip.c | 2 +- arch/x86/kernel/cpu/amd.c | 14 ++++---------- arch/x86/kernel/cpu/common.c | 1 + arch/x86/kernel/cpu/intel_cacheinfo.c | 11 ++--------- arch/x86/kernel/smpboot.c | 18 ++++++++---------- 7 files changed, 17 insertions(+), 31 deletions(-)
arch/x86/include/asm/processor.h +1 -0
@@ -112,6 +112,7 @@ struct cpuinfo_x86 {u32 microcode;/* CPUs sharing the last level cache: */ cpumask_t llc_shared_map; +u16 llc_id; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -1
@@ -33,7 +33,6 @@ static inline bool cpu_has_ht_siblings(void)DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map); -DECLARE_PER_CPU (u16, cpu_llc_id);DECLARE_PER_CPU (int, cpu_number);static inline struct cpumask *cpu_sibling_mask (int cpu)
arch/x86/kernel/apic/apic_numachip.c +1 -1
@@ -202,7 +202,7 @@ static void __init map_csrs(void)static void fixup_cpu_id (struct cpuinfo_x86 *c,int node) { c->phys_proc_id = node; -per_cpu (cpu_llc_id,smp_processor_id ()) = node; + c->llc_id = node; }static int __init numachip_system_init (void )
arch/x86/kernel/cpu/amd.c +4 -10
@@ -268,7 +268,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) {u32 nodes, cores_per_cu =1 ;u8 node_id; -int cpu =smp_processor_id ();/* get information required for multi-node processors */ if (cpu_has (c,X86_FEATURE_TOPOEXT )) {
@@ -301,7 +300,7 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) cus_per_node = cores_per_node / cores_per_cu;/* store NodeID, use llc_shared_map to store sibling info */ -per_cpu (cpu_llc_id, cpu) = node_id; + c->llc_id = node_id;/* core id has to be in the [0 .. cores_per_node - 1] range */ c->cpu_core_id %= cores_per_node;
@@ -318,7 +317,6 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c) {#ifdef CONFIG_X86_HT unsigned bits; -int cpu =smp_processor_id (); bits = c->x86_coreid_bits;/* Low order bits define the core id (index of core in socket) */
@@ -326,18 +324,14 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)/* Convert the initial APIC ID into the socket ID */ c->phys_proc_id = c->initial_apicid >> bits;/* use socket ID also for last level cache */ -per_cpu (cpu_llc_id, cpu) = c->phys_proc_id; + c->llc_id = c->phys_proc_id;amd_get_topology (c);#endif }int amd_get_nb_id (int cpu) { -int id =0 ; -#ifdef CONFIG_SMP - id =per_cpu (cpu_llc_id, cpu); -#endif -return id; +return cpu_data (cpu).llc_id; }EXPORT_SYMBOL_GPL (amd_get_nb_id);
@@ -350,7 +344,7 @@ static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c) node =numa_cpu_node (cpu);if (node ==NUMA_NO_NODE ) - node =per_cpu (cpu_llc_id, cpu); + node = c->llc_id;/* * If core numbers are inconsistent, it's likely a multi-fabric platform,
arch/x86/kernel/cpu/common.c +1 -0
@@ -787,6 +787,7 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) c->x86_model_id[0 ] ='\0' ;/* Unset */ c->x86_max_cores =1 ; c->x86_coreid_bits =0 ; + c->llc_id =BAD_APICID ;#ifdef CONFIG_X86_64 c->x86_clflush_size =64 ; c->x86_phys_bits =36 ;
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -9
@@ -579,9 +579,6 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)unsigned int new_l1d =0 , new_l1i =0 ;/* Cache sizes from cpuid(4) */ unsigned int new_l2 =0 , new_l3 =0 , i;/* Cache sizes from cpuid(4) */ unsigned int l2_id =0 , l3_id =0 , num_threads_sharing, index_msb; -#ifdef CONFIG_X86_HT -unsigned int cpu = c->cpu_index; -#endif if (c->cpuid_level >3 ) {static int is_initialized;
@@ -700,16 +697,12 @@ unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)if (new_l2) { l2 = new_l2; -#ifdef CONFIG_X86_HT -per_cpu (cpu_llc_id, cpu) = l2_id; -#endif + c->llc_id = l2_id; }if (new_l3) { l3 = new_l3; -#ifdef CONFIG_X86_HT -per_cpu (cpu_llc_id, cpu) = l3_id; -#endif + c->llc_id = l3_id; } c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
arch/x86/kernel/smpboot.c +8 -10
@@ -116,9 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* Last level cache ID of each logical CPU */ -DEFINE_PER_CPU (u16, cpu_llc_id) =BAD_APICID ; -/* representing HT siblings of each logical CPU */ DEFINE_PER_CPU (cpumask_var_t, cpu_sibling_map);EXPORT_PER_CPU_SYMBOL (cpu_sibling_map);
@@ -353,7 +350,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)if (cpu_has (c,X86_FEATURE_TOPOEXT )) {if (c->phys_proc_id == o->phys_proc_id && -per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i) && + c->llc_id == o->llc_id && c->compute_unit_id == o->compute_unit_id)link_thread_siblings (cpu, i); } else if (c->phys_proc_id == o->phys_proc_id &&
@@ -374,12 +371,13 @@ void __cpuinit set_cpu_sibling_map(int cpu) }for_each_cpu (i, cpu_sibling_setup_mask) { -if (per_cpu (cpu_llc_id, cpu) !=BAD_APICID && -per_cpu (cpu_llc_id, cpu) ==per_cpu (cpu_llc_id, i)) { +struct cpuinfo_x86 *o = &cpu_data (i); + +if (c->llc_id !=BAD_APICID && c->llc_id == o->llc_id) {cpumask_set_cpu (i, &c->llc_shared_map); -cpumask_set_cpu (cpu, &cpu_data (i).llc_shared_map); +cpumask_set_cpu (cpu, &o->llc_shared_map); } -if (c->phys_proc_id ==cpu_data (i).phys_proc_id) { +if (c->phys_proc_id == o->phys_proc_id) {cpumask_set_cpu (i,cpu_core_mask (cpu));cpumask_set_cpu (cpu,cpu_core_mask (i));/*
@@ -397,9 +395,9 @@ void __cpuinit set_cpu_sibling_map(int cpu)* the other cpus in this package */ if (i != cpu) -cpu_data (i).booted_cores++; + o->booted_cores++; }else if (i != cpu && !c->booted_cores) - c->booted_cores =cpu_data (i).booted_cores; + c->booted_cores = o->booted_cores; } } }
Signature · 1 line
1.7.9
PATCH v2 3/5 x86: Move per cpu cpu_sibling_map to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/perf_event_p4.h | 2 +- arch/x86/include/asm/processor.h | 2 ++ arch/x86/include/asm/smp.h | 6 ------ arch/x86/include/asm/topology.h | 2 +- arch/x86/kernel/cpu/intel_cacheinfo.c | 4 ++-- arch/x86/kernel/smpboot.c | 27 +++++++++++---------------- arch/x86/oprofile/op_model_p4.c | 5 +---- arch/x86/xen/smp.c | 1 - drivers/cpufreq/p4-clockmod.c | 4 +--- drivers/cpufreq/speedstep-ich.c | 6 +++--- drivers/hwmon/coretemp.c | 6 +----- 11 files changed, 23 insertions(+), 42 deletions(-)
arch/x86/include/asm/perf_event_p4.h +1 -1
@@ -189,7 +189,7 @@ static inline int p4_ht_thread(int cpu) {#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) -return cpu !=cpumask_first (__get_cpu_var (cpu_sibling_map)); + return cpu != cpumask_first(&cpu_data(cpu).sibling_map));#endif return 0 ; }
arch/x86/include/asm/processor.h +2 -0
@@ -113,6 +113,8 @@ struct cpuinfo_x86 {/* CPUs sharing the last level cache: */ cpumask_t llc_shared_map;u16 llc_id; +/* representing HT siblings of each logical CPU */ +cpumask_t sibling_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -31,15 +31,9 @@ static inline bool cpu_has_ht_siblings(void)return has_siblings; } -DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_map);DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);DECLARE_PER_CPU (int, cpu_number); -static inline struct cpumask *cpu_sibling_mask (int cpu) -{ -return per_cpu (cpu_sibling_map, cpu); -} -static inline struct cpumask *cpu_core_mask (int cpu) {return per_cpu (cpu_core_map, cpu);
arch/x86/include/asm/topology.h +1 -1
@@ -161,7 +161,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);#define topology_physical_package_id (cpu) (cpu_data(cpu).phys_proc_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id)#define topology_core_cpumask (cpu) (per_cpu(cpu_core_map, cpu)) -#define topology_thread_cpumask (cpu) (per_cpu(cpu_sibling_map, cpu)) +#define topology_thread_cpumask (cpu) (&cpu_data(cpu).sibling_map)/* indicates that pointers to the topology cpumask_t maps are valid */ #define arch_provides_topology_pointers yes
arch/x86/kernel/cpu/intel_cacheinfo.c +2 -2
@@ -739,11 +739,11 @@ static int __cpuinit cache_shared_amd_cpu_map_setup(unsigned int cpu, int index) } }else if ((c->x86 ==0x15 ) && ((index ==1 ) || (index ==2 ))) { ret =1 ; -for_each_cpu (i,cpu_sibling_mask (cpu)) { +for_each_cpu (i, &c->sibling_map) {if (!per_cpu (ici_cpuid4_info, i))continue ; this_leaf =CPUID4_INFO_IDX (i, index); -for_each_cpu (sibling,cpu_sibling_mask (cpu)) { +for_each_cpu (sibling, &c->sibling_map) {if (!cpu_online (sibling))continue ;set_bit (sibling, this_leaf->shared_cpu_map);
arch/x86/kernel/smpboot.c +11 -16
@@ -116,10 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* representing HT siblings of each logical CPU */ -DEFINE_PER_CPU (cpumask_var_t, cpu_sibling_map); -EXPORT_PER_CPU_SYMBOL (cpu_sibling_map); -/* representing HT and core siblings of each logical CPU */ DEFINE_PER_CPU (cpumask_var_t, cpu_core_map);EXPORT_PER_CPU_SYMBOL (cpu_core_map);
@@ -328,8 +324,8 @@ void __cpuinit smp_store_cpu_info(int id)static void __cpuinit link_thread_siblings (int cpu1,int cpu2) { -cpumask_set_cpu (cpu1,cpu_sibling_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_sibling_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).sibling_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).sibling_map);cpumask_set_cpu (cpu1,cpu_core_mask (cpu2));cpumask_set_cpu (cpu2,cpu_core_mask (cpu1));cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map);
@@ -359,13 +355,13 @@ void __cpuinit set_cpu_sibling_map(int cpu) } } }else { -cpumask_set_cpu (cpu,cpu_sibling_mask (cpu)); +cpumask_set_cpu (cpu, &c->sibling_map); }cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) { -cpumask_copy (cpu_core_mask (cpu),cpu_sibling_mask (cpu)); +cpumask_copy (cpu_core_mask (cpu), &c->sibling_map); c->booted_cores =1 ;return ; }
@@ -383,12 +379,12 @@ void __cpuinit set_cpu_sibling_map(int cpu)/* * Does this new cpu bringup a new core? */ -if (cpumask_weight (cpu_sibling_mask (cpu)) ==1 ) { +if (cpumask_weight (&c->sibling_map) ==1 ) {/* * for each core in package, increment * the booted_cores for this new cpu */ -if (cpumask_first (cpu_sibling_mask (i)) == i) +if (cpumask_first (&o->sibling_map) == i) c->booted_cores++;/* * increment the core count for all
@@ -910,7 +906,7 @@ static __init void disable_smp(void)physid_set_mask_of_physid (boot_cpu_physical_apicid, &phys_cpu_present_map); else physid_set_mask_of_physid(0, &phys_cpu_present_map); -cpumask_set_cpu (0 ,cpu_sibling_mask (0 )); +cpumask_set_cpu (0 , &cpu_data (0 ).sibling_map);cpumask_set_cpu (0 ,cpu_core_mask (0 )); }
@@ -1048,7 +1044,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)current_thread_info ()->cpu =0 ;/* needed? */ for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
@@ -1243,13 +1238,13 @@ static void remove_siblinginfo(int cpu)/*/ * last thread sibling in this cpu core going down */ -if (cpumask_weight (cpu_sibling_mask (cpu)) ==1 ) +if (cpumask_weight (&c->sibling_map) ==1 )cpu_data (sibling).booted_cores--; } -for_each_cpu (sibling,cpu_sibling_mask (cpu)) -cpumask_clear_cpu (cpu,cpu_sibling_mask (sibling)); -cpumask_clear (cpu_sibling_mask (cpu)); +for_each_cpu (sibling, &c->sibling_map) +cpumask_clear_cpu (cpu, &c->sibling_map); +cpumask_clear (&c->sibling_map);cpumask_clear (cpu_core_mask (cpu)); c->phys_proc_id =0 ; c->cpu_core_id =0 ;
arch/x86/oprofile/op_model_p4.c +1 -4
@@ -370,11 +370,8 @@ static struct p4_event_binding p4_events[NUM_EVENTS] = {or "odd" part of all the divided resources. */ static unsigned int get_stagger (void ) { -#ifdef CONFIG_SMP int cpu =smp_processor_id (); -return cpu !=cpumask_first (__get_cpu_var (cpu_sibling_map)); -#endif -return 0 ; +return cpu !=cpumask_first (&cpu_data (cpu).sibling_map); }
arch/x86/xen/smp.c +0 -1
@@ -223,7 +223,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)cpu_data (0 ).x86_max_cores =1 ;for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_sibling_map, i),GFP_KERNEL );zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); }set_cpu_sibling_map (0 );
drivers/cpufreq/p4-clockmod.c +1 -3
@@ -203,9 +203,7 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)int cpuid =0 ;unsigned int i; -#ifdef CONFIG_SMP -cpumask_copy (policy->cpus,cpu_sibling_mask (policy->cpu)); -#endif +cpumask_copy (policy->cpus, &c->sibling_map);/* Errata workaround */ cpuid = (c->x86 <<8 ) | (c->x86_model <<4 ) | c->x86_mask;
drivers/cpufreq/speedstep-ich.c +3 -3
@@ -326,14 +326,14 @@ static void get_freqs_on_cpu(void *_get_freqs)static int speedstep_cpu_init (struct cpufreq_policy *policy) { +struct cpuinfo_x86 *c = &cpu_data (policy->cpu);int result;unsigned int policy_cpu, speed;struct get_freqs gf;/* only run on CPU to be set, or on its sibling */ -#ifdef CONFIG_SMP -cpumask_copy (policy->cpus,cpu_sibling_mask (policy->cpu)); -#endif +cpumask_copy (policy->cpus, c->sibling_map); + policy_cpu =cpumask_any_and (policy->cpus, cpu_online_mask);/* detect low and high frequency and transition latency */
drivers/hwmon/coretemp.c +1 -5
@@ -61,11 +61,7 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");#define TO_CORE_ID (cpu) cpu_data(cpu).cpu_core_id#define TO_ATTR_NO (cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO) -#ifdef CONFIG_SMP -#define for_each_sibling (i, cpu) for_each_cpu(i, cpu_sibling_mask(cpu)) -#else -#define for_each_sibling (i, cpu) for (i = 0; false; ) -#endif +#define for_each_sibling (i, cpu) for_each_cpu(i, &cpu_data(cpu).sibling_map)/* * Per-Core Temperature Data
Signature · 1 line
1.7.9
PATCH v2 4/5 x86: Move per cpu cpu_core_map to a field in struct cpuinfo_x86
In reply to Kevin WinchesterThis simplifies the various code paths using this field as it groups the per-cpu data together.
--- arch/x86/include/asm/processor.h | 5 +++++ arch/x86/include/asm/smp.h | 6 ------ arch/x86/include/asm/topology.h | 4 ++-- arch/x86/kernel/cpu/proc.c | 3 +-- arch/x86/kernel/smpboot.c | 35 ++++++++++++++--------------------- arch/x86/xen/smp.c | 4 ---- drivers/cpufreq/acpi-cpufreq.c | 2 +- drivers/cpufreq/powernow-k8.c | 13 +++---------- 8 files changed, 26 insertions(+), 46 deletions(-)
arch/x86/include/asm/processor.h +5 -0
@@ -115,6 +115,11 @@ struct cpuinfo_x86 {u16 llc_id;/* representing HT siblings of each logical CPU */ cpumask_t sibling_map; +/* +* representing all execution threads on a logical CPU, i.e. per +* physical socket +*/ +cpumask_t core_map; } __attribute__((__aligned__(SMP_CACHE_BYTES)));#define X86_VENDOR_INTEL 0
arch/x86/include/asm/smp.h +0 -6
@@ -31,14 +31,8 @@ static inline bool cpu_has_ht_siblings(void)return has_siblings; } -DECLARE_PER_CPU (cpumask_var_t, cpu_core_map);DECLARE_PER_CPU (int, cpu_number); -static inline struct cpumask *cpu_core_mask (int cpu) -{ -return per_cpu (cpu_core_map, cpu); -} -DECLARE_EARLY_PER_CPU (u16, x86_cpu_to_apicid);DECLARE_EARLY_PER_CPU (u16, x86_bios_cpu_apicid);#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86_32 )
arch/x86/include/asm/topology.h +2 -2
@@ -160,7 +160,7 @@ extern const struct cpumask *cpu_coregroup_mask(int cpu);#ifdef ENABLE_TOPO_DEFINES #define topology_physical_package_id (cpu) (cpu_data(cpu).phys_proc_id)#define topology_core_id (cpu) (cpu_data(cpu).cpu_core_id) -#define topology_core_cpumask (cpu) (per_cpu(cpu_core_map, cpu)) +#define topology_core_cpumask (cpu) (&cpu_data(cpu).core_map)#define topology_thread_cpumask (cpu) (&cpu_data(cpu).sibling_map)/* indicates that pointers to the topology cpumask_t maps are valid */
@@ -176,7 +176,7 @@ void x86_pci_root_bus_resources(int bus, struct list_head *resources);#ifdef CONFIG_SMP #define mc_capable () ((boot_cpu_data.x86_max_cores > 1) && \ - (cpumask_weight(cpu_core_mask(0)) != nr_cpu_ids)) + (cpumask_weight(&boot_cpu_data.core_map) != nr_cpu_ids))#define smt_capable () (smp_num_siblings > 1)#endif
arch/x86/kernel/cpu/proc.c +1 -2
@@ -13,8 +13,7 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,#ifdef CONFIG_SMP if (c->x86_max_cores * smp_num_siblings >1 ) {seq_printf (m,"physical id\t: %d\n" , c->phys_proc_id); -seq_printf (m,"siblings\t: %d\n" , -cpumask_weight (cpu_core_mask (cpu))); +seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (&c->core_map));seq_printf (m,"core id\t\t: %d\n" , c->cpu_core_id);seq_printf (m,"cpu cores\t: %d\n" , c->booted_cores);seq_printf (m,"apicid\t\t: %d\n" , c->apicid);
arch/x86/kernel/smpboot.c +14 -21
@@ -116,10 +116,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;int smp_num_siblings =1 ;EXPORT_SYMBOL (smp_num_siblings); -/* representing HT and core siblings of each logical CPU */ -DEFINE_PER_CPU (cpumask_var_t, cpu_core_map); -EXPORT_PER_CPU_SYMBOL (cpu_core_map); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
@@ -326,8 +322,8 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2) {cpumask_set_cpu (cpu1, &cpu_data (cpu2).sibling_map);cpumask_set_cpu (cpu2, &cpu_data (cpu1).sibling_map); -cpumask_set_cpu (cpu1,cpu_core_mask (cpu2)); -cpumask_set_cpu (cpu2,cpu_core_mask (cpu1)); +cpumask_set_cpu (cpu1, &cpu_data (cpu2).core_map); +cpumask_set_cpu (cpu2, &cpu_data (cpu1).core_map);cpumask_set_cpu (cpu1, &cpu_data (cpu2).llc_shared_map);cpumask_set_cpu (cpu2, &cpu_data (cpu1).llc_shared_map); }
@@ -361,7 +357,7 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu, &c->llc_shared_map);if (__this_cpu_read (cpu_info.x86_max_cores) ==1 ) { -cpumask_copy (cpu_core_mask (cpu), &c->sibling_map); +cpumask_copy (&c->core_map, &c->sibling_map); c->booted_cores =1 ;return ; }
@@ -374,8 +370,8 @@ void __cpuinit set_cpu_sibling_map(int cpu)cpumask_set_cpu (cpu, &o->llc_shared_map); }if (c->phys_proc_id == o->phys_proc_id) { -cpumask_set_cpu (i,cpu_core_mask (cpu)); -cpumask_set_cpu (cpu,cpu_core_mask (i)); +cpumask_set_cpu (i, &c->core_map); +cpumask_set_cpu (cpu, &o->core_map);/* * Does this new cpu bringup a new core? */
@@ -404,11 +400,11 @@ const struct cpumask *cpu_coregroup_mask(int cpu)struct cpuinfo_x86 *c = &cpu_data (cpu);/* * For perf, we return last level cache shared map. -* And for power savings, we return cpu_core_map +* And for power savings, we return core map. */ if ((sched_mc_power_savings || sched_smt_power_savings) && !(cpu_has (c,X86_FEATURE_AMD_DCM ))) -return cpu_core_mask (cpu); +return &c->core_map;else return &c->llc_shared_map; }
@@ -907,7 +903,7 @@ static __init void disable_smp(void)else physid_set_mask_of_physid (0 , &phys_cpu_present_map);cpumask_set_cpu (0 , &cpu_data (0 ).sibling_map); -cpumask_set_cpu (0 ,cpu_core_mask (0 )); +cpumask_set_cpu (0 , &cpu_data (0 ).core_map); }/*
@@ -1030,8 +1026,6 @@ static void __init smp_cpu_index_default(void)*/ void __init native_smp_prepare_cpus (unsigned int max_cpus) { -unsigned int i; -preempt_disable ();smp_cpu_index_default ();
@@ -1043,9 +1037,6 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus)mb ();current_thread_info ()->cpu =0 ;/* needed? */ -for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); - }set_cpu_sibling_map (0 );
@@ -1233,19 +1224,21 @@ static void remove_siblinginfo(int cpu)int sibling;struct cpuinfo_x86 *c = &cpu_data (cpu); -for_each_cpu (sibling,cpu_core_mask (cpu)) { -cpumask_clear_cpu (cpu,cpu_core_mask (sibling)); +for_each_cpu (sibling, &c->core_map) { +struct cpuinfo_x86 *o = &cpu_data (sibling); + +cpumask_clear_cpu (cpu, &o->core_map);/*/ * last thread sibling in this cpu core going down */ if (cpumask_weight (&c->sibling_map) ==1 ) -cpu_data (sibling).booted_cores--; + o->booted_cores--; }for_each_cpu (sibling, &c->sibling_map)cpumask_clear_cpu (cpu, &c->sibling_map);cpumask_clear (&c->sibling_map); -cpumask_clear (cpu_core_mask (cpu)); +cpumask_clear (&c->core_map); c->phys_proc_id =0 ; c->cpu_core_id =0 ;cpumask_clear_cpu (cpu, cpu_sibling_setup_mask);
arch/x86/xen/smp.c +0 -4
@@ -206,7 +206,6 @@ static void __init xen_smp_prepare_boot_cpu(void)static void __init xen_smp_prepare_cpus (unsigned int max_cpus) {unsigned cpu; -unsigned int i;if (skip_ioapic_setup) { char *m = (max_cpus == 0) ?
@@ -222,9 +221,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus)smp_store_cpu_info (0 );cpu_data (0 ).x86_max_cores =1 ; -for_each_possible_cpu (i) { -zalloc_cpumask_var (&per_cpu (cpu_core_map, i),GFP_KERNEL ); - }set_cpu_sibling_map (0 );if (xen_smp_intr_init (0 ))
drivers/cpufreq/acpi-cpufreq.c +1 -1
@@ -557,7 +557,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)dmi_check_system (sw_any_bug_dmi_table);if (bios_with_sw_any_bug &&cpumask_weight (policy->cpus) ==1 ) { policy->shared_type =CPUFREQ_SHARED_TYPE_ALL ; -cpumask_copy (policy->cpus,cpu_core_mask (cpu)); +cpumask_copy (policy->cpus, &c->core_map); }#endif
drivers/cpufreq/powernow-k8.c +3 -10
@@ -66,13 +66,6 @@ static struct msr __percpu *msrs;static struct cpufreq_driver cpufreq_amd64_driver; -#ifndef CONFIG_SMP -static inline const struct cpumask *cpu_core_mask (int cpu) -{ -return cpumask_of (0 ); -} -#endif -/* Return a frequency in MHz, given an input fid */ static u32 find_freq_from_fid (u32 fid) {
@@ -715,7 +708,7 @@ static int fill_powernow_table(struct powernow_k8_data *data,pr_debug ("cfid 0x%x, cvid 0x%x\n" , data->currfid, data->currvid); data->powernow_table = powernow_table; -if (cpumask_first (cpu_core_mask (data->cpu)) == data->cpu) +if (cpumask_first (&cpu_data (data->cpu).core_map) == data->cpu)print_basics (data);for (j =0 ; j < data->numps; j++)
@@ -884,7 +877,7 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) powernow_table[data->acpi_data.state_count].index =0 ; data->powernow_table = powernow_table; -if (cpumask_first (cpu_core_mask (data->cpu)) == data->cpu) +if (cpumask_first (&cpu_data (data->cpu).core_map) == data->cpu)print_basics (data);/* notify BIOS that we exist */
@@ -1326,7 +1319,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)if (cpu_family ==CPU_HW_PSTATE )cpumask_copy (pol->cpus,cpumask_of (pol->cpu));else -cpumask_copy (pol->cpus,cpu_core_mask (pol->cpu)); +cpumask_copy (pol->cpus, &c->core_map); data->available_cores = pol->cpus;if (cpu_family ==CPU_HW_PSTATE )
Signature · 1 line
1.7.9
PATCH v2 5/5 x86: Remove #ifdef CONFIG_SMP sections by moving smp_num_siblings into common.c
In reply to Kevin Winchestersmp_num_siblings was defined in arch/x86/kernel/smpboot.c, making it necessary to wrap any UP relevant code referencing it with #ifdef CONFIG_SMP.
Instead, move the definition to arch/x86/kernel/cpu/common.c, thus making it available always.
--- arch/x86/include/asm/perf_event_p4.h | 14 +++----------- arch/x86/include/asm/smp.h | 6 +----- arch/x86/include/asm/topology.h | 4 +--- arch/x86/kernel/cpu/amd.c | 4 ---- arch/x86/kernel/cpu/common.c | 6 ++++-- arch/x86/kernel/cpu/perf_event_p4.c | 4 ++-- arch/x86/kernel/cpu/proc.c | 5 ++--- arch/x86/kernel/cpu/topology.c | 2 -- arch/x86/kernel/process.c | 3 +-- arch/x86/kernel/smpboot.c | 4 ---- arch/x86/oprofile/nmi_int.c | 6 ------ arch/x86/oprofile/op_model_p4.c | 6 ------ 12 files changed, 14 insertions(+), 50 deletions(-)
arch/x86/include/asm/perf_event_p4.h +3 -11
@@ -8,6 +8,8 @@#include <linux/cpu.h> #include <linux/bitops.h> +#include <asm/smp.h> +/* * NetBurst has performance MSRs shared between * threads if HT is turned on, ie for both logical
@@ -177,20 +179,10 @@ static inline u64 p4_clear_ht_bit(u64 config)return config & ~P4_CONFIG_HT ; } -static inline int p4_ht_active (void ) -{ -#ifdef CONFIG_SMP -return smp_num_siblings >1 ; -#endif -return 0 ; -} -static inline int p4_ht_thread (int cpu) { -#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) - return cpu != cpumask_first(&cpu_data(cpu).sibling_map)); -#endif +return cpu !=cpumask_first (&cpu_data (cpu).sibling_map);return 0 ; }
arch/x86/include/asm/smp.h +1 -5
@@ -24,11 +24,7 @@ extern unsigned int num_processors;static inline bool cpu_has_ht_siblings (void ) { -bool has_siblings = false; -#ifdef CONFIG_SMP - has_siblings = cpu_has_ht && smp_num_siblings >1 ; -#endif -return has_siblings; +return cpu_has_ht && smp_num_siblings >1 ; }DECLARE_PER_CPU (int, cpu_number);
arch/x86/include/asm/topology.h +1 -3
@@ -174,11 +174,9 @@ static inline void arch_fix_phys_package_id(int num, u32 slot)struct pci_bus ;void x86_pci_root_bus_resources (int bus,struct list_head *resources); -#ifdef CONFIG_SMP #define mc_capable () ((boot_cpu_data.x86_max_cores > 1) && \ (cpumask_weight(&boot_cpu_data.core_map) != nr_cpu_ids)) -#define smt_capable () (smp_num_siblings > 1) -#endif +#define smt_capable () (smp_num_siblings > 1)#ifdef CONFIG_NUMA extern int get_mp_bus_to_node (int busnum);
arch/x86/kernel/cpu/amd.c +0 -4
@@ -263,7 +263,6 @@ static int __cpuinit nearby_node(int apicid)* Assumption: Number of cores in each internal node is the same. * (2) AMD processors supporting compute units */ -#ifdef CONFIG_X86_HT static void __cpuinit amd_get_topology (struct cpuinfo_x86 *c) {u32 nodes, cores_per_cu =1 ;
@@ -307,7 +306,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c) c->compute_unit_id %= cus_per_node; } } -#endif /* * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
@@ -315,7 +313,6 @@ static void __cpuinit amd_get_topology(struct cpuinfo_x86 *c)*/ static void __cpuinit amd_detect_cmp (struct cpuinfo_x86 *c) { -#ifdef CONFIG_X86_HT unsigned bits; bits = c->x86_coreid_bits;
@@ -326,7 +323,6 @@ static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)/* use socket ID also for last level cache */ c->llc_id = c->phys_proc_id;amd_get_topology (c); -#endif }int amd_get_nb_id (int cpu)
arch/x86/kernel/cpu/common.c +4 -2
@@ -47,6 +47,10 @@ cpumask_var_t cpu_initialized_mask;cpumask_var_t cpu_callout_mask;cpumask_var_t cpu_callin_mask; +/* Number of siblings per CPU package */ +int smp_num_siblings =1 ; +EXPORT_SYMBOL (smp_num_siblings); +/* representing cpus for which sibling maps can be computed */ cpumask_var_t cpu_sibling_setup_mask;
@@ -452,7 +456,6 @@ void __cpuinit cpu_detect_cache_sizes(struct cpuinfo_x86 *c)void __cpuinit detect_ht (struct cpuinfo_x86 *c) { -#ifdef CONFIG_X86_HT u32 eax, ebx, ecx, edx;int index_msb, core_bits;static bool printed;
@@ -498,7 +501,6 @@ out: c->cpu_core_id); printed =1 ; } -#endif }static void __cpuinit get_cpu_vendor (struct cpuinfo_x86 *c)
arch/x86/kernel/cpu/perf_event_p4.c +2 -2
@@ -775,7 +775,7 @@ static int p4_validate_raw_event(struct perf_event *event)* if an event is shared across the logical threads * the user needs special permissions to be able to use it */ -if (p4_ht_active () && p4_event_bind_map[v].shared) { +if (smt_capable () && p4_event_bind_map[v].shared) {if (perf_paranoid_cpu () && !capable (CAP_SYS_ADMIN ))return -EACCES ; }
@@ -816,7 +816,7 @@ static int p4_hw_config(struct perf_event *event) event->hw.config =p4_config_pack_escr (escr) |p4_config_pack_cccr (cccr); -if (p4_ht_active () &&p4_ht_thread (cpu)) +if (smt_capable () &&p4_ht_thread (cpu)) event->hw.config =p4_set_ht_bit (event->hw.config);if (event->attr.type ==PERF_TYPE_RAW ) {
arch/x86/kernel/cpu/proc.c +2 -3
@@ -1,16 +1,16 @@ -#include <linux/smp.h> #include <linux/timex.h> #include <linux/string.h> #include <linux/seq_file.h> #include <linux/cpufreq.h> +#include <asm/smp.h> +/* * Get CPU information for use by the procfs. */ static void show_cpuinfo_core (struct seq_file *m,struct cpuinfo_x86 *c,unsigned int cpu) { -#ifdef CONFIG_SMP if (c->x86_max_cores * smp_num_siblings >1 ) {seq_printf (m,"physical id\t: %d\n" , c->phys_proc_id);seq_printf (m,"siblings\t: %d\n" ,cpumask_weight (&c->core_map));
@@ -19,7 +19,6 @@ static void show_cpuinfo_core(struct seq_file *m, struct cpuinfo_x86 *c,seq_printf (m,"apicid\t\t: %d\n" , c->apicid);seq_printf (m,"initial apicid\t: %d\n" , c->initial_apicid); } -#endif }#ifdef CONFIG_X86_32
arch/x86/kernel/cpu/topology.c +0 -2
@@ -28,7 +28,6 @@*/ void __cpuinit detect_extended_topology (struct cpuinfo_x86 *c) { -#ifdef CONFIG_SMP unsigned int eax, ebx, ecx, edx, sub_index;unsigned int ht_mask_width, core_plus_mask_width;unsigned int core_select_mask, core_level_siblings;
@@ -95,5 +94,4 @@ void __cpuinit detect_extended_topology(struct cpuinfo_x86 *c) printed =1 ; }return ; -#endif }
arch/x86/kernel/process.c +1 -2
@@ -586,12 +586,11 @@ static void amd_e400_idle(void)void __cpuinit select_idle_routine (const struct cpuinfo_x86 *c) { -#ifdef CONFIG_SMP if (pm_idle == poll_idle && smp_num_siblings >1 ) {printk_once (KERN_WARNING "WARNING: polling idle and HT enabled," " performance may degrade.\n" ); } -#endif +if (pm_idle)return ;
arch/x86/kernel/smpboot.c +0 -4
@@ -112,10 +112,6 @@ static struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;#define set_idle_for_cpu (x, p) (idle_thread_array[(x)] = (p))#endif -/* Number of siblings per CPU package */ -int smp_num_siblings =1 ; -EXPORT_SYMBOL (smp_num_siblings); -/* Per CPU bogomips and other parameters */ DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info);EXPORT_PER_CPU_SYMBOL (cpu_info);
arch/x86/oprofile/nmi_int.c +0 -6
@@ -572,11 +572,6 @@ static int __init p4_init(char **cpu_type)if (cpu_model >6 || cpu_model ==5 )return 0 ; -#ifndef CONFIG_SMP - *cpu_type ="i386/p4" ; - model = &op_p4_spec; -return 1 ; -#else switch (smp_num_siblings) {case 1 : *cpu_type ="i386/p4" ;
@@ -588,7 +583,6 @@ static int __init p4_init(char **cpu_type) model = &op_p4_ht2_spec;return 1 ; } -#endif printk (KERN_INFO "oprofile: P4 HyperThreading detected with > 2 threads\n" );printk (KERN_INFO "oprofile: Reverting to timer mode.\n" );
arch/x86/oprofile/op_model_p4.c +0 -6
@@ -42,21 +42,15 @@ static unsigned int num_controls = NUM_CONTROLS_NON_HT;kernel boot-time. */ static inline void setup_num_counters (void ) { -#ifdef CONFIG_SMP if (smp_num_siblings ==2 ) { num_counters =NUM_COUNTERS_HT2 ; num_controls =NUM_CONTROLS_HT2 ; } -#endif }static inline int addr_increment (void ) { -#ifdef CONFIG_SMP return smp_num_siblings ==2 ?2 :1 ; -#else -return 1 ; -#endif }
Signature · 1 line
1.7.9
Borislav Petkov
maintainerRe: [PATCH] x86: Move per cpu cpu_llc_shared_map to a field in struct cpuinfo_x86
In reply to Kevin WinchesterQuoted 5 lines · Kevin Winchester
Quoted 5 lines
arch/x86/kernel/smpboot.c +0
-1@@ -225,7 +225,6 @@ static void __init xen_smp_prepare_cpus(unsigned int max_cpus) for_each_possible_cpu(i) { zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); - zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
Quoted 8 lines
arch/x86/kernel/smpboot.c void __init native_smp_prepare_cpus(unsigned int max_cpus) · line 1056
Quoted 3 lines
arch/x86/kernel/smpboot.c +0
-0} set_cpu_sibling_map(0);I just realized that I took out a couple of allocations here for
cpu_llc_shared_map, without replacing them. Am I leaving cpuinfo_x86.llc_shared_map unallocated then, and just writing to whatever address that field happened to get?
AFAICT, yes, you need to alloc the cpumask too, i.e. something like
zalloc_cpumask_var(cpu_info(i).llc_shared_map, GFP_KERNEL);
assuming this happens before the cpumask gets initted in set_cpu_sibling_map() et al. Just give the whole init path a hard staring, and try to figure out the proper init sequence.
HTH.
P.S.: I'm currently travelling but will give your patch a run when I get back, thanks.
Signature · 2 lines
Regards/Gruss, Boris.
Re: MCE, AMD: Hide smp-only code around CONFIG_SMP
In reply to Ingo MolnarQuoted 37 lines · Ingo Molnar
Quoted 34 lines · Kevin Winchester
Quoted 20 lines · Ingo Molnar
Quoted 4 lines · Borislav Petkov
+++
b/arch/x86/include/asm/smp.harch/x86/include/asm/smp.h +0
-0@@ -33,8 +33,15 @@ static inline bool cpu_has_ht_siblings(void) DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_map);arch/x86/include/asm/smp.h static inline bool cpu_has_ht_siblings(void) · line 43
Quoted 10 lines
arch/x86/include/asm/smp.h +7
-1DECLARE_PER_CPU(cpumask_var_t, cpu_core_map); -/* cpus sharing the last level cache: */ + +#ifdef CONFIG_SMP +/* CPUs sharing the last level cache: */ DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map); +#else +static DECLARE_BITMAP(cpu_llc_shared_bits, NR_CPUS) __read_mostly = { [0] = 1UL }; +static struct cpumask *const cpu_llc_shared_map =to_cpumask (cpu_llc_shared_bits); +#endif Why not just expose it like on SMP?
Quoted 6 lines
We want to *reduce* the specialness of UP, not increase it - one more word of .data and .text does not matter much - UP is becoming more and more an oddball, rarely tested config. By the time these changes hit any real boxes it will be even more oddball.
It seems that
cpu_llc_shared_mapis actually defined inarch/x86/kernel/smpboot.c, which is not compiled/linked for UP builds.
Is there an equivalent file for UP that could be used instead, or could the:
Quoted 8 lines
Quoted 3 lines
DEFINE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);be moved to some other file?
Yes, it should be moved into struct
cpuinfo_x86, and thus we'd removecpu_llc_shared_mapaltogether, it would be namedcpu->llc_shared_mapor so - taking up a single bit (or maybe zero bits) on UP.
I just sent out a patch trying this out. I built and booted it on SMP and UP and didn't see any issues, but I don't have more than my one PC on which to test, so I hope I didn't miss anything. I did notice a few other per cpu variables (e.g. cpu_llc_id) that perhaps could perhaps use the same treatment. Where would we want to draw the line here?
Quoted 10 lines
Quoted 5 lines
Generally, it sounds like you might approve of an eventual merging of the boot paths for SMP and UP. Is that true? I wonder how much work that would be. That would really reduce the specialness of UP.
I generally approve just about any patch that works and reduces complexity! :-) The boot path is rather ambitious, but if you want to try, feel free ...
Yes, having walked through the boot path a little, it does seem rather ambitious. The UP/SMP division seems to be coded right into init/main.c, rather than being at the architecture level, so it would be hard to make changes without disrupting other arches.
Signature · 1 line
Kevin Winchester
tip-bot for Borislav Petkov
maintainer[tip:x86/urgent] x86/mce/AMD: Fix UP build error
In reply to Borislav PetkovCommit-ID: 3f806e50981825fa56a7f1938f24c0680816be45 Gitweb: http://git.kernel.org/tip/3f806e50981825fa56a7f1938f24c0680816be45 Author: Borislav Petkov <[email protected]> AuthorDate: Fri, 3 Feb 2012 20:18:01 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 22 Feb 2012 13:36:30 +0100
x86/mce/AMD: Fix UP build error
141168c36cde ("x86: Simplify code by removing a !SMP #ifdefs from 'struct cpuinfo_x86'") removed a bunch of CONFIG_SMP ifdefs around code touching struct cpuinfo_x86 members but also caused the following build error with Randy's randconfigs:
mce_amd.c:(.cpuinit.text+0x4723): undefined reference to `cpu_llc_shared_map'
Restore the #ifdef in threshold_create_bank() which creates symlinks on the non-BSP CPUs.
There's a better patch series being worked on by Kevin Winchester which will solve this in a cleaner fashion, but that series is too ambitious for v3.3 merging - so we first queue up this trivial fix and then do the rest for v3.4.
--- arch/x86/kernel/cpu/mcheck/mce_amd.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kernel/cpu/mcheck/mce_amd.c +2 -0
@@ -528,6 +528,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)sprintf (name,"threshold_bank%i" , bank); +#ifdef CONFIG_SMP if (cpu_data (cpu).cpu_core_id && shared_bank[bank]) {/* symlink */ i =cpumask_first (cpu_llc_shared_mask (cpu));
@@ -553,6 +554,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank) goto out; } +#endif b =kzalloc (sizeof (struct threshold_bank ),GFP_KERNEL );if (!b) {