Skip to contentSkip to conversation

tip/x86/apic - merging snippet

PATCH In review Cyrill Gorcunov 2 participants 13 messages Aug 23, 2008 x86

lore
Share & tools
lore
#0 lore raw

cover tip/x86/apic - merging snippet

Hi, it seems I'm braking apic merging (due to lack of time)
so here is small series of merging patches. The pactes actually becoming more and more... well... harmfull I would say so please check them twise - especially:

5/8 - I've moved hard_smp_processor_id to apic from the header
since for x86 we're linked to apic code anyway
6/8 - setup_local_APIC now uses preempt_disable/enable on 32bit
mode

Any comments are quite welcome.

The patches are over the -tip/x86/apic

commit 11494547b1754c4f3bd7f707ab869e2adf54d52f

Author: Yinghai Lu <[email protected]>
Date:   Thu Aug 21 01:01:19 2008 -0700

x86: fix apic version warning

after following patch,

I noticed Yinghai posted variables ordering patch - if the series would conflict - just letme know.

- Cyrill -

#1 lore raw

PATCH 1/8 x86: apic_64.c - setup_APIC_timer has to be __cpuinit function

There is no need to hold this code if CPU_HOTPLUG is not defined

---
 arch/x86/kernel/apic_64.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/kernel/apic_64.c +1 -1
index 37e0376..5c908dc 100644
@@ -392,7 +392,7 @@ static void lapic_timer_broadcast(cpumask_t mask)
  * Setup the local APIC timer for this CPU. Copy the initilized values
  * of the boot CPU and register the clock event in the framework.
  */
-static void setup_APIC_timer(void)
+static void __cpuinit setup_APIC_timer(void)
 {
 	struct clock_event_device *levt = &__get_cpu_var(lapic_events);
 
Signature · 1 line
1.6.0.6.gc667
#2 lore raw

PATCH 2/8 x86: apic - introduce get_physical_broadcast for 64bit

In reply to Cyrill Gorcunov

We don't really use it now on 64bit mode but
could reserve it for future.

---
 arch/x86/kernel/apic_64.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
arch/x86/kernel/apic_64.c +8 -0
index 5c908dc..6272c60 100644
@@ -241,6 +241,14 @@ void __cpuinit enable_NMI_through_LVT0(void)
 }
 
 /**
+ * get_physical_broadcast - Get number of physical broadcast IDs
+ */
+int get_physical_broadcast(void)
+{
+	return modern_apic() ? 0xff : 0xf;
+}
+
+/**
  * lapic_get_maxlvt - get the maximum number of local vector table entries
  */
 int lapic_get_maxlvt(void)
Signature · 1 line
1.6.0.6.gc667
#3 lore raw

PATCH 3/8 x86: apic - unify setup_apicpmtimer

In reply to Cyrill Gorcunov
---
 arch/x86/kernel/apic_32.c |   10 ++++++++++
 arch/x86/kernel/apic_64.c |    2 ++
 2 files changed, 12 insertions(+), 0 deletions(-)
arch/x86/kernel/apic_32.c +10 -0
index b8d80c2..ad295cf 100644
@@ -1778,6 +1778,16 @@ static int __init parse_nolapic_timer(char *arg)
 }
 early_param("nolapic_timer", parse_nolapic_timer);
 
