Re: [uclinux-dist-devel] [PATCH/RFC] asm-generic/mutex-dec.h: add SMP support

From: Mike Frysinger
Date: Mon Jun 06 2011 - 18:34:12 EST


On Mon, Jun 6, 2011 at 17:31, Mike Frysinger wrote:
> On Mon, Jun 6, 2011 at 17:23, Andrew Morton wrote:
>> On Sun, 29 May 2011 23:19:28 -0400 Mike Frysinger wrote:
>>> To make these guys work on SMP systems, we just need to sprinkle a few
>>> barriers around.
>>>
>>> diff --git a/include/asm-generic/mutex-dec.h b/include/asm-generic/mutex-dec.h
>>> index f104af7..e746c3c 100644
>>> --- a/include/asm-generic/mutex-dec.h
>>> +++ b/include/asm-generic/mutex-dec.h
>>> @@ -22,6 +22,8 @@ __mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
>>> Â{
>>> Â Â Â if (unlikely(atomic_dec_return(count) < 0))
>>> Â Â Â Â Â Â Â fail_fn(count);
>>> + Â Â else
>>> + Â Â Â Â Â Â smp_mb();
>>> Â}
>>>
>>> Â/**
>>> @@ -39,6 +41,7 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
>>> Â{
>>> Â Â Â if (unlikely(atomic_dec_return(count) < 0))
>>> Â Â Â Â Â Â Â return fail_fn(count);
>>> + Â Â smp_mb();
>>> Â Â Â return 0;
>>> Â}
>>>
>>> @@ -58,6 +61,7 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
>>> Âstatic inline void
>>> Â__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
>>> Â{
>>> + Â Â smp_mb();
>>> Â Â Â if (unlikely(atomic_inc_return(count) <= 0))
>>> Â Â Â Â Â Â Â fail_fn(count);
>>> Â}
>>> @@ -82,8 +86,10 @@ __mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
>>> Âstatic inline int
>>> Â__mutex_fastpath_trylock(atomic_t *count, int (*fail_fn)(atomic_t *))
>>> Â{
>>> - Â Â if (likely(atomic_cmpxchg(count, 1, 0) == 1))
>>> + Â Â if (likely(atomic_cmpxchg(count, 1, 0) == 1)) {
>>> + Â Â Â Â Â Â smp_mb();
>>> Â Â Â Â Â Â Â return 1;
>>> + Â Â }
>>> Â Â Â return 0;
>>> Â}
>>
>> This patch basically reverts Nick's a8ddac7e53e89cb ("mutex: speed up
>> generic mutex implementations"). ÂWhat's up with that?
>>
>> I could try to review this patch but I'm pathetic with barriers. ÂHelp.
>
> thanks for that tip. Âi think we can chalk this patch up to the
> origins of the Blackfin SMP port ... it branched this code before
> Nick's patch, and never incorporated common changes back. Âso i'll
> just drop it once i boot up a system to double check and convert the
> Blackfin code over to the asm-generic version completely to avoid
> future issues.

seems to be ok (and our core atomic's do include barriers themselves),
so let's just drop this patch on the floor and forget about it.
thanks all!
-mike
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/