Colors of Ray+Hue'

http://stackoverflow.com/questions/30236620/what-is-wmb-in-linux-driver

What is wmb() in linux driver


WMB macro: Write Memory Barrior

Let's assume a serial port, where you have to write bytes to a certain address. The serial chip will then send these bytes over the wires. It is then important that you do not mess up the writes - they have to stay in order or everything is garbled.

But the following is not enough:

   *serial = 'h';
   *serial = 'e';
   *serial = 'l';
   *serial = 'l';
   *serial = 'o';

Because the compiler, the processor, the memory subsystems and the buses in between are allowed to reorder your stores as optimization.

so you'll have to add code that will ensure the stores do not get tangled up. That's what, amongst others, the wmb() macro does: prevent reordering of the stores.

Note that just making the serial pointer volatile is not enough: while it ensures the compiler will not reorder, the other mechanisms mentioned can still wreak havoc. This is documented in another kernel doc piece.

'Linux Kernel' 카테고리의 다른 글

Linear VS Physical Address  (0) 2016.08.10
Block I/O Operation  (0) 2016.08.06
What is the return address of kmalloc() ? Physical or Virtual?  (0) 2016.07.29
Memory Mapping  (0) 2016.07.28
고정 크기 ramdisk 만들기 및 swap 영역 사용  (0) 2016.03.22