From: Ingo Molnar <mingo@elte.hu>
To: Nicolas Pitre <nico@cam.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
Arjan van de Ven <arjan@infradead.org>,
Russell King <rmk+lkml@arm.linux.org.uk>
Subject: Re: [patch 1/3] mutex subsystem: trylock
Date: Tue, 27 Dec 2005 12:51:29 +0100 [thread overview]
Message-ID: <20051227115129.GB23587@elte.hu> (raw)
In-Reply-To: <Pine.LNX.4.64.0512261411530.1496@localhost.localdomain>
* Nicolas Pitre <nico@cam.org> wrote:
> In the spirit of uniformity, this patch provides architecture specific
> trylock implementations. This allows for a pure xchg-based
> implementation, as well as an optimized ARMv6 implementation.
hm, i dont really like the xchg variant:
> +static inline int
> +__mutex_trylock(atomic_t *count)
> +{
> + int prev = atomic_xchg(count, 0);
> +
> + if (unlikely(prev < 0)) {
> + /*
> + * The lock was marked contended so we must restore that
> + * state. If while doing so we get back a prev value of 1
> + * then we just own it.
> + *
> + * IN all cases this has the potential to trigger the
> + * slowpath for the owner's unlock path - but this is not
> + * a big problem in practice.
> + */
> + prev = atomic_xchg(count, -1);
> + if (prev < 0)
> + prev = 0;
> + }
here we go to great trouble trying to avoid the 'slowpath', while we
unconditionally force the next unlock into the slowpath! So we have not
won anything. (on a cycle count basis it's probably even a net loss)
The same applies to atomic_dec_return() based trylock variant. Only the
cmpxchg based one, and the optimized ARM variant should be used as a
'fastpath'.
another thing is that this solution still leaves that ugly #ifdef in
kernel/mutex.c.
so i took a different solution that solves both problems. The API
towards architectures is now:
static inline int
__mutex_fastpath_trylock(atomic_t *count, int (*fn)(atomic_t *))
note the new 'fn' parameter: this enables mutex-null.h to do a simple:
#define __mutex_fastpath_trylock(count, fn_name) fn_name(count)
and the final ugly debugging related #ifdef is gone from kernel/mutex.c!
Furthermore, both the mutex-xchg.h and the mutex-dec.h non-cmpxchg
variant will fall back to the spinlock implementation.
Ingo
next prev parent reply other threads:[~2005-12-27 11:51 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-12-23 16:16 [patch 00/11] mutex subsystem, -V7 Ingo Molnar
2005-12-24 5:15 ` Nicolas Pitre
2005-12-24 5:23 ` Nicolas Pitre
2005-12-26 19:24 ` Nicolas Pitre
2005-12-26 19:25 ` [patch 1/3] mutex subsystem: trylock Nicolas Pitre
2005-12-27 11:51 ` Ingo Molnar [this message]
2005-12-27 20:47 ` Nicolas Pitre
2005-12-28 7:48 ` Ingo Molnar
2005-12-28 8:13 ` Ingo Molnar
2005-12-28 16:29 ` Nicolas Pitre
2005-12-28 17:09 ` Ingo Molnar
2005-12-27 12:05 ` Arjan van de Ven
2005-12-27 13:15 ` Ingo Molnar
2005-12-29 4:06 ` Nicolas Pitre
2005-12-29 8:33 ` Ingo Molnar
2005-12-29 9:01 ` Nick Piggin
2005-12-29 17:15 ` Nicolas Pitre
2005-12-30 2:05 ` Nick Piggin
2005-12-29 16:46 ` Nicolas Pitre
2005-12-29 3:22 ` Nicolas Pitre
2005-12-26 19:25 ` [patch 2/3] mutex subsystem: fastpath inlining Nicolas Pitre
2005-12-27 11:55 ` Ingo Molnar
2005-12-27 21:59 ` Nicolas Pitre
2005-12-28 7:41 ` Ingo Molnar
2005-12-29 2:53 ` Nicolas Pitre
2005-12-29 8:41 ` Ingo Molnar
2006-01-06 21:20 ` Nicolas Pitre
2005-12-26 19:26 ` [patch 3/3] mutex subsystem: inline mutex_is_locked() Nicolas Pitre
2005-12-27 11:37 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20051227115129.GB23587@elte.hu \
--to=mingo@elte.hu \
--cc=arjan@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nico@cam.org \
--cc=rmk+lkml@arm.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome