* in x86 architecture ,why the function atomic_sub_and_test() does not disable the interrupt?
@ 2010-04-06 5:13 杨硕
2010-04-06 6:07 ` Roland Dreier
0 siblings, 1 reply; 3+ messages in thread
From: 杨硕 @ 2010-04-06 5:13 UTC (permalink / raw)
To: linux-kernel
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;
}
TIA:)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: in x86 architecture ,why the function atomic_sub_and_test() does not disable the interrupt?
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
0 siblings, 1 reply; 3+ messages in thread
From: Roland Dreier @ 2010-04-06 6:07 UTC (permalink / raw)
To: 杨硕; +Cc: linux-kernel
> 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).
--
Roland Dreier <rolandd@cisco.com> || For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/index.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: 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
0 siblings, 0 replies; 3+ messages in thread
From: H. Peter Anvin @ 2010-04-06 20:11 UTC (permalink / raw)
To: Roland Dreier; +Cc: 杨硕, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-04-06 20:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox