From: Peter Zijlstra > Sent: 11 July 2018 12:10 .. > Adding SYNC to WRITE_ONCE()/atomic* will hurt performance lots and will > ultimately not guarantee anything more; and as Will said, keep you > chasing dragons where people forgot to use WRITE_ONCE() where they maybe > should've.
Also WRITE_ONCE() is there to solve an entirely different problem. If you have a function that does: <lots of code without any function calls> foo->bar = 1; the compiler is allowed to write other (unrelated) values to foo->bar in the generated code for <lots of code>. A long time ago I used a compiler that managed to convert: if (foo->bar == 2) foo->bar = 3; into: if (foo->bar == 2) { foo->bar = 0; foo->bar = 3; } When an interrupt read the value 0 a lot of linked list got screwed up. WRITE_ONCE() is there to ensure that doesn't happen. (In my case 'foo' was a 2-bit wide bitfield, and I suspect you can't use WRITE_ONCE() on bitfields.) David