aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kthread.h
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2010-06-29 04:07:09 -0400
committerTejun Heo <tj@kernel.org>2010-06-29 04:07:09 -0400
commitb56c0d8937e665a27d90517ee7a746d0aa05af46 (patch)
treefefff33fe3bbebfc8d60ba581e5343dc6cb56a70 /include/linux/kthread.h
parent53c5f5ba42c194cb13dd3083ed425f2c5b1ec439 (diff)
kthread: implement kthread_worker
Implement simple work processor for kthread. This is to ease using kthread. Single thread workqueue used to be used for things like this but workqueue won't guarantee fixed kthread association anymore to enable worker sharing. This can be used in cases where specific kthread association is necessary, for example, when it should have RT priority or be assigned to certain cgroup. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'include/linux/kthread.h')
-rw-r--r--include/linux/kthread.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index aabc8a13ba71..f93cb6979edc 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -34,4 +34,68 @@ int kthread_should_stop(void);
34int kthreadd(void *unused); 34int kthreadd(void *unused);
35extern struct task_struct *kthreadd_task; 35extern struct task_struct *kthreadd_task;
36 36
37/*
38 * Simple work processor based on kthread.
39 *
40 * This provides easier way to make use of kthreads. A kthread_work
41 * can be queued and flushed using queue/flush_kthread_work()
42 * respectively. Queued kthread_works are processed by a kthread
43 * running kthread_worker_fn().
44 *
45 * A kthread_work can't be freed while it is executing.
46 */
47struct kthread_work;
48typedef void (*kthread_work_func_t)(struct kthread_work *work);
49
50struct kthread_worker {
51 spinlock_t lock;
52 struct list_head work_list;
53 struct task_struct *task;
54};
55
56struct kthread_work {
57 struct list_head node;
58 kthread_work_func_t func;
59 wait_queue_head_t done;
60 atomic_t flushing;
61 int queue_seq;
62 int done_seq;
63};
64
65#define KTHREAD_WORKER_INIT(worker) { \
66 .lock = SPIN_LOCK_UNLOCKED, \
67 .work_list = LIST_HEAD_INIT((worker).work_list), \
68 }
69
70#define KTHREAD_WORK_INIT(work, fn) { \
71 .node = LIST_HEAD_INIT((work).node), \
72 .func = (fn), \
73 .done = __WAIT_QUEUE_HEAD_INITIALIZER((work).done), \
74 .flushing = ATOMIC_INIT(0), \
75 }
76
77#define DEFINE_KTHREAD_WORKER(worker) \
78 struct kthread_worker worker = KTHREAD_WORKER_INIT(worker)
79
80#define DEFINE_KTHREAD_WORK(work, fn) \
81 struct kthread_work work = KTHREAD_WORK_INIT(work, fn)
82
83static inline void init_kthread_worker(struct kthread_worker *worker)
84{
85 *worker = (struct kthread_worker)KTHREAD_WORKER_INIT(*worker);
86}
87
88static inline void init_kthread_work(struct kthread_work *work,
89 kthread_work_func_t fn)
90{
91 *work = (struct kthread_work)KTHREAD_WORK_INIT(*work, fn);
92}
93
94int kthread_worker_fn(void *worker_ptr);
95
96bool queue_kthread_work(struct kthread_worker *worker,
97 struct kthread_work *work);
98void flush_kthread_work(struct kthread_work *work);
99void flush_kthread_worker(struct kthread_worker *worker);
100
37#endif /* _LINUX_KTHREAD_H */ 101#endif /* _LINUX_KTHREAD_H */