Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
kthread.h File Reference
#include <linux/err.h>
#include <linux/sched.h>

Go to the source code of this file.

Data Structures

struct  kthread_worker
 
struct  kthread_work
 

Macros

#define kthread_create(threadfn, data, namefmt, arg...)   kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)
 
#define kthread_run(threadfn, data, namefmt,...)
 
#define KTHREAD_WORKER_INIT(worker)
 
#define KTHREAD_WORK_INIT(work, fn)
 
#define DEFINE_KTHREAD_WORKER(worker)   struct kthread_worker worker = KTHREAD_WORKER_INIT(worker)
 
#define DEFINE_KTHREAD_WORK(work, fn)   struct kthread_work work = KTHREAD_WORK_INIT(work, fn)
 
#define DEFINE_KTHREAD_WORKER_ONSTACK(worker)   DEFINE_KTHREAD_WORKER(worker)
 
#define DEFINE_KTHREAD_WORK_ONSTACK(work, fn)   DEFINE_KTHREAD_WORK(work, fn)
 
#define init_kthread_worker(worker)
 
#define init_kthread_work(work, fn)
 

Typedefs

typedef void(* kthread_work_func_t )(struct kthread_work *work)
 

Functions

 __printf (4, 5) struct task_struct *kthread_create_on_node(int(*threadfn)(void *data)
 
struct task_structkthread_create_on_cpu (int(*threadfn)(void *data), void *data, unsigned int cpu, const char *namefmt)
 
void kthread_bind (struct task_struct *k, unsigned int cpu)
 
int kthread_stop (struct task_struct *k)
 
bool kthread_should_stop (void)
 
bool kthread_should_park (void)
 
bool kthread_freezable_should_stop (bool *was_frozen)
 
voidkthread_data (struct task_struct *k)
 
int kthread_park (struct task_struct *k)
 
void kthread_unpark (struct task_struct *k)
 
void kthread_parkme (void)
 
int kthreadd (void *unused)
 
int tsk_fork_get_node (struct task_struct *tsk)
 
void __init_kthread_worker (struct kthread_worker *worker, const char *name, struct lock_class_key *key)
 
int kthread_worker_fn (void *worker_ptr)
 
bool queue_kthread_work (struct kthread_worker *worker, struct kthread_work *work)
 
void flush_kthread_work (struct kthread_work *work)
 
void flush_kthread_worker (struct kthread_worker *worker)
 

Variables

voiddata
 
void int node
 
void int const char namefmt []
 
struct task_structkthreadd_task
 

Macro Definition Documentation

#define DEFINE_KTHREAD_WORK (   work,
  fn 
)    struct kthread_work work = KTHREAD_WORK_INIT(work, fn)

Definition at line 93 of file kthread.h.

#define DEFINE_KTHREAD_WORK_ONSTACK (   work,
  fn 
)    DEFINE_KTHREAD_WORK(work, fn)

Definition at line 112 of file kthread.h.

#define DEFINE_KTHREAD_WORKER (   worker)    struct kthread_worker worker = KTHREAD_WORKER_INIT(worker)

Definition at line 90 of file kthread.h.

#define DEFINE_KTHREAD_WORKER_ONSTACK (   worker)    DEFINE_KTHREAD_WORKER(worker)

Definition at line 111 of file kthread.h.

#define init_kthread_work (   work,
  fn 
)
Value:
do { \
memset((work), 0, sizeof(struct kthread_work)); \
INIT_LIST_HEAD(&(work)->node); \
(work)->func = (fn); \
init_waitqueue_head(&(work)->done); \
} while (0)

Definition at line 124 of file kthread.h.

#define init_kthread_worker (   worker)
Value:
do { \
static struct lock_class_key __key; \
__init_kthread_worker((worker), "("#worker")->lock", &__key); \
} while (0)

Definition at line 118 of file kthread.h.

#define kthread_create (   threadfn,
  data,
  namefmt,
  arg... 
)    kthread_create_on_node(threadfn, data, -1, namefmt, ##arg)

Definition at line 13 of file kthread.h.

#define kthread_run (   threadfn,
  data,
  namefmt,
  ... 
)
Value:
({ \
= kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \
if (!IS_ERR(__k)) \
wake_up_process(__k); \
__k; \
})

kthread_run - create and wake a thread. : the function to run until signal_pending(current). : data ptr for . : printf-style name for the thread.

Description: Convenient wrapper for kthread_create() followed by wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM).

Definition at line 31 of file kthread.h.

#define KTHREAD_WORK_INIT (   work,
  fn 
)
Value:
{ \
.node = LIST_HEAD_INIT((work).node), \
.func = (fn), \
}

Definition at line 84 of file kthread.h.

#define KTHREAD_WORKER_INIT (   worker)
Value:
{ \
.lock = __SPIN_LOCK_UNLOCKED((worker).lock), \
.work_list = LIST_HEAD_INIT((worker).work_list), \
}

Definition at line 79 of file kthread.h.

Typedef Documentation

typedef void(* kthread_work_func_t)(struct kthread_work *work)

Definition at line 63 of file kthread.h.

Function Documentation

void __init_kthread_worker ( struct kthread_worker worker,
const char name,
struct lock_class_key key 
)

Definition at line 460 of file kthread.c.

__printf ( ,
 
)
void flush_kthread_work ( struct kthread_work work)

