2008-03-27 17:11:54

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 0/9] integrate smp.h

Hi,

here's the last series I was owing.

After that, smp_32.h and smp_64.h are gone, merged into smp.h

as usual, compiled tested in ~ 8 randconfigs for each architecture, and boot tested
in all my hardware.

enjoy

full diffstat:

a/include/asm-x86/smp_32.h | 12 -----
a/include/asm-x86/smp_64.h | 12 -----
b/arch/x86/xen/smp.c | 7 +--
b/include/asm-x86/smp.h | 27 ++++++++++++
b/include/asm-x86/smp_32.h | 27 ------------
b/include/asm-x86/smp_64.h | 7 ++-
include/asm-x86/smp.h | 57 ++++++++++++++++++++++---
include/asm-x86/smp_32.h | 34 ---------------
include/asm-x86/smp_64.h | 100 ++++++++-------------------------------------
9 files changed, 104 insertions(+), 179 deletions(-)


2008-03-27 17:11:10

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 8/9] [PATCH] x86: change naming of cpu_initialized_mask for xen

xen does not use the global cpu_initialized mask, but rather,
a specific one. So we change its name so it won't conflict with the upcoming
movement of cpu_initialized_mask from smp_64.h to smp_32.h.

Signed-off-by: Glauber Costa <[email protected]>
CC: Jeremy Fitzhardinge <[email protected]>
---
arch/x86/xen/smp.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 6b3c37b..92dd3db 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -35,7 +35,7 @@
#include "xen-ops.h"
#include "mmu.h"

-static cpumask_t cpu_initialized_map;
+static cpumask_t xen_cpu_initialized_map;
static DEFINE_PER_CPU(int, resched_irq) = -1;
static DEFINE_PER_CPU(int, callfunc_irq) = -1;
static DEFINE_PER_CPU(int, debug_irq) = -1;
@@ -189,7 +189,7 @@ void __init xen_smp_prepare_cpus(unsigned int max_cpus)
if (xen_smp_intr_init(0))
BUG();

- cpu_initialized_map = cpumask_of_cpu(0);
+ xen_cpu_initialized_map = cpumask_of_cpu(0);

/* Restrict the possible_map according to max_cpus. */
while ((num_possible_cpus() > 1) && (num_possible_cpus() > max_cpus)) {
@@ -220,7 +220,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
struct vcpu_guest_context *ctxt;
struct gdt_page *gdt = &per_cpu(gdt_page, cpu);

- if (cpu_test_and_set(cpu, cpu_initialized_map))
+ if (cpu_test_and_set(cpu, xen_cpu_initialized_map))
return 0;

ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
--
1.5.0.6

2008-03-27 17:11:28

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 9/9] [PATCH] x86: merge smp_32.h and smp_64.h into smp.h

Merge what's left from smp_32.h and smp_64.h into smp.h
By now, they're basically extern definitions.

Signed-off-by: Glauber Costa <[email protected]>
---
include/asm-x86/smp.h | 11 +++++------
include/asm-x86/smp_32.h | 12 ------------
include/asm-x86/smp_64.h | 11 -----------
3 files changed, 5 insertions(+), 29 deletions(-)
delete mode 100644 include/asm-x86/smp_32.h
delete mode 100644 include/asm-x86/smp_64.h

diff --git a/include/asm-x86/smp.h b/include/asm-x86/smp.h
index 5f6ea69..bd3778d 100644
--- a/include/asm-x86/smp.h
+++ b/include/asm-x86/smp.h
@@ -19,6 +19,11 @@
#include <asm/thread_info.h>

extern cpumask_t cpu_callout_map;
+extern cpumask_t cpu_initialized;
+extern cpumask_t cpu_callin_map;
+
+extern void (*mtrr_hook)(void);
+extern void zap_low_mappings(void);

extern int smp_num_siblings;
extern unsigned int num_processors;
@@ -166,12 +171,6 @@ extern int safe_smp_processor_id(void);
#define stack_smp_processor_id() 0
#endif

-#ifdef CONFIG_X86_32
-# include "smp_32.h"
-#else
-# include "smp_64.h"
-#endif
-
#ifdef CONFIG_X86_LOCAL_APIC

