Question about wmb() and rmb() and task switching

Hans Petter Selasky hps at selasky.org
Fri Sep 23 11:41:29 UTC 2016


Hi,

Does use of wmb() and rmb() for amd64 as defined in 
sys/amd64/include/atomic.h required use of critical_enter()/critical_exit().

I was looking at the code in sys/amd64/amd64/cpu_switch.S which switches 
between threads and I don't see any "sfence" instructions in there.

Given the following piece of dummy code:

var_a = 1;
var_b = 2;
wmb();

If there is a task switch between writing var_a and var_b so that the 
thread in question continues executing on another core, can it happen 
that the write to var_a is not flushed when wmb() is executed?

var_a = 1;
<task switch to different CPU core>
var_b = 2;
wmb();

--HPS


More information about the freebsd-current mailing list