From: "H. Peter Anvin" <hpa@zytor.com>
To: Roland Dreier <rdreier@cisco.com>
Cc: 杨硕 <shanqn@gmail.com>, linux-kernel@vger.kernel.org
Subject: Re: in x86 architecture ,why the function atomic_sub_and_test() does not disable the interrupt?
Date: Tue, 06 Apr 2010 13:11:12 -0700 [thread overview]
Message-ID: <4BBB9560.6070905@zytor.com> (raw)
In-Reply-To: <adahbnp6rmr.fsf@roland-alpha.cisco.com>
On 04/05/2010 11:07 PM, Roland Dreier wrote:
> > static inline int atomic_sub_and_test(int i, atomic_t *v)
> > {
> > unsigned char c;
> >
> > asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
> > : "+m" (v->counter), "=qm" (c)
> > : "ir" (i) : "memory");
> > return c;
> > }
>
> Why would disabling interrupts be necessary? The LOCK_PREFIX makes the
> subl atomic, and the sete just operates using the flag set by subl, so
> it doesn't matter if any interrupts occur or not (since returning from
> an interrupt must obviously restore flags).
Even without the LOCK prefix, subl would be atomic against local
interrupts. The LOCK prefix is only necessary to make it atomic against
other processors.
-hpa
prev parent reply other threads:[~2010-04-06 20:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-06 5:13 in x86 architecture ,why the function atomic_sub_and_test() does not disable the interrupt? 杨硕
2010-04-06 6:07 ` Roland Dreier
2010-04-06 20:11 ` H. Peter Anvin [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=4BBB9560.6070905@zytor.com \
--to=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rdreier@cisco.com \
--cc=shanqn@gmail.com \
/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