Thread (20 messages) 20 messages, 5 authors, 2018-07-06

Re: [PATCH 2/3] locking: Clarify requirements for smp_mb__after_spinlock()

From: Peter Zijlstra <peterz@infradead.org>
Date: 2018-07-02 12:50:30
Also in: lkml

On Thu, Jun 28, 2018 at 07:30:45PM +0200, Andrea Parri wrote:
On Thu, Jun 28, 2018 at 05:05:50PM +0200, Peter Zijlstra wrote:
quoted
On Thu, Jun 28, 2018 at 12:41:19PM +0200, Andrea Parri wrote:
quoted
- * This barrier must provide two things:
- *
- *   - it must guarantee a STORE before the spin_lock() is ordered against a
- *     LOAD after it, see the comments at its two usage sites.
- *
- *   - it must ensure the critical section is RCsc.
- *
- * The latter is important for cases where we observe values written by other
- * CPUs in spin-loops, without barriers, while being subject to scheduling.
- *
- * CPU0			CPU1			CPU2
- *
- *			for (;;) {
- *			  if (READ_ONCE(X))
- *			    break;
- *			}
- * X=1
- *			<sched-out>
- *						<sched-in>
- *						r = X;
- *
- * without transitivity it could be that CPU1 observes X!=0 breaks the loop,
- * we get migrated and CPU2 sees X==0.
Please don't remove that; that explains _why_ we need a full memory
barrier here.
Peter:

Both you and Boqun stated that the above snippet is "bad":

  http://lkml.kernel.org/r/20180312085646.GE4064@hirez.programming.kicks-ass.net

and I do agree with your assessment! ;-)
Right..
I've no objection to keep that comment (together with the
"clarification" suggested in this patch) _once_ replaced
that snippet with something else (say, with the snippet
Boqun suggested in:

  http://lkml.kernel.org/r/20180312085600.aczjkpn73axzs2sb@tardis ):

is this what you mean?
Yes. I much prefer to explain the why for rule than to just state them.
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help