static inline int logical_smp_processor_id(void)
diff --git a/include/asm-x86/smp_32.h b/include/asm-x86/smp_32.h
deleted file mode 100644
index d9ae5ac..0000000
--- a/include/asm-x86/smp_32.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef __ASM_SMP_H
-#define __ASM_SMP_H
-
-#ifndef __ASSEMBLY__
-
-extern cpumask_t cpu_callin_map;
-
-extern void (*mtrr_hook)(void);
-extern void zap_low_mappings(void);
-
-#endif /* !ASSEMBLY */
-#endif
diff --git a/include/asm-x86/smp_64.h b/include/asm-x86/smp_64.h
deleted file mode 100644
index 058f413..0000000
--- a/include/asm-x86/smp_64.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#ifndef __ASM_SMP_H
-#define __ASM_SMP_H
-
-extern cpumask_t cpu_initialized;
-extern cpumask_t cpu_callin_map;
-
-extern int smp_call_function_mask(cpumask_t mask, void (*func)(void *),
- void *info, int wait);
-
-#endif
-
--
1.5.0.6

2008-03-27 17:11:41

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 7/9] [PATCH] x86: merge SMP definitions of smp.h

we merge everything that is inside CONFIG_SMP
to smp.h. They differ a little bit, so we use
CONFIG_X86_32_SMP and CONFIG_X86_64_SMP as markers.

Signed-off-by: Glauber Costa <[email protected]>
---
include/asm-x86/smp.h | 33 ++++++++++++++++++++++++++++++++-
include/asm-x86/smp_32.h | 21 ---------------------
include/asm-x86/smp_64.h | 27 ---------------------------
3 files changed, 32 insertions(+), 49 deletions(-)

diff --git a/include/asm-x86/smp.h b/include/asm-x86/smp.h
index 1cd434d..5f6ea69 100644
--- a/include/asm-x86/smp.h
+++ b/include/asm-x86/smp.h
@@ -131,8 +131,39 @@ extern unsigned long setup_trampoline(void);

void smp_store_cpu_info(int id);
#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
-#else
+
+/* We don't mark CPUs online until __cpu_up(), so we need another measure */
+static inline int num_booting_cpus(void)
+{
+ return cpus_weight(cpu_callout_map);
+}
+#endif /* CONFIG_SMP */
+
+#ifdef CONFIG_X86_32_SMP
+/*
+ * This function is needed by all SMP systems. It must _always_ be valid
+ * from the initial startup. We map APIC_BASE very early in page_setup(),
+ * so this is correct in the x86 case.
+ */
+DECLARE_PER_CPU(int, cpu_number);
+#define raw_smp_processor_id() (x86_read_percpu(cpu_number))
+extern int safe_smp_processor_id(void);
+
+#elif defined(CONFIG_X86_64_SMP)
+#define raw_smp_processor_id() read_pda(cpunumber)
+
+#define stack_smp_processor_id() \
+({ \
+ struct thread_info *ti; \
+ __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
+ ti->cpu; \
+})
+#define safe_smp_processor_id() smp_processor_id()
+
+#else /* !CONFIG_X86_32_SMP && !CONFIG_X86_64_SMP */
#define cpu_physical_id(cpu) boot_cpu_physical_apicid
+#define safe_smp_processor_id() 0
+#define stack_smp_processor_id() 0
#endif

#ifdef CONFIG_X86_32
diff --git a/include/asm-x86/smp_32.h b/include/asm-x86/smp_32.h
index 694d324..d9ae5ac 100644
--- a/include/asm-x86/smp_32.h
+++ b/include/asm-x86/smp_32.h
@@ -8,26 +8,5 @@ extern cpumask_t cpu_callin_map;
extern void (*mtrr_hook)(void);
extern void zap_low_mappings(void);

-#ifdef CONFIG_SMP
-/*
- * This function is needed by all SMP systems. It must _always_ be valid
- * from the initial startup. We map APIC_BASE very early in page_setup(),
- * so this is correct in the x86 case.
- */
-DECLARE_PER_CPU(int, cpu_number);
-#define raw_smp_processor_id() (x86_read_percpu(cpu_number))
-
-extern int safe_smp_processor_id(void);
-
-/* We don't mark CPUs online until __cpu_up(), so we need another measure */
-static inline int num_booting_cpus(void)
-{
- return cpus_weight(cpu_callout_map);
-}
-
-#else /* CONFIG_SMP */
-#define safe_smp_processor_id() 0
-#endif /* !CONFIG_SMP */
-
#endif /* !ASSEMBLY */
#endif
diff --git a/include/asm-x86/smp_64.h b/include/asm-x86/smp_64.h
index 8ea4952..058f413 100644
--- a/include/asm-x86/smp_64.h
+++ b/include/asm-x86/smp_64.h
@@ -7,32 +7,5 @@ extern cpumask_t cpu_callin_map;
extern int smp_call_function_mask(cpumask_t mask, void (*func)(void *),
void *info, int wait);

-#ifdef CONFIG_SMP
-
-#define raw_smp_processor_id() read_pda(cpunumber)
-
-#define stack_smp_processor_id() \
-({ \
- struct thread_info *ti; \
- asm("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
- ti->cpu; \
-})
-
-/*
- * On x86 all CPUs are mapped 1:1 to the APIC space. This simplifies
- * scheduling and IPI sending and compresses data structures.
- */
-static inline int num_booting_cpus(void)
-{
- return cpus_weight(cpu_callout_map);
-}
-
-#define safe_smp_processor_id() smp_processor_id()
-#else /* CONFIG_SMP */
-#define stack_smp_processor_id() 0
-#define safe_smp_processor_id() 0
-#endif /* !CONFIG_SMP */
-
-
#endif

--
1.5.0.6

2008-03-27 17:12:18

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 1/9] [PATCH] x86: surround hard_smp_processor_id in APIC_DEFINITION

APIC_DEFINITION is not defined in x86_64, so in practice, we keep
our old code here. But as a nice side effect, the code is now
equal to smp_32.h.

Signed-off-by: Glauber Costa <[email protected]>
---
include/asm-x86/smp_64.h | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/include/asm-x86/smp_64.h b/include/asm-x86/smp_64.h
index c53a011..2520633 100644
--- a/include/asm-x86/smp_64.h
+++ b/include/asm-x86/smp_64.h
@@ -52,12 +52,16 @@ static inline int logical_smp_processor_id(void)
return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
}

-#include <mach_apicdef.h>
+# ifdef APIC_DEFINITION
+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 GET_APIC_ID(*(u32 *)(APIC_BASE + APIC_ID));
}
+# endif /* APIC_DEFINITION */

#endif

--
1.5.0.6

2008-03-27 17:12:31

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 2/9] [PATCH] x86: provide bogus hard_smp_processor_id

We provide a bogus macro for x86_64 in case CONFIG_X86_LOCAL_APIC
is not set. It will always be set for x86_64, so the effect
is just to make the code equal to i386.

Signed-off-by: Glauber Costa <[email protected]>
---
include/asm-x86/smp_64.h | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/include/asm-x86/smp_64.h b/include/asm-x86/smp_64.h
index 2520633..c46585e 100644
--- a/include/asm-x86/smp_64.h
+++ b/include/asm-x86/smp_64.h
@@ -46,6 +46,8 @@ static inline int num_booting_cpus(void)

#define safe_smp_processor_id() smp_processor_id()

+#ifdef CONFIG_X86_LOCAL_APIC
+
static inline int logical_smp_processor_id(void)
{
/* we don't want to mark this access volatile - bad code generation */
@@ -63,5 +65,13 @@ static inline int hard_smp_processor_id(void)
}
# endif /* APIC_DEFINITION */

+#else /* CONFIG_X86_LOCAL_APIC */
+
+# ifndef CONFIG_SMP
+# define hard_smp_processor_id() 0
+# endif
+
+#endif /* CONFIG_X86_LOCAL_APIC */
+
#endif

--
1.5.0.6

2008-03-27 17:12:51

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 3/9] [PATCH] x86: merge hard/logical_smp_processor_id

The code is now the same between i386 and x86_64. We already
know what happens when it reaches this point: They go away
from the arch-specific headers, and suddenly appears in the common
header.

Signed-off-by: Glauber Costa <[email protected]>
---
include/asm-x86/smp.h | 27 +++++++++++++++++++++++++++
include/asm-x86/smp_32.h | 27 ---------------------------
include/asm-x86/smp_64.h | 27 ---------------------------
3 files changed, 27 insertions(+), 54 deletions(-)

diff --git a/include/asm-x86/smp.h b/include/asm-x86/smp.h
index 664f9c0..eb05804 100644
--- a/include/asm-x86/smp.h
+++ b/include/asm-x86/smp.h
@@ -128,6 +128,33 @@ void smp_store_cpu_info(int id);
# include "smp_64.h"
#endif

