percpu.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #ifndef _ASM_GENERIC_PERCPU_H_
  2. #define _ASM_GENERIC_PERCPU_H_
  3. #include <linux/compiler.h>
  4. #include <linux/threads.h>
  5. #ifdef CONFIG_SMP
  6. extern unsigned long __per_cpu_offset[NR_CPUS];
  7. #define per_cpu_offset(x) (__per_cpu_offset[x])
  8. /* var is in discarded region: offset to particular copy we want */
  9. #define per_cpu(var, cpu) (*({ \
  10. extern int simple_identifier_##var(void); \
  11. RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]); }))
  12. #define __get_cpu_var(var) per_cpu(var, smp_processor_id())
  13. #define __raw_get_cpu_var(var) per_cpu(var, raw_smp_processor_id())
  14. /* A macro to avoid #include hell... */
  15. #define percpu_modcopy(pcpudst, src, size) \
  16. do { \
  17. unsigned int __i; \
  18. for_each_possible_cpu(__i) \
  19. memcpy((pcpudst)+__per_cpu_offset[__i], \
  20. (src), (size)); \
  21. } while (0)
  22. #else /* ! SMP */
  23. #define per_cpu(var, cpu) (*((void)(cpu), &per_cpu__##var))
  24. #define __get_cpu_var(var) per_cpu__##var
  25. #define __raw_get_cpu_var(var) per_cpu__##var
  26. #endif /* SMP */
  27. #define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##name
  28. #endif /* _ASM_GENERIC_PERCPU_H_ */