2009-12-19 00:27:13

by Christoph Lameter

[permalink] [raw]
Subject: [this_cpu_xx V8 09/16] Allow arch to provide inc/dec functionality for each size separately

Current this_cpu ops only allow an arch to specify add RMW operations or inc
and dec for all sizes. Some arches can do more efficient inc and dec
operations. Allow size specific override of fallback functions like with
the other operations.

Signed-off-by: Christoph Lameter <[email protected]>

---
include/linux/percpu.h | 96 +++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 90 insertions(+), 6 deletions(-)

Index: linux-2.6/include/linux/percpu.h
===================================================================
--- linux-2.6.orig/include/linux/percpu.h 2009-12-18 13:34:13.000000000 -0600
+++ linux-2.6/include/linux/percpu.h 2009-12-18 14:19:25.000000000 -0600
@@ -257,6 +257,18 @@ do { \
} \
} while (0)

+#define __pcpu_size_call_noparam(stem, variable) \
+do { \
+ switch(sizeof(variable)) { \
+ case 1: stem##1(variable);break; \
+ case 2: stem##2(variable);break; \
+ case 4: stem##4(variable);break; \
+ case 8: stem##8(variable);break; \
+ default: \
+ __bad_size_call_parameter();break; \
+ } \
+} while (0)
+
/*
* Optimized manipulation for memory allocated through the per cpu
* allocator or for addresses of per cpu variables (can be determined
@@ -352,11 +364,35 @@ do { \
#endif

#ifndef this_cpu_inc
-# define this_cpu_inc(pcp) this_cpu_add((pcp), 1)
+# ifndef this_cpu_inc_1
+# define this_cpu_inc_1(pcp) __this_cpu_add((pcp), 1)
+# endif
+# ifndef this_cpu_inc_2
+# define this_cpu_inc_2(pcp) __this_cpu_add((pcp), 1)
+# endif
+# ifndef this_cpu_inc_4
+# define this_cpu_inc_4(pcp) __this_cpu_add((pcp), 1)
+# endif
+# ifndef this_cpu_inc_8
+# define this_cpu_inc_8(pcp) __this_cpu_add((pcp), 1)
+# endif
+# define this_cpu_inc(pcp) __pcpu_size_call_noparam(this_cpu_inc_, (pcp))
#endif

#ifndef this_cpu_dec
-# define this_cpu_dec(pcp) this_cpu_sub((pcp), 1)
+# ifndef this_cpu_dec_1
+# define this_cpu_dec_1(pcp) __this_cpu_sub((pcp), 1)
+# endif
+# ifndef this_cpu_dec_2
+# define this_cpu_dec_2(pcp) __this_cpu_sub((pcp), 1)
+# endif
+# ifndef this_cpu_dec_4
+# define this_cpu_dec_4(pcp) __this_cpu_sub((pcp), 1)
+# endif
+# ifndef this_cpu_dec_8
+# define this_cpu_dec_8(pcp) __this_cpu_sub((pcp), 1)
+# endif
+# define this_cpu_dec(pcp) __pcpu_size_call_noparam(this_cpu_dec_, (pcp))
#endif

#ifndef this_cpu_and
@@ -479,11 +515,35 @@ do { \
#endif

#ifndef __this_cpu_inc
-# define __this_cpu_inc(pcp) __this_cpu_add((pcp), 1)
+# ifndef __this_cpu_inc_1
+# define __this_cpu_inc_1(pcp) __this_cpu_add_1((pcp), 1)
+# endif
+# ifndef __this_cpu_inc_2
+# define __this_cpu_inc_2(pcp) __this_cpu_add_2((pcp), 1)
+# endif
+# ifndef __this_cpu_inc_4
+# define __this_cpu_inc_4(pcp) __this_cpu_add_4((pcp), 1)
+# endif
+# ifndef __this_cpu_inc_8
+# define __this_cpu_inc_8(pcp) __this_cpu_add_8((pcp), 1)
+# endif
+# define __this_cpu_inc(pcp) __pcpu_size_call_noparam(__this_cpu_inc_, (pcp))
#endif

#ifndef __this_cpu_dec
-# define __this_cpu_dec(pcp) __this_cpu_sub((pcp), 1)
+# ifndef __this_cpu_dec_1
+# define __this_cpu_dec_1(pcp) __this_cpu_sub((pcp), 1)
+# endif
+# ifndef __this_cpu_dec_2
+# define __this_cpu_dec_2(pcp) __this_cpu_sub((pcp), 1)
+# endif
+# ifndef __this_cpu_dec_4
+# define __this_cpu_dec_4(pcp) __this_cpu_sub((pcp), 1)
+# endif
+# ifndef __this_cpu_dec_8
+# define __this_cpu_dec_8(pcp) __this_cpu_sub((pcp), 1)
+# endif
+# define __this_cpu_dec(pcp) __pcpu_size_call_noparam(__this_cpu_dec_, (pcp))
#endif

#ifndef __this_cpu_and
@@ -570,11 +630,35 @@ do { \
#endif

#ifndef irqsafe_cpu_inc
-# define irqsafe_cpu_inc(pcp) irqsafe_cpu_add((pcp), 1)
+# ifndef irqsafe_cpu_inc_1
+# define irqsafe_cpu_inc_1(pcp) irqsafe_cpu_add_1((pcp), 1)
+# endif
+# ifndef irqsafe_cpu_inc_2
+# define irqsafe_cpu_inc_2(pcp) irqsafe_cpu_add_2((pcp), 1)
+# endif
+# ifndef irqsafe_cpu_inc_4
+# define irqsafe_cpu_inc_4(pcp) irqsafe_cpu_add_4((pcp), 1)
+# endif
+# ifndef irqsafe_cpu_inc_8
+# define irqsafe_cpu_inc_8(pcp) irqsafe_cpu_add_8((pcp), 1)
+# endif
+# define irqsafe_cpu_inc(pcp) __pcpu_size_call_noparam(irqsafe_cpu_inc_, (pcp))
#endif

#ifndef irqsafe_cpu_dec
-# define irqsafe_cpu_dec(pcp) irqsafe_cpu_sub((pcp), 1)
+# ifndef irqsafe_cpu_dec_1
+# define irqsafe_cpu_dec_1(pcp) irqsafe_cpu_sub_1((pcp), 1)
+# endif
+# ifndef irqsafe_cpu_dec_2
+# define irqsafe_cpu_dec_2(pcp) irqsafe_cpu_sub_2((pcp), 1)
+# endif
+# ifndef irqsafe_cpu_dec_4
+# define irqsafe_cpu_dec_4(pcp) irqsafe_cpu_sub_4((pcp), 1)
+# endif
+# ifndef irqsafe_cpu_dec_8
+# define irqsafe_cpu_dec_8(pcp) irqsafe_cpu_sub_8((pcp), 1)
+# endif
+# define irqsafe_cpu_dec(pcp) __pcpu_size_call_noparam(irqsafe_cpu_dec_, (pcp))
#endif

#ifndef irqsafe_cpu_and

--


2009-12-21 07:23:28

by Tejun Heo

[permalink] [raw]
Subject: Re: [this_cpu_xx V8 09/16] Allow arch to provide inc/dec functionality for each size separately

On 12/19/2009 07:26 AM, Christoph Lameter wrote:
> Current this_cpu ops only allow an arch to specify add RMW operations or inc
> and dec for all sizes. Some arches can do more efficient inc and dec
> operations. Allow size specific override of fallback functions like with
> the other operations.

Wouldn't it be better to use __builtin_constant_p() and switching in
arch add/dec macros? It just seems a bit extreme to define all those
different variants from generic header. I'm quite unsure whether
providing overrides for all the different size variants from generic
header is necessary at all. If an arch is gonna override the
operation, it's probably best to just let it override the whole thing.

Thanks.

--
tejun

2009-12-22 15:57:31

by Christoph Lameter

[permalink] [raw]
Subject: Re: [this_cpu_xx V8 09/16] Allow arch to provide inc/dec functionality for each size separately

On Mon, 21 Dec 2009, Tejun Heo wrote:

> On 12/19/2009 07:26 AM, Christoph Lameter wrote:
> > Current this_cpu ops only allow an arch to specify add RMW operations or inc
> > and dec for all sizes. Some arches can do more efficient inc and dec
> > operations. Allow size specific override of fallback functions like with
> > the other operations.
>
> Wouldn't it be better to use __builtin_constant_p() and switching in
> arch add/dec macros? It just seems a bit extreme to define all those

Yes that could be done but I am on vacation till next year ;-)...

2009-12-23 02:06:07

by Tejun Heo

[permalink] [raw]
Subject: Re: [this_cpu_xx V8 09/16] Allow arch to provide inc/dec functionality for each size separately

Hello, Christoph.

On 12/23/2009 12:56 AM, Christoph Lameter wrote:
> On Mon, 21 Dec 2009, Tejun Heo wrote:
>
>> On 12/19/2009 07:26 AM, Christoph Lameter wrote:
>>> Current this_cpu ops only allow an arch to specify add RMW operations or inc
>>> and dec for all sizes. Some arches can do more efficient inc and dec
>>> operations. Allow size specific override of fallback functions like with
>>> the other operations.
>>
>> Wouldn't it be better to use __builtin_constant_p() and switching in
>> arch add/dec macros? It just seems a bit extreme to define all those
>
> Yes that could be done but I am on vacation till next year ;-)...

I'm not sure how much I would be working from now till the end of the
year but if I end up doing some work I'll give it a shot.

Happy holidays and enjoy your vacation!

--
tejun