From 3a99ebd35f838e54aa4b285c31478e025da227b5 Mon Sep 17 00:00:00 2001 From: Christoph Lameter Date: Wed, 31 Oct 2007 17:30:06 -0700 Subject: [PATCH] this_cpu Support for this_cpu_ptr() is important for those arches that allow a faster way to get to the per cpu area of the local processor. Signed-off-by: Christoph Lameter --- include/asm-generic/percpu.h | 4 ++++ include/asm-ia64/percpu.h | 3 +++ include/asm-powerpc/percpu.h | 3 +++ include/asm-s390/percpu.h | 4 ++++ include/asm-sparc64/percpu.h | 2 ++ include/asm-x86/percpu_32.h | 2 ++ include/asm-x86/percpu_64.h | 4 ++++ include/linux/percpu.h | 7 +++++++ 8 files changed, 29 insertions(+), 0 deletions(-) diff --git a/include/asm-generic/percpu.h b/include/asm-generic/percpu.h index d85172e..e89327f 100644 --- a/include/asm-generic/percpu.h +++ b/include/asm-generic/percpu.h @@ -26,6 +26,8 @@ extern unsigned long __per_cpu_offset[NR_CPUS]; #define __get_cpu_var(var) per_cpu(var, smp_processor_id()) #define __raw_get_cpu_var(var) per_cpu(var, raw_smp_processor_id()) +#define this_cpu_offset() __per_cpu_offset(raw_smp_processor_id()) + /* A macro to avoid #include hell... */ #define percpu_modcopy(pcpudst, src, size) \ do { \ @@ -53,4 +55,6 @@ do { \ #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var) #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var) +#define this_cpu_offset() 0 + #endif /* _ASM_GENERIC_PERCPU_H_ */ diff --git a/include/asm-ia64/percpu.h b/include/asm-ia64/percpu.h index c4f1e32..e238044 100644 --- a/include/asm-ia64/percpu.h +++ b/include/asm-ia64/percpu.h @@ -51,6 +51,8 @@ extern unsigned long __per_cpu_offset[NR_CPUS]; /* Equal to __per_cpu_offset[smp_processor_id()], but faster to access: */ DECLARE_PER_CPU(unsigned long, local_per_cpu_offset); +#define this_cpu_offset() __ia64_per_cpu_var(local_per_cpu_offset) + #define per_cpu(var, cpu) (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu])) #define __get_cpu_var(var) (*RELOC_HIDE(&per_cpu__##var, __ia64_per_cpu_var(local_per_cpu_offset))) #define __raw_get_cpu_var(var) (*RELOC_HIDE(&per_cpu__##var, __ia64_per_cpu_var(local_per_cpu_offset))) @@ -65,6 +67,7 @@ extern void *per_cpu_init(void); #define __get_cpu_var(var) per_cpu__##var #define __raw_get_cpu_var(var) per_cpu__##var #define per_cpu_init() (__phys_per_cpu_start) +#define this_cpu_offset() 0 #endif /* SMP */ diff --git a/include/asm-powerpc/percpu.h b/include/asm-powerpc/percpu.h index 6b22962..aad82b1 100644 --- a/include/asm-powerpc/percpu.h +++ b/include/asm-powerpc/percpu.h @@ -16,6 +16,8 @@ #define __my_cpu_offset() get_paca()->data_offset #define per_cpu_offset(x) (__per_cpu_offset(x)) +#define this_cpu_offset() __my_cpu_offset() + /* Separate out the type, so (int[3], foo) works. */ #define DEFINE_PER_CPU(type, name) \ __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name @@ -51,6 +53,7 @@ extern void setup_per_cpu_areas(void); #define per_cpu(var, cpu) (*((void)(cpu), &per_cpu__##var)) #define __get_cpu_var(var) per_cpu__##var #define __raw_get_cpu_var(var) per_cpu__##var +#define this_cpu_offset() 0 #endif /* SMP */ diff --git a/include/asm-s390/percpu.h b/include/asm-s390/percpu.h index 545857e..ad94708 100644 --- a/include/asm-s390/percpu.h +++ b/include/asm-s390/percpu.h @@ -51,6 +51,8 @@ extern unsigned long __per_cpu_offset[NR_CPUS]; #define per_cpu(var,cpu) __reloc_hide(var,__per_cpu_offset[cpu]) #define per_cpu_offset(x) (__per_cpu_offset[x]) +#define this_cpu_offset() S390_lowcore.percpu_offset + /* A macro to avoid #include hell... */ #define percpu_modcopy(pcpudst, src, size) \ do { \ @@ -71,6 +73,8 @@ do { \ #define __raw_get_cpu_var(var) __reloc_hide(var,0) #define per_cpu(var,cpu) __reloc_hide(var,0) +#define this_cpu_offset() 0 + #endif /* SMP */ #define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##name diff --git a/include/asm-sparc64/percpu.h b/include/asm-sparc64/percpu.h index a1f53a4..6c35872 100644 --- a/include/asm-sparc64/percpu.h +++ b/include/asm-sparc64/percpu.h @@ -5,6 +5,8 @@ register unsigned long __local_per_cpu_offset asm("g5"); +#define this_cpu_offset() __local_per_cpu_offset + #ifdef CONFIG_SMP #define setup_per_cpu_areas() do { } while (0) diff --git a/include/asm-x86/percpu_32.h b/include/asm-x86/percpu_32.h index a7ebd43..9a5bb5c 100644 --- a/include/asm-x86/percpu_32.h +++ b/include/asm-x86/percpu_32.h @@ -72,6 +72,8 @@ DECLARE_PER_CPU(unsigned long, this_cpu_off); RELOC_HIDE(&per_cpu__##var, x86_read_percpu(this_cpu_off)); \ })) +#define this_cpu_offset() x86_read_percpu(this_cpu_off) + #define __get_cpu_var(var) __raw_get_cpu_var(var) /* A macro to avoid #include hell... */ diff --git a/include/asm-x86/percpu_64.h b/include/asm-x86/percpu_64.h index 5abd482..697ce96 100644 --- a/include/asm-x86/percpu_64.h +++ b/include/asm-x86/percpu_64.h @@ -14,6 +14,8 @@ #define __per_cpu_offset(cpu) (cpu_pda(cpu)->data_offset) #define __my_cpu_offset() read_pda(data_offset) +#define this_cpu_offset() read_pda(data_offset) + #define per_cpu_offset(x) (__per_cpu_offset(x)) /* Separate out the type, so (int[3], foo) works. */ @@ -58,6 +60,8 @@ extern void setup_per_cpu_areas(void); #define __get_cpu_var(var) per_cpu__##var #define __raw_get_cpu_var(var) per_cpu__##var +#define this_cpu_offset() 0 + #endif /* SMP */ #define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##name diff --git a/include/linux/percpu.h b/include/linux/percpu.h index e77250a..4b167c0 100644 --- a/include/linux/percpu.h +++ b/include/linux/percpu.h @@ -51,6 +51,13 @@ (__typeof__(ptr))(p + q); \ }) +#define this_cpu_ptr(ptr) \ +({ \ + void *p = ptr; \ + (__typeof__(ptr))(p + this_cpu_offset()); \ +}) + + extern void *__alloc_percpu(size_t size); extern void percpu_free(void *__pdata); -- 1.5.3.4