-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel-barrier
18 lines (10 loc) · 946 Bytes
/
kernel-barrier
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Linux kernel barriers
There are many barriers in Linux kernel to implete ordered read or write operations, to ensure the code is not reordered by compiler or the processor itself, so barriers are applied to kernel.
1. mb(), rmb(), wmb(), read_barrier_depends()
mb() is a combination of rmb() and wmb(), it ensures orders of read and write.
rmb() ensures that the read prior to rmb() should be completed before rmb(), and read after should not take place before rmb();
wmb() ensure that the write prior to wmb() should be completed before wmb(), and the write below wmb() should not take place before wmb().
that is to say read and write can't across the barrier.
read_barrier_depends() is not as strict as rmb(), but it at least ensures the read below this barrier can't be executed before the one it depends which is above the barrier.
2. some barriers relate to SMP
smp_rmb(), smp_wmb(), smp_mb(), smp_read_barrier_depends()