成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

使用 Litmus 驗證內存重排

存儲 存儲軟件
perfbook 一書在講 memory barrier 相關的概念時,都使用了一個叫 litmus 的工具,現在被集成在 herdtools[2] 中,安裝好 herdtools 就已經有了 litmus,上面提到的所有讀寫重排/亂序的情況我們都可以進行測試。

[[405494]]

本文轉載自微信公眾號「碼農桃花源」,作者曹春暉。轉載本文請聯系碼農桃花源公眾號。

At the same time, x86 defines quite a strict memory model, which bans most possible reorderings, roughly summarized as follows:

Stores have a single global order of visibility, observed consistently by all CPUs, subject to one loosening of this rule below. Local load operations are never reordered with respect to other local load operations.

Local store operations are never reordered with respect to other local store operations (i.e., a store that appears earlier in the instruction stream always appears earlier in the global order).

Local load operations may be reordered with respect to earlier local store operations, such that the load appears to execute earlier wrt the global store order than the local store, but the reverse (earlier load, older store) is not true.

簡單概括一下,就是在 x86 平臺采用較強的內存序,只有 store load 會發生亂序。

看各位八股文老仙們背的實在辛苦,本文提供一點可以直接實操證明這些問題的手段。

perfbook 一書在講 memory barrier 相關的概念時,都使用了一個叫 litmus 的工具,現在被集成在 herdtools[2] 中,安裝好 herdtools 就已經有了 litmus,上面提到的所有讀寫重排/亂序的情況我們都可以進行測試。

讀寫亂序測試

  1. X86 RW 
  2. { x=0; y=0; } 
  3.  P0          | P1          ; 
  4.  MOV EAX,[y] | MOV EAX,[x] ; 
  5.  MOV [x],$1  | MOV [y],$1  ; 
  6. locations [x;y;] 
  7. exists (0:EAX=1 /\ 1:EAX=1) 
  1. %%%%%%%%%%%%%%%%%%%%%%%%% 
  2. % Results for sb.litmus % 
  3. %%%%%%%%%%%%%%%%%%%%%%%%% 
  4. X86 OOO 
  5.  
  6. {x=0; y=0;} 
  7.  
  8.  P0          | P1          ; 
  9.  MOV EAX,[y] | MOV EAX,[x] ; 
  10.  MOV [x],$1  | MOV [y],$1  ; 
  11.  
  12. locations [x; y;] 
  13. exists (0:EAX=1 /\ 1:EAX=1) 
  14. Generated assembler 
  15.  ##START _litmus_P0 
  16.  movl -4(%rsi,%rcx,4), %eax 
  17.  movl $1, -4(%rbx,%rcx,4) 
  18.  ##START _litmus_P1 
  19.  movl -4(%rbx,%rcx,4), %eax 
  20.  movl $1, -4(%rsi,%rcx,4) 
  21.  
  22. Test OOO Allowed 
  23. Histogram (2 states) 
  24. 500000:>0:EAX=1; 1:EAX=0; x=1; y=1; 
  25. 500000:>0:EAX=0; 1:EAX=1; x=1; y=1; 
  26. No 
  27.  
  28. Witnesses 
  29. Positive: 0, Negative: 1000000 
  30. Condition exists (0:EAX=1 /\ 1:EAX=1) is NOT validated 
  31. Hash=7cdd62e8647b817c1615cf8eb9d2117b 
  32. Observation OOO Never 0 1000000 
  33. Time OOO 0.14 

寫讀亂序測試

  1. X86 RW 
  2. { x=0; y=0; } 
  3.  P0          | P1          ; 
  4.  MOV EAX,[y] | MOV EAX,[x] ; 
  5.  MOV [x],$1  | MOV [y],$1  ; 
  6. locations [x;y;] 
  7. exists (0:EAX=1 /\ 1:EAX=1) 
  1. %%%%%%%%%%%%%%%%%%%%%%%%%% 
  2. % Results for sb2.litmus % 
  3. %%%%%%%%%%%%%%%%%%%%%%%%%% 
  4. X86 OOO 
  5.  
  6. {x=0; y=0;} 
  7.  
  8.  P0          | P1          ; 
  9.  MOV [x],$1  | MOV [y],$1  ; 
  10.  MOV EAX,[y] | MOV EAX,[x] ; 
  11.  
  12. locations [x; y;] 
  13. exists (0:EAX=0 /\ 1:EAX=0) 
  14. Generated assembler 
  15.  ##START _litmus_P0 
  16.  movl $1, -4(%rbx,%rcx,4) 
  17.  movl -4(%rsi,%rcx,4), %eax 
  18.  ##START _litmus_P1 
  19.  movl $1, -4(%rsi,%rcx,4) 
  20.  movl -4(%rbx,%rcx,4), %eax 
  21.  
  22. Test OOO Allowed 
  23. Histogram (4 states) 
  24. 2     *>0:EAX=0; 1:EAX=0; x=1; y=1; 
  25. 499998:>0:EAX=1; 1:EAX=0; x=1; y=1; 
  26. 499999:>0:EAX=0; 1:EAX=1; x=1; y=1; 
  27. 1     :>0:EAX=1; 1:EAX=1; x=1; y=1; 
  28. Ok 
  29.  
  30. Witnesses 
  31. Positive: 2, Negative: 999998 
  32. Condition exists (0:EAX=0 /\ 1:EAX=0) is validated 
  33. Hash=2d53e83cd627ba17ab11c875525e078b 
  34. Observation OOO Sometimes 2 999998 
  35. Time OOO 0.12 