+#ifdef CONFIG_X86_LOCAL_APIC
+
+static inline int logical_smp_processor_id(void)
+{
+ /* we don't want to mark this access volatile - bad code generation */
+ return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
+}
+
+# ifdef APIC_DEFINITION
+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 GET_APIC_ID(*(u32 *)(APIC_BASE + APIC_ID));
+}
+# endif /* APIC_DEFINITION */
+
+#else /* CONFIG_X86_LOCAL_APIC */
+
+# ifndef CONFIG_SMP
+# define hard_smp_processor_id() 0
+# endif
+
+#endif /* CONFIG_X86_LOCAL_APIC */
+
#ifdef CONFIG_HOTPLUG_CPU
extern void cpu_exit_clear(void);
extern void cpu_uninit(void);
diff --git a/include/asm-x86/smp_32.h b/include/asm-x86/smp_32.h
index cb3ada2..53432db 100644
--- a/include/asm-x86/smp_32.h
+++ b/include/asm-x86/smp_32.h
@@ -42,32 +42,5 @@ static inline int num_booting_cpus(void)
#define safe_smp_processor_id() 0
#endif /* !CONFIG_SMP */

-#ifdef CONFIG_X86_LOCAL_APIC
-
-static inline int logical_smp_processor_id(void)
-{
- /* we don't want to mark this access volatile - bad code generation */
- return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
-}
-
-# ifdef APIC_DEFINITION
-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 GET_APIC_ID(*(u32 *)(APIC_BASE + APIC_ID));
-}
-# endif /* APIC_DEFINITION */
-
-#else /* CONFIG_X86_LOCAL_APIC */
-
-# ifndef CONFIG_SMP
-# define hard_smp_processor_id() 0
-# endif
-
-#endif /* CONFIG_X86_LOCAL_APIC */
-
#endif /* !ASSEMBLY */
#endif
diff --git a/include/asm-x86/smp_64.h b/include/asm-x86/smp_64.h
index c46585e..015d36e 100644
--- a/include/asm-x86/smp_64.h
+++ b/include/asm-x86/smp_64.h
@@ -46,32 +46,5 @@ static inline int num_booting_cpus(void)

#define safe_smp_processor_id() smp_processor_id()

-#ifdef CONFIG_X86_LOCAL_APIC
-
-static inline int logical_smp_processor_id(void)
-{
- /* we don't want to mark this access volatile - bad code generation */
- return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
-}
-
-# ifdef APIC_DEFINITION
-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 GET_APIC_ID(*(u32 *)(APIC_BASE + APIC_ID));
-}
-# endif /* APIC_DEFINITION */
-
-#else /* CONFIG_X86_LOCAL_APIC */
-
-# ifndef CONFIG_SMP
-# define hard_smp_processor_id() 0
-# endif
-
-#endif /* CONFIG_X86_LOCAL_APIC */
-
#endif

--
1.5.0.6

2008-03-27 17:13:12

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 5/9] [PATCH] x86: merge includes in smp.h

move all include directives from smp_{32,64}.h to smp.h.

Signed-off-by: Glauber Costa <[email protected]>
---
include/asm-x86/smp.h | 13 +++++++++++++
include/asm-x86/smp_32.h | 13 -------------
include/asm-x86/smp_64.h | 16 ----------------
3 files changed, 13 insertions(+), 29 deletions(-)

diff --git a/include/asm-x86/smp.h b/include/asm-x86/smp.h
index eb05804..1cd434d 100644
--- a/include/asm-x86/smp.h
+++ b/include/asm-x86/smp.h
@@ -5,6 +5,19 @@
#include <linux/init.h>
#include <asm/percpu.h>

+/*
+ * We need the APIC definitions automatically as part of 'smp.h'
+ */
+#ifdef CONFIG_X86_LOCAL_APIC
+# include <asm/mpspec.h>
+# include <asm/apic.h>
+# ifdef CONFIG_X86_IO_APIC
+# include <asm/io_apic.h>
+# endif
+#endif
+#include <asm/pda.h>
+#include <asm/thread_info.h>
+
extern cpumask_t cpu_callout_map;

