x86, xsave: some code cleanups and reworks
Subsystems (4)
cover x86, xsave: some code cleanups and reworks
This patch series contains some cleanups and reworks I made during code review and feature implementation for upcoming cpus.
Most patches refactor the xsave initialization that is very dependent on fpu initialization. This series starts to decouple this a little bit as xsave not only supports fpu features. Also this is an attempt to ease the xsave interface by making some of the functions and variables static.
There is also one patch that removes boot_cpu_id variable, which is not really related to xsave. Maybe this should be applied to another branch.
The patches are relative to today's tip/x86/xsave branch.
(The patches are small for better review and rebasing.)
-Robert
PATCH 1/10 x86, xsave: do not include asm/i387.h in asm/xsave.h
There are no dependencies to asm/i387.h. Instead, if including only xsave.h the following error occurs:
.../arch/x86/include/asm/i387.h:110: error: ‘XSTATE_FP’ undeclared (first use in this function) .../arch/x86/include/asm/i387.h:110: error: (Each undeclared identifier is reported only once .../arch/x86/include/asm/i387.h:110: error: for each function it appears in.)
This patch fixes this.
--- arch/x86/include/asm/xsave.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
arch/x86/include/asm/xsave.h +0 -1
@@ -3,7 +3,6 @@#include <linux/types.h> #include <asm/processor.h> -#include <asm/i387.h> #define XSTATE_FP 0x1#define XSTATE_SSE 0x2
Signature · 1 line
1.7.1.1
Re: [PATCH 01/10] x86, xsave: do not include asm/i387.h in asm/xsave.h
Quoted 19 lines · Robert Richter
There are no dependencies to
asm/i387.h. Instead, if including onlyxsave.hthe following error occurs:
.../arch/x86/include/asm/i387.h:110: error: ‘XSTATE_FP’ undeclared (first use in this function).../arch/x86/include/asm/i387.h:110: error: (Each undeclared identifier is reported only once.../arch/x86/include/asm/i387.h:110: error: for each function it appears in.)This patch fixes this.
Signed-off-by Robert Richter <[email protected]>--- arch/x86/include/asm/xsave.h | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)arch/x86/include/asm/xsave.h +0
-0
arch/x86/include/asm/xsave.h line 8
Quoted 7 lines
arch/x86/include/asm/xsave.h +0
-1@@ -3,7 +3,6 @@#include <linux/types.h> #include <asm/processor.h> -#include <asm/i387.h> #define XSTATE_FP 0x1#define XSTATE_SSE 0x2
PATCH 2/10 x86, xsave: 32/64 bit boot cpu check unification in initialization
In reply to Robert RichterBoot cpu id is always 0, thus simplifying and unifying boot cpu check.
boot_cpu_id is there for historical reasons and was renamed to boot_cpu_physical_apicid in patch:
c70dcb7 x86: change boot_cpu_id to boot_cpu_physical_apicid
However, there are some remaining occurrences of boot_cpu_id that are never touched in the kernel and thus its value is always 0.
--- arch/x86/kernel/cpu/common.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/common.c +1 -1
@@ -1273,7 +1273,7 @@ void __cpuinit cpu_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (smp_processor_id () == boot_cpu_id) +if (!smp_processor_id ())init_thread_xstate ();xsave_init ();
Signature · 1 line
1.7.1.1
Re: [PATCH 02/10] x86, xsave: 32/64 bit boot cpu check unification in initialization
Quoted 20 lines · Robert Richter
Boot cpu id is always 0, thus simplifying and unifying boot cpu check.
boot_cpu_idis there for historical reasons and was renamed toboot_cpu_physical_apicidin patch:c70dcb7 x86: change
boot_cpu_idtoboot_cpu_physical_apicidHowever, there are some remaining occurrences of
boot_cpu_idthat are never touched in the kernel and thus its value is always 0.Signed-off-by Robert Richter <[email protected]>--- arch/x86/kernel/cpu/common.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)arch/x86/kernel/cpu/common.c +0
-0
arch/x86/kernel/cpu/common.c void __cpuinit cpu_init(void) · line 1279
Quoted 8 lines
arch/x86/kernel/cpu/common.c +1
-1@@ -1273,7 +1273,7 @@ void __cpuinit cpu_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (smp_processor_id () == boot_cpu_id) +if (!smp_processor_id ())init_thread_xstate ();xsave_init ();
[tip:x86/xsave] x86, xsave: 32/64 bit boot cpu check unification in initialization
In reply to Robert RichterCommit-ID: db10db48b2c530def21bfd76d576702c7df7f620 Gitweb: http://git.kernel.org/tip/db10db48b2c530def21bfd76d576702c7df7f620 Author: Robert Richter <[email protected]> AuthorDate: Tue, 20 Jul 2010 20:50:49 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 20 Jul 2010 16:21:38 -0700
x86, xsave: 32/64 bit boot cpu check unification in initialization
Boot cpu id is always 0, thus simplifying and unifying boot cpu check.
boot_cpu_id is there for historical reasons and was renamed to boot_cpu_physical_apicid in patch:
c70dcb7 x86: change boot_cpu_id to boot_cpu_physical_apicid
However, there are some remaining occurrences of boot_cpu_id that are never touched in the kernel and thus its value is always 0.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/cpu/common.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/cpu/common.c +1 -1
@@ -1273,7 +1273,7 @@ void __cpuinit cpu_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (smp_processor_id () == boot_cpu_id) +if (!smp_processor_id ())init_thread_xstate ();xsave_init ();
PATCH 3/10 x86: removing boot_cpu_id variable
In reply to Robert Richterboot_cpu_id is there for historical reasons and was renamed to boot_cpu_physical_apicid in patch:
c70dcb7 x86: change boot_cpu_id to boot_cpu_physical_apicid
However, there are some remaining occurrences of boot_cpu_id that are never touched in the kernel and thus its value is always 0.
This patch removes boot_cpu_id at all.
--- arch/x86/include/asm/apb_timer.h | 1 - arch/x86/include/asm/cpu.h | 1 - arch/x86/kernel/apb_timer.c | 2 +- arch/x86/kernel/apic/io_apic.c | 12 ++++++------ arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/intel.c | 2 +- arch/x86/kernel/reboot.c | 2 +- arch/x86/kernel/setup.c | 1 - arch/x86/kernel/setup_percpu.c | 4 ++-- arch/x86/mm/k8topology_64.c | 6 +++--- 11 files changed, 16 insertions(+), 19 deletions(-)
arch/x86/include/asm/apb_timer.h +0 -1
@@ -54,7 +54,6 @@ extern struct clock_event_device *global_clock_event;extern unsigned long apbt_quick_calibrate (void );extern int arch_setup_apbt_irqs (int irq,int trigger,int mask,int cpu);extern void apbt_setup_secondary_clock (void ); -extern unsigned int boot_cpu_id;extern int disable_apbt_percpu;extern struct sfi_timer_table_entry *sfi_get_mtmr (int hint);
arch/x86/include/asm/cpu.h +0 -1
@@ -32,6 +32,5 @@ extern void arch_unregister_cpu(int);DECLARE_PER_CPU (int, cpu_state); -extern unsigned int boot_cpu_id;#endif /* _ASM_X86_CPU_H */
arch/x86/kernel/apb_timer.c +1 -1
@@ -367,7 +367,7 @@ void apbt_setup_secondary_clock(void)/* Don't register boot CPU clockevent */ cpu =smp_processor_id (); -if (cpu == boot_cpu_id) +if (!cpu)return ;/* * We need to calculate the scaled math multiplication factor for
arch/x86/kernel/apic/io_apic.c +6 -6
@@ -162,7 +162,7 @@ int __init arch_early_irq_init(void) cfg = irq_cfgx; count =ARRAY_SIZE (irq_cfgx); - node=cpu_to_node (boot_cpu_id); + node =cpu_to_node (0 );for (i =0 ; i < count; i++) { desc =irq_to_desc (i);
@@ -1483,7 +1483,7 @@ static void __init setup_IO_APIC_irqs(void)int notcon =0 ;struct irq_desc *desc;struct irq_cfg *cfg; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );apic_printk (APIC_VERBOSE ,KERN_DEBUG "init IO_APIC IRQs\n" );
@@ -1548,7 +1548,7 @@ static void __init setup_IO_APIC_irqs(void)void setup_IO_APIC_irq_extra (u32 gsi) {int apic_id =0 , pin, idx, irq; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );struct irq_desc *desc;struct irq_cfg *cfg;
@@ -2925,7 +2925,7 @@ static inline void __init check_timer(void) {struct irq_desc *desc =irq_to_desc (0 );struct irq_cfg *cfg = desc->chip_data; -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );int apic1, pin1, apic2, pin2;unsigned long flags;int no_pin1 =0 ;
@@ -3279,7 +3279,7 @@ unsigned int create_irq_nr(unsigned int irq_want, int node)int create_irq (void ) { -int node =cpu_to_node (boot_cpu_id); +int node =cpu_to_node (0 );unsigned int irq_want;int irq;
@@ -3901,7 +3901,7 @@ static int __io_apic_set_pci_routing(struct device *dev, int irq,if (dev) node =dev_to_node (dev);else - node =cpu_to_node (boot_cpu_id); + node =cpu_to_node (0 ); desc =irq_to_desc_alloc_node (irq, node);if (!desc) {
arch/x86/kernel/cpu/amd.c +1 -1
@@ -148,7 +148,7 @@ static void __cpuinit amd_k7_smp_check(struct cpuinfo_x86 *c) {#ifdef CONFIG_SMP /* calling is from identify_secondary_cpu() ? */ -if (c->cpu_index == boot_cpu_id) +if (!c->cpu_index)return ;/*
arch/x86/kernel/cpu/common.c +1 -1
@@ -664,7 +664,7 @@ static void __init early_identify_cpu(struct cpuinfo_x86 *c) this_cpu->c_early_init (c);#ifdef CONFIG_SMP - c->cpu_index = boot_cpu_id; + c->cpu_index =0 ;#endif filter_cpuid_features (c, false); }
arch/x86/kernel/cpu/intel.c +1 -1
@@ -169,7 +169,7 @@ static void __cpuinit intel_smp_check(struct cpuinfo_x86 *c) {#ifdef CONFIG_SMP /* calling is from identify_secondary_cpu() ? */ -if (c->cpu_index == boot_cpu_id) +if (!c->cpu_index)return ;/*
arch/x86/kernel/reboot.c +1 -1
@@ -84,7 +84,7 @@ static int __init reboot_setup(char *str) }/* we will leave sorting out the final value when we are ready to reboot, since we might not -have set up boot_cpu_id or smp_num_cpu */ +have detected BSP APIC ID or smp_num_cpu */ break ;#endif /* CONFIG_SMP */
arch/x86/kernel/setup.c +0 -1
@@ -124,7 +124,6 @@ unsigned long max_pfn_mapped;RESERVE_BRK (dmi_alloc,65536 );#endif -unsigned int boot_cpu_id__read_mostly ;static __initdata unsigned long _brk_start = (unsigned long )__brk_base;unsigned long _brk_end = (unsigned long )__brk_base;
arch/x86/kernel/setup_percpu.c +2 -2
@@ -244,7 +244,7 @@ void __init setup_per_cpu_areas(void)* Up to this point, the boot CPU has been using .init.data * area. Reload any changed state for the boot CPU. */ -if (cpu == boot_cpu_id) +if (!cpu)switch_to_new_gdt (cpu); }
@@ -262,7 +262,7 @@ void __init setup_per_cpu_areas(void)* make sure boot cpu numa_node is right, when boot cpu is on the * node that doesn't have mem installed */ -set_cpu_numa_node (boot_cpu_id,early_cpu_to_node (boot_cpu_id)); +set_cpu_numa_node (0 ,early_cpu_to_node (0 ));#endif /* Setup node to cpumask map */
arch/x86/mm/k8topology_64.c +3 -3
@@ -54,8 +54,8 @@ static __init int find_northbridge(void)static __init void early_get_boot_cpu_id (void ) {/* -* need to get boot_cpu_id so can use that to create apicid_to_node -* in k8_scan_nodes() +* need to get the APIC ID of the BSP so can use that to +* create apicid_to_node in k8_scan_nodes() */ #ifdef CONFIG_X86_MPPARSE /*
@@ -212,7 +212,7 @@ int __init k8_scan_nodes(void) bits = boot_cpu_data.x86_coreid_bits; cores = (1 <<bits); apicid_base =0 ; -/* need to get boot_cpu_id early for system with apicid lifting */ +/* get the APIC ID of the BSP early for systems with apicid lifting */ early_get_boot_cpu_id ();if (boot_cpu_physical_apicid >0 ) {pr_info ("BSP APIC ID: %02x\n" , boot_cpu_physical_apicid);
Signature · 1 line
1.7.1.1
PATCH 4/10 x86, xsave: moving boot cpu initialization to xsave_init()
In reply to Robert RichterThis patch moves boot cpu initialization to xsave_init(). Now all cpus are initialized in one single function.
--- arch/x86/kernel/cpu/common.c | 6 ------ arch/x86/kernel/i387.c | 5 ----- arch/x86/kernel/xsave.c | 14 ++++++++++++-- 3 files changed, 12 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/common.c +0 -6
@@ -1270,12 +1270,6 @@ void __cpuinit cpu_init(void)clear_used_math ();mxcsr_feature_mask_init (); -/* -* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -init_thread_xstate (); - xsave_init(); }#endif
arch/x86/kernel/i387.c +0 -5
@@ -93,11 +93,6 @@ void __cpuinit fpu_init(void)write_cr0 (oldcr0 & ~(X86_CR0_TS |X86_CR0_EM ));/* clear TS and EM */ -/* -* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -init_thread_xstate ();xsave_init ();mxcsr_feature_mask_init ();
arch/x86/kernel/xsave.c +12 -2
@@ -360,7 +360,7 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -void __cpuinit xsave_init (void ) +static void __cpuinit __xsave_init (void ) {if (!cpu_has_xsave)return ;
@@ -446,7 +446,7 @@ void __ref xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -xsave_init (); +__xsave_init ();/* * Recompute the context size for enabled features
@@ -463,3 +463,13 @@ void __ref xsave_cntxt_init(void)"cntxt size 0x%x\n" , pcntxt_mask, xstate_size); } + +void __cpuinit xsave_init (void ) +{ +/* +* Boot processor to setup the FP and extended state context info. +*/ +if (!smp_processor_id ()) +init_thread_xstate (); +__xsave_init (); +}
Signature · 1 line
1.7.1.1
Re: [PATCH 04/10] x86, xsave: moving boot cpu initialization to xsave_init()
Quoted 9 lines · Robert Richter
This patch moves boot cpu initialization to
xsave_init(). Now all cpus are initialized in one single function.Signed-off-by Robert Richter <[email protected]>--- arch/x86/kernel/cpu/common.c | 6 ------ arch/x86/kernel/i387.c | 5 ----- arch/x86/kernel/xsave.c | 14 ++++++++++++-- 3 files changed, 12 insertions(+), 13 deletions(-)
Quoted 70 lines
arch/x86/kernel/cpu/common.c +0
-6@@ -1270,12 +1270,6 @@ void __cpuinit cpu_init(void)clear_used_math ();mxcsr_feature_mask_init (); -/* -* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -init_thread_xstate (); - xsave_init(); }#endif arch/x86/kernel/i387.c +0
-5@@ -93,11 +93,6 @@ void __cpuinit fpu_init(void)write_cr0 (oldcr0 & ~(X86_CR0_TS |X86_CR0_EM ));/* clear TS and EM */ -/* -* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -init_thread_xstate ();xsave_init ();mxcsr_feature_mask_init ();arch/x86/kernel/xsave.c +12
-2@@ -360,7 +360,7 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -void __cpuinit xsave_init (void ) +static void __cpuinit __xsave_init (void ) {if (!cpu_has_xsave)return ;@@ -446,7 +446,7 @@ void __ref xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -xsave_init (); +__xsave_init ();/* * Recompute the context size for enabled features @@ -463,3 +463,13 @@ void __ref xsave_cntxt_init(void)"cntxt size 0x%x\n" , pcntxt_mask, xstate_size); } + +void __cpuinit xsave_init (void ) +{ +/* +* Boot processor to setup the FP and extended state context info. +*/ +if (!smp_processor_id ()) +init_thread_xstate (); +__xsave_init (); +}
[tip:x86/xsave] x86, xsave: Move boot cpu initialization to xsave_init()
In reply to Robert RichterCommit-ID: 82d4150cec83b9775f84810b39a1c0b91585d429 Gitweb: http://git.kernel.org/tip/82d4150cec83b9775f84810b39a1c0b91585d429 Author: Robert Richter <[email protected]> AuthorDate: Tue, 20 Jul 2010 20:50:51 +0200 Committer: H. Peter Anvin <[email protected]> CommitDate: Tue, 20 Jul 2010 16:21:44 -0700
x86, xsave: Move boot cpu initialization to xsave_init()
This patch moves boot cpu initialization to xsave_init(). Now all cpus are initialized in one single function.
LKML-Reference: <[email protected]>
--- arch/x86/kernel/cpu/common.c | 6 ------ arch/x86/kernel/i387.c | 5 ----- arch/x86/kernel/xsave.c | 14 ++++++++++++-- 3 files changed, 12 insertions(+), 13 deletions(-)
arch/x86/kernel/cpu/common.c +0 -6
@@ -1270,12 +1270,6 @@ void __cpuinit cpu_init(void)clear_used_math ();mxcsr_feature_mask_init (); -/* -* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -init_thread_xstate (); - xsave_init(); }#endif
arch/x86/kernel/i387.c +0 -5
@@ -93,11 +93,6 @@ void __cpuinit fpu_init(void)write_cr0 (oldcr0 & ~(X86_CR0_TS |X86_CR0_EM ));/* clear TS and EM */ -/* -* Boot processor to setup the FP and extended state context info. -*/ -if (!smp_processor_id ()) -init_thread_xstate ();xsave_init ();mxcsr_feature_mask_init ();
arch/x86/kernel/xsave.c +12 -2
@@ -360,7 +360,7 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -void __cpuinit xsave_init (void ) +static void __cpuinit __xsave_init (void ) {if (!cpu_has_xsave)return ;
@@ -446,7 +446,7 @@ void __ref xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -xsave_init (); +__xsave_init ();/* * Recompute the context size for enabled features
@@ -463,3 +463,13 @@ void __ref xsave_cntxt_init(void)"cntxt size 0x%x\n" , pcntxt_mask, xstate_size); } + +void __cpuinit xsave_init (void ) +{ +/* +* Boot processor to setup the FP and extended state context info. +*/ +if (!smp_processor_id ()) +init_thread_xstate (); +__xsave_init (); +}
PATCH 5/10 x86, xsave: make xsave_cntxt_init() static
In reply to Robert RichterThere is a lot of cross referencing between fpu and xsave code. This patch reduces this by making xsave_cntxt_init() a static function.
--- arch/x86/include/asm/xsave.h | 1 - arch/x86/kernel/i387.c | 5 ++--- arch/x86/kernel/xsave.c | 9 +++++++-- 3 files changed, 9 insertions(+), 6 deletions(-)
arch/x86/include/asm/xsave.h +0 -1
@@ -28,7 +28,6 @@ extern u64 pcntxt_mask;extern struct xsave_struct *init_xstate_buf;extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS ]; -extern void xsave_cntxt_init (void );extern void xsave_init (void );extern void update_regset_xstate_info (unsigned int size,u64 xstate_mask);extern int init_fpu (struct task_struct *child);
arch/x86/kernel/i387.c +2 -3
@@ -66,10 +66,9 @@ void __cpuinit init_thread_xstate(void)return ; } -if (cpu_has_xsave) { -xsave_cntxt_init (); +if (cpu_has_xsave) +/* xstate_size was already initialized */ return ; - }if (cpu_has_fxsr) xstate_size =sizeof (struct i387_fxsave_struct );
arch/x86/kernel/xsave.c +7 -2
@@ -429,10 +429,13 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -void __ref xsave_cntxt_init (void ) +static void __cpuinit xsave_cntxt_init (void ) {unsigned int eax, ebx, ecx, edx; +if (!cpu_has_xsave) +return ; +cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); pcntxt_mask = eax + ((u64 )edx <<32 );
@@ -469,7 +472,9 @@ void __cpuinit xsave_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (!smp_processor_id ()) +if (!smp_processor_id ()) { +xsave_cntxt_init ();init_thread_xstate (); + }__xsave_init (); }
Signature · 1 line
1.7.1.1
Re: [PATCH 05/10] x86, xsave: make xsave_cntxt_init() static
Quoted 9 lines · Robert Richter
There is a lot of cross referencing between fpu and xsave code. This patch reduces this by making
xsave_cntxt_init()a static function.Signed-off-by Robert Richter <[email protected]>--- arch/x86/include/asm/xsave.h | 1 - arch/x86/kernel/i387.c | 5 ++--- arch/x86/kernel/xsave.c | 9 +++++++-- 3 files changed, 9 insertions(+), 6 deletions(-)
Perhaps we can fold this patch into
[PATCH 06/10] x86, xsave: do not initialize xsave in fpu_init()
and probably do fpu_init() first followed by xsave_init() so that fpu_init() will set xstate_size based on fpu features and xsave_init() can later overwrite xstate_size based on xstate features.
thanks.
Quoted 60 lines
arch/x86/include/asm/xsave.h +0
-1@@ -28,7 +28,6 @@ extern u64 pcntxt_mask;extern struct xsave_struct *init_xstate_buf;extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS ]; -extern void xsave_cntxt_init (void );extern void xsave_init (void );extern void update_regset_xstate_info (unsigned int size,u64 xstate_mask);extern int init_fpu (struct task_struct *child);arch/x86/kernel/i387.c +2
-3@@ -66,10 +66,9 @@ void __cpuinit init_thread_xstate(void)return ; } -if (cpu_has_xsave) { -xsave_cntxt_init (); +if (cpu_has_xsave) +/* xstate_size was already initialized */ return ; - }if (cpu_has_fxsr) xstate_size =sizeof (struct i387_fxsave_struct );arch/x86/kernel/xsave.c +7
-2@@ -429,10 +429,13 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -void __ref xsave_cntxt_init (void ) +static void __cpuinit xsave_cntxt_init (void ) {unsigned int eax, ebx, ecx, edx; +if (!cpu_has_xsave) +return ; +cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); pcntxt_mask = eax + ((u64 )edx <<32 );@@ -469,7 +472,9 @@ void __cpuinit xsave_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (!smp_processor_id ()) +if (!smp_processor_id ()) { +xsave_cntxt_init ();init_thread_xstate (); + }__xsave_init (); }
Re: [PATCH 05/10] x86, xsave: make xsave_cntxt_init() static
Quoted 6 lines · Suresh Siddha
Perhaps we can fold this patch into
[PATCH 06/10] x86, xsave: do not initialize xsave infpu_init()and probably do
fpu_init()first followed byxsave_init()so thatfpu_init()will setxstate_sizebased on fpu features andxsave_init()can later overwritexstate_sizebased on xstate features.
Yes, I will do this instead.
Lookin at this, I found that xsave is broken for (!HAVE_HWFP). This should be the case if config MATH_EMULATION and 'no387' kernel parameter are set and xsave exists. xsave will not work because x86/math-emu and xsave share the same memory. But this case can be treated as corner case. Maybe we should simply disable xsave then.
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
H. Peter Anvin
reviewerRe: [PATCH 05/10] x86, xsave: make xsave_cntxt_init() static
Quoted 9 lines · Robert Richter
Quoted 6 lines · Suresh Siddha
Perhaps we can fold this patch into
[PATCH 06/10] x86, xsave: do not initialize xsave infpu_init()and probably do
fpu_init()first followed byxsave_init()so thatfpu_init()will setxstate_sizebased on fpu features andxsave_init()can later overwritexstate_sizebased on xstate features.
Quoted 8 lines
Yes, I will do this instead.
Lookin at this, I found that xsave is broken for (!HAVE_HWFP). This should be the case if config
MATH_EMULATIONand 'no387' kernel parameter are set and xsave exists. xsave will not work because x86/math-emu and xsave share the same memory. But this case can be treated as corner case. Maybe we should simply disable xsave then.
Yes, I think we should. It is *extremely* unlikely that any such real hardware will ever be created at this point, and if so we can burn that bridge when we get to it.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
PATCH 6/10 x86, xsave: do not initialize xsave in fpu_init()
In reply to Robert RichterAs xsave also supports other than fpu features, it should be initialized independently of the fpu. This patch moves this out of fpu initialization.
--- arch/x86/include/asm/i387.h | 1 - arch/x86/kernel/cpu/common.c | 2 ++ arch/x86/kernel/i387.c | 17 ++++++++++++++--- arch/x86/kernel/xsave.c | 4 +--- 4 files changed, 17 insertions(+), 7 deletions(-)
arch/x86/include/asm/i387.h +0 -1
@@ -31,7 +31,6 @@ extern void mxcsr_feature_mask_init(void);extern int init_fpu (struct task_struct *child); extern asmlinkage void math_state_restore(void);extern void __math_state_restore (void ); -extern void init_thread_xstate (void );extern int dump_fpu (struct pt_regs *,struct user_i387_struct *);extern user_regset_active_fn fpregs_active, xfpregs_active;
arch/x86/kernel/cpu/common.c +2 -0
@@ -1209,6 +1209,7 @@ void __cpuinit cpu_init(void)clear_all_debug_regs ();dbg_restore_debug_regs (); +xsave_init ();fpu_init ();raw_local_save_flags (kernel_eflags);
@@ -1271,5 +1272,6 @@ void __cpuinit cpu_init(void)mxcsr_feature_mask_init ();xsave_init (); + fpu_init(); }#endif
arch/x86/kernel/i387.c +14 -3
@@ -59,7 +59,7 @@ void __cpuinit mxcsr_feature_mask_init(void)stts (); } -void __cpuinit init_thread_xstate (void ) +static void __cpuinit init_thread_xstate (void ) {if (!HAVE_HWFP ) { xstate_size =sizeof (struct i387_soft_struct );
@@ -83,6 +83,7 @@ void __cpuinit init_thread_xstate(void)* Called at bootup to set up the initial FPU state that is later cloned * into all processes. */ +void __cpuinit fpu_init (void ) {unsigned long oldcr0 =read_cr0 ();
@@ -92,14 +93,24 @@ void __cpuinit fpu_init(void)write_cr0 (oldcr0 & ~(X86_CR0_TS |X86_CR0_EM ));/* clear TS and EM */ -xsave_init (); +if (!smp_processor_id ()) +init_thread_xstate ();mxcsr_feature_mask_init ();/* clean state in init */ current_thread_info ()->status =0 ; clear_used_math(); } -#endif /* CONFIG_X86_64 */ + +#else /* CONFIG_X86_64 */ + +void __cpuinit fpu_init (void ) +{ +if (!smp_processor_id ()) +init_thread_xstate (); +} + +#endif /* CONFIG_X86_32 */ static void fpu_finit (struct fpu *fpu) {
arch/x86/kernel/xsave.c +1 -3
@@ -472,9 +472,7 @@ void __cpuinit xsave_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (!smp_processor_id ()) { +if (!smp_processor_id ())xsave_cntxt_init (); -init_thread_xstate (); - }__xsave_init (); }
Signature · 1 line
1.7.1.1
Re: [PATCH 06/10] x86, xsave: do not initialize xsave in fpu_init()
Quoted 5 lines · Robert Richter
As xsave also supports other than fpu features, it should be initialized independently of the fpu. This patch moves this out of fpu initialization.
Signed-off-by Robert Richter <[email protected]>
As I mentioned in the previous patch, can we do xsave_init() after fpu_init(). fpu_init() does some basic initialization like clearing TS and EM bits etc. xsave_init() can be followed after this.
thanks.
Quoted 101 lines
--- arch/x86/include/asm/i387.h | 1 - arch/x86/kernel/cpu/common.c | 2 ++ arch/x86/kernel/i387.c | 17 ++++++++++++++--- arch/x86/kernel/xsave.c | 4 +--- 4 files changed, 17 insertions(+), 7 deletions(-)arch/x86/include/asm/i387.h +0
-1@@ -31,7 +31,6 @@ extern void mxcsr_feature_mask_init(void);extern int init_fpu (struct task_struct *child); extern asmlinkage void math_state_restore(void);extern void __math_state_restore (void ); -extern void init_thread_xstate (void );extern int dump_fpu (struct pt_regs *,struct user_i387_struct *);extern user_regset_active_fn fpregs_active, xfpregs_active;arch/x86/kernel/cpu/common.c +2
-0@@ -1209,6 +1209,7 @@ void __cpuinit cpu_init(void)clear_all_debug_regs ();dbg_restore_debug_regs (); +xsave_init ();fpu_init ();raw_local_save_flags (kernel_eflags);@@ -1271,5 +1272,6 @@ void __cpuinit cpu_init(void)mxcsr_feature_mask_init ();xsave_init (); + fpu_init(); }#endif arch/x86/kernel/i387.c +14
-3@@ -59,7 +59,7 @@ void __cpuinit mxcsr_feature_mask_init(void)stts (); } -void __cpuinit init_thread_xstate (void ) +static void __cpuinit init_thread_xstate (void ) {if (!HAVE_HWFP ) { xstate_size =sizeof (struct i387_soft_struct );@@ -83,6 +83,7 @@ void __cpuinit init_thread_xstate(void)* Called at bootup to set up the initial FPU state that is later cloned * into all processes. */ +void __cpuinit fpu_init (void ) {unsigned long oldcr0 =read_cr0 ();@@ -92,14 +93,24 @@ void __cpuinit fpu_init(void)write_cr0 (oldcr0 & ~(X86_CR0_TS |X86_CR0_EM ));/* clear TS and EM */ -xsave_init (); +if (!smp_processor_id ()) +init_thread_xstate ();mxcsr_feature_mask_init ();/* clean state in init */ current_thread_info ()->status =0 ; clear_used_math(); } -#endif /* CONFIG_X86_64 */ + +#else /* CONFIG_X86_64 */ + +void __cpuinit fpu_init (void ) +{ +if (!smp_processor_id ()) +init_thread_xstate (); +} + +#endif /* CONFIG_X86_32 */ static void fpu_finit (struct fpu *fpu) {arch/x86/kernel/xsave.c +1
-3@@ -472,9 +472,7 @@ void __cpuinit xsave_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (!smp_processor_id ()) { +if (!smp_processor_id ())xsave_cntxt_init (); -init_thread_xstate (); - }__xsave_init (); }
PATCH 7/10 x86, xsave: reduce cpu_has_xsave checks
In reply to Robert RichterThis moves the cpu_has_xsave check at the beginning of xsave_init(). All other checks may removed then.
--- arch/x86/kernel/xsave.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/xsave.c +3 -6
@@ -362,9 +362,6 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);*/ static void __cpuinit __xsave_init (void ) { -if (!cpu_has_xsave) -return ; -set_in_cr4 (X86_CR4_OSXSAVE );/*
@@ -433,9 +430,6 @@ static void __cpuinit xsave_cntxt_init(void) {unsigned int eax, ebx, ecx, edx; -if (!cpu_has_xsave) -return ; -cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); pcntxt_mask = eax + ((u64 )edx <<32 );
@@ -469,6 +463,9 @@ static void __cpuinit xsave_cntxt_init(void)void __cpuinit xsave_init (void ) { +if (!cpu_has_xsave) +return ; +/* * Boot processor to setup the FP and extended state context info. */
Signature · 1 line
1.7.1.1
Re: [PATCH 07/10] x86, xsave: reduce cpu_has_xsave checks
Quoted 4 lines · Robert Richter
This moves the
cpu_has_xsavecheck at the beginning ofxsave_init(). All other checks may removed then.Signed-off-by Robert Richter <[email protected]>
Quoted 38 lines
--- arch/x86/kernel/xsave.c | 9 +++------ 1 files changed, 3 insertions(+), 6 deletions(-)arch/x86/kernel/xsave.c +3
-6@@ -362,9 +362,6 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);*/ static void __cpuinit __xsave_init (void ) { -if (!cpu_has_xsave) -return ; -set_in_cr4 (X86_CR4_OSXSAVE );/* @@ -433,9 +430,6 @@ static void __cpuinit xsave_cntxt_init(void) {unsigned int eax, ebx, ecx, edx; -if (!cpu_has_xsave) -return ; -cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); pcntxt_mask = eax + ((u64 )edx <<32 );@@ -469,6 +463,9 @@ static void __cpuinit xsave_cntxt_init(void)void __cpuinit xsave_init (void ) { +if (!cpu_has_xsave) +return ; +/* * Boot processor to setup the FP and extended state context info. */
PATCH 8/10 x86, xsave: introduce xstate enable functions
In reply to Robert RichterThe patch renames xsave_cntxt_init() and __xsave_init() into xstate_enable_boot_cpu() and xstate_enable() as this names are more meaningful.
It also removes the duplicate xcr setup for the boot cpu.
--- arch/x86/kernel/xsave.c | 19 ++++++++----------- 1 files changed, 8 insertions(+), 11 deletions(-)
arch/x86/kernel/xsave.c +8 -11
@@ -360,15 +360,10 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -static void __cpuinit __xsave_init (void ) +static inline void xstate_enable (u64 mask) {set_in_cr4 (X86_CR4_OSXSAVE ); - -/* -* Enable all the features that the HW is capable of -* and the Linux kernel is aware of. -*/ -xsetbv (XCR_XFEATURE_ENABLED_MASK , pcntxt_mask); +xsetbv (XCR_XFEATURE_ENABLED_MASK , mask); }/*
@@ -426,7 +421,7 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -static void __cpuinit xsave_cntxt_init (void ) +static void __cpuinit xstate_enable_boot_cpu (void ) {unsigned int eax, ebx, ecx, edx;
@@ -443,7 +438,8 @@ static void __cpuinit xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -__xsave_init (); + +xstate_enable (pcntxt_mask);/* * Recompute the context size for enabled features
@@ -470,6 +466,7 @@ void __cpuinit xsave_init(void)* Boot processor to setup the FP and extended state context info. */ if (!smp_processor_id ()) -xsave_cntxt_init (); -__xsave_init (); +xstate_enable_boot_cpu (); +else +xstate_enable (pcntxt_mask); }
Signature · 1 line
1.7.1.1
Re: [PATCH 08/10] x86, xsave: introduce xstate enable functions
Quoted 7 lines · Robert Richter
The patch renames
xsave_cntxt_init()and__xsave_init()intoxstate_enable_boot_cpu()andxstate_enable()as this names are more meaningful.It also removes the duplicate xcr setup for the boot cpu.
Signed-off-by Robert Richter <[email protected]>
Quoted 55 lines
--- arch/x86/kernel/xsave.c | 19 ++++++++----------- 1 files changed, 8 insertions(+), 11 deletions(-)arch/x86/kernel/xsave.c +8
-11@@ -360,15 +360,10 @@ unsigned int sig_xstate_size = sizeof(struct _fpstate);/* * Enable the extended processor state save/restore feature */ -static void __cpuinit __xsave_init (void ) +static inline void xstate_enable (u64 mask) {set_in_cr4 (X86_CR4_OSXSAVE ); - -/* -* Enable all the features that the HW is capable of -* and the Linux kernel is aware of. -*/ -xsetbv (XCR_XFEATURE_ENABLED_MASK , pcntxt_mask); +xsetbv (XCR_XFEATURE_ENABLED_MASK , mask); }/* @@ -426,7 +421,7 @@ static void __init setup_xstate_init(void)/* * Enable and initialize the xsave feature. */ -static void __cpuinit xsave_cntxt_init (void ) +static void __cpuinit xstate_enable_boot_cpu (void ) {unsigned int eax, ebx, ecx, edx;@@ -443,7 +438,8 @@ static void __cpuinit xsave_cntxt_init(void)* Support only the state known to OS. */ pcntxt_mask = pcntxt_mask &XCNTXT_MASK ; -__xsave_init (); + +xstate_enable (pcntxt_mask);/* * Recompute the context size for enabled features @@ -470,6 +466,7 @@ void __cpuinit xsave_init(void)* Boot processor to setup the FP and extended state context info. */ if (!smp_processor_id ()) -xsave_cntxt_init (); -__xsave_init (); +xstate_enable_boot_cpu (); +else +xstate_enable (pcntxt_mask); }
PATCH 9/10 x86, xsave: check cpuid level for XSTATE_CPUID (0x0d)
In reply to Robert RichterThe patch adds a check that tests if XSTATE_CPUID exists.
--- arch/x86/include/asm/xsave.h | 2 ++ arch/x86/kernel/xsave.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletions(-)
arch/x86/include/asm/xsave.h +2 -0
@@ -4,6 +4,8 @@#include <linux/types.h> #include <asm/processor.h> +#define XSTATE_CPUID 0x0000000d +#define XSTATE_FP 0x1#define XSTATE_SSE 0x2#define XSTATE_YMM 0x4
arch/x86/kernel/xsave.c +7 -1
@@ -423,9 +423,15 @@ static void __init setup_xstate_init(void)*/ static void __cpuinit xstate_enable_boot_cpu (void ) { +struct cpuinfo_x86 *c = &cpu_data (0 );unsigned int eax, ebx, ecx, edx; -cpuid_count (0xd ,0 , &eax, &ebx, &ecx, &edx); +if (c->cpuid_level <XSTATE_CPUID ) { +WARN (1 ,KERN_ERR "XSTATE_CPUID missing\n" ); +return ; + } + +cpuid_count (XSTATE_CPUID ,0 , &eax, &ebx, &ecx, &edx); pcntxt_mask = eax + ((u64 )edx <<32 );if ((pcntxt_mask &XSTATE_FPSSE ) !=XSTATE_FPSSE ) {
Signature · 1 line
1.7.1.1
Re: [PATCH 09/10] x86, xsave: check cpuid level for XSTATE_CPUID (0x0d)
Quoted 3 lines · Robert Richter
The patch adds a check that tests if
XSTATE_CPUIDexists.Signed-off-by Robert Richter <[email protected]>
While we are at this, can you please rename the other hardcoded 0xd's with XSTATE_CPUID in xsave.c?
Quoted 1 line
+ struct
cpuinfo_x86*c =&cpu_data(0);
Can we use boot_cpu_data instead of cpu_data(0).
thanks.
H. Peter Anvin
reviewerRe: [PATCH 09/10] x86, xsave: check cpuid level for XSTATE_CPUID (0x0d)
Quoted 12 lines · Suresh Siddha
Quoted 3 lines · Robert Richter
The patch adds a check that tests if
XSTATE_CPUIDexists.Signed-off-by Robert Richter <[email protected]>While we are at this, can you please rename the other hardcoded 0xd's with
XSTATE_CPUIDinxsave.c?Quoted 1 line
+ struct
cpuinfo_x86*c =&cpu_data(0);Can we use
boot_cpu_datainstead ofcpu_data(0).
Not the same thing!
boot_cpu_data is the intersection of all the boot CPU features (and yes, it's misnamed); cpu_data(0) is the CPU data for CPU 0.
-hpa
H. Peter Anvin
reviewerRe: [PATCH 09/10] x86, xsave: check cpuid level for XSTATE_CPUID (0x0d)
In reply to Suresh SiddhaQuoted 12 lines · Suresh Siddha
Quoted 3 lines · Robert Richter
The patch adds a check that tests if
XSTATE_CPUIDexists.Signed-off-by Robert Richter <[email protected]>While we are at this, can you please rename the other hardcoded 0xd's with
XSTATE_CPUIDinxsave.c?Quoted 1 line
+ struct
cpuinfo_x86*c =&cpu_data(0);Can we use
boot_cpu_datainstead ofcpu_data(0).
I think boot_cpu_data is the right thing for the early stuff like this (early_cpu_init() initializes boot_cpu_data, not cpu_data(0)) so just use boot_cpu_data.cpuid_level instead of forming a pointer.
-hpa
PATCH 10/10 x86, xsave: make init_xstate_buf static
In reply to Robert RichterThe pointer is only used in xsave.c. Making it static.
--- arch/x86/include/asm/xsave.h | 1 - arch/x86/kernel/xsave.c | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-)
arch/x86/include/asm/xsave.h +0 -1
@@ -27,7 +27,6 @@extern unsigned int xstate_size;extern u64 pcntxt_mask; -extern struct xsave_struct *init_xstate_buf;extern u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS ];extern void xsave_init (void );
arch/x86/kernel/xsave.c +5 -5
@@ -16,6 +16,11 @@*/ u64 pcntxt_mask; +/* +* Represents init state for the supported extended state. +*/ +static struct xsave_struct *init_xstate_buf; +struct _fpx_sw_bytes fx_sw_reserved;#ifdef CONFIG_IA32_EMULATION struct _fpx_sw_bytes fx_sw_reserved_ia32;
@@ -348,11 +353,6 @@ static void prepare_fx_sw_frame(void)#endif } -/* -* Represents init state for the supported extended state. -*/ -struct xsave_struct *init_xstate_buf; -#ifdef CONFIG_X86_64 unsigned int sig_xstate_size =sizeof (struct _fpstate );#endif
Signature · 1 line
1.7.1.1
Re: [PATCH 10/10] x86, xsave: make init_xstate_buf static
Quoted 3 lines · Robert Richter
The pointer is only used in
xsave.c. Making it static.Signed-off-by Robert Richter <[email protected]>
Quoted 14 lines · Robert Richter
This patch series contains some cleanups and reworks I made during code review and feature implementation for upcoming cpus.
Most patches refactor the xsave initialization that is very dependent on fpu initialization. This series starts to decouple this a little bit as xsave not only supports fpu features. Also this is an attempt to ease the xsave interface by making some of the functions and variables static.
There is also one patch that removes
boot_cpu_idvariable, which is not really related to xsave. Maybe this should be applied to another branch.
Quoted 6 lines
The patches are relative to today's tip/x86/xsave branch.
(The patches are small for better review and rebasing.)
-Robert
Hi Robert, I recall there was a thread related to boot_cpu_id and cpu = 0. Unfortunately I can't find it neither in my mbox nor somewhere in net at moment. Ie technically speaking -- yes boot_cpu_id will be 0 but perhaps instead of magic !cpu and friends explicit boot_cpu_id might be better for code reading. It might be is_boot_cpu() macro helper or so as well.
Though I don't have strong opinion but for ones who will be reading the code first time it might be confusing :) Agreed?
-- Cyrill
Quoted 17 lines · Cyrill Gorcunov
Quoted 16 lines · Robert Richter
This patch series contains some cleanups and reworks I made during code review and feature implementation for upcoming cpus.
Most patches refactor the xsave initialization that is very dependent on fpu initialization. This series starts to decouple this a little bit as xsave not only supports fpu features. Also this is an attempt to ease the xsave interface by making some of the functions and variables static.
There is also one patch that removes
boot_cpu_idvariable, which is not really related to xsave. Maybe this should be applied to another branch.The patches are relative to today's tip/x86/xsave branch.
Quoted 8 lines
Quoted 4 lines
(The patches are small for better review and rebasing.)
-Robert
Hi Robert, I recall there was a thread related to
boot_cpu_idand cpu = 0. Unfortunately I can't find it neither in my mbox nor somewhere in net at moment.
I found this patch:
b3572e3 x86/voyager: fix compile breakage caused by dc1e35c6e95e8923cf1d3510438b63c600fee1e2
indicating that boot cpu id could be different than 0.
But either this is broken again, or the issue is gone in a different way.
Quoted 7 lines
Ie technically speaking -- yes
boot_cpu_idwill be 0
but perhaps instead of magic !cpu and friends explicitboot_cpu_idmight be better for code reading. It might beis_boot_cpu()macro helper or so as well.Though I don't have strong opinion but for ones who will be reading the code first time it might be confusing :) Agreed?
That's true, but once you know...
I could make a follow on patch with an is_boot_cpu() macro. Ingo, what do you think?
But first question is, is it always !smp_processor_id()? At least current implementation indicates this:
void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c) {
BUG_ON(c == &boot_cpu_data);
...
with:
#define boot_cpu_data cpu_data[0]
... which is valid for 32 and 64 bit.
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
Quoted 27 lines · Robert Richter
Quoted 17 lines · Cyrill Gorcunov
Quoted 16 lines · Robert Richter
This patch series contains some cleanups and reworks I made during code review and feature implementation for upcoming cpus.
Most patches refactor the xsave initialization that is very dependent on fpu initialization. This series starts to decouple this a little bit as xsave not only supports fpu features. Also this is an attempt to ease the xsave interface by making some of the functions and variables static.
There is also one patch that removes
boot_cpu_idvariable, which is not really related to xsave. Maybe this should be applied to another branch.The patches are relative to today's tip/x86/xsave branch.
Quoted 8 lines
Quoted 4 lines
(The patches are small for better review and rebasing.)
-Robert
Hi Robert, I recall there was a thread related to
boot_cpu_idand cpu = 0. Unfortunately I can't find it neither in my mbox nor somewhere in net at moment.
Quoted 8 lines
I found this patch:
b3572e3 x86/voyager: fix compile breakage caused by
dc1e35c6e95e8923cf1d3510438b63c600fee1e2indicating that boot cpu id could be different than 0.
But either this is broken again, or the issue is gone in a different way.
Voyager code was removed from the tree since then.
thanks
suresh
Quoted 27 lines · Robert Richter
Quoted 17 lines · Cyrill Gorcunov
Quoted 16 lines · Robert Richter
This patch series contains some cleanups and reworks I made during code review and feature implementation for upcoming cpus.
Most patches refactor the xsave initialization that is very dependent on fpu initialization. This series starts to decouple this a little bit as xsave not only supports fpu features. Also this is an attempt to ease the xsave interface by making some of the functions and variables static.
There is also one patch that removes
boot_cpu_idvariable, which is not really related to xsave. Maybe this should be applied to another branch.The patches are relative to today's tip/x86/xsave branch.
Quoted 8 lines
Quoted 4 lines
(The patches are small for better review and rebasing.)
-Robert
Hi Robert, I recall there was a thread related to
boot_cpu_idand cpu = 0. Unfortunately I can't find it neither in my mbox nor somewhere in net at moment.
Quoted 6 lines
I found this patch:
b3572e3 x86/voyager: fix compile breakage caused by
dc1e35c6e95e8923cf1d3510438b63c600fee1e2indicating that boot cpu id could be different than 0.
yeah, I forgot about voyager indeed but seems this is quite specific to voyager trick
Quoted 8 lines
But either this is broken again, or the issue is gone in a different way.
Quoted 5 lines
Ie technically speaking -- yes
boot_cpu_idwill be 0
but perhaps instead of magic !cpu and friends explicitboot_cpu_idmight be better for code reading. It might beis_boot_cpu()macro helper or so as well.
Quoted 5 lines
Quoted 2 lines
Though I don't have strong opinion but for ones who will be reading the code first time it might be confusing :) Agreed?
That's true, but once you know...
yes, but before you know ;)
Quoted 6 lines
I could make a follow on patch with an
is_boot_cpu()macro. Ingo, what do you think?But first question is, is it always !smp_processor_id()? At least current implementation indicates this:
I guess so, since it's assigned from boot_cpu_id iirc
Quoted 11 lines
void
__cpuinitidentify_secondary_cpu(struct cpuinfo_x86 *c){
BUG_ON(c == &boot_cpu_data);
...with:
#define
boot_cpu_datacpu_data[0]... which is valid for 32 and 64 bit.
I suppose this is just self-protection for "what if something will go wrong and this will be called on non-BP cpu".
Quoted 6 lines
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
-- Cyrill
On Wed, Jul 21, 2010 at 12:07:29AM +0400, Cyrill Gorcunov wrote:
...
Quoted 7 lines
Quoted 4 lines
But first question is, is it always !smp_processor_id()? At least current implementation indicates this:
I guess so, since it's assigned from
boot_cpu_idiirc
well, not true, this id is being set in setup_per_cpu_areas() note the snippet
if (cpu == boot_cpu_id) switch_to_new_gdt(cpu);
but cycle of assignment is done over all possible cpus so smp_processor_id will be = 0 for BP but definitely it's confusing and better to check for BP via explicit cpu == boot_cpu_id I think. Though I might be missing something.
Quoted 11 lines
Quoted 11 lines
void
__cpuinitidentify_secondary_cpu(struct cpuinfo_x86 *c){
BUG_ON(c == &boot_cpu_data);
...with:
#define
boot_cpu_datacpu_data[0]... which is valid for 32 and 64 bit.
-- Cyrill
Quoted 9 lines · Cyrill Gorcunov
note the snippet
if (cpu == boot_cpu_id) switch_to_new_gdt(cpu);but cycle of assignment is done over all possible cpus so
smp_processor_idwill be = 0 for BP but definitely it's confusing and better to check for BP via explicit cpu ==boot_cpu_idI think. Though I might be missing something.
This in smpboot.c makes it clear:
void __cpuinit smp_store_cpu_info(int id)
{
struct cpuinfo_x86 *c = &cpu_data(id);
copy_cpuinfo_x86(c, &boot_cpu_data);
c->cpu_index = id;
if (id != 0)
identify_secondary_cpu(c);
}So boot cpu id is always 0.
Also note, as Hans Peter already pointed out, this for CONFIG_SMP:
&cpu_data(0) != &boot_cpu_data
The data in boot_cpu_data is (partly) already available after early_cpu_init(). It is later copied to the &cpu_data() structures. So boot_cpu_data should be used for init code.
Also, to make the test obviously, instead of testing (cpu == boot_cpu_id) I rather tend to use an is_boot_cpu() macro as you suggested in your earlier mail.
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
Quoted 24 lines · Robert Richter
Quoted 9 lines · Cyrill Gorcunov
note the snippet
if (cpu == boot_cpu_id) switch_to_new_gdt(cpu);but cycle of assignment is done over all possible cpus so
smp_processor_idwill be = 0 for BP but definitely it's confusing and better to check for BP via explicit cpu ==boot_cpu_idI think. Though I might be missing something.This in
smpboot.cmakes it clear:void
__cpuinitsmp_store_cpu_info(int id){ struct cpuinfo_x86 *c = &cpu_data(id); copy_cpuinfo_x86(c, &boot_cpu_data); c->cpu_index = id; if (id != 0) identify_secondary_cpu(c); }
Quoted 1 line
So boot cpu id is always 0.
yeah, thanks!
Quoted 9 lines
Also note, as Hans Peter already pointed out, this for
CONFIG_SMP:
&cpu_data(0)!=&boot_cpu_dataThe data in
boot_cpu_datais (partly) already available afterearly_cpu_init(). It is later copied to the&cpu_data()structures. Soboot_cpu_datashould be used for init code.
Quoted 10 lines
Also, to make the test obviously, instead of testing (cpu ==
boot_cpu_id) I rather tend to use anis_boot_cpu()macro as you suggested in your earlier mail.-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
ok, thanks Robert!
-- Cyrill
H. Peter Anvin
reviewerQuoted 4 lines · Cyrill Gorcunov
well, not true, this id is being set in
setup_per_cpu_areas()note the snippet
Quoted 8 lines
if (cpu == boot_cpu_id) switch_to_new_gdt(cpu);but cycle of assignment is done over all possible cpus so
smp_processor_idwill be = 0 for BP but definitely it's confusing and better to check for BP via explicit cpu ==boot_cpu_idI think. Though I might be missing something.
I think the style (!smp_processor_id()) is already in use in other places, but we should be consistent in style; if you want to introduce a new style I certainly agree that (is_boot_cpu()) is pretty clear but it should be introduced universally.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Quoted 14 lines · H. Peter Anvin
Quoted 4 lines · Cyrill Gorcunov
well, not true, this id is being set in
setup_per_cpu_areas()note the snippetQuoted 8 lines
if (cpu == boot_cpu_id) switch_to_new_gdt(cpu);but cycle of assignment is done over all possible cpus so
smp_processor_idwill be = 0 for BP but definitely it's confusing and better to check for BP via explicit cpu ==boot_cpu_idI think. Though I might be missing something.
Quoted 7 lines
I think the style (!smp_processor_id()) is already in use in other places, but we should be consistent in style; if you want to introduce a new style I certainly agree that (
is_boot_cpu()) is pretty clear but it should be introduced universally.-hpa
yes, also I bet there will be places with patterns like
cpu = smp_processor_id(); if (!cpu) or if (cpu == 0)
so every single smp_processor_id and "raw" version as well should be checked. I'll take a look as only get ability. If Robert (or anyone) will like to beat me on this -- I would be only glad ;)
-- Cyrill
Quoted 15 lines · Cyrill Gorcunov
Quoted 14 lines · H. Peter Anvin
Quoted 12 lines · Cyrill Gorcunov
well, not true, this id is being set in
setup_per_cpu_areas()note the snippetif (cpu == boot_cpu_id) switch_to_new_gdt(cpu);but cycle of assignment is done over all possible cpus so
smp_processor_idwill be = 0 for BP but definitely it's confusing and better to check for BP via explicit cpu ==boot_cpu_idI think. Though I might be missing something.
Quoted 8 lines
Quoted 7 lines
I think the style (!smp_processor_id()) is already in use in other places, but we should be consistent in style; if you want to introduce a new style I certainly agree that (
is_boot_cpu()) is pretty clear but it should be introduced universally.-hpa
Peter, also I think such tuning must be done at merge window time only, just to not break other's patch queues.
-- Cyrill
H. Peter Anvin
reviewerQuoted 4 lines · Cyrill Gorcunov
Peter, also I think such tuning must be done at merge window time only, just to not break other's patch queues.
Realistically it should be done right after the merge window for the *next* merge window.
-hpa
Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. I don't speak on their behalf.
Quoted 11 lines · H. Peter Anvin
Quoted 4 lines · Cyrill Gorcunov
Peter, also I think such tuning must be done at merge window time only, just to not break other's patch queues.
Realistically it should be done right after the merge window for the *next* merge window.
-hpa
ok, which means Robert should use old conventional test at the moment instead of introducing is_boot_cpu I suppose.
-- Cyrill
Quoted 7 lines · Cyrill Gorcunov
Quoted 6 lines · H. Peter Anvin
Quoted 4 lines · Cyrill Gorcunov
Peter, also I think such tuning must be done at merge window time only, just to not break other's patch queues.
Quoted 8 lines
Quoted 5 lines
Realistically it should be done right after the merge window for the *next* merge window.
-hpa
ok, which means Robert should use old conventional test at the moment instead of introducing
is_boot_cpuI suppose.
Yes, I am just using:
if (!smp_processor_id())
...
Cyrill, if you like, I will leave it up to you to introduce the is_boot_cpu() macro.
I still have patch 7/7 in my new posting in that removes the boot_cpu_id. If your patch comes soon this will be obsolete as all places will have the macro then.
Thanks,
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
Quoted 14 lines · Robert Richter
Quoted 13 lines · Cyrill Gorcunov
Quoted 11 lines · H. Peter Anvin
Quoted 4 lines · Cyrill Gorcunov
Peter, also I think such tuning must be done at merge window time only, just to not break other's patch queues.
Realistically it should be done right after the merge window for the *next* merge window.
-hpa
Quoted 7 lines
Quoted 2 lines
ok, which means Robert should use old conventional test at the moment instead of introducing
is_boot_cpuI suppose.Yes, I am just using:
if (!smp_processor_id())
...
ok, I see
Quoted 3 lines
Cyrill, if you like, I will leave it up to you to introduce the
is_boot_cpu()macro.
ok Robert, I may handle it, notes below
Quoted 5 lines
I still have patch 7/7 in my new posting in that removes the
boot_cpu_id. If your patch comes soon this will be obsolete as all places will have the macro then.
I guess I can make it in a hour or so (since need to check all possible places) but it might break other's queue I fear. That is why hpa noted such things should go after merge window.
So I don't know Robert what would be preferred. If Peter pick up your patch for now -- I may just keep it somewhere localy to not loose the traces of boot_cpu_id and use this patch as helper. I just fear I can forget about this promise to introduce is_boot_cpu helper later ;)
Another option could be -- introduce it now and send to trivial@ ML so it'll be picked up there and pushed upstream after merge window.
Quoted 8 lines
Thanks,
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
-- Cyrill
Quoted 25 lines · Robert Richter
Quoted 7 lines · Cyrill Gorcunov
Quoted 6 lines · H. Peter Anvin
Quoted 4 lines · Cyrill Gorcunov
Peter, also I think such tuning must be done at merge window time only, just to not break other's patch queues.
Quoted 8 lines
Quoted 5 lines
Realistically it should be done right after the merge window for the *next* merge window.
-hpa
ok, which means Robert should use old conventional test at the moment instead of introducing
is_boot_cpuI suppose.Yes, I am just using:
if (!smp_processor_id())
...Cyrill, if you like, I will leave it up to you to introduce the
is_boot_cpu()macro.
Quoted 12 lines
I still have patch 7/7 in my new posting in that removes the
boot_cpu_id. If your patch comes soon this will be obsolete as all places will have the macro then.Thanks,
-Robert
Signature · 2 lines
Advanced Micro Devices, Inc. Operating System Research Center
Robert, Peter, it might be something like the patch below. I've compile-tested it only. On top of current -tip with Robert's patch applied. If you find it convenient we could queue it somewhere and give it a shot. Complains are welcome. Initially I thought about kepping boot_cpu_id as macro too (to be consistent with say IA-64) but not sure so I drop this idea.
-- Cyrill
---
x86: Introduce is_boot_cpu() helper
This allow us to make clear the code snippets where we test for cpu being bootstrap one instead of open coded test with zero.
--- arch/x86/include/asm/apb_timer.h | 2 ++ arch/x86/include/asm/cpu.h | 1 - arch/x86/include/asm/smp.h | 2 ++ arch/x86/kernel/apb_timer.c | 2 +- arch/x86/kernel/apic/apic.c | 6 +++--- arch/x86/kernel/apic/nmi.c | 2 +- arch/x86/kernel/apm_32.c | 2 +- arch/x86/kernel/cpu/amd.c | 2 +- arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/intel.c | 2 +- arch/x86/kernel/i387.c | 2 +- arch/x86/kernel/setup_percpu.c | 2 +- arch/x86/kernel/smpboot.c | 4 ++-- arch/x86/kernel/traps.c | 2 +- arch/x86/xen/smp.c | 4 ++-- arch/x86/xen/suspend.c | 2 +- 16 files changed, 21 insertions(+), 18 deletions(-)
arch/x86/include/asm/apb_timer.h +2 -0
@@ -59,6 +59,8 @@ extern struct sfi_timer_table_entry *sfiextern void sfi_free_mtmr (struct sfi_timer_table_entry *mtmr);extern int sfi_mtimer_num; +#define is_boot_cpu (cpu) ((cpu) == 0) +#else /* CONFIG_APB_TIMER */ static inline unsigned long apbt_quick_calibrate (void ) {return 0 ; }
arch/x86/include/asm/cpu.h +0 -1
@@ -32,5 +32,4 @@ extern void arch_unregister_cpu(int);DECLARE_PER_CPU (int, cpu_state); -#endif /* _ASM_X86_CPU_H */
arch/x86/include/asm/smp.h +2 -0
@@ -203,5 +203,7 @@ extern int hard_smp_processor_id(void);#endif /* CONFIG_X86_LOCAL_APIC */ +#define is_boot_cpu (cpu) ((cpu) == 0) +#endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_SMP_H */
arch/x86/kernel/apb_timer.c +1 -1
@@ -343,7 +343,7 @@ void apbt_setup_secondary_clock(void)/* Don't register boot CPU clockevent */ cpu =smp_processor_id (); -if (!cpu) +if (is_boot_cpu (cpu))return ;/* * We need to calculate the scaled math multiplication factor for
arch/x86/kernel/apic/apic.c +3 -3
@@ -1293,7 +1293,7 @@ void __cpuinit setup_local_APIC(void)* TODO: set up through-local-APIC from through-I/O-APIC? --macro */ value =apic_read (APIC_LVT0 ) &APIC_LVT_MASKED ; -if (!smp_processor_id () && (pic_mode || !value)) { +if (is_boot_cpu (smp_processor_id ()) && (pic_mode || !value)) { value =APIC_DM_EXTINT ;apic_printk (APIC_VERBOSE ,"enabled ExtINT on CPU#%d\n" ,smp_processor_id ());
@@ -1307,7 +1307,7 @@ void __cpuinit setup_local_APIC(void)/* * only the BP should see the LINT1 NMI signal, obviously. */ -if (!smp_processor_id ()) +if (is_boot_cpu (smp_processor_id ())) value =APIC_DM_NMI ;else value =APIC_DM_NMI |APIC_LVT_MASKED ;
@@ -1319,7 +1319,7 @@ void __cpuinit setup_local_APIC(void)#ifdef CONFIG_X86_MCE_INTEL /* Recheck CMCI information after local APIC is up on CPU #0 */ -if (smp_processor_id () ==0 ) +if (is_boot_cpu (smp_processor_id ()))cmci_recheck ();#endif }
arch/x86/kernel/apic/nmi.c +1 -1
@@ -316,7 +316,7 @@ void setup_apic_nmi_watchdog(void *unuse/* cheap hack to support suspend/resume */ /* if cpu0 is not active neither should the other cpus */ -if (smp_processor_id () !=0 &&atomic_read (&nmi_active) <=0 ) +if (!is_boot_cpu (smp_processor_id ()) &&atomic_read (&nmi_active) <=0 )return ;switch (nmi_watchdog) {
arch/x86/kernel/apm_32.c +1 -1
@@ -1746,7 +1746,7 @@ static int apm(void *unused)* Method suggested by Ingo Molnar. */ set_cpus_allowed_ptr (current,cpumask_of (0 )); -BUG_ON (smp_processor_id () !=0 ); + BUG_ON(!is_boot_cpu(smp_processor_id());if (apm_info.connection_version ==0 ) { apm_info.connection_version = apm_info.bios.version;
arch/x86/kernel/cpu/amd.c +1 -1
@@ -148,7 +148,7 @@ static void __cpuinit amd_k7_smp_check(s {#ifdef CONFIG_SMP /* calling is from identify_secondary_cpu() ? */ -if (!c->cpu_index) +if (is_boot_cpu (c->cpu_index))return ;/*
arch/x86/kernel/cpu/common.c +1 -1
@@ -1273,7 +1273,7 @@ void __cpuinit cpu_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (smp_processor_id () == boot_cpu_id) + if (is_boot_cpu(smp_processor_id())init_thread_xstate ();xsave_init ();
arch/x86/kernel/cpu/intel.c +1 -1
@@ -169,7 +169,7 @@ static void __cpuinit intel_smp_check(st {#ifdef CONFIG_SMP /* calling is from identify_secondary_cpu() ? */ -if (!c->cpu_index) +if (is_boot_cpu (c->cpu_index))return ;/*
arch/x86/kernel/i387.c +1 -1
@@ -96,7 +96,7 @@ void __cpuinit fpu_init(void)/* * Boot processor to setup the FP and extended state context info. */ -if (!smp_processor_id ()) +if (is_boot_cpu (smp_processor_id ()))init_thread_xstate ();xsave_init ();
arch/x86/kernel/setup_percpu.c +1 -1
@@ -244,7 +244,7 @@ void __init setup_per_cpu_areas(void)* Up to this point, the boot CPU has been using .init.data * area. Reload any changed state for the boot CPU. */ -if (!cpu) +if (is_boot_cpu (cpu))switch_to_new_gdt (cpu); }
arch/x86/kernel/smpboot.c +2 -2
@@ -369,7 +369,7 @@ void __cpuinit smp_store_cpu_info(int idcopy_cpuinfo_x86 (c, &boot_cpu_data); c->cpu_index = id; -if (id !=0 ) +if (!is_boot_cpu (id))identify_secondary_cpu (c); }
@@ -1319,7 +1319,7 @@ int native_cpu_disable(void)* interrupts only being able to be serviced by the BSP. * Especially so if we're not using an IOAPIC -zwane */ -if (cpu ==0 ) +if (is_boot_cpu (cpu))return -EBUSY ;if (nmi_watchdog ==NMI_LOCAL_APIC )
arch/x86/kernel/traps.c +1 -1
@@ -385,7 +385,7 @@ static notrace __kprobes void default_do cpu =smp_processor_id ();/* Only the BSP gets external NMIs from the system. */ -if (!cpu) +if (is_boot_cpu (cpu)) reason =get_nmi_reason ();if (!(reason &0xc0 )) {
arch/x86/xen/smp.c +2 -2
@@ -167,7 +167,7 @@ static void __init xen_fill_possible_mapstatic void __init xen_smp_prepare_boot_cpu (void ) { -BUG_ON (smp_processor_id () !=0 ); +BUG_ON (!is_boot_cpu (smp_processor_id ()));native_smp_prepare_boot_cpu ();/* We've switched to the "real" per-cpu gdt, so make sure the
@@ -336,7 +336,7 @@ static void xen_smp_cpus_done(unsigned istatic int xen_cpu_disable (void ) {unsigned int cpu =smp_processor_id (); -if (cpu ==0 ) +if (is_boot_cpu (cpu))return -EBUSY ;cpu_disable_common ();
arch/x86/xen/suspend.c +1 -1
@@ -52,7 +52,7 @@ static void xen_vcpu_notify_restore(voidunsigned long reason = (unsigned long )data;/* Boot processor notified via generic timekeeping_resume() */ -if (smp_processor_id () ==0 ) +if (is_boot_cpu (smp_processor_id ()))return ;clockevents_notify (reason,NULL );
H. Peter Anvin
reviewerQuoted 5 lines · Robert Richter
There is also one patch that removes
boot_cpu_idvariable, which is not really related to xsave. Maybe this should be applied to another branch.
Probably, yes.
-hpa