aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/percpu.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/linux/percpu.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/linux/percpu.h')
-rw-r--r--include/linux/percpu.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/include/linux/percpu.h b/include/linux/percpu.h
new file mode 100644
index 000000000000..5451eb1e781d
--- /dev/null
+++ b/include/linux/percpu.h
@@ -0,0 +1,61 @@
1#ifndef __LINUX_PERCPU_H
2#define __LINUX_PERCPU_H
3#include <linux/spinlock.h> /* For preempt_disable() */
4#include <linux/slab.h> /* For kmalloc() */
5#include <linux/smp.h>
6#include <linux/string.h> /* For memset() */
7#include <asm/percpu.h>
8
9/* Enough to cover all DEFINE_PER_CPUs in kernel, including modules. */
10#ifndef PERCPU_ENOUGH_ROOM
11#define PERCPU_ENOUGH_ROOM 32768
12#endif
13
14/* Must be an lvalue. */
15#define get_cpu_var(var) (*({ preempt_disable(); &__get_cpu_var(var); }))
16#define put_cpu_var(var) preempt_enable()
17
18#ifdef CONFIG_SMP
19
20struct percpu_data {
21 void *ptrs[NR_CPUS];
22 void *blkp;
23};
24
25/*
26 * Use this to get to a cpu's version of the per-cpu object allocated using
27 * alloc_percpu. Non-atomic access to the current CPU's version should
28 * probably be combined with get_cpu()/put_cpu().
29 */
30#define per_cpu_ptr(ptr, cpu) \
31({ \
32 struct percpu_data *__p = (struct percpu_data *)~(unsigned long)(ptr); \
33 (__typeof__(ptr))__p->ptrs[(cpu)]; \
34})
35
36extern void *__alloc_percpu(size_t size, size_t align);
37extern void free_percpu(const void *);
38
39#else /* CONFIG_SMP */
40
41#define per_cpu_ptr(ptr, cpu) (ptr)
42
43static inline void *__alloc_percpu(size_t size, size_t align)
44{
45 void *ret = kmalloc(size, GFP_KERNEL);
46 if (ret)
47 memset(ret, 0, size);
48 return ret;
49}
50static inline void free_percpu(const void *ptr)
51{
52 kfree(ptr);
53}
54
55#endif /* CONFIG_SMP */
56
57/* Simple wrapper for the common case: zeros memory. */
58#define alloc_percpu(type) \
59 ((type *)(__alloc_percpu(sizeof(type), __alignof__(type))))
60
61#endif /* __LINUX_PERCPU_H */