Re: [PATCH] fix vmstat per cpu usage

Andrew Morton
2006-08-02T14:43:15Z

On Wed, 2 Aug 2006 15:30:06 +0200
Jan Blunck <jblunck@suse.de> wrote:

> Here comes another idea. To find further wrong usage of percpu variables I
> wrote the following patch. It still needs some work for the other archs but
> I'm interested in your feedback about that.
>
> ...
>
> Index: linux-2.6/include/asm-generic/percpu.h
> ===================================================================
> --- linux-2.6.orig/include/asm-generic/percpu.h
> +++ linux-2.6/include/asm-generic/percpu.h
> @@ -14,7 +14,9 @@ extern unsigned long __per_cpu_offset[NR
> __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
>
> /* var is in discarded region: offset to particular copy we want */
> -#define per_cpu(var, cpu) (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]))
> +#define per_cpu(var, cpu) (*({ \
> + int user_error_##var __attribute__ ((unused)); \
> + RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]); }))

What's it do? Forces a syntax error if `var' isn't a simple identifier?

Seems sane, although I'd check that the compiler doesn't accidentally
waste a stack slot for that local. Perhaps it's be safer to make
it a non-existing function:

extern int user_error#var(void);