当前位置: 首页 > 图文教程 > 操作系统 > Unix/Linux > Linux操作系统内核中工作队列的操作

Unix/Linux
Linux下Socket连接超时的一种实现方法
谈一谈至关重要的Linux系统Swap交换区
Linux系统GRUB引导单用户模式三种方式
实例解析:虚拟机中Lvs的负载均衡实验
实用技巧:DOS文件转换成UNIX文件格式
Linux系统多进程查看及调配管理方法
非常实用 Linux系统开机提速我有绝招!
Linux系统中的文件目录结构介绍(表)
Linux操作系统如何完美装载Windows分区
Linux系统访问Windows分区FAT32和NTFS
高手进阶 Linux系统下MTD/CFI驱动介绍
新手看招 Linux系统的参数配置优化技巧
Xmanager 远程登陆Linux系统后配置Xdm
新手学堂:Emacs只启动一个进程的方法
小技巧 在Linux桌面上建立“我的文档”
Linux slab 分配器详解
拨开云雾:Lastlog文件不断变大的原因
使用ImageMagick 的提示与技巧
认识Linux操作系统中的播客客户端
Linux系统中显示设备配置工具介绍

Unix/Linux 中的 Linux操作系统内核中工作队列的操作


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-01   浏览: 38 ::
收藏到网摘: n/a

本文档的Copyleft归yfydz所有,使用GPL发布,可以自由拷贝,转载,转载时请保持文档的完整性,严禁用于任何商业用途。

msn: [email protected]

来源:http://yfydz.cublog.cn

1. 前言

工作队列(workqueue)的Linux内核中的定义的用来处理不是很紧急事件的回调方式处理方法.

以下代码的linux内核版本为2.6.19.2, 源代码文件主要为kernel/workqueue.c.

2. 数据结构

/* include/linux/workqueue.h */

// 工作节点结构

struct work_struct {

// 等待时间

unsigned long pending;

// 链表节点

struct list_head entry;

// workqueue回调函数

void (*func)(void *);

// 回调函数func的数据

void *data;

// 指向CPU相关数据, 一般指向struct cpu_workqueue_struct结构

void *wq_data;

// 定时器

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 until

* remove_sequence is >= the insert_sequence which pertained when

* flush_scheduled_work() was called.

*/

// 这个结构是针对每个CPU的

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;

// 进程指针

struct task_struct *thread;

int run_depth; /* Detect run_workqueue() recursion depth */

} ____cacheline_aligned;

/*

* The externally visible workqueue abstraction is an array of

* per-CPU workqueues:

*/

// 工作队列结构

struct workqueue_struct {

struct cpu_workqueue_struct *cpu_wq;

const char *name;

struct list_head list; /* Empty if single thread */

};

kernel/workqueue.c中定义了一个工作队列链表,