Messages in this thread | | | Date | 16 Dec 2005 07:49:24 -0500 | From | linux@horizon ... | Subject | Re: [PATCH 1/19] MUTEX: Introduce simple mutex implementation |
| |
> Now my point about using LL/SC is that: > > 1,C,A cmpxchg(0,1) [failed] > 1,C,A cmpxchg(1,3) [success] > 3,C,A ... > > Can be turned into: > > 1,C,A x = LL() > 1,C,A x |= 2; > 1,C,A SC(3) [success] > 3,C,A ...
... which can be turned back into
1,C,A x = load() 1,C,A x' = x | 2; 1,C,A cmpxchg(x,x') [success] 3,C,A ...
which will fail and retry in exactly the same contention cases as the LL/SC. The only thing that LL gives you that's nice is a hint that an SC is due very soon and so resisting a cache eviction for a couple of cycles might be a good idea.
The reason that we tend to do the former is optimism that the lock won't be held. If that's a bad assumption, make it more pessimistic.
LL/SC can detect double changes during the critical section, but it's very similar in expressive power to load + CMPXCHG. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |