~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/kthread.h

Version: ~ [ linux-5.5-rc7 ] ~ [ linux-5.4.13 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.97 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.166 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.210 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.210 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef _LINUX_KTHREAD_H
  2 #define _LINUX_KTHREAD_H
  3 /* Simple interface for creating and stopping kernel threads without mess. */
  4 #include <linux/err.h>
  5 #include <linux/sched.h>
  6 
  7 __printf(4, 5)
  8 struct task_struct *kthread_create_on_node(int (*threadfn)(void *data),
  9                                            void *data,
 10                                            int node,
 11                                            const char namefmt[], ...);
 12 
 13 #define kthread_create(threadfn, data, namefmt, arg...) \
 14         kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)
 15 
 16 
 17 struct task_struct *kthread_create_on_cpu(int (*threadfn)(void *data),
 18                                           void *data,
 19                                           unsigned int cpu,
 20                                           const char *namefmt);
 21 
 22 /**
 23  * kthread_run - create and wake a thread.
 24  * @threadfn: the function to run until signal_pending(current).
 25  * @data: data ptr for @threadfn.
 26  * @namefmt: printf-style name for the thread.
 27  *
 28  * Description: Convenient wrapper for kthread_create() followed by
 29  * wake_up_process().  Returns the kthread or ERR_PTR(-ENOMEM).
 30  */
 31 #define kthread_run(threadfn, data, namefmt, ...)                          \
 32 ({                                                                         \
 33         struct task_struct *__k                                            \
 34                 = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
 35         if (!IS_ERR(__k))                                                  \
 36                 wake_up_process(__k);                                      \
 37         __k;                                                               \
 38 })
 39 
 40 void kthread_bind(struct task_struct *k, unsigned int cpu);
 41 int kthread_stop(struct task_struct *k);
 42 bool kthread_should_stop(void);
 43 bool kthread_should_park(void);
 44 bool kthread_freezable_should_stop(bool *was_frozen);
 45 void *kthread_data(struct task_struct *k);
 46 int kthread_park(struct task_struct *k);
 47 void kthread_unpark(struct task_struct *k);
 48 void kthread_parkme(void);
 49 
 50 int kthreadd(void *unused);
 51 extern struct task_struct *kthreadd_task;
 52 extern int tsk_fork_get_node(struct task_struct *tsk);
 53 
 54 /*
 55  * Simple work processor based on kthread.
 56  *
 57  * This provides easier way to make use of kthreads.  A kthread_work
 58  * can be queued and flushed using queue/flush_kthread_work()
 59  * respectively.  Queued kthread_works are processed by a kthread
 60  * running kthread_worker_fn().
 61  */
 62 struct kthread_work;
 63 typedef void (*kthread_work_func_t)(struct kthread_work *work);
 64 
 65 struct kthread_worker {
 66         spinlock_t              lock;
 67         struct list_head        work_list;
 68         struct task_struct      *task;
 69         struct kthread_work     *current_work;
 70 };
 71 
 72 struct kthread_work {
 73         struct list_head        node;
 74         kthread_work_func_t     func;
 75         wait_queue_head_t       done;
 76         struct kthread_worker   *worker;
 77 };
 78 
 79 #define KTHREAD_WORKER_INIT(worker)     {                               \
 80         .lock = __SPIN_LOCK_UNLOCKED((worker).lock),                    \
 81         .work_list = LIST_HEAD_INIT((worker).work_list),                \
 82         }
 83 
 84 #define KTHREAD_WORK_INIT(work, fn)     {                               \
 85         .node = LIST_HEAD_INIT((work).node),                            \
 86         .func = (fn),                                                   \
 87         .done = __WAIT_QUEUE_HEAD_INITIALIZER((work).done),             \
 88         }
 89 
 90 #define DEFINE_KTHREAD_WORKER(worker)                                   \
 91         struct kthread_worker worker = KTHREAD_WORKER_INIT(worker)
 92 
 93 #define DEFINE_KTHREAD_WORK(work, fn)                                   \
 94         struct kthread_work work = KTHREAD_WORK_INIT(work, fn)
 95 
 96 /*
 97  * kthread_worker.lock and kthread_work.done need their own lockdep class
 98  * keys if they are defined on stack with lockdep enabled.  Use the
 99  * following macros when defining them on stack.
100  */
101 #ifdef CONFIG_LOCKDEP
102 # define KTHREAD_WORKER_INIT_ONSTACK(worker)                            \
103         ({ init_kthread_worker(&worker); worker; })
104 # define DEFINE_KTHREAD_WORKER_ONSTACK(worker)                          \
105         struct kthread_worker worker = KTHREAD_WORKER_INIT_ONSTACK(worker)
106 # define KTHREAD_WORK_INIT_ONSTACK(work, fn)                            \
107         ({ init_kthread_work((&work), fn); work; })
108 # define DEFINE_KTHREAD_WORK_ONSTACK(work, fn)                          \
109         struct kthread_work work = KTHREAD_WORK_INIT_ONSTACK(work, fn)
110 #else
111 # define DEFINE_KTHREAD_WORKER_ONSTACK(worker) DEFINE_KTHREAD_WORKER(worker)
112 # define DEFINE_KTHREAD_WORK_ONSTACK(work, fn) DEFINE_KTHREAD_WORK(work, fn)
113 #endif
114 
115 extern void __init_kthread_worker(struct kthread_worker *worker,
116                         const char *name, struct lock_class_key *key);
117 
118 #define init_kthread_worker(worker)                                     \
119         do {                                                            \
120                 static struct lock_class_key __key;                     \
121                 __init_kthread_worker((worker), "("#worker")->lock", &__key); \
122         } while (0)
123 
124 #define init_kthread_work(work, fn)                                     \
125         do {                                                            \
126                 memset((work), 0, sizeof(struct kthread_work));         \
127                 INIT_LIST_HEAD(&(work)->node);                          \
128                 (work)->func = (fn);                                    \
129                 init_waitqueue_head(&(work)->done);                     \
130         } while (0)
131 
132 int kthread_worker_fn(void *worker_ptr);
133 
134 bool queue_kthread_work(struct kthread_worker *worker,
135                         struct kthread_work *work);
136 void flush_kthread_work(struct kthread_work *work);
137 void flush_kthread_worker(struct kthread_worker *worker);
138 
139 #endif /* _LINUX_KTHREAD_H */
140 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp