Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
kthread.c File Reference
#include <linux/sched.h>
#include <linux/kthread.h>
#include <linux/completion.h>
#include <linux/err.h>
#include <linux/cpuset.h>
#include <linux/unistd.h>
#include <linux/file.h>
#include <linux/export.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/freezer.h>
#include <linux/ptrace.h>
#include <trace/events/sched.h>

Go to the source code of this file.

Data Structures

struct  kthread_create_info
 
struct  kthread
 
struct  kthread_flush_work
 

Macros

#define to_kthread(tsk)   container_of((tsk)->vfork_done, struct kthread, exited)
 

Enumerations

enum  KTHREAD_BITS { KTHREAD_IS_PER_CPU = 0, KTHREAD_SHOULD_STOP, KTHREAD_SHOULD_PARK, KTHREAD_IS_PARKED }
 

Functions

bool kthread_should_stop (void)
 
 EXPORT_SYMBOL (kthread_should_stop)
 
bool kthread_should_park (void)
 
bool kthread_freezable_should_stop (bool *was_frozen)
 
 EXPORT_SYMBOL_GPL (kthread_freezable_should_stop)
 
voidkthread_data (struct task_struct *task)
 
void kthread_parkme (void)
 
int tsk_fork_get_node (struct task_struct *tsk)
 
struct task_structkthread_create_on_node (int(*threadfn)(void *data), void *data, int node, const char namefmt[],...)
 
 EXPORT_SYMBOL (kthread_create_on_node)
 
void kthread_bind (struct task_struct *p, unsigned int cpu)
 
 EXPORT_SYMBOL (kthread_bind)
 
struct task_structkthread_create_on_cpu (int(*threadfn)(void *data), void *data, unsigned int cpu, const char *namefmt)
 
void kthread_unpark (struct task_struct *k)
 
int kthread_park (struct task_struct *k)
 
int kthread_stop (struct task_struct *k)
 
 EXPORT_SYMBOL (kthread_stop)
 
int kthreadd (void *unused)
 
void __init_kthread_worker (struct kthread_worker *worker, const char *name, struct lock_class_key *key)
 
 EXPORT_SYMBOL_GPL (__init_kthread_worker)
 
int kthread_worker_fn (void *worker_ptr)
 
 EXPORT_SYMBOL_GPL (kthread_worker_fn)
 
bool queue_kthread_work (struct kthread_worker *worker, struct kthread_work *work)
 
 EXPORT_SYMBOL_GPL (queue_kthread_work)
 
void flush_kthread_work (struct kthread_work *work)
 
 EXPORT_SYMBOL_GPL (flush_kthread_work)
 
void flush_kthread_worker (struct kthread_worker *worker)
 
 EXPORT_SYMBOL_GPL (flush_kthread_worker)
 

Variables

struct task_structkthreadd_task
 

Macro Definition Documentation

#define to_kthread (   tsk)    container_of((tsk)->vfork_done, struct kthread, exited)

Definition at line 55 of file kthread.c.

Enumeration Type Documentation

Enumerator:
KTHREAD_IS_PER_CPU 
KTHREAD_SHOULD_STOP 
KTHREAD_SHOULD_PARK 
KTHREAD_IS_PARKED 

Definition at line 48 of file kthread.c.

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.

EXPORT_SYMBOL ( kthread_should_stop  )
EXPORT_SYMBOL ( kthread_create_on_node  )
EXPORT_SYMBOL ( kthread_bind  )
EXPORT_SYMBOL ( kthread_stop  )
EXPORT_SYMBOL_GPL ( kthread_freezable_should_stop  )
EXPORT_SYMBOL_GPL ( __init_kthread_worker  )
EXPORT_SYMBOL_GPL ( kthread_worker_fn  )
EXPORT_SYMBOL_GPL ( queue_kthread_work  )
EXPORT_SYMBOL_GPL ( flush_kthread_work  )
EXPORT_SYMBOL_GPL ( flush_kthread_worker  )
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.

struct task_struct* kthread_create_on_node ( int(*)(void *data threadfn,
void data,
int  node,
const char  namefmt[],
  ... 
)
read

kthread_create_on_node - create a kthread. : the function to run until signal_pending(current). : data ptr for . : memory node number. : printf-style name for the thread.

Description: This helper function creates and names a kernel thread. The thread will be stopped: use wake_up_process() to start it. See also kthread_run().

If thread is going to be bound on a particular cpu, give its node in , to get NUMA affinity for kthread stack, or else give -1. When woken, the thread will run () with as its argument. () can either call do_exit() directly if it is a standalone thread for which no one will call kthread_stop(), or return when 'kthread_should_stop()' is true (which means kthread_stop() has been called). The return value should be zero or a negative error number; it will be passed to kthread_stop().

Returns a task_struct or ERR_PTR(-ENOMEM).

Definition at line 221 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

struct task_struct* kthreadd_task

Definition at line 24 of file kthread.c.