[RFR]: 8187227: __m68k_cmpxchg() is not being used correctly

John Paul Adrian Glaubitz glaubitz at physik.fu-berlin.de
Tue Sep 12 19:58:52 UTC 2017


Hi David!

Sorry for the late reply!

On 09/06/2017 04:11 AM, David Holmes wrote:
> Not really a review but I was curious about this ...

Ok :). Looks like a review though.

> On 5/09/2017 8:00 PM, John Paul Adrian Glaubitz wrote:
> I am surprised this even works at all. So trying to follow the logic if initially "prev == oldval" then the cas actually succeeds, but the loop logic thinks it
> failed and so retries. It re-reads the current value into prev, which no longer equals oldval, so the loop terminates and it returns "prev" which may actually
> be the value that was updated by the successful cas; or it could be a different value if some other thread has since also performed a successful cas. So this
> function would always report failure, even on success (except in ABA situation)! I can't see how anything would work in that case ??

I have to admit, compare-and-swap always gets me confused, so I have to carefully re-check the logic.

It goes like this:

1) store value of memory into prev
2) check if it's not equal to oldval (which is false at this point),
   thus continue and don't return
3) perform exchange, newprev contains oldval on success
4) if prev and newprev are identical, we actually made a
   successful exchange, hence return oldval
5) if newprev != prev, the exchange failed and we have
   whatever was in the memory location
6) write memory location contents into prev
7) if prev is not oldval, it means there was no exchange,
   hence return what was in the memory location

Does that make any sense?

> BTW m68k_compare_and_swap does not need to have a loop at all, it only has to
> do the cas and return the correct value. A loop would only be needed if the
> low-level cas can fail spuriously - which does not seem to be the case.
Good point. I will ask Andreas Schwab, who is the Linux m68k expert, on his opinion.

Adrian

-- 
 .''`.  John Paul Adrian Glaubitz
: :' :  Debian Developer - glaubitz at debian.org
`. `'   Freie Universitaet Berlin - glaubitz at physik.fu-berlin.de
  `-    GPG: 62FF 8A75 84E0 2956 9546  0006 7426 3B37 F5B5 F913


More information about the hotspot-dev mailing list