源码文件:linux-2.6.0/kernel/workqueue.c
工作队列结构体
/*
* The externally visible workqueue abstraction is an array of
* per-CPU workqueues:
*/
struct
workqueue_struct {
struct
cpu_workqueue_struct cpu_wq[NR_CPUS];
};
每cpu工作队列结构体
/*
* The per-CPU workqueue.
*
* The sequence counters are for flush_scheduled_work(). It wants to wait
* until until all currently-scheduled works are completed, but it doesn't
* want to be livelocked by new, incoming ones. So it waits until
* remove_sequence is >= the insert_sequence which pertained when
* flush_scheduled_work() was called.
*/
struct
cpu_workqueue_struct {
spinlock_t
lock;
long
remove_sequence;
/* Least-recently added (next to run) */
long
insert_sequence;
/* Next to add */
struct
list_head worklist;
wait_queue_head_t
more_work;
wait_queue_head_t
work_done;
struct
workqueue_struct
*
wq;
task_t
*
thread;
struct
completion
exit
;
} ____cacheline_aligned;
涉及到工作队列的主要结构体就上面的2个。2.6.0版本中,工作队列是比较好理解的。cpu_workqueue_struct结构体分布在每个CPU上,它包含一条工作链,链中的每个节点为work_struct。在创建一个work_struct时,把它插入到cpu_workqueue_struct结构体中的工作链表尾部。至于这个work_struct插入到哪个CPU上的工作链,由所在的CPU决定。