Messages in this thread | | | Date | Fri, 16 Jan 2009 06:51:03 +0900 | From | Tejun Heo <> | Subject | Re: [patch] add optimized generic percpu accessors |
| |
Hello, Roel.
roel kluin wrote: >> +#ifndef percpu_read >> +# define percpu_read(var) \ >> + ({ \ >> + typeof(per_cpu_var(var)) __tmp_var__; \ >> + __tmp_var__ = get_cpu_var(var); \ >> + put_cpu_var(var); \ >> + __tmp_var__; \ >> + }) >> +#endif > > I'm sorry for your eyes, but since var occurs twice, isn't it better to do: > > # define percpu_read(var) \ > ({ \ > typeof(var) __pcpu_read_var__ = var; > \ > typeof(per_cpu_var(__pcpu_read_var__)) __tmp_var__; \ > __tmp_var__ = get_cpu_var(__pcpu_read_var__); \ > put_cpu_var(__pcpu_read_var__); \ > __tmp_var__; \ > }) > >> + >> +#define __percpu_generic_to_op(var, val, op) \ >> +do { \ >> + get_cpu_var(var) op val; \ >> + put_cpu_var(var); \ >> +} while (0) > > and: > > #define __percpu_generic_to_op(var, val, op) \ > do { \ > typeof(var) __pcpu_gto_var__ = var; > \ > get_cpu_var(__pcpu_gto_var__) op val; > \ > put_cpu_var(__pcpu_gto_var__); > \ > } while (0)
@var has to be simple identifier as it ends up getting concatenated to a string. There's even a check for it in get_cpu_var() macro. Please also note that lack of any protecting ()'s around @var for the same reason. So, basically, typeof(var) just doesn't exist.
Thanks.
-- tejun
| |