讀讀和寫寫亂序測試

這里我沒想到太好的辦法,所以將讀讀和寫寫混在一起進行測試,無論是 WW 會發生重排,或是 RR 會發生重排,都可能會出現在 P0 中,EAX = 2,EBX = 0 的情況。

  1. X86 OOO 
  2. { x=0; y=0; } 
  3.  P0          | P1          ; 
  4.  MOV EAX,[x] | MOV [y],$1  ; 
  5.  MOV EBX,[y] | MOV [x],$2  ; 
  6. locations [x;y;] 
  7. exists (0:EAX=2 /\ 0:EBX=0) 
  1. %%%%%%%%%%%%%%%%%%%%%%%%%% 
  2. % Results for sb3.litmus % 
  3. %%%%%%%%%%%%%%%%%%%%%%%%%% 
  4. X86 OOO 
  5.  
  6. {x=0; y=0;} 
  7.  
  8.  P0          | P1         ; 
  9.  MOV EAX,[x] | MOV [y],$1 ; 
  10.  MOV EBX,[y] | MOV [x],$2 ; 
  11.  
  12. locations [x; y;] 
  13. exists (0:EAX=2 /\ 0:EBX=0) 
  14. Generated assembler 
  15.  ##START _litmus_P0 
  16.  movl -4(%rbx,%rcx,4), %eax 
  17.  movl -4(%rdx,%rcx,4), %r11d 
  18.  ##START _litmus_P1 
  19.  movl $1, -4(%rdi,%rax,4) 
  20.  movl $2, -4(%rcx,%rax,4) 
  21.  
  22. Test OOO Allowed 
  23. Histogram (3 states) 
  24. 500000:>0:EAX=0; 0:EBX=0; x=2; y=1; 
  25. 1     :>0:EAX=0; 0:EBX=1; x=2; y=1; 
  26. 499999:>0:EAX=2; 0:EBX=1; x=2; y=1; 
  27. No 
  28.  
  29. Witnesses 
  30. Positive: 0, Negative: 1000000 
  31. Condition exists (0:EAX=2 /\ 0:EBX=0) is NOT validated 
  32. Hash=74f6930f2a61d6cfec9fb5ea3132555e 
  33. Observation OOO Never 0 1000000 
  34. Time OOO 0.11 

[1]

這么: https://stackoverflow.com/questions/50307693/does-an-x86-cpu-reorder-instructions

[2]

herdtools: https://github.com/herd/herdtools7

 

責任編輯:武曉燕 來源: 碼農桃花源
相關推薦

2020-11-08 14:32:01

JavaScript變量內存管理

2024-01-10 08:03:25

JMM重排序處理器

2010-06-02 11:06:15

Linux 內存監控

2010-09-25 12:38:40

JVM內存模型

2010-02-26 09:18:24

Visual Stud

2010-11-30 15:31:38

SharePoint Kerberos

2009-09-22 12:57:42

ibmdwWeb

2014-06-09 10:33:40

2009-08-03 17:31:26

.NET驗證控件

2009-03-20 14:38:14

CAM介紹CAMXML結構驗證

2023-09-19 08:00:00

Python開發

2014-07-03 09:39:34

Java內存分析mat工具

2010-11-08 10:07:23

SQL Server內

2018-11-14 19:30:57

前端Javascript性能優化

2021-10-29 11:27:52

鏈表數據結構算法

2019-09-17 14:31:37

磁盤排序IO

2019-06-29 14:34:27

磁盤IO排序

2013-08-27 14:23:18

瀏覽器重繪

2009-08-04 15:20:59

ASP.NET數據驗證數據驗證控件

2010-07-20 16:34:54

MySQL內存
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产一区二区三区在线免费 | 中文字幕在线观看一区二区 | 99爱国产 | 国产精品乱码一区二区三区 | 国产精品久久久爽爽爽麻豆色哟哟 | 成人免费网视频 | 日韩www视频| 少妇一区在线观看 | 国产视频第一页 | 成人黄色电影在线播放 | 91九色在线观看 | 91av亚洲 | 日日夜夜天天 | 欧美h| 国产免费自拍 | 秋霞性生活| 亚洲乱码一区二区三区在线观看 | 国产精品18久久久 | 欧美一区二区三区在线播放 | 亚洲成人三级 | 日日天天 | av一区二区三区四区 | 在线视频中文字幕 | 琪琪午夜伦伦电影福利片 | 亚洲激情第一页 | 国产一区二区三区免费 | 超碰8 | 人人人人干| 中文字幕1区| 黄色片在线观看网址 | 日本久久久久久 | 免费同性女女aaa免费网站 | 精品久久国产老人久久综合 | 久久国产一区二区三区 | 国产精品久久久久999 | 国产精品明星裸体写真集 | 欧美一级视频在线观看 | 日韩av一二三区 | 爱草视频 | 国产成人精品a视频一区www | 在线观看黄色电影 |