[thiscpuops upgrade 03/10] percpu: Generic support for this_cpu_add,sub,dec,inc_return

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Christoph Lameter
Date: Tuesday, November 23, 2010 - 4:51 pm

Introduce generic support for this_cpu_add_return etc.

The fallback is to realize these operations with __this_cpu_ops.

Signed-off-by: Christoph Lameter <cl@linux.com>

---
 include/linux/percpu.h |   70 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

Index: linux-2.6/include/linux/percpu.h
===================================================================
--- linux-2.6.orig/include/linux/percpu.h	2010-11-23 17:29:46.000000000 -0600
+++ linux-2.6/include/linux/percpu.h	2010-11-23 17:31:14.000000000 -0600
@@ -240,6 +240,20 @@ extern void __bad_size_call_parameter(vo
 	pscr_ret__;							\
 })
 
+#define __pcpu_size_call_return2(stem, variable, ...)			\
+({	typeof(variable) pscr_ret__;					\
+	__verify_pcpu_ptr(&(variable));					\
+	switch(sizeof(variable)) {					\
+	case 1: pscr_ret__ = stem##1(variable, __VA_ARGS__);break;	\
+	case 2: pscr_ret__ = stem##2(variable, __VA_ARGS__);break;	\
+	case 4: pscr_ret__ = stem##4(variable, __VA_ARGS__);break;	\
+	case 8: pscr_ret__ = stem##8(variable, __VA_ARGS__);break;	\
+	default:							\
+		__bad_size_call_parameter();break;			\
+	}								\
+	pscr_ret__;							\
+})
+
 #define __pcpu_size_call(stem, variable, ...)				\
 do {									\
 	__verify_pcpu_ptr(&(variable));					\
@@ -529,6 +543,62 @@ do {									\
 # define __this_cpu_xor(pcp, val)	__pcpu_size_call(__this_cpu_xor_, (pcp), (val))
 #endif
 
+#define _this_cpu_generic_add_return(pcp, val)				\
+({	typeof(pcp) ret__;						\
+	preempt_disable();						\
+	__this_cpu_add((pcp), val);					\
+	ret__ = __this_cpu_read((pcp));					\
+	preempt_enable();						\
+	ret__;								\
+})
+
+#ifndef this_cpu_add_return
+# ifndef this_cpu_add_return_1
+#  define this_cpu_add_return_1(pcp, val)	_this_cpu_generic_add_return(pcp, val)
+# endif
+# ifndef this_cpu_add_return_2
+#  define this_cpu_add_return_2(pcp, val)	_this_cpu_generic_add_return(pcp, val)
+# endif
+# ifndef this_cpu_add_return_4
+#  define this_cpu_add_return_4(pcp, val)	_this_cpu_generic_add_return(pcp, val)
+# endif
+# ifndef this_cpu_add_return_8
+#  define this_cpu_add_return_8(pcp, val)	_this_cpu_generic_add_return(pcp, val)
+# endif
+# define this_cpu_add_return(pcp, val)	__pcpu_size_call_return2(this_cpu_add_return_, (pcp), val)
+#endif
+
+#define this_cpu_sub_return(pcp, val)	this_cpu_add_return(pcp, -(val))
+#define this_cpu_inc_return(pcp)	this_cpu_add_return(pcp, 1)
+#define this_cpu_dec_return(pcp)	this_cpu_add_return(pcp, -1)
+
+#define __this_cpu_generic_add_return(pcp, val)				\
+({	typeof(pcp) ret__;						\
+	__this_cpu_add((pcp), val);					\
+	ret__ = __this_cpu_read((pcp));					\
+	ret__;								\
+})
+
+#ifndef __this_cpu_add_return
+# ifndef __this_cpu_add_return_1
+#  define __this_cpu_add_return_1(pcp, val)	__this_cpu_generic_add_return(pcp, val)
+# endif
+# ifndef __this_cpu_add_return_2
+#  define __this_cpu_add_return_2(pcp, val)	__this_cpu_generic_add_return(pcp, val)
+# endif
+# ifndef __this_cpu_add_return_4
+#  define __this_cpu_add_return_4(pcp, val)	__this_cpu_generic_add_return(pcp, val)
+# endif
+# ifndef __this_cpu_add_return_8
+#  define __this_cpu_add_return_8(pcp, val)	__this_cpu_generic_add_return(pcp, val)
+# endif
+# define __this_cpu_add_return(pcp, val)	__pcpu_size_call_return2(this_cpu_add_return_, (pcp), val)
+#endif
+
+#define __this_cpu_sub_return(pcp, val)	this_cpu_add_return(pcp, -(val))
+#define __this_cpu_inc_return(pcp)	this_cpu_add_return(pcp, 1)
+#define __this_cpu_dec_return(pcp)	this_cpu_add_return(pcp, -1)
+
 /*
  * IRQ safe versions of the per cpu RMW operations. Note that these operations
  * are *not* safe against modification of the same variable from another

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[thiscpuops upgrade 00/10] Upgrade of this_cpu_ops, Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 02/10] vmstat: Optimize zone counter m ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 03/10] percpu: Generic support for thi ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 04/10] x86: Support for this_cpu_add,s ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 05/10] x86: Use this_cpu_inc_return fo ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 06/10] vmstat: Use this_cpu_inc_return ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 07/10] highmem: Use this_cpu_xx_return ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 08/10] percpu: generic this_cpu_cmpxch ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 09/10] x86: this_cpu_cmpxchg and this_ ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
[thiscpuops upgrade 10/10] Lockless (and preemptless) fast ..., Christoph Lameter, (Tue Nov 23, 4:51 pm)
Re: [thiscpuops upgrade 09/10] x86: this_cpu_cmpxchg and t ..., Mathieu Desnoyers, (Tue Nov 23, 5:44 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Mathieu Desnoyers, (Tue Nov 23, 6:02 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Mathieu Desnoyers, (Tue Nov 23, 6:05 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Tue Nov 23, 8:09 pm)
Re: [thiscpuops upgrade 09/10] x86: this_cpu_cmpxchg and t ..., Christoph Lameter, (Tue Nov 23, 8:11 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Tue Nov 23, 8:13 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Tue Nov 23, 9:37 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Wed Nov 24, 9:14 am)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Wed Nov 24, 9:17 am)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Wed Nov 24, 9:45 am)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Wed Nov 24, 9:55 am)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Wed Nov 24, 11:08 am)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Jeremy Fitzhardinge, (Wed Nov 24, 12:37 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Christoph Lameter, (Wed Nov 24, 12:53 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Mathieu Desnoyers, (Wed Nov 24, 12:56 pm)
Re: [thiscpuops upgrade 10/10] Lockless (and preemptless) ..., Jeremy Fitzhardinge, (Wed Nov 24, 1:01 pm)
Re: [thiscpuops upgrade 03/10] percpu: Generic support for ..., Christoph Lameter, (Fri Nov 26, 9:37 am)
Re: [thiscpuops upgrade 05/10] x86: Use this_cpu_inc_retur ..., Christoph Lameter, (Fri Nov 26, 10:02 am)