+#ifdef CONFIG_X86_64
+static __init int setup_apicpmtimer(char *s)
+{
+	apic_calibrate_pmtmr = 1;
+	notsc_setup(NULL);
+	return 0;
+}
+__setup("apicpmtimer", setup_apicpmtimer);
+#endif
+
 static int __init apic_set_verbosity(char *arg)
 {
 	if (!arg)  {
arch/x86/kernel/apic_64.c +2 -0
index 6272c60..03641d7 100644
@@ -1806,6 +1806,7 @@ static int __init parse_nolapic_timer(char *arg)
 }
 early_param("nolapic_timer", parse_nolapic_timer);
 
+#ifdef CONFIG_X86_64
 static __init int setup_apicpmtimer(char *s)
 {
 	apic_calibrate_pmtmr = 1;
@@ -1813,6 +1814,7 @@ static __init int setup_apicpmtimer(char *s)
 	return 0;
 }
 __setup("apicpmtimer", setup_apicpmtimer);
+#endif
 
 static int __init apic_set_verbosity(char *arg)
 {
Signature · 1 line
1.6.0.6.gc667
#4 lore raw

PATCH 4/8 x86: apic_64.c - add sanity check for spurious vector definition

In reply to Cyrill Gorcunov

Do not check for SPUTIOUS_APIC_VECTOR definition twice. Check it once - is what we need.

---
 arch/x86/kernel/apic_64.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
arch/x86/kernel/apic_64.c +7 -2
index 03641d7..b220726 100644
@@ -45,6 +45,13 @@
 #include <mach_ipi.h>
 #include <mach_apic.h>
 
+/*
+ * Sanity check
+ */
+#if ((SPURIOUS_APIC_VECTOR & 0x0F) != 0x0F)
+# error SPURIOUS_APIC_VECTOR definition error
+#endif
+
 /* Disable local APIC timer from the kernel commandline or via dmi quirk */
 static int disable_apic_timer __cpuinitdata;
 static int apic_calibrate_pmtmr __initdata;
@@ -929,8 +936,6 @@ void __cpuinit setup_local_APIC(void)
 	preempt_disable();
 	value = apic_read(APIC_LVR);
 
-	BUILD_BUG_ON((SPURIOUS_APIC_VECTOR & 0x0f) != 0x0f);
-
 	/*
 	 * Double-check whether this APIC is really registered.
 	 * This is meaningless in clustered apic mode, so we skip it.
Signature · 1 line
1.6.0.6.gc667
#5 lore raw

PATCH 5/8 x86: apic - unify hard_smp_processor_id

In reply to Cyrill Gorcunov

Move hard_smp_processor_id to apic_32.c.
There is no need to keep it in header - we are linked to apic_xx.c code anyway.

---
 arch/x86/kernel/apic_32.c |    5 +++++
 include/asm-x86/smp.h     |   10 ----------
 2 files changed, 5 insertions(+), 10 deletions(-)
arch/x86/kernel/apic_32.c +5 -0
index ad295cf..c71a77c 100644
@@ -1569,6 +1569,11 @@ void __cpuinit generic_processor_info(int apicid, int version)
 	cpu_set(cpu, cpu_present_map);
 }
 
+int hard_smp_processor_id(void)
+{
+	return read_apic_id();
+}
+
 /*
  * Power management
  */
include/asm-x86/smp.h +0 -10
index 29324c1..914a73d 100644
@@ -185,17 +185,7 @@ static inline unsigned int read_apic_id(void)
 }
 #endif
 
-
-# if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
 extern int hard_smp_processor_id(void);
-# else
-#include <mach_apicdef.h>
-static inline int hard_smp_processor_id(void)
-{
-	/* we don't want to mark this access volatile - bad code generation */
-	return read_apic_id();
-}
-# endif /* APIC_DEFINITION */
 
 #else /* CONFIG_X86_LOCAL_APIC */
 
Signature · 1 line
1.6.0.6.gc667
#6 lore raw

Re: [PATCH 5/8] x86: apic - unify hard_smp_processor_id

Quoted 49 lines · Cyrill Gorcunov

Move hard_smp_processor_id to apic_32.c.
There is no need to keep it in header - we are linked to apic_xx.c code anyway.

---
 arch/x86/kernel/apic_32.c |    5 +++++
 include/asm-x86/smp.h     |   10 ----------
 2 files changed, 5 insertions(+), 10 deletions(-)
arch/x86/kernel/apic_32.c +5 -0
index ad295cf..c71a77c 100644
@@ -1569,6 +1569,11 @@ void __cpuinit generic_processor_info(int apicid, int version)
       cpu_set(cpu, cpu_present_map);
 }
 
+int hard_smp_processor_id(void)
+{
+       return read_apic_id();
+}
+
 /*
 * Power management
 */
include/asm-x86/smp.h +0 -11
index 29324c1..914a73d 100644
@@ -185,17 +185,7 @@ static inline unsigned int read_apic_id(void)
 }
 #endif
 
-
-# if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
 extern int hard_smp_processor_id(void);
-# else
-#include <mach_apicdef.h>
-static inline int hard_smp_processor_id(void)
-{
-       /* we don't want to mark this access volatile - bad code generation */
-       return read_apic_id();
-}
-# endif /* APIC_DEFINITION */
 
 #else /* CONFIG_X86_LOCAL_APIC */
 
--
Quoted 3 lines

1.6.0.6.gc667

this one seems have some problem with 32bit with genericarch

because we have

int hard_smp_processor_id(void)

{
        return genapic->get_apic_id(*(unsigned long *)(APIC_BASE+APIC_ID));
}

arch/x86/mach-generic/probe.c

updated 64 bit to have MACRO.

YH

#7 lore raw

Re: [PATCH 5/8] x86: apic - unify hard_smp_processor_id

[Yinghai Lu - Sat, Aug 23, 2008 at 12:13:21PM -0700]

| On Sat, Aug 23, 2008 at 6:01 AM, Cyrill Gorcunov <[email protected]> wrote:
| > Move hard_smp_processor_id to apic_32.c.
| > There is no need to keep it in header - we are linked to
| > apic_xx.c code anyway.
| >
| > Signed-off-by: Cyrill Gorcunov <[email protected]>
| > ---
| >  arch/x86/kernel/apic_32.c |    5 +++++
| >  include/asm-x86/smp.h     |   10 ----------
| >  2 files changed, 5 insertions(+), 10 deletions(-)
| >
| > diff --git a/arch/x86/kernel/apic_32.c b/arch/x86/kernel/apic_32.c
| > index ad295cf..c71a77c 100644
| > --- a/arch/x86/kernel/apic_32.c
| > +++ b/arch/x86/kernel/apic_32.c
| > @@ -1569,6 +1569,11 @@ void __cpuinit generic_processor_info(int apicid, int version)
| >        cpu_set(cpu, cpu_present_map);
| >  }
| >
| > +int hard_smp_processor_id(void)
| > +{
| > +       return read_apic_id();
| > +}
| > +
| >  /*
| >  * Power management
| >  */
| > diff --git a/include/asm-x86/smp.h b/include/asm-x86/smp.h
| > index 29324c1..914a73d 100644
| > --- a/include/asm-x86/smp.h
| > +++ b/include/asm-x86/smp.h
| > @@ -185,17 +185,7 @@ static inline unsigned int read_apic_id(void)
| >  }
| >  #endif
| >
| > -
| > -# if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
| >  extern int hard_smp_processor_id(void);
| > -# else
| > -#include <mach_apicdef.h>
| > -static inline int hard_smp_processor_id(void)
| > -{
| > -       /* we don't want to mark this access volatile - bad code generation */
| > -       return read_apic_id();
| > -}
| > -# endif /* APIC_DEFINITION */
| >
| >  #else /* CONFIG_X86_LOCAL_APIC */
| >
| > --
| > 1.6.0.6.gc667
| >
| >
| 
| this one seems have some problem with 32bit with genericarch
| 
| because we have
| 
| int hard_smp_processor_id(void)
| {
|         return genapic->get_apic_id(*(unsigned long *)(APIC_BASE+APIC_ID));
| }
| 
| arch/x86/mach-generic/probe.c
| 
| updated 64 bit to have MACRO.
| 
| YH
| 

thanks Yinghai, but isn't it called _after_ x86 apic chip initialized?

- Cyrill -

#8 lore raw

Re: [PATCH 5/8] x86: apic - unify hard_smp_processor_id

Quoted 71 lines · Cyrill Gorcunov

[Yinghai Lu - Sat, Aug 23, 2008 at 12:13:21PM -0700]

| On Sat, Aug 23, 2008 at 6:01 AM, Cyrill Gorcunov <[email protected]> wrote:
| > Move hard_smp_processor_id to apic_32.c.
| > There is no need to keep it in header - we are linked to
| > apic_xx.c code anyway.
| >
| > Signed-off-by: Cyrill Gorcunov <[email protected]>
| > ---
| >  arch/x86/kernel/apic_32.c |    5 +++++
| >  include/asm-x86/smp.h     |   10 ----------
| >  2 files changed, 5 insertions(+), 10 deletions(-)
| >
| > diff --git a/arch/x86/kernel/apic_32.c b/arch/x86/kernel/apic_32.c
| > index ad295cf..c71a77c 100644
| > --- a/arch/x86/kernel/apic_32.c
| > +++ b/arch/x86/kernel/apic_32.c
| > @@ -1569,6 +1569,11 @@ void __cpuinit generic_processor_info(int apicid, int version)
| >        cpu_set(cpu, cpu_present_map);
| >  }
| >
| > +int hard_smp_processor_id(void)
| > +{
| > +       return read_apic_id();
| > +}
| > +
| >  /*
| >  * Power management
| >  */
| > diff --git a/include/asm-x86/smp.h b/include/asm-x86/smp.h
| > index 29324c1..914a73d 100644
| > --- a/include/asm-x86/smp.h
| > +++ b/include/asm-x86/smp.h
| > @@ -185,17 +185,7 @@ static inline unsigned int read_apic_id(void)
| >  }
| >  #endif
| >
| > -
| > -# if defined(APIC_DEFINITION) || defined(CONFIG_X86_64)
| >  extern int hard_smp_processor_id(void);
| > -# else
| > -#include <mach_apicdef.h>
| > -static inline int hard_smp_processor_id(void)
| > -{
| > -       /* we don't want to mark this access volatile - bad code generation */
| > -       return read_apic_id();
| > -}
| > -# endif /* APIC_DEFINITION */
| >
| >  #else /* CONFIG_X86_LOCAL_APIC */
| >
| > --
| > 1.6.0.6.gc667
| >
| >
|
| this one seems have some problem with 32bit with genericarch
|
| because we have
|
| int hard_smp_processor_id(void)
| {
|         return genapic->get_apic_id(*(unsigned long *)(APIC_BASE+APIC_ID));
| }
|
| arch/x86/mach-generic/probe.c
|
| updated 64 bit to have MACRO.
|
| YH
|
Quoted 2 lines

thanks Yinghai, but isn't it called _after_ x86 apic chip initialized?

32 bit need to do sth special when subarch

YH

#9 lore raw

Re: [PATCH 5/8] x86: apic - unify hard_smp_processor_id

In reply to Cyrill Gorcunov

[Cyrill Gorcunov - Sat, Aug 23, 2008 at 11:45:41PM +0400]
...

| | 
| | this one seems have some problem with 32bit with genericarch
| | 
| | because we have
| | 
| | int hard_smp_processor_id(void)
| | {
| |         return genapic->get_apic_id(*(unsigned long *)(APIC_BASE+APIC_ID));
| | }
| | 
| | arch/x86/mach-generic/probe.c
| | 
| | updated 64 bit to have MACRO.
| | 
| | YH
| | 
| 
| thanks Yinghai, but isn't it called _after_ x86 apic chip
| initialized?
| 
| 		- Cyrill -

it's not related to initializaton - ignore my prev mail please. (just a notice: If you've 64bit version updated to MACRO dont forget you will need read_apic_id as well).

- Cyrill -

#10 lore raw

PATCH 6/8 x86: apic - unify setup_local_APIC

In reply to Cyrill Gorcunov

- remove useless read of APIC_LVR
- wrap with preempt_disable/enable
- check for integrated APIC just in place

---
 arch/x86/kernel/apic_32.c |   33 ++++++++++++++++++++----
 arch/x86/kernel/apic_64.c |   59 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 82 insertions(+), 10 deletions(-)
arch/x86/kernel/apic_32.c +27 -6
index c71a77c..5340295 100644
@@ -75,7 +75,9 @@ char system_vectors[NR_VECTORS] = { [0 ... NR_VECTORS-1] = SYS_VECTOR_FREE};
  */
 unsigned int apic_verbosity;
 
+#ifdef CONFIG_X86_32
 int pic_mode;
+#endif
 
 /* Have we found an MP table */
 int smp_found_config;
