Re: [GIT PULL] ring-buffer: Replace this_cpu_*() with __this_cpu_*()

From: Christoph Lameter
Date: Tue Mar 24 2015 - 15:37:50 EST


Here is a potential patch for this.

Subject: [percpu] make this_cpu_read/write operate like raw_cpu_read/write

As noted threre is not much of a point in disabling preemption or interrupts
for this_cpu_read/write since the processor may change afterwards anyways
if preemption is on. Thus we should be able to use the raw versions instead.

The most that could go amiss is that the guaranteed local read/writes now
become operaton that may rarely be done from a remote cpu and thus cause
cache line evictions.

Signed-off-by: Christoph Lameter <cl@xxxxxxxxx>

Index: linux/include/asm-generic/percpu.h
===================================================================
--- linux.orig/include/asm-generic/percpu.h 2014-08-05 10:43:51.569894168 -0500
+++ linux/include/asm-generic/percpu.h 2015-03-24 14:18:07.655034405 -0500
@@ -105,15 +105,6 @@ do { \
(__ret); \
})

-#define this_cpu_generic_read(pcp) \
-({ \
- typeof(pcp) __ret; \
- preempt_disable(); \
- __ret = *this_cpu_ptr(&(pcp)); \
- preempt_enable(); \
- __ret; \
-})
-
#define this_cpu_generic_to_op(pcp, val, op) \
do { \
unsigned long __flags; \
@@ -292,32 +283,40 @@ do { \
raw_cpu_generic_cmpxchg_double(pcp1, pcp2, oval1, oval2, nval1, nval2)
#endif

+/*
+ * this_cpu_read/write is not per cpu atomic but that does not matter
+ * since the cpu may change afte the operation anyways. At most we
+ * kick out a per cpu area cacheline.
+ */
#ifndef this_cpu_read_1
-#define this_cpu_read_1(pcp) this_cpu_generic_read(pcp)
+#define this_cpu_read_1(pcp) raw_cpu_read_1(pcp)
#endif
#ifndef this_cpu_read_2
-#define this_cpu_read_2(pcp) this_cpu_generic_read(pcp)
+#define this_cpu_read_2(pcp) raw_cpu_read_2(pcp)
#endif
#ifndef this_cpu_read_4
-#define this_cpu_read_4(pcp) this_cpu_generic_read(pcp)
+#define this_cpu_read_4(pcp) raw_cpu_read_4(pcp)
#endif
#ifndef this_cpu_read_8
-#define this_cpu_read_8(pcp) this_cpu_generic_read(pcp)
+#define this_cpu_read_8(pcp) raw_cpu_read_8(pcp)
#endif

#ifndef this_cpu_write_1
-#define this_cpu_write_1(pcp, val) this_cpu_generic_to_op(pcp, val, =)
+#define this_cpu_write_1(pcp, val) raw_cpu_write_1(pcp, val)
#endif
#ifndef this_cpu_write_2
-#define this_cpu_write_2(pcp, val) this_cpu_generic_to_op(pcp, val, =)
+#define this_cpu_write_2(pcp, val) raw_cpu_write_2(pcp, val)
#endif
#ifndef this_cpu_write_4
-#define this_cpu_write_4(pcp, val) this_cpu_generic_to_op(pcp, val, =)
+#define this_cpu_write_4(pcp, val) raw_cpu_write_4(pcp, val)
#endif
#ifndef this_cpu_write_8
-#define this_cpu_write_8(pcp, val) this_cpu_generic_to_op(pcp, val, =)
+#define this_cpu_write_8(pcp, val) raw_cpu_write_8(pcp, val)
#endif

+/*
+ * this cpu rmv operations must be fully per cpu atomic.
+ */
#ifndef this_cpu_add_1
#define this_cpu_add_1(pcp, val) this_cpu_generic_to_op(pcp, val, +=)
#endif
--
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/