diff options
Diffstat (limited to 'include/linux/kthread.h')
-rw-r--r-- | include/linux/kthread.h | 61 |
1 files changed, 46 insertions, 15 deletions
diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 685ea65eb803..1e923e5e88e8 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h | |||
@@ -4,10 +4,15 @@ | |||
4 | #include <linux/err.h> | 4 | #include <linux/err.h> |
5 | #include <linux/sched.h> | 5 | #include <linux/sched.h> |
6 | 6 | ||
7 | struct task_struct *kthread_create(int (*threadfn)(void *data), | 7 | struct task_struct *kthread_create_on_node(int (*threadfn)(void *data), |
8 | void *data, | 8 | void *data, |
9 | const char namefmt[], ...) | 9 | int node, |
10 | __attribute__((format(printf, 3, 4))); | 10 | const char namefmt[], ...) |
11 | __attribute__((format(printf, 4, 5))); | ||
12 | |||
13 | #define kthread_create(threadfn, data, namefmt, arg...) \ | ||
14 | kthread_create_on_node(threadfn, data, -1, namefmt, ##arg) | ||
15 | |||
11 | 16 | ||
12 | /** | 17 | /** |
13 | * kthread_run - create and wake a thread. | 18 | * kthread_run - create and wake a thread. |
@@ -34,6 +39,7 @@ void *kthread_data(struct task_struct *k); | |||
34 | 39 | ||
35 | int kthreadd(void *unused); | 40 | int kthreadd(void *unused); |
36 | extern struct task_struct *kthreadd_task; | 41 | extern struct task_struct *kthreadd_task; |
42 | extern int tsk_fork_get_node(struct task_struct *tsk); | ||
37 | 43 | ||
38 | /* | 44 | /* |
39 | * Simple work processor based on kthread. | 45 | * Simple work processor based on kthread. |
@@ -64,7 +70,7 @@ struct kthread_work { | |||
64 | }; | 70 | }; |
65 | 71 | ||
66 | #define KTHREAD_WORKER_INIT(worker) { \ | 72 | #define KTHREAD_WORKER_INIT(worker) { \ |
67 | .lock = SPIN_LOCK_UNLOCKED, \ | 73 | .lock = __SPIN_LOCK_UNLOCKED((worker).lock), \ |
68 | .work_list = LIST_HEAD_INIT((worker).work_list), \ | 74 | .work_list = LIST_HEAD_INIT((worker).work_list), \ |
69 | } | 75 | } |
70 | 76 | ||
@@ -81,16 +87,41 @@ struct kthread_work { | |||
81 | #define DEFINE_KTHREAD_WORK(work, fn) \ | 87 | #define DEFINE_KTHREAD_WORK(work, fn) \ |
82 | struct kthread_work work = KTHREAD_WORK_INIT(work, fn) | 88 | struct kthread_work work = KTHREAD_WORK_INIT(work, fn) |
83 | 89 | ||
84 | static inline void init_kthread_worker(struct kthread_worker *worker) | 90 | /* |
85 | { | 91 | * kthread_worker.lock and kthread_work.done need their own lockdep class |
86 | *worker = (struct kthread_worker)KTHREAD_WORKER_INIT(*worker); | 92 | * keys if they are defined on stack with lockdep enabled. Use the |
87 | } | 93 | * following macros when defining them on stack. |
88 | 94 | */ | |
89 | static inline void init_kthread_work(struct kthread_work *work, | 95 | #ifdef CONFIG_LOCKDEP |
90 | kthread_work_func_t fn) | 96 | # define KTHREAD_WORKER_INIT_ONSTACK(worker) \ |
91 | { | 97 | ({ init_kthread_worker(&worker); worker; }) |
92 | *work = (struct kthread_work)KTHREAD_WORK_INIT(*work, fn); | 98 | # define DEFINE_KTHREAD_WORKER_ONSTACK(worker) \ |
93 | } | 99 | struct kthread_worker worker = KTHREAD_WORKER_INIT_ONSTACK(worker) |
100 | # define KTHREAD_WORK_INIT_ONSTACK(work, fn) \ | ||
101 | ({ init_kthread_work((&work), fn); work; }) | ||
102 | # define DEFINE_KTHREAD_WORK_ONSTACK(work, fn) \ | ||
103 | struct kthread_work work = KTHREAD_WORK_INIT_ONSTACK(work, fn) | ||
104 | #else | ||
105 | # define DEFINE_KTHREAD_WORKER_ONSTACK(worker) DEFINE_KTHREAD_WORKER(worker) | ||
106 | # define DEFINE_KTHREAD_WORK_ONSTACK(work, fn) DEFINE_KTHREAD_WORK(work, fn) | ||
107 | #endif | ||
108 | |||
109 | extern void __init_kthread_worker(struct kthread_worker *worker, | ||
110 | const char *name, struct lock_class_key *key); | ||
111 | |||
112 | #define init_kthread_worker(worker) \ | ||
113 | do { \ | ||
114 | static struct lock_class_key __key; \ | ||
115 | __init_kthread_worker((worker), "("#worker")->lock", &__key); \ | ||
116 | } while (0) | ||
117 | |||
118 | #define init_kthread_work(work, fn) \ | ||
119 | do { \ | ||
120 | memset((work), 0, sizeof(struct kthread_work)); \ | ||
121 | INIT_LIST_HEAD(&(work)->node); \ | ||
122 | (work)->func = (fn); \ | ||
123 | init_waitqueue_head(&(work)->done); \ | ||
124 | } while (0) | ||
94 | 125 | ||
95 | int kthread_worker_fn(void *worker_ptr); | 126 | int kthread_worker_fn(void *worker_ptr); |
96 | 127 | ||