当前位置:网站首页>blocking non-blocking poll mechanism asynchronous
blocking non-blocking poll mechanism asynchronous
2022-08-10 11:08:00 【life needs depth】
1 Blocking
Blocking operation: When performing device operations, if resources cannot be obtained, the process will be suspended until the operable conditions are met before the operation is performed.
read()-->HelloRead
How to implement blocking in the driver?You can define a sleep waiting queue
wait_queue_head_t q;//Define a sleep waiting queue head
init_waitqueue_head(&q);//Initialize the sleep waiting queue
Use: helloRead:
wait_event_interruptible(q,con)-->Sleep the process requesting to read data--"The sleep period can be interrupted
wait_event(q,con)-->The sleep period cannot be interrupted
HelloWrite:-->Wake up the read process to read data after writing data
wake_up_interruptible(&q);-->Wake up the sleep process that can be interrupted
wake_up;
con=1;
con: The wake-up condition of the sleep process process: 1 wake up 0 sleep
Note: When the process is running normally, the process is waiting to be run in the running pair column.
When the process sleeps, the process waits in the sleep waiting queue to be woken up to run
2 Non-blocking
Non-blocking operation: It means that when the device operation cannot be performed, it does not sleep or suspend the process, but immediately returns an incorrect value to the requesting process, and the underlying device driver passes the non-stopThe query device operation can be performed until the operation can be performed and a correct result is returned to the requesting process.
read-->non-blocking
application layer: open("dev/haha0",O_RDWR|O_NONBLOCK);
Driver layer: HelloRead()
if (no data can be read in the device)
{
if (the O_NONBLOCK flag is passed in by the application layer)
{
Return an incorrect value to the application
} }
else
{
Blocking the process;
blocking the process;
blocking the process
g_charcount: Indicates the number of characters actually written to the kernel
3 poll mechanism
io multiplexing--"select poll epoll
HelloPoll(struct file *pFile, struct poll_table_struct *ptable)
Implementation: 1 Put the process of monitoring the file descriptor into the monitoring queue--"poll_wait(pFile,&q,ptable)
ptable: polling table
Add the process currently operating the file to the sleep waiting queue, add the queue to ptable.
2 The system monitors the sleeping process in the monitoring queue. If there is IO data on the file descriptor of the sleeping process, the system will activate the process.
return mask;
mask: a bit mask used to describe whether the operation can be executed immediately without blockingStatus (each BIT bit can be represented by a macro)
POLLIN: data can be read
POLLRDNORM: normal data can be read
POLLOUT: data can be written
POLLERR: specified file descriptioncharacter error
4 Asynchronous IO
Asynchronous IO: The read process goes to the device to read data. If the device has no data to read, then the current process is blocked. If the kernel detects that the device has data to read, it will send a notification signal to the read process.The read process will execute the processing action corresponding to the signal to read the data.
Application:
A (read data process)
1 Register a signal handler function signal(SIGIO,hander);
2 Open the device file fd=open("/dev/haha0",...);
3 3 Set the host of the file descriptor fcntl(fd,F_SETOWN,getpid());
4 Read the flag of the file descriptor int flags=fcntl(fd,F_GETFL);
5 Set the file descriptor flag fcntl(fd,F_SETFL,flags|FASYNC)->Asynchronous notification flag
while(1);
hander-->read()
Note: fcntl: is a system call function, used to set or get a fileDescriptor properties
B (write data process)
1 open("/dev/haha0");
2 write-->helloWrite-->signal to the reading process
3 close
Driver:
1 HelloFasync
1 Define a global asynchronous notification structure--"Associated signal sender and receiver
2 Initialize asynchronous notification structure
fasync_helper(fd,pFile,on,&fasync)
2 HelloWrite
kill_fasync(&fasync,SIGIO,POLL_IN);
SIGIO-->fasync-->fd(read)--"getpid()==A
边栏推荐
- Redis(三)——配置文件详解、发布和订阅、新数据类型
- 大连理工&鹏城&UAE提出用于伪装目标检测的混合尺度三重网络ZoomNet,性能SOTA!
- 关于json转换器缺失的问题,报错内容:No converter found for return value of type
- database constraints
- Gartner reiterates the important value of 'data weaving'
- Unsafe的一些使用技巧
- 兼容移动和PC的loading加载和toast消息插件
- String interception function in SQL
- 让软件飞——“X+”技术揭秘
- 第2章-矩阵及其运算-矩阵运算(2)
猜你喜欢
mysql5.7 installation and deployment - yum installation
Redis(三)——配置文件详解、发布和订阅、新数据类型
第3章-线性方程组(3)
越折腾越好用的 3 款开源 APP
交换 生成树 知识总结
ESP8266 Tutorial 2 - Burn AT Firmware
GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
js猜拳小游戏源码
「首席工程师」首席(Principal )工程师修炼之道
Get started quickly and conquer three different distributed architecture calling schemes
随机推荐
Dialogue with Chen Ciliang: Nezha wants to popularize high-end products
ZZULIOJ 1116 删除元素【删】
JWT 实现登录认证 + Token 自动续期方案
runtime-core.esm-bundler.js?d2dd:218 Uncaught TypeError: formRef.value?.validate is not a function
Memory problems difficult to locate, it is because you do not use ASAN
String interception function in SQL
MySQL executes the query process
Unsafe的一些使用技巧
FastReport.Net 2022.2.17 Crack
Automated Testing and Selenium
Summary of whitespace, space and escape characters in C language
Research on motion capture system for indoor combined positioning technology
【知识论概念】《理由论的进展》鲁汶大学2022最新220页博士论文
PTA 7-2 Summation and Counting of Diagonal Elements of Square Matrices Solution
EasyCVR级联时,修改下级平台名称将不同步至上级平台
文本选中圆角样式border-radius
[C language] Header file #include
, conio is Console Input/Output (console input and output) 2023版揽胜运动曝光,安全、舒适一个不落
使用cpolar远程连接群晖NAS(升级固定链接2)
Mobile and PC compatible loading and toast message plugins