From: Ingo Molnar <mingo@elte.hu>
To: Frederic Weisbecker <fweisbec@gmail.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] x86: optimize a bit __raw_read_trylock
Date: Mon, 26 Jan 2009 14:07:03 +0100 [thread overview]
Message-ID: <20090126130703.GA16792@elte.hu> (raw)
In-Reply-To: <497cd085.2283420a.5373.49e7@mx.google.com>
* Frederic Weisbecker <fweisbec@gmail.com> wrote:
> The current version of __raw_read_trylock starts with decrementing the lock
> and read its new value as a separate operation after that.
>
> That makes 3 dereferences (read, write (after sub), read) whereas
> a single atomic_dec_return does only two pointers dereferences (read, write).
>
> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
> ---
> arch/x86/include/asm/spinlock.h | 3 +--
> 1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
> index 2bd6b11..139b424 100644
> --- a/arch/x86/include/asm/spinlock.h
> +++ b/arch/x86/include/asm/spinlock.h
> @@ -267,8 +267,7 @@ static inline int __raw_read_trylock(raw_rwlock_t *lock)
> {
> atomic_t *count = (atomic_t *)lock;
>
> - atomic_dec(count);
> - if (atomic_read(count) >= 0)
> + if (atomic_dec_return(count) >= 0)
> return 1;
> atomic_inc(count);
> return 0;
nice one ... applied it to tip/x86/asm, thanks Frederic!
Ingo
prev parent reply other threads:[~2009-01-26 13:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-25 20:50 [PATCH 1/2] x86: optimize a bit __raw_read_trylock Frederic Weisbecker
2009-01-26 13:07 ` Ingo Molnar [this message]
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=20090126130703.GA16792@elte.hu \
--to=mingo@elte.hu \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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