当前位置:网站首页>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);
边栏推荐
- JS dom2 and dom3
- PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (2)
- Form verification hidden input box is displayed before verification
- Implementation of 10m multifunctional signal generator with FPGA
- Resnet50 + k-fold cross validation + data enhancement + drawing (accuracy, recall, F value)
- Establish an engineering template based on STM32 in keil -- detailed steps
- Control buzzer based on C51
- 点击按钮,下滑到指定的位置
- Realization of digital tube display based on C51
- 12. < tag dynamic programming and subsequence, subarray> lt.72. edit distance
猜你喜欢

"Wei Lai Cup" 2022 Niuke summer multi school training camp 2, sign in question GJK

The problem of modifying the coordinate system of point cloud image loaded by ndtmatching function in autoware

C语言提高篇(一)

Basic working principle and LTSpice simulation of 6T SRAM

第十四天:续第十三天标签相关知识

Cookie和Session

Mathematical modeling - location of police stations

C language improvement (I)

Custom MVC principle and framework implementation
![[one · data | chained binary tree]](/img/83/d62a47f1264673f1e898335303a7a6.png)
[one · data | chained binary tree]
随机推荐
年中总结 | 与自己对话,活在当下,每走一步都算数
忽略微信设置字体
Related function records about string processing (long-term update)
Leetcode 242. valid anagram
JetPack--Navigation实现页面跳转
Rgbd point cloud down sampling
响应式织梦模板装修设计类网站
[circuit design] convert AC AC to DC
关于字符串处理的相关函数记录(长期更新)
Mathematical modeling -- cold proof simulation of low temperature protective clothing with phase change materials
[cloud native] what is the microservice architecture
QT source code analysis -- QObject (4)
leetcode 242. Valid Anagram(有效的字母异位词)
Complete collection of common error handling in MySQL installation
Click the button to slide to the specified position
Detailed explanation of IVX low code platform series -- Overview (II)
QT learning notes -37.qregex and regular expressions
【ONE·Data || 数组堆简单实现及其延伸】
iVX低代码平台系列详解 -- 概述篇(二)
全志T3/A40i工业核心板,4核[email protected],国产化率达100%