Re: [PATCH 2/3] x86: Remove cmpxchg from i386 NMI nesting code

From: Steven Rostedt
Date: Fri Jun 08 2012 - 13:36:13 EST


On Fri, 2012-06-08 at 10:28 -0700, H. Peter Anvin wrote:
> On 06/08/2012 09:41 AM, Steven Rostedt wrote:
>
> >>
> >> #define nmi_nesting_postprocess() \
> >> do { \
> >> - if (cmpxchg(&__get_cpu_var(nmi_state), \
> >> - NMI_EXECUTING, NMI_NOT_RUNNING) != NMI_EXECUTING) \
> >> + if (!local_dec_and_test(&__get_cpu_var(nmi_state))) \
> >
> > Now this is where I think the patch helps. I'm almost certain that
> > local_dec_and_test is faster than a cmpxchg by many cycles. Especially
> > on i386.
> >
>
> On i386 it's infinite, but again, I don't think the code will ever be
> exercised on i386. I'm much more concerned about performance on current
> processors.

I'm not worried about non i386 here. Some context missing from the patch
is that this code is surrounded by:

#ifdef CONFIG_X86_32

[...]

#else

The '#else' part does something completely different, as this work is
done in the assembly handler on x86_64.

And yes, this code is executed on i386 (well when I boot my x86_64 into
an i386 kernel it does).


>
> But yes, local_dec_and_test should at least not be more expensive. Even
> better, use this_cpu_dec_return().

Oh! That would make this much better! I'll update the patch set.

Thanks!

-- Steve




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/