Article Title: how to operate a work queue in the Linux operating system kernel. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Copyleft of this document belongs to yfydz and can be freely copied and reproduced when published using GPL. it is strictly prohibited to be used for any commercial purposes.
Msn: yfydz_no1@hotmail.com
Source: http://yfydz.cublog.cn
1. Preface
The method defined in the Linux kernel of workqueue is used to handle callback methods that are not very urgent.
The Linux kernel version of the following code is 2.6.19.2. the source code file is mainly kernel/workqueue. c.
2. Data structure
/* Include/linux/workqueue. h */
// Work node structure
Struct work_struct {
// Wait time
Unsigned long pending;
// Linked list node
Struct list_head entry;
// Workqueue callback function
Void (* func) (void *);
// Callback function func data
Void * data;
// Point to CPU-related data, generally to the struct cpu_workqueue_struct structure
Void * wq_data;
// Timer
Struct timer_list timer;
};
Struct execute_work {
Struct work_struct work;
};
/* Kernel/workqueue. c */
/*
* The per-CPU workqueue (if single thread, we always use the first
* Possible cpu ).
*
* The sequence counters are for flush_scheduled_work (). It wants to wait
* Until all currently-scheduled works are completed, but it doesn' t
* Want to be livelocked by new, incoming ones. So it waits
* Remove_sequence is> = the insert_sequence which pertained when
* Flush_scheduled_work () was called.
*/
// This structure is for each CPU
Struct cpu_workqueue_struct {
// Structure lock
Spinlock_t lock;
// The number of the next node to be executed
Long remove_sequence;/* Least-recently added (next to run )*/
// The serial number of the next node to be inserted
Long insert_sequence;/* Next to add */
// Linked list node of the working organization
Struct list_head worklist;
// Waiting queue for processing
Wait_queue_head_t more_work;
// Wait queue after processing
Wait_queue_head_t work_done;
// Work queue node
Struct workqueue_struct * wq;
// Process pointer
Struct task_struct * thread;
Int run_depth;/* Detect run_workqueue () recursion depth */
}____ Cacheline_aligned;
/*
* The externally visible workqueue specified action is an array
* Per-CPU workqueues:
*/
// Work queue structure
Struct workqueue_struct {
Struct cpu_workqueue_struct * cpu_wq;
Const char * name;
Struct list_head list;/* Empty if single thread */
};
A work queue linked list is defined in kernel/workqueue. c. All Work queues can be attached to this linked list:
Static LIST_HEAD (workqueues );
[1] [2] [3] [4] [5] [6] Next page