tasklet and workqueue(from linux kernel development )

来源:互联网 发布:ubuntu 开启samba 编辑:程序博客网 时间:2024/05/16 12:03

difference between those two mechanism :

tasklet is delayed for short time ,and it cannot sleep !

workqueue can be delayed for long time ,and it can sleep in the interrupt time !

workqueue is treated as kernel thread !

tasklet is made on the top of softirq!

they all used in interrupt handler (bottom half )!

what is the softirq ?

it is a mechanism  looksmart like software interrupt !

detail about workqueue:it deferred work into kernel thread! so code of this bottom half can run in the process context ! And workqueue has all the benefit of process !it is   scheduled and can be sleep !

use workqueue is going to create a new kernel thread !

workqueue is usually an interface to create a kernel thread to handle workqueue elsewhere!

kernel thread is called worker thread !

the workqueue subsystem implement and provide a default worker thread for deferred work queue!

default worker thread (kernel thread )is named events/n,n is the processor number !

that is how much processor ,then how many work thread!we can create our own kernel thread if necessary !

default worker thread is preferred !but also our own worker thread get some benefit !  

the worker thread is represented by the structure workerqueue _struct (like task_struct  of process )

 struct workqueue_struct {
struct cpu_workqueue_struct cpu_wq[NR_CPUS];/////////////////////////////////////////////////
struct list_head list;
const char *name;
int singlethread;
int freezeable;
int rt;
};

 

 

struct cpu_workqueue _struct is per -processor ! workqueue of each processor have one such structure !

struct cpu_workqueue_struct {
spinlock_t lock; /* lock protecting this structure */
struct list_head worklist; /* list of work */
wait_queue_head_t more_work;
struct work_struct *current_struct;
struct workqueue_struct *wq; /* associated workqueue_struct */
task_t *thread; /* associated thread *//////////////////////////////////////////////////////////////
};

each processor have one worker thread !

 

struct work_struct {
atomic_long_t data;
struct list_head entry;
work_func_t func;
};

 

function associated with worker thread

those structure is strung into a link list ! one node is each structure of worker thread of each processor

原创粉丝点击