中断下半部_工作队列(work queue)

2023-05-16

1>work_queue:<linux/workqueue.h> __3.0.4
2>description:
中断下半部,在内核线程的进程上下文中执行推后的工作.
它是唯一能在进程上下文运行的中断下半部实现机制,也只有它才可以睡眠.
3>创建推后的工作:
DECLARE_WORK(const char *name, void (*func)(struct work_struct *work));
INIT_WORK(struct work_struct *work, void (*func)(struct work_struct *work));

struct work_struct {
    atomic_long_t data;
    struct list_head entry;
    work_func_t func;                                                                                                                     
#ifdef CONFIG_LOCKDEP
    struct lockdep_map lockdep_map;
#endif
};
typedef void (*work_func_t)(struct work_struct *work);
4>工作队列处理函数:
/* 除了不能访问用户空间,它的确比软中断和tasklet方便不少.
 * 只有系统调用陷入内核,用户空间的内存才会被映射.
 */
void *func(struct work_struct *work);
5>调度(提交)工作:
/* 把创建好的工作提交到缺省的worker线程(每个cpu一个,event/cpuno.).
 * 有时把这种工作队列也叫共享队列,因为很多驱动程序都将推后执行的工作提交到默认worker线程.
 */
int schedule_work(struct work_struct *work);
int schedule_delayed_work(struct delayed_work *work, unsigned long delay);
int schedule_on_each_cpu(work_func_t func);
6>刷新工作队列:
/* 实际上,它只是等待(睡眠),直到缺省工作队列上的工作被执行.
 * complete()实现.
 */
void flush_scheduled_work(void);
/*等待指定的工作被执行*/
bool flush_work(struct work_struct *work);
bool flush_delayed_work(struct delayed_work *dwork);
7>取消工作:
bool cancel_delayed_work(struct delayed_work *work);
bool cancel_work_sync(struct work_struct *work);
bool cancel_delayed_work_sync(struct delayed_work *dwork);



8>创建一个新的workqueue和对应的worker线程(每个cpu一个).

/* 如果一个任务是处理器密集型和性能要求严格的
 * 那么可以选择创建自己的worker(工作者)线程
 * 当然,每个处理器一个.
 */
struct workqueue_struct *create_workqueue(const char *name);

/* struct workqueue_struct *alloc_workqueue(const char *name, unsigned int flags, int max_active);
 * the maximum number of execution contexts per cpu, up to 512.
 */
9>调度(提交)队列
int queue_work(struct workqueue_struct *wq, struct work_struct *work);
int queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *work, unsigned long delay);
10>刷新一个工作队列:
/* 等待(睡眠),直到指定队列上的工作被执行.
 * 事实上除了指定工作队列,它和flush_scheduled_work()没有区别.
 */
void flush_workqueue(struct workqueue_struct *wq);
11>释放一个工作队列:
void destroy_workqueue(struct workqueue_struct *wq);


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

中断下半部_工作队列(work queue) 的相关文章

随机推荐