当前位置:网站首页>Membarrier (personal learning and understanding)
Membarrier (personal learning and understanding)
2022-04-23 05:27:00 【What’smean】
memebarrier It's the realization of Linux Kernel synchronization mechanism , Is a way to ensure the order of memory access ; Similar to the function of locking .
example :
There are two threads writer、reader Running on the Linux On different nuclei of , They all operate on the same circular queue .
writer_index Mark bit for write , Before each write writer_index+1 To write ; Initial value bit 0;
reader_index Mark bit for reading , Before each reading reader_index+1 read ; The initial value is 0;
Conditions :reader_index-writer_index!=1 Can write
writer_index-reader_index!=0 Can be read
if CPU Execute out of order :
( Default initial index All for 0)
writer Check reader_index - writer_index != 1 First writer_index+1, Write again , And before writing reader Find out writer_index-reader_index!=0 , Think you can read , But there is no readable data in the queue .
( Default initial reader_index - writer_index = 1)
Similarly, read first reader_index-1, here writer Find out reader_index - writer_index != 1 Write when you think there is a writable space , Will cause reader The data not read out is writer Write overwrite .
Supplementary knowledge : Disorderly execution : Disorderly execution (out-of-order execution) Refer to CPU It adopts the technology that allows multiple instructions to be sent separately to each corresponding circuit unit for processing without following the sequence specified in the program . example Core The out of order execution engine says that a certain section of the program has 7 Orders , here CPU It will be analyzed according to the idle state of each unit circuit and whether each instruction can be executed in advance , Send the instructions that can be executed in advance to the corresponding circuit immediately .
It's like asking A、B、C Three celebrities wrote banners for the party “ Spring Festival Gala ” Six big words , Write two words each . If at this time on a large piece of paper in order by A Write well " Spring Festival " Then give it to B Write " Get together ", And then by C Write " Evening party ", So what is this A When writing ,B and C Must wait , And in the B When writing C Still have to wait and A It's all right .
But if three people write on three sheets of paper at the same time , that B and C You don't have to wait to write your own at the same time , even to the extent that C and B It's better than A It doesn't matter to write it first ( It's like disorderly execution ), But when they're done, they have to put it on the banner again ( Naturally, it can be done by others , Just like CPU Rearrange cells after out of order execution in ) Press " Spring Festival Gala " In order to hang out .
For the above reasons , Memory masking is introduced into the kernel (membarrier) The concept of , One of the multiple cores sends out a memory mask , Then all other read and write operations of checking the memory segment are stopped , Also have barrier After that c The assembly corresponding to the code , You can't run to barrier Go before .( The above is an old version of membarrier, The new version of the membarrier In each kernel, there are optional rules to follow .)
A kernel performs a similar process after reading and writing fence Instructions , Release after all operations are completed .
Point out if there is a deviation , thank you
版权声明
本文为[What’smean]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220544124692.html
边栏推荐
- 2021-10-08
- TSlint注释忽略错误和RESTful理解
- Log introduction and building web application
- C#测试调用PaddleSharp模块识别图片文字
- Call the interface to get the time
- [the background color changes after clicking a line]
- Traversal array, object parent-child communication props / $emit
- 可執行程序執行流程
- Project manager's thinking mode worth trying: project success equation
- Click the Add button - a box appears (similar to adding learning experience - undergraduate - Graduate)
猜你喜欢
Project manager's thinking mode worth trying: project success equation
Excel 2016 cannot open the file for the first time. Sometimes it is blank and sometimes it is very slow. You have to open it for the second time
(十一)vscode代码格式化配置
Laravel database
Cloud computing and cloud native architecture design of openshift
2021-10-08
Three of three JS (webgl) is simple to draw lines / arcs according to points (based on linegeometry / line2 / linematerial, draw two arc segments based on the center of the circle)
Intel SGX preliminary learning and understanding notes (continuously updated)
What are the reasons for the failure of digital transformation?
Solution of how to log in with mobile phone verification code in wireless network
随机推荐
Simple and basic use of switch and if
修仙真实世界与游戏世界
Implementation of resnet-34 CNN with kears
Study notes: unity customsrp-13-colorgrading
JSP -- Introduction to JSP
Semi synchronous replication of MariaDB
Understand the relationship between promise async await
Study notes: unity customsrp-12-hdr
What are the reasons for the failure of digital transformation?
The introduction of lean management needs to achieve these nine points in advance
Good test data management, in the end how to do?
Use pagoda + Xdebug + vscode to debug code remotely
可执行程序执行流程
Various situations of data / component binding
Why can't V-IF and V-for be used together
Redis的基本知识
Wbpack configuring production development environment
Uncle wolf is looking for a translator -- Plato -- ongoing translation
五一劳动节期间什么理财产品会有收益?
Devops life cycle, all you want to know is here!