extern int smp_num_siblings;
diff --git a/include/asm-x86/smp_32.h b/include/asm-x86/smp_32.h
index 53432db..694d324 100644
--- a/include/asm-x86/smp_32.h
+++ b/include/asm-x86/smp_32.h
@@ -2,19 +2,6 @@
#define __ASM_SMP_H

#ifndef __ASSEMBLY__
-#include <linux/cpumask.h>
-#include <linux/init.h>
-
-/*
- * We need the APIC definitions automatically as part of 'smp.h'
- */
-#ifdef CONFIG_X86_LOCAL_APIC
-# include <asm/mpspec.h>
-# include <asm/apic.h>
-# ifdef CONFIG_X86_IO_APIC
-# include <asm/io_apic.h>
-# endif
-#endif

extern cpumask_t cpu_callin_map;

diff --git a/include/asm-x86/smp_64.h b/include/asm-x86/smp_64.h
index b83151d..eead92e 100644
--- a/include/asm-x86/smp_64.h
+++ b/include/asm-x86/smp_64.h
@@ -1,22 +1,6 @@
#ifndef __ASM_SMP_H
#define __ASM_SMP_H

-#include <linux/cpumask.h>
-#include <linux/init.h>
-
-/*
- * We need the APIC definitions automatically as part of 'smp.h'
- */
-#ifdef CONFIG_X86_LOCAL_APIC
-# include <asm/mpspec.h>
-# include <asm/apic.h>
-# ifdef CONFIG_X86_IO_APIC
-# include <asm/io_apic.h>
-# endif
-#endif
-#include <asm/pda.h>
-#include <asm/thread_info.h>
-
extern cpumask_t cpu_initialized;
extern cpumask_t cpu_callin_map;

--
1.5.0.6

2008-03-27 17:13:31

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 4/9] [PATCH] x86: surround apic headers in apic definitions

Although those constants are always defined in x86_64,
and will have the effect of just including the headers
in the very way we did before, I'm doing this in a separate
patch to be conservative and avoid surprises.

Signed-off-by: Glauber Costa <[email protected]>
---
include/asm-x86/smp_64.h | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/asm-x86/smp_64.h b/include/asm-x86/smp_64.h
index 015d36e..b83151d 100644
--- a/include/asm-x86/smp_64.h
+++ b/include/asm-x86/smp_64.h
@@ -7,9 +7,13 @@
/*
* We need the APIC definitions automatically as part of 'smp.h'
*/
-#include <asm/apic.h>
-#include <asm/io_apic.h>
-#include <asm/mpspec.h>
+#ifdef CONFIG_X86_LOCAL_APIC
+# include <asm/mpspec.h>
+# include <asm/apic.h>
+# ifdef CONFIG_X86_IO_APIC
+# include <asm/io_apic.h>
+# endif
+#endif
#include <asm/pda.h>
#include <asm/thread_info.h>

--
1.5.0.6

2008-03-27 17:13:46

by Glauber Costa

[permalink] [raw]
Subject: [PATCH 6/9] [PATCH] x86: split safe_smp_processor_id

This implementation in x86_64 is clean and consistent, but we
sacrifice it for the sake of being equal to i386 (since the other
way around would be harder).

Signed-off-by: Glauber Costa <[email protected]>
---
include/asm-x86/smp_64.h | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/asm-x86/smp_64.h b/include/asm-x86/smp_64.h
index eead92e..8ea4952 100644
--- a/include/asm-x86/smp_64.h
+++ b/include/asm-x86/smp_64.h
@@ -27,12 +27,12 @@ static inline int num_booting_cpus(void)
return cpus_weight(cpu_callout_map);
}

+#define safe_smp_processor_id() smp_processor_id()
#else /* CONFIG_SMP */
#define stack_smp_processor_id() 0
-
+#define safe_smp_processor_id() 0
#endif /* !CONFIG_SMP */

-#define safe_smp_processor_id() smp_processor_id()

#endif

--
1.5.0.6

2008-03-28 09:08:15

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH 0/9] integrate smp.h


* Glauber Costa <[email protected]> wrote:

> Hi,
>
> here's the last series I was owing.
>
> After that, smp_32.h and smp_64.h are gone, merged into smp.h
>
> as usual, compiled tested in ~ 8 randconfigs for each architecture,
> and boot tested in all my hardware.

thanks, applied - lets see how it goes.

> 9 files changed, 104 insertions(+), 179 deletions(-)

neat!

Ingo