当前位置:网站首页>Will IO always occupy CPU? A good question about concurrent / parallel systems (turn)
Will IO always occupy CPU? A good question about concurrent / parallel systems (turn)
2022-07-18 14:26:00 【Love Xiao's program ape】
This is a good one about concurrency / Problems with parallel systems . The simple answer is :IO The required CPU Very few resources . Most of the work is assigned to DMA(Direct Memory Access) Direct memory access Accomplished .
Let's not talk about traditional 5 Big IO Model , Let's talk about concurrency first (Concurrencey). A very loose explanation is to do at the same time A and B Two things . First do the process for a while A, Then context switches , Do it for a while B. After a while, I'll cut back and continue to do A. So it gives us an illusion , We are doing at the same time A and B Two things . This is the famous process model .
It looks cool , But in fact, there are no eggs . because A,B You have to finish both things, no ? Whether you finish A Do it again B Or switch back and forth , It should take the same time . Even more , Because we also need to consider the overhead of context switching . So when I first learned the concurrent process model , There are 10000 white eyes in my heart .( I feel the same way )
however , If there is more inside the computer CPU A part is working ? If A This matter CPU It can be assigned to other parts to help it complete ? Is the situation completely different ? System IO It happens to be such a perfect example .
For disk IO, The real scene may be like this :
CPU say : Brother hard disk, help me copy a small movie I want to see to main memory , thank you , Pro - .
Hard disk said : well ! I'll call you after the exam .
CPU say : mua ! Then I'll play games !
...
CPU Fight and fight (100 Nanoseconds have passed )
...
Hard disk said : Small C I finished the exam .
CPU say : Teacher Cang, I'm coming !
Of course, we can also download teacher Cang's works online , This is the Internet IO. But the situation is basically the same ,CPU Children's shoes are waiting for a little movie , Played a round of roll, roll .
therefore , It is precisely because of this assignment , Communications , Waiting process , Concurrent system shows its significance . Of course, the actual process may be 10000 times more complicated than this . such as CPU I won't talk to the hard disk directly , There is a middleman between them , It's called DMA(Direct Memory Access) chip
CPU Calculate file address ——> delegate DMA Read the file ——> DMA Take over the bus ——> CPU Of A Process blocking , Hang up ——> CPU Switch to B process ——>
DMA Notify after reading the document CPU( An interrupt exception )——> CPU Switch back to the A Process operation file
This process , Corresponding to the figure below ( Picture source :《UNIX Network programming 》), notice application Is this a timeline ?aio_read After the operation , It's all blank ,CPU No matter the , You can do other things .

Suppose the file was originally read CPU Need to wait 50 nanosecond . Now, although the two context switches need to be consumed separately 5 nanosecond .CPU Still made money 40 Nanosecond time slice . You can see from the above picture , What I just talked about is tradition 5 Big IO In the model “ asynchronous IO” The general process of . Want to know more about , It is recommended to read directly 《UNIX Network programming 》 Volume 1 sockets , Classic !
although IO It won't take up a lot of CPU Time , But very often IO It will still be very wasteful CPU The time of the , So face a lot IO The task of , Sometimes you need an algorithm to merge IO, Or by cache To relieve IO Stressful .
边栏推荐
- Talk about your understanding of reflection mechanism
- Gd32f4xx IAP upgrade ideas
- Codeforces Round #803 (Div. 2) B. Rising Sand
- 8、某网络拓扑如图所示,路由器R1通过接口E1、E2分别连接局域网1、局域网2,通过接口L0连接路由器R2,并通过路由器R2连接域名服务器与互联网。R1的L0接口的IP地址是202.118.2.1/2
- Basic use of Anaconda
- HMS Core图形图像技术展现最新功能和应用场景,加速构建数智生活
- Binary search tree BST
- MySQL的DML(數據操縱語言)
- altium designer怎么添加元件库
- Tomato learning notes -vscade configuring makefile (using task.jason and launch.jason)
猜你喜欢
![[C language note sharing] custom type: structure, enumeration, Union (recommended Collection)](/img/25/4a17c260b2b506ae1224520d9b85d1.png)
[C language note sharing] custom type: structure, enumeration, Union (recommended Collection)

认识多银行资金系统(四)-----计划任务、账户资金监控

基于单片机的氢气监测报警系统设计(#0492)

Customize MVC

基于单片机的氢气监测系统设计(#0491)

基于单片机的氢气监测系统设计(#0490)

Codeforces Round #803 (Div. 2) C. 3SUM Closure

Codeforces Round #803 (Div. 2) D. Fixed Point Guessing
![[pytorch quantitative practice (1)]](/img/d4/26dec935fdbdb719a78254288ba585.png)
[pytorch quantitative practice (1)]

Force buckle (977 and 189)
随机推荐
Design of combustible gas smoke system based on single chip microcomputer (0488)
ARM64银河麒麟桌面系统V10(SP1) markdown编辑器 retext 顶替Typora
[phantom engine UE] ue5 dynamic Pak resource loading method
Codeforces Global Round 21 D. Permutation Graph
[leetcode brush questions]
Some useful web addresses
Understanding multi bank capital system (II) -- today's homepage
斑马888-TT不认新纸
Clear the temporary table and check the memory occupied by the temporary table
自定义MVC
ts中的联合类型和类型保护
Microservice learning
8、某网络拓扑如图所示,路由器R1通过接口E1、E2分别连接局域网1、局域网2,通过接口L0连接路由器R2,并通过路由器R2连接域名服务器与互联网。R1的L0接口的IP地址是202.118.2.1/2
Is it safe to open an account for flush stocks? How to buy REITs funds
Tomato学习笔记-Vscode配置Makefile(使用task.jason和launch.jason)
Liquibase first use
通用分页2.0
[image recognition based on yolov5]
Interview reply 2 (summarize the bad answers in the interview)
【边缘部署 AI】