Linux 内核工作队列
来源:互联网 发布:水晶之泉水坝重要数据 编辑:程序博客网 时间:2024/04/30 14:15
工作队列也是内核一种延时执行任务机制,显然,内核需要定义一个队列,然后队列上面存放需要执行的任务,而任务执行则有内核线程来调用任务。
工作队列定义如下:
/* * The externally visible workqueue. It relays the issued work items to * the appropriate worker_pool through its pool_workqueues. */struct workqueue_struct { struct list_head pwqs; /* WR: all pwqs of this wq */ struct list_head list; /* PR: list of all workqueues */
struct mutex mutex; /* protects this wq */ int work_color; /* WQ: current work color */ int flush_color; /* WQ: current flush color */ atomic_t nr_pwqs_to_flush; /* flush in progress */ struct wq_flusher *first_flusher; /* WQ: first flusher */ struct list_head flusher_queue; /* WQ: flush waiters */ struct list_head flusher_overflow; /* WQ: flush overflow list */
struct list_head maydays; /* MD: pwqs requesting rescue */ struct worker *rescuer; /* I: rescue worker */
int nr_drainers; /* WQ: drain in progress */ int saved_max_active; /* WQ: saved pwq max_active */
struct workqueue_attrs *unbound_attrs; /* PW: only for unbound wqs */ struct pool_workqueue *dfl_pwq; /* PW: only for unbound wqs */
#ifdef CONFIG_SYSFS struct wq_device *wq_dev; /* I: for sysfs interface */#endif#ifdef CONFIG_LOCKDEP struct lockdep_map lockdep_map;#endif char name[WQ_NAME_LEN]; /* I: workqueue name */
/* * Destruction of workqueue_struct is sched-RCU protected to allow * walking the workqueues list without grabbing wq_pool_mutex. * This is used to dump all workqueues from sysrq. */ struct rcu_head rcu;
/* hot fields used during command issue, aligned to cacheline */ unsigned int flags ____cacheline_aligned; /* WQ: WQ_* flags */ struct pool_workqueue __percpu *cpu_pwqs; /* I: per-cpu pwqs */ struct pool_workqueue __rcu *numa_pwq_tbl[]; /* PWR: unbound pwqs indexed by node */};
队列上任务定义如下:
struct work_struct { atomic_long_t data; struct list_head entry; work_func_t func;#ifdef CONFIG_LOCKDEP struct lockdep_map lockdep_map;#endif};
或者一种带有延时性质的任务:
struct delayed_work { struct work_struct work; struct timer_list timer;
/* target workqueue and CPU ->timer uses to queue ->work */ struct workqueue_struct *wq; int cpu;};
工作任务加入工作队列由函数__queue_work()处理,其对外提供接口有:
1. 指定CPU下队列
bool queue_work_on(int cpu, struct workqueue_struct *wq, struct work_struct *work)
2. 延时加入
void delayed_work_timer_fn(unsigned long __data)
3.
void __queue_delayed_work(int cpu, struct workqueue_struct *wq, struct delayed_work *dwork, unsigned long delay)
bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq, struct delayed_work *dwork, unsigned long delay)
4.
bool flush_delayed_work(struct delayed_work *dwork)
内核中常用的队列:
extern struct workqueue_struct *system_wq;extern struct workqueue_struct *system_highpri_wq;extern struct workqueue_struct *system_long_wq;extern struct workqueue_struct *system_unbound_wq;extern struct workqueue_struct *system_freezable_wq;extern struct workqueue_struct *system_power_efficient_wq;extern struct workqueue_struct *system_freezable_power_efficient_wq;
- linux 内核 工作队列
- Linux内核工作队列
- Linux内核:工作队列
- Linux 内核工作队列
- Linux内核:工作队列
- linux内核工作队列
- linux内核的工作队列
- tasklet、工作队列 - [linux内核]
- Linux内核机制:工作队列
- 论linux内核工作队列
- Linux内核中的工作队列
- 内核中工作队列(linux工作队列)
- 内核中工作队列(linux工作队列)
- 内核中工作队列(linux工作队列)
- linux内核分析之工作队列
- Linux内核中工作队列的操作
- Linux内核实践之工作队列
- linux内核知识之工作队列(workqueue)
- Docker tag
- Docker安全
- 高仿qq聊天:qt界面
- 在OpenCV中图像边界扩展 copyMakeBorder 的实现
- C++入门③:基础的C++知识
- Linux 内核工作队列
- CF 592
- BZOJ 3112 [Zjoi2013]防守战线
- POJ 1742 Coins (背包)
- 端口的分类及用socket建立连接时client端为什么不建议绑定
- 第四次c++实验 质数的选取
- 腾讯云服务器PHP环境搭建
- switch...case和if...else效率比较
- Makefile中的函数