当前位置:网站首页>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
边栏推荐
- What role do tools play in digital transformation?
- 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)
- Multiple mainstream SQL queries only take the latest one of the data
- C# ,类库
- Data bus realizes the communication between brother components
- Open source rule engine - Ice: dedicated to solving flexible and complex hard coding problems
- 2021-10-12
- 4 most common automated test challenges and Countermeasures
- How to add beautiful code blocks in word | a very complete method to sort out and compare
- The introduction of lean management needs to achieve these nine points in advance
猜你喜欢

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

JS array common methods

2021-09-27

Nécessité de précharger les cookies dans le sélénium

Source code analysis of how to use jump table in redis

C#测试调用PaddleSharp模块识别图片文字

The title bar will be pushed to coincide with the status bar

es6数组的使用

Various situations of data / component binding

Basic use of sqlyog
随机推荐
Executable program execution process
Data bus realizes the communication between brother components
Three 之 three.js (webgl)简单实现根据点绘制线/弧线(基于LineGeometry / Line2 / LineMaterial,绘制两点基于圆心的弧线段)
Fast application fuzzy search
Good test data management, in the end how to do?
Understand the relationship between promise async await
五一劳动节期间什么理财产品会有收益?
Various situations of data / component binding
Study notes: unity customsrp-13-colorgrading
The 2021 IT industry project management survey report was released!
d. TS --- for more detailed knowledge, please refer to the introduction on the official website (chapter of declaration document)
Top 25 Devops tools in 2021 (Part 2)
Modèle axé sur le domaine DDD (III) - gestion des transactions à l'aide de Saga
MFC implementation resources are implemented separately by DLL
Implementation of resnet-34 CNN with kears
Study notes: unity customsrp-12-hdr
[triangle Yang Hui triangle printing odd even cycle JS for break cycle]
My old programmer's perception of the dangers and opportunities of the times?
Self incrementing sequence creation of MySQL
Edit, cancel, pull up menu