Re: [PATCH 3/5] x86: Reset the debug_stack update counter

From: H. Peter Anvin
Date: Thu May 31 2012 - 15:19:38 EST


On 05/30/2012 06:28 PM, Steven Rostedt wrote:
>>
> diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c index
> 9087527..c1fffc5 100644 --- a/arch/x86/kernel/nmi.c +++
> b/arch/x86/kernel/nmi.c @@ -450,8 +450,10 @@ static inline void
> nmi_nesting_preprocess(struct pt_regs *regs)
>
> static inline void nmi_nesting_postprocess(void) { - if
> (unlikely(__get_cpu_var(update_debug_stack))) + if
> (unlikely(__get_cpu_var(update_debug_stack))) {
> debug_stack_reset(); + __get_cpu_var(update_debug_stack) = 0; + }
> } #endif
>

Please don't use __get_cpu_var(); it causes a pointer to be manifest,
which is free or almost free on most architectures but quite expensive
on x86.

Instead use this_cpu_read()/this_cpu_write().

Consider:

#include <linux/types.h>
#include <linux/percpu.h>

static DEFINE_PER_CPU(int, percpu_test);

int read_foo(void)
{
return __get_cpu_var(percpu_test);
}

void write_foo(int x)
{
__get_cpu_var(percpu_test) = x;
}

int read_bar(void)
{
return this_cpu_read(percpu_test);
}

void write_bar(int x)
{
this_cpu_write(percpu_test, x);
}

... and the corresponding assembly code (with gcc boilerplate removed):

read_foo:
movq $percpu_test, %rax #, tcp_ptr__
add %gs:this_cpu_off, %rax # this_cpu_off, tcp_ptr__
movl (%rax), %eax # *D.8429_3, *D.8429_3
ret

write_foo:
movq $percpu_test, %rax #, tcp_ptr__
add %gs:this_cpu_off, %rax # this_cpu_off, tcp_ptr__
movl %edi, (%rax) # x, *D.8435_3
ret

read_bar:
movl %gs:percpu_test,%eax # percpu_test, pfo_ret__

write_bar:
movl %edi,%gs:percpu_test # x, percpu_test
ret

--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.

--
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/