Blame view

include/asm-generic/percpu.h 1.77 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  #ifndef _ASM_GENERIC_PERCPU_H_
  #define _ASM_GENERIC_PERCPU_H_
  #include <linux/compiler.h>
ae1ee11be   Rusty Russell   [PATCH] i386: Use...
4
  #include <linux/threads.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
  
  #define __GENERIC_PER_CPU
  #ifdef CONFIG_SMP
  
  extern unsigned long __per_cpu_offset[NR_CPUS];
a875a69f8   Ingo Molnar   [PATCH] lockdep: ...
10
  #define per_cpu_offset(x) (__per_cpu_offset[x])
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
  /* Separate out the type, so (int[3], foo) works. */
  #define DEFINE_PER_CPU(type, name) \
      __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
5fb7dc37d   Fenghua Yu   define new percpu...
14
15
16
17
  #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name)		\
      __attribute__((__section__(".data.percpu.shared_aligned"))) \
      __typeof__(type) per_cpu__##name				\
      ____cacheline_aligned_in_smp
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
  /* var is in discarded region: offset to particular copy we want */
632bbfeee   Jan Blunck   [PATCH] trigger a...
19
  #define per_cpu(var, cpu) (*({				\
a666ecfbf   Jan Blunck   [PATCH] Fix typo ...
20
  	extern int simple_identifier_##var(void);	\
632bbfeee   Jan Blunck   [PATCH] trigger a...
21
  	RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]); }))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  #define __get_cpu_var(var) per_cpu(var, smp_processor_id())
bfe5d8341   Paul Mackerras   [PATCH] Define __...
23
  #define __raw_get_cpu_var(var) per_cpu(var, raw_smp_processor_id())
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
  
  /* A macro to avoid #include hell... */
  #define percpu_modcopy(pcpudst, src, size)			\
  do {								\
  	unsigned int __i;					\
0a9450227   KAMEZAWA Hiroyuki   [PATCH] for_each_...
29
  	for_each_possible_cpu(__i)				\
394e3902c   Andrew Morton   [PATCH] more for_...
30
31
  		memcpy((pcpudst)+__per_cpu_offset[__i],		\
  		       (src), (size));				\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
36
  } while (0)
  #else /* ! SMP */
  
  #define DEFINE_PER_CPU(type, name) \
      __typeof__(type) per_cpu__##name
5fb7dc37d   Fenghua Yu   define new percpu...
37
38
  #define DEFINE_PER_CPU_SHARED_ALIGNED(type, name)	\
      DEFINE_PER_CPU(type, name)
11c80c836   Jan Beulich   [PATCH] adjust pe...
39
  #define per_cpu(var, cpu)			(*((void)(cpu), &per_cpu__##var))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
  #define __get_cpu_var(var)			per_cpu__##var
bfe5d8341   Paul Mackerras   [PATCH] Define __...
41
  #define __raw_get_cpu_var(var)			per_cpu__##var
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
46
47
48
49
50
  
  #endif	/* SMP */
  
  #define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##name
  
  #define EXPORT_PER_CPU_SYMBOL(var) EXPORT_SYMBOL(per_cpu__##var)
  #define EXPORT_PER_CPU_SYMBOL_GPL(var) EXPORT_SYMBOL_GPL(per_cpu__##var)
  
  #endif /* _ASM_GENERIC_PERCPU_H_ */