public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] memory ordering in __kfifo primitives
@ 2006-08-10  0:18 Paul E. McKenney
  2006-08-10  0:29 ` Andrew Morton
  2006-08-10  0:33 ` Paul E. McKenney
  0 siblings, 2 replies; 14+ messages in thread
From: Paul E. McKenney @ 2006-08-10  0:18 UTC (permalink / raw)
  To: stelian; +Cc: linux-kernel, akpm, paulus, anton, open-iscsi, pradeep, mashirle

Hello!

Both __kfifo_put() and __kfifo_get() have header comments stating
that if there is but one concurrent reader and one concurrent writer,
locking is not necessary.  This is almost the case, but a couple of
memory barriers are needed.  Another option would be to change the
header comments to remove the bit about locking not being needed, and
to change the those callers who currently don't use locking to add
the required locking.  The attachment analyzes this approach, but the
patch below seems simpler.

Signed-off-by: Paul E. McKenney <paulmck@us.ibm.com>
---

 kfifo.c |    4 ++++
 1 files changed, 4 insertions(+)

diff -urpNa -X dontdiff linux-2.6.18-rc2/kernel/kfifo.c linux-2.6.18-rc2-kfifo/kernel/kfifo.c
--- linux-2.6.18-rc2/kernel/kfifo.c	2006-07-15 14:53:08.000000000 -0700
+++ linux-2.6.18-rc2-kfifo/kernel/kfifo.c	2006-08-09 14:01:53.000000000 -0700
@@ -129,6 +129,8 @@ unsigned int __kfifo_put(struct kfifo *f
 	/* then put the rest (if any) at the beginning of the buffer */
 	memcpy(fifo->buffer, buffer + l, len - l);
 
+	smp_wmb();
+
 	fifo->in += len;
 
 	return len;
@@ -161,6 +163,8 @@ unsigned int __kfifo_get(struct kfifo *f
 	/* then get the rest (if any) from the beginning of the buffer */
 	memcpy(buffer + l, fifo->buffer, len - l);
 
+	smp_mb();
+
 	fifo->out += len;
 
 	return len;

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

end of thread, other threads:[~2006-08-10 20:53 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-10  0:18 [PATCH] memory ordering in __kfifo primitives Paul E. McKenney
2006-08-10  0:29 ` Andrew Morton
2006-08-10  1:01   ` Paul E. McKenney
2006-08-10  0:33 ` Paul E. McKenney
2006-08-10  5:48   ` Mike Christie
2006-08-10 13:41     ` Paul E. McKenney
2006-08-10 14:26       ` Stelian Pop
2006-08-10 15:39         ` Paul E. McKenney
2006-08-10 15:47           ` Stelian Pop
2006-08-10 16:11             ` Paul E. McKenney
2006-08-10 16:23               ` Stelian Pop
2006-08-10 16:47                 ` Paul E. McKenney
2006-08-10 20:27                   ` Stelian Pop
2006-08-10 20:54                     ` Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox