From: Arjan van de Ven <arjan@infradead.org>
To: Bruno Santos <bsantos@av.it.pt>
Cc: linux-kernel@vger.kernel.org
Subject: Re: semaphore: lockless fastpath using atomic_{inc,dec}_return
Date: Wed, 9 Jul 2008 13:05:04 -0700 [thread overview]
Message-ID: <20080709130504.728f37d8@infradead.org> (raw)
In-Reply-To: <4874EDB5.7030007@av.it.pt>
> >
> From your words if we do:
>
> spin_lock()
> val = --foo;
> spin_unlock();
>
> Has the same cost than:
>
> val = atomic_dec_return(&foo);
yes
> How come I have the same number of atomic ops?
>
> Let's consider the fast case scenario (semaphore is unlocked for the
> 'down' and has no waiters for 'up') in x86:
> - with the spinlock only approach we have 2 atomic ops, xadd for
> lock, inc for unlock. The unlock doesn't come for free in x86 after
> all.
the unlock does not use an atomic operation.
--
If you want to reach me at my work email, use arjan@linux.intel.com
For development, discussion and tips for power savings,
visit http://www.lesswatts.org
next prev parent reply other threads:[~2008-07-09 20:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-09 15:39 Bruno Santos
2008-07-09 15:50 ` Arjan van de Ven
2008-07-09 16:56 ` Bruno Santos
2008-07-09 19:27 ` Bruno Santos
2008-07-09 20:05 ` Arjan van de Ven [this message]
-- strict thread matches above, loose matches on Subject: below --
2008-07-09 13:13 Bruno Santos
2008-07-09 14:16 ` Arjan van de Ven
2008-07-09 14:24 ` Christoph Lameter
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=20080709130504.728f37d8@infradead.org \
--to=arjan@infradead.org \
--cc=bsantos@av.it.pt \
--cc=linux-kernel@vger.kernel.org \
/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