netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] atomic: add atomic_inc_not_zero_hint()
@ 2010-11-05 16:53 Eric Dumazet
  2010-11-05 17:20 ` Andrew Morton
  0 siblings, 1 reply; 21+ messages in thread
From: Eric Dumazet @ 2010-11-05 16:53 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-kernel, David Miller, netdev, Arnaldo Carvalho de Melo,
	Christoph Lameter, Ingo Molnar, Andi Kleen, Paul E. McKenney,
	Nick Piggin

Andrew

atomic_inc_not_zero() / atomic_add_unless() ... are spreaded in many
arch/xxx/include/asm/atomic.h, but they are generic.

Apparently there is no centralization of some common atomic features...

What do you think adding a new file so that we can move common
definitions in it ?

Thanks

[PATCH] atomic: add atomic_inc_not_zero_hint()

Followup of perf tools session in Netfilter WorkShop 2010

In network stack we make high usage of atomic_inc_not_zero() in contexts
we know the probable value of atomic before increment (2 for udp sockets
for example)

Using a special version of atomic_inc_not_zero() giving this hint can
help processor to use less bus transactions.

On x86 (MESI protocol) for example, this avoids entering Shared state,
because "lock cmpxchg" issues an RFO (Read For Ownership)

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: David Miller <davem@davemloft.net>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Nick Piggin <npiggin@kernel.dk>
---
 include/linux/atomic.h |   29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/include/linux/atomic.h b/include/linux/atomic.h
new file mode 100644
index 0000000..c04327a
--- /dev/null
+++ b/include/linux/atomic.h
@@ -0,0 +1,29 @@
+#ifndef _LINUX_ATOMIC_H
+#define _LINUX_ATOMIC_H
+#include <asm/atomic.h>
+
+/**
+ * atomic_inc_not_zero_hint - increment if not null
+ * @v: pointer of type atomic_t
+ * @hint: probable value of the atomic before the increment
+ *
+ * This version of atomic_inc_not_zero() gives a hint of probable
+ * value of the atomic. This helps processor to not read the memory
+ * before doing the atomic read/modify/write cycle, lowering
+ * number of bus transactions on some arches.
+ * Note: hint MUST not be 0 !
+ */
+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
+{
+	int val, c = hint;
+
+ 	do {
+		val = atomic_cmpxchg(v, c, c + 1);
+		if (val == c)
+			return 1;
+		c = val;
+	} while (c);
+
+	return 0;
+}
+#endif /* _LINUX_ATOMIC_H */



^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2010-11-15 14:47 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-05 16:53 [PATCH] atomic: add atomic_inc_not_zero_hint() Eric Dumazet
2010-11-05 17:20 ` Andrew Morton
2010-11-05 18:00   ` Eric Dumazet
2010-11-05 18:08     ` Andrew Morton
2010-11-05 18:20       ` Eric Dumazet
2010-11-05 18:28         ` Andrew Morton
2010-11-05 19:20           ` Eric Dumazet
2010-11-05 19:39             ` Andrew Morton
2010-11-05 19:46               ` Eric Dumazet
2010-11-05 19:51             ` Paul E. McKenney
2010-11-12 19:14               ` Christoph Lameter
2010-11-13 22:26                 ` Paul E. McKenney
2010-11-15 13:57                   ` Christoph Lameter
2010-11-15 14:07                     ` Andi Kleen
2010-11-15 14:16                       ` Christoph Lameter
2010-11-15 14:17                     ` Eric Dumazet
2010-11-15 14:25                       ` Christoph Lameter
2010-11-15 14:39                         ` Andi Kleen
2010-11-15 14:47                         ` Eric Dumazet
2010-11-05 18:40     ` Paul E. McKenney
2010-11-05 19:12       ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).