파이프라인상에서의 dmb(Data Memory Barrier) 동작방식

이전 포스팅에서 살펴본 사전 지식들을 바탕으로 아래 문서의 문구들을 참고하여 파이프라인 상에서 dmb 가 동작하는 방식을 그냥 제 나름대로 상상으로 정리해 봅니다. 관련 자료를 찾기가 상당히 어렵더군요.

Memory Barriers: a Hardware View for Software Hackers

The memory barrier smp_mb() will cause the CPU to flush its sotre buffer before applying each subsequent store to its variable’s cache line. The CPU could either simply stall until the store buffer was empty before proceeding, or it could use the store buffer to hold subsequent stores until all of the prio.r entries in the store buffer had been applied.

아래 내용은 완전히 제 상상입니다.

가정
  • dmb 명령은 operand 를 필요로 하는 명령어가 아니므로 reservation station 을 할당하지 않는다.
  • dmb 명령은 ALU 나 FPU 등과 같은 Execution Unit 을 사용할 일도 없다.
  • dmb 명령은 다른 명령들처럼 reorder buffer 는 똑같이 entry 를 하나 할당받는다.
    따라서, 다른 명령들과 함께 dmb 명령이 순차적으로 reorder buffer 에 들어가게 된다.
동작방식
  • commit 시에 reorder buffer 의 제일 오래된 명령어가 dmb 인지 검사한다.
  • dmb 명령어가 가장 오래된 명령어이면, 현재 store buffer 에 남아있는 store 를 모두 flush 시킨다.
    이 때 만약 store buffer 내의 load/store 간에 서로 의존성이 있어서 완료가 아직 안되었을 경우,
    이의 완료까지 기다린 후 flush 까지 시킨다. (register 로의 load 도 모두 완료된다.)
    store buffer 에서 flush 되는 순서는 물론 순차적(in-order)이 된다.
  • reorder buffer 에서 dmb 명령어를 제거한다.
  • store buffer 를 flush 하게 되면 Local Cache 에 변경사항이 적용되고, 이후과정은 cache coherence 에 맡겨진다.

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x