@@ -1031,9 +1033,10 @@ static void __cpuinit lapic_setup_esr(void)
  */
 void __cpuinit setup_local_APIC(void)
 {
-	unsigned long value, integrated;
+	unsigned int value;
 	int i, j;
 
+#ifdef CONFIG_X86_32
 	/* Pound the ESR really hard over the head with a big hammer - mbligh */
 	if (esr_disable) {
 		apic_write(APIC_ESR, 0);
@@ -1041,14 +1044,16 @@ void __cpuinit setup_local_APIC(void)
 		apic_write(APIC_ESR, 0);
 		apic_write(APIC_ESR, 0);
 	}
+#endif
 
-	integrated = lapic_is_integrated();
+	preempt_disable();
 
 	/*
 	 * Double-check whether this APIC is really registered.
+	 * This is meaningless in clustered apic mode, so we skip it.
 	 */
 	if (!apic_id_registered())
-		WARN_ON_ONCE(1);
+		BUG();
 
 	/*
 	 * Intel recommends to set DFR, LDR and TPR before enabling
@@ -1094,6 +1099,7 @@ void __cpuinit setup_local_APIC(void)
 	 */
 	value |= APIC_SPIV_APIC_ENABLED;
 
+#ifdef CONFIG_X86_32
 	/*
 	 * Some unknown Intel IO/APIC (or APIC) errata is biting us with
 	 * certain networking cards. If high frequency interrupts are
@@ -1114,8 +1120,13 @@ void __cpuinit setup_local_APIC(void)
 	 * See also the comment in end_level_ioapic_irq().  --macro
 	 */
 
-	/* Enable focus processor (bit==0) */
+	/*
+	 * - enable focus processor (bit==0)
+	 * - 64bit mode always use processor focus
+	 *   so no need to set it
+	 */
 	value &= ~APIC_SPIV_FOCUS_DISABLED;
+#endif
 
 	/*
 	 * Set spurious IRQ vector
@@ -1134,7 +1145,15 @@ 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)) {
+#ifdef CONFIG_X86_32
+	/*
+	 * a bit strange form to reduce variables being
+	 * checked: it should be (pic_mode || !value)
+	 * so we swirl it
+	 */
+	value |= !!!pic_mode;
+#endif
+	if (!smp_processor_id() && !value) {
 		value = APIC_DM_EXTINT;
 		apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
 				smp_processor_id());
@@ -1152,9 +1171,11 @@ void __cpuinit setup_local_APIC(void)
 		value = APIC_DM_NMI;
 	else
 		value = APIC_DM_NMI | APIC_LVT_MASKED;
-	if (!integrated)		/* 82489DX */
+	if (lapic_is_integrated())		/* 82489DX */
 		value |= APIC_LVT_LEVEL_TRIGGER;
 	apic_write(APIC_LVT1, value);
+
+	preempt_enable();
 }
 
 void __cpuinit end_local_APIC_setup(void)
arch/x86/kernel/apic_64.c +55 -4

97 lines not on this page · raw message

Signature · 1 line
1.6.0.6.gc667
#11 lore raw

PATCH 7/8 x86: apic_32.c should use __cpuinit section

In reply to Cyrill Gorcunov

All callers are __init or __cpuinit so there is no need to hold this code without CPU_HOTPLUG being set.

---
 arch/x86/kernel/apic_32.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
arch/x86/kernel/apic_32.c +3 -3
index 5340295..0c608ac 100644
@@ -383,7 +383,7 @@ static void lapic_timer_broadcast(cpumask_t mask)
  * Setup the local APIC timer for this CPU. Copy the initilized values
  * of the boot CPU and register the clock event in the framework.
  */
-static void __devinit setup_APIC_timer(void)
+static void __cpuinit setup_APIC_timer(void)
 {
 	struct clock_event_device *levt = &__get_cpu_var(lapic_events);
 
@@ -652,7 +652,7 @@ void __init setup_boot_APIC_clock(void)
 	setup_APIC_timer();
 }
 
-void __devinit setup_secondary_APIC_clock(void)
+void __cpuinit setup_secondary_APIC_clock(void)
 {
 	setup_APIC_timer();
 }
@@ -1732,7 +1732,7 @@ static struct sys_device device_lapic = {
 	.cls	= &lapic_sysclass,
 };
 
-static void __devinit apic_pm_activate(void)
+static void __cpuinit apic_pm_activate(void)
 {
 	apic_pm_state.active = 1;
 }
Signature · 1 line
1.6.0.6.gc667
#12 lore raw

PATCH 8/8 x86: apic - unify smp_apic_timer_interrupt

In reply to Cyrill Gorcunov
---
 arch/x86/kernel/apic_32.c |    3 +++
 arch/x86/kernel/apic_64.c |    2 ++
 2 files changed, 5 insertions(+), 0 deletions(-)
arch/x86/kernel/apic_32.c +3 -0
index 0c608ac..a7193cb 100644
@@ -718,6 +718,9 @@ void smp_apic_timer_interrupt(struct pt_regs *regs)
 	 * Besides, if we don't timer interrupts ignore the global
 	 * interrupt lock, which is the WrongThing (tm) to do.
 	 */
+#ifdef CONFIG_X86_64
+	exit_idle();
+#endif
 	irq_enter();
 	local_apic_timer_interrupt();
 	irq_exit();
arch/x86/kernel/apic_64.c +2 -0
index 99b5f97..bcfa91d 100644
@@ -617,7 +617,9 @@ void smp_apic_timer_interrupt(struct pt_regs *regs)
 	 * Besides, if we don't timer interrupts ignore the global
 	 * interrupt lock, which is the WrongThing (tm) to do.
 	 */
+#ifdef CONFIG_X86_64
 	exit_idle();
+#endif
 	irq_enter();
 	local_apic_timer_interrupt();
 	irq_exit();
Signature · 1 line
1.6.0.6.gc667