当前位置:网站首页>Work queue_ queue
Work queue_ queue
2022-07-29 02:20:00 【Mubai 001】
brief introduction
Work queues are a way of delaying work in the kernel , Delayed work can be scheduled and used repeatedly in countless scenarios .
Data structure composition
/* @data: func Parameters of
* @entry: Pointer to connect work
* @func: Work processing function
*/
struct work_struct {
atomic_long_t data;
struct list_head entry;
work_func_t func;
#ifdef CONFIG_LOCKDEP
struct lockdep_map lockdep_map;
#endif
};
Usage flow
API route :kernel/kernel/workqueue.c; kernel/include/linux/workqueue.h
Create a work queue :
a. Create a service for a single CPU The work queue of
/* @name: Team name
* RETURNS: Pointer to the allocated workqueue on success, %NULL on failure.
*/
create_singlethread_workqueue(name);
b. In every one of them CPU Create a work queue on
/* @name: Team name
* RETURNS: Pointer to the allocated workqueue on success, %NULL on failure.
*/
create_workqueue(name);
be relative to create_singlethread_workqueue, create_workqueue Will also be assigned a wq The work queue of , But the difference is , For many CPU In terms of system , For each CPU, Will create a per-CPU Of cwq structure , Corresponding to each cwq, Will generate a new worker_thread process . But when used queue_work towards cwq Submit on file work Node time , Which is CPU Call this function , Then ask the CPU Corresponding cwq Upper worklist To add work node .
Initialize work items
a. Dynamic registration
//kernel/include/linux/workqueue.h
INIT_WORK(_work, _func)
b. Static registration
//kernel/include/linux/workqueue.h
DECLARE_WORK(_work, _func)
Using static registration, you can omit the definition _work, And DECLARE_WORK It needs to be preprocessed at the head of the code .
Run the specified work item
a. Custom queue run queue_work
/* @wq: workqueue to use
* @work: work to queue
* Returns %false if @work was already on a queue, %true otherwise.
*/
queue_work(struct workqueue_struct *wq, struct work_struct *work)
b. The system work queue is running schedule_work
/* @work: work item
* Returns %false if @work was already on the kernel-global workqueue and %true otherwise.
*/
schedule_work(struct work_struct *work)
queue_work, Run work items using a custom queue
schedule_work, Call the work queue of the system to run the work item .
Summary :
In general , The work item needs to be called repeatedly in the specified situation , Select timer +queue_work. If it is specified, call once , Then use schedule_work, Use the work queue of the system to execute the required work items .
Usage flow
1. Declare variables
struct test_work_dev work_dev;
static struct workqueue_struct * test1_workqueue = NULL;
2. Declare callback functions
void test1_callback(struct work_struct *work);
3. Initialize queue entry
#if defined (DECLARE_WORK_SUPPORT )
static DECLARE_WORK(test1_item, (void *) test1_callback);
#endif
#if !defined(DECLARE_WORK_SUPPORT)
static struct work_struct test1_item;
test1_workqueue = create_singlethread_workqueue("test1_wq");
INIT_WORK(&test1_item, test1_callback);
#endif
4. Define callback
void test1_callback(struct work_struct *work)
{
printk("test1_callback!");
}
5. Dispatch
queue_work(test1_workqueue, &test1_item);
边栏推荐
- 【RT学习笔记1】RT-Thread外设例程——控制Led灯闪烁
- Jetpack -- understand the use of ViewModel and livedata
- [electronic components] constant voltage, amplify the current of the load (triode knowledge summary)
- Anti crawler mechanism solution: JS code generates random strings locally
- QT memory management tips
- [circuit design] convert AC AC to DC
- 特殊流&Properties属性集实例遇到的问题及解决方法
- Understand the clock tree in STM32 in simple terms
- Mathematical modeling -- the laying of water pipes
- Mathematical modeling - location of police stations
猜你喜欢

响应式织梦模板装修设计类网站

基于对象的实时空间音频渲染丨Dev for Dev 专栏

Realization of digital tube display based on C51

记一次 ERROR scheduler.AsyncEventQueue: Dropping event from queue shared导致OOM

Implementation of 10m multifunctional signal generator with FPGA

自定义mvc原理和框架实现

Using local cache + global cache to realize user rights management of small systems

Rgbd point cloud down sampling

试着换个角度理解低代码平台设计的本质

【云原生与5G】微服务加持5G核心网
随机推荐
指针——黄金阶段
年中总结 | 与自己对话,活在当下,每走一步都算数
webview攻击
【RT学习笔记1】RT-Thread外设例程——控制Led灯闪烁
基于C51实现数码管的显示
2022.7.28-----leetcode.1331
[cloud native] what is the microservice architecture
向量相似度评估方法
Resolve the conflict with vetur when using eslint, resulting in double quotation marks and comma at the end of saving
Website Collection
QT source code analysis -- QObject (4)
响应式织梦模板家装建材类网站
Problems encountered in special flow & properties property set instances and Solutions
Flexible layout single selection
Awvs cannot start problem
The number of consecutive subarrays whose leetcode/ product is less than k
表单校验 隐藏的输入框 显示才校验
自定义mvc原理和框架实现
Excel 打开包含汉字的 csv 文件出现乱码该怎么办?
Understand the clock tree in STM32 in simple terms