当前位置:网站首页>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);
边栏推荐
- 即时通讯场景下安全合规的实践和经验
- Verilog procedure assignment statements: blocking & non blocking
- H5 background music is played automatically by touch
- Mysql存储json格式数据
- Leetcode 242. valid anagram
- Navigation--实现Fragment之间数据传递和数据共享
- “蔚来杯“2022牛客暑期多校训练营3,签到题CAJHF
- [cloud native] what is the microservice architecture
- 连PostgreSQL问题:expected authentication request from server, but received v
- The growth path of embedded engineers
猜你喜欢

awvs无法启动问题

npm install 报错 Error: EPERM: operation not permitted, rename
![[circuit design] open collector OC output of triode](/img/48/5a111b81f0d99990fbcc5263313c07.jpg)
[circuit design] open collector OC output of triode
[email protected],国产化率达100%"/>全志T3/A40i工业核心板,4核[email protected],国产化率达100%

“蔚来杯“2022牛客暑期多校训练营2,签到题GJK

WebView attack

Read the recent trends of okaleido tiger and tap the value and potential behind it

开启TLS加密的Proftpd安全FTP服务器安装指南

Cookies and sessions

PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (2)
随机推荐
Custom MVC principle and framework implementation
Cookie和Session
Problems encountered in special flow & properties property set instances and Solutions
JS dom2 and dom3
Website Collection
[MySQL] SQL aliases the table
autoware中ndtmatching功能加载点云图坐标系修正的问题
Mathematical modeling -- cold proof simulation of low temperature protective clothing with phase change materials
弹性布局 单选
记一次 ERROR scheduler.AsyncEventQueue: Dropping event from queue shared导致OOM
Qt 内存管理小技巧
Related function records about string processing (long-term update)
Motionlayout -- realize animation in visual editor
Prevent repeated clicks
Feynman learning method (symbol table)
Character flow comprehensive exercise problem solving process
Summarize in the middle of the year | talk to yourself, live in the present, and count every step
webview攻击
[cloud native] what is the microservice architecture
【ONE·Data || 数组堆简单实现及其延伸】