From: Nicolas Pitre <nico@cam.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Arjan van de Ven <arjan@infradead.org>,
lkml <linux-kernel@vger.kernel.org>
Subject: Re: [patch 1/3] mutex subsystem: trylock
Date: Wed, 28 Dec 2005 23:06:53 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.64.0512282222400.3309@localhost.localdomain> (raw)
In-Reply-To: <20051227131501.GA29134@elte.hu>
On Tue, 27 Dec 2005, Ingo Molnar wrote:
>
> * Arjan van de Ven <arjan@infradead.org> wrote:
>
> > > + * 1) if the exclusive store fails we fail, and
> > > + *
> > > + * 2) if the decremented value is not zero we don't even attempt the store.
> >
> >
> > btw I really think that 1) is wrong. trylock should do everything it
> > can to get the semaphore short of sleeping. Just because some
> > cacheline got written to (which might even be shared!) in the middle
> > of the atomic op is not a good enough reason to fail the trylock imho.
> > Going into the slowpath.. fine. But here it's a quality of
> > implementation issue; you COULD get the semaphore without sleeping (at
> > least probably, you'd have to retry to know for sure) but because
> > something wrote to the same cacheline as the lock... no. that's just
> > not good enough.. sorry.
>
> point. I solved this in my tree by calling the generic trylock <fn> if
> there's an __ex_flag failure in the ARMv6 case. Should be rare (and thus
> the call is under unlikely()), and should thus still enable the fast
> implementation.
I'd solve it like this instead (on top of your latest patches):
Index: linux-2.6/include/asm-arm/mutex.h
===================================================================
--- linux-2.6.orig/include/asm-arm/mutex.h
+++ linux-2.6/include/asm-arm/mutex.h
@@ -110,12 +110,7 @@ do { \
/*
* For __mutex_fastpath_trylock we use another construct which could be
- * described as an "incomplete atomic decrement" or a "single value cmpxchg"
- * since it has two modes of failure:
- *
- * 1) if the exclusive store fails we fail, and
- *
- * 2) if the decremented value is not zero we don't even attempt the store.
+ * described as a "single value cmpxchg".
*
* This provides the needed trylock semantics like cmpxchg would, but it is
* lighter and less generic than a true cmpxchg implementation.
@@ -123,27 +118,22 @@ do { \
static inline int
__mutex_fastpath_trylock(atomic_t *count, int (*fn_name)(atomic_t *))
{
- int __ex_flag, __res;
+ int __ex_flag, __res, __orig;
__asm__ (
- "ldrex %0, [%2] \n"
- "subs %0, %0, #1 \n"
- "strexeq %1, %0, [%2] \n"
+ "1: ldrex %0, [%3] \n"
+ "subs %1, %0, #1 \n"
+ "strexeq %2, %1, [%3] \n"
+ "movlt %0, #0 \n"
+ "cmpeq %2, #0 \n"
+ "bgt 1b \n"
- : "=&r" (__res), "=&r" (__ex_flag)
+ : "=&r" (__orig), "=&r" (__res), "=&r" (__ex_flag)
: "r" (&count->counter)
: "cc", "memory" );
- /*
- * We must not return a synthetic 'failure' if the conditional
- * did not succeed - drop back into the generic slowpath if
- * this happens (should be rare):
- */
- if (unlikely(__ex_flag))
- return fn_name(count);
-
- return __res == 0;
+ return __orig;
}
#endif
Nicolas
next prev parent reply other threads:[~2005-12-29 4:06 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
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 [this message]
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=Pine.LNX.4.64.0512282222400.3309@localhost.localdomain \
--to=nico@cam.org \
--cc=arjan@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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
all inboxes | Powered by JetHome®