1. 程式人生 > >linux-2.6.0工作佇列關鍵資料結構

linux-2.6.0工作佇列關鍵資料結構

原始碼檔案: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決定。