Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

documentation: Clarify wake-up/memory-barrier relationship

This commit adds an example demonstrating that if a wake_up() doesn't
actually wake something up, no memory ordering is provided.

Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>

+15
+15
Documentation/memory-barriers.txt
··· 1893 1893 <general barrier> STORE current->state 1894 1894 LOAD event_indicated 1895 1895 1896 + To repeat, this write memory barrier is present if and only if something 1897 + is actually awakened. To see this, consider the following sequence of 1898 + events, where X and Y are both initially zero: 1899 + 1900 + CPU 1 CPU 2 1901 + =============================== =============================== 1902 + X = 1; STORE event_indicated 1903 + smp_mb(); wake_up(); 1904 + Y = 1; wait_event(wq, Y == 1); 1905 + wake_up(); load from Y sees 1, no memory barrier 1906 + load from X might see 0 1907 + 1908 + In contrast, if a wakeup does occur, CPU 2's load from X would be guaranteed 1909 + to see 1. 1910 + 1896 1911 The available waker functions include: 1897 1912 1898 1913 complete();