flush_kthread_work - flush a kthread_work : work to flush

If is queued or executing, wait for it to finish execution.

Definition at line 581 of file kthread.c.

void flush_kthread_worker ( struct kthread_worker worker)

flush_kthread_worker - flush all current works on a kthread_worker : worker to flush

Wait until all currently executing or pending works on are finished.

Definition at line 622 of file kthread.c.

void kthread_bind ( struct task_struct p,
unsigned int  cpu 
)

kthread_bind - bind a just-created kthread to a cpu. : thread created by kthread_create(). : cpu (might not be online, must be possible) for to run on.

Description: This function is equivalent to set_cpus_allowed(), except that doesn't need to be online, and the thread must be stopped (i.e., just returned from kthread_create()).

Definition at line 275 of file kthread.c.

struct task_struct* kthread_create_on_cpu ( int(*)(void *data threadfn,
void data,
unsigned int  cpu,
const char namefmt 
)
read

kthread_create_on_cpu - Create a cpu bound kthread : the function to run until signal_pending(current). : data ptr for . : The cpu on which the thread should be bound, : printf-style name for the thread. Format is restricted to "name.*%u". Code fills in cpu number.

Description: This helper function creates and names a kernel thread The thread will be woken and put into park mode.

Definition at line 297 of file kthread.c.

void* kthread_data ( struct task_struct task)

kthread_data - return data value specified on kthread creation : kthread task in question

Return the data value specified when kthread was created. The caller is responsible for ensuring the validity of when calling this function.

Definition at line 120 of file kthread.c.

bool kthread_freezable_should_stop ( bool was_frozen)

kthread_freezable_should_stop - should this freezable kthread return now? : optional out parameter, indicates whether current was frozen

kthread_should_stop() for freezable kthreads, which will enter refrigerator if necessary. This function is safe from kthread_stop() / freezer deadlock and freezable kthreads should use this function instead of calling try_to_freeze() directly.

Definition at line 96 of file kthread.c.

int kthread_park ( struct task_struct k)

kthread_park - park a thread created by kthread_create(). : thread created by kthread_create().

Sets kthread_should_park() for to return true, wakes it, and waits for it to return. This can also be called after kthread_create() instead of calling wake_up_process(): the thread will park without calling threadfn().

Returns 0 if the thread is parked, -ENOSYS if the thread exited. If called by the kthread itself just the park bit is set.

Definition at line 368 of file kthread.c.

void kthread_parkme ( void  )

Definition at line 138 of file kthread.c.

bool kthread_should_park ( void  )

kthread_should_park - should this kthread park now?

When someone calls kthread_park() on your kthread, it will be woken and this will return true. You should then do the necessary cleanup and call kthread_parkme()

Similar to kthread_should_stop(), but this keeps the thread alive and in a park position. kthread_unpark() "restarts" the thread and calls the thread function again.

Definition at line 82 of file kthread.c.

bool kthread_should_stop ( void  )

kthread_should_stop - should this kthread return now?

When someone calls kthread_stop() on your kthread, it will be woken and this will return true. You should then return, and your return value will be passed through to kthread_stop().

Definition at line 65 of file kthread.c.

int kthread_stop ( struct task_struct k)

kthread_stop - stop a thread created by kthread_create(). : thread created by kthread_create().

Sets kthread_should_stop() for to return true, wakes it, and waits for it to exit. This can also be called after kthread_create() instead of calling wake_up_process(): the thread will exit without calling threadfn().

If threadfn() may call do_exit() itself, the caller must ensure task_struct can't go away.

Returns the result of threadfn(), or %-EINTR if wake_up_process() was never called.

Definition at line 402 of file kthread.c.

void kthread_unpark ( struct task_struct k)

kthread_unpark - unpark a thread created by kthread_create(). : thread created by kthread_create().

Sets kthread_should_park() for to return false, wakes it, and waits for it to return. If the thread is marked percpu then its bound to the cpu again.

Definition at line 335 of file kthread.c.

int kthread_worker_fn ( void worker_ptr)

kthread_worker_fn - kthread function to process kthread_worker : pointer to initialized kthread_worker

This function can be used as to kthread_create() or kthread_run() with argument pointing to an initialized kthread_worker. The started kthread will process work_list until the it is stopped with kthread_stop(). A kthread can also call this function directly after extra initialization.

Different kthreads can be used for the same kthread_worker as long as there's only one kthread attached to it at any given time. A kthread_worker without an attached kthread simply collects queued kthread_works.

Definition at line 486 of file kthread.c.

int kthreadd ( void unused)

Definition at line 423 of file kthread.c.

bool queue_kthread_work ( struct kthread_worker worker,
struct kthread_work work 
)

queue_kthread_work - queue a kthread_work : target kthread_worker : kthread_work to queue

Queue to work processor for async execution. must have been created with kthread_worker_create(). Returns true if was successfully queued, false if it was already pending.

Definition at line 547 of file kthread.c.

int tsk_fork_get_node ( struct task_struct tsk)

Definition at line 175 of file kthread.c.

Variable Documentation

Definition at line 9 of file kthread.h.

struct task_struct* kthreadd_task

Definition at line 24 of file kthread.c.

void int const char namefmt[]

Definition at line 9 of file kthread.h.

Definition at line 9 of file kthread.h.