linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH tip/core/rcu 0/4] Documentation changes for 3.14
@ 2013-11-16  0:10 Paul E. McKenney
  2013-11-16  0:10 ` [PATCH tip/core/rcu 1/4] rcu: Fix typo in Documentation/RCU/trace.txt Paul E. McKenney
  0 siblings, 1 reply; 9+ messages in thread
From: Paul E. McKenney @ 2013-11-16  0:10 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, laijs, dipankar, akpm, mathieu.desnoyers, josh, niv, tglx,
	peterz, rostedt, dhowells, edumazet, darren, fweisbec, sbw

Hello!

This series contains documentation updates:

1.	Fix a typo in Documentation/RCU/trace.txt.

2.	Fix formatting blows in kernel-parameters.txt.

3.	Fix memory barrier usage in the circular-buffer example.

4.	Replace some memory barriers in the circular-buffer example
	with load-acquire and store-release to reduce memory-barrier
	overhead while still keeping things safe.

							Thanx, Paul

 b/Documentation/RCU/trace.txt         |    2 -
 b/Documentation/circular-buffers.txt  |   57 +++++++++++++++++++---------------
 b/Documentation/kernel-parameters.txt |    9 ++---
 3 files changed, 37 insertions(+), 31 deletions(-)


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

* [PATCH tip/core/rcu 1/4] rcu: Fix typo in Documentation/RCU/trace.txt
  2013-11-16  0:10 [PATCH tip/core/rcu 0/4] Documentation changes for 3.14 Paul E. McKenney
@ 2013-11-16  0:10 ` Paul E. McKenney
  2013-11-16  0:10   ` [PATCH tip/core/rcu 2/4] rcu: Fix formatting blows in kernel-parameters.txt Paul E. McKenney
                     ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Paul E. McKenney @ 2013-11-16  0:10 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, laijs, dipankar, akpm, mathieu.desnoyers, josh, niv, tglx,
	peterz, rostedt, dhowells, edumazet, darren, fweisbec, sbw,
	Paul E. McKenney

From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 Documentation/RCU/trace.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/RCU/trace.txt b/Documentation/RCU/trace.txt
index f3778f8952da..7f5c57d78f3a 100644
--- a/Documentation/RCU/trace.txt
+++ b/Documentation/RCU/trace.txt
@@ -443,7 +443,7 @@ The output of "cat rcu/rcuboost" looks as follows:
     balk: nt=0 egt=6541 bt=0 nb=0 ny=126 nos=0
 
 This information is output only for rcu_preempt.  Each two-line entry
-corresponds to a leaf rcu_node strcuture.  The fields are as follows:
+corresponds to a leaf rcu_node structure.  The fields are as follows:
 
 o	"n:m" is the CPU-number range for the corresponding two-line
 	entry.  In the sample output above, the first entry covers
-- 
1.8.1.5


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

* [PATCH tip/core/rcu 2/4] rcu: Fix formatting blows in kernel-parameters.txt
  2013-11-16  0:10 ` [PATCH tip/core/rcu 1/4] rcu: Fix typo in Documentation/RCU/trace.txt Paul E. McKenney
@ 2013-11-16  0:10   ` Paul E. McKenney
  2013-11-16  0:10   ` [PATCH tip/core/rcu 3/4] documentation: Fix circular-buffer example Paul E. McKenney
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Paul E. McKenney @ 2013-11-16  0:10 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, laijs, dipankar, akpm, mathieu.desnoyers, josh, niv, tglx,
	peterz, rostedt, dhowells, edumazet, darren, fweisbec, sbw,
	Paul E. McKenney

From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 Documentation/kernel-parameters.txt | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index c3dc13e90a40..3f2f0d04d35c 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2604,7 +2604,6 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			for RCU-preempt, and "s" for RCU-sched, and "N"
 			is the CPU number.  This reduces OS jitter on the
 			offloaded CPUs, which can be useful for HPC and
-
 			real-time workloads.  It can also improve energy
 			efficiency for asymmetric multiprocessors.
 
@@ -2620,8 +2619,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			periodically wake up to do the polling.
 
 	rcutree.blimit=	[KNL]
-			Set maximum number of finished RCU callbacks to process
-			in one batch.
+			Set maximum number of finished RCU callbacks to
+			process in one batch.
 
 	rcutree.rcu_fanout_leaf= [KNL]
 			Increase the number of CPUs assigned to each
@@ -2640,8 +2639,8 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			value is one, and maximum value is HZ.
 
 	rcutree.qhimark= [KNL]
-			Set threshold of queued
-			RCU callbacks over which batch limiting is disabled.
+			Set threshold of queued RCU callbacks beyond which
+			batch limiting is disabled.
 
 	rcutree.qlowmark= [KNL]
 			Set threshold of queued RCU callbacks below which
-- 
1.8.1.5


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

* [PATCH tip/core/rcu 3/4] documentation: Fix circular-buffer example.
  2013-11-16  0:10 ` [PATCH tip/core/rcu 1/4] rcu: Fix typo in Documentation/RCU/trace.txt Paul E. McKenney
  2013-11-16  0:10   ` [PATCH tip/core/rcu 2/4] rcu: Fix formatting blows in kernel-parameters.txt Paul E. McKenney
@ 2013-11-16  0:10   ` Paul E. McKenney
  2013-11-16  0:10   ` [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release Paul E. McKenney
  2013-11-16 11:58   ` David Howells
  3 siblings, 0 replies; 9+ messages in thread
From: Paul E. McKenney @ 2013-11-16  0:10 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, laijs, dipankar, akpm, mathieu.desnoyers, josh, niv, tglx,
	peterz, rostedt, dhowells, edumazet, darren, fweisbec, sbw,
	Paul E. McKenney

From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>

The code sample in Documentation/circular-buffers.txt appears to have a
few ordering bugs.  This patch therefore applies the needed fixes.

Reported-by: Lech Fomicki <lfomicki@poczta.fm>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 Documentation/circular-buffers.txt | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/Documentation/circular-buffers.txt b/Documentation/circular-buffers.txt
index 8117e5bf6065..a36bed3db4ee 100644
--- a/Documentation/circular-buffers.txt
+++ b/Documentation/circular-buffers.txt
@@ -170,7 +170,7 @@ The producer will look something like this:
 
 		smp_wmb(); /* commit the item before incrementing the head */
 
-		buffer->head = (head + 1) & (buffer->size - 1);
+		ACCESS_ONCE(buffer->head) = (head + 1) & (buffer->size - 1);
 
 		/* wake_up() will make sure that the head is committed before
 		 * waking anyone up */
@@ -183,9 +183,14 @@ This will instruct the CPU that the contents of the new item must be written
 before the head index makes it available to the consumer and then instructs the
 CPU that the revised head index must be written before the consumer is woken.
 
-Note that wake_up() doesn't have to be the exact mechanism used, but whatever
-is used must guarantee a (write) memory barrier between the update of the head
-index and the change of state of the consumer, if a change of state occurs.
+Note that wake_up() does not guarantee any sort of barrier unless something
+is actually awakened.  We therefore cannot rely on it for ordering.  However,
+there is always one element of the array left empty.  Therefore, the
+producer must produce two elements before it could possibly corrupt the
+element currently being read by the consumer.  Therefore, the unlock-lock
+pair between consecutive invocations of the consumer provides the necessary
+ordering between the read of the index indicating that the consumer has
+vacated a given element and the write by the producer to that same element.
 
 
 THE CONSUMER
@@ -200,7 +205,7 @@ The consumer will look something like this:
 
 	if (CIRC_CNT(head, tail, buffer->size) >= 1) {
 		/* read index before reading contents at that index */
-		smp_read_barrier_depends();
+		smp_rmb();
 
 		/* extract one item from the buffer */
 		struct item *item = buffer[tail];
@@ -209,7 +214,7 @@ The consumer will look something like this:
 
 		smp_mb(); /* finish reading descriptor before incrementing tail */
 
-		buffer->tail = (tail + 1) & (buffer->size - 1);
+		ACCESS_ONCE(buffer->tail) = (tail + 1) & (buffer->size - 1);
 	}
 
 	spin_unlock(&consumer_lock);
@@ -223,7 +228,10 @@ Note the use of ACCESS_ONCE() in both algorithms to read the opposition index.
 This prevents the compiler from discarding and reloading its cached value -
 which some compilers will do across smp_read_barrier_depends().  This isn't
 strictly needed if you can be sure that the opposition index will _only_ be
-used the once.
+used the once.  Similarly, ACCESS_ONCE() is used in both algorithms to
+write the thread's index.  This documents the fact that we are writing
+to something that can be read concurrently and also prevents the compiler
+from tearing the store.
 
 
 ===============
-- 
1.8.1.5


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

* [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
  2013-11-16  0:10 ` [PATCH tip/core/rcu 1/4] rcu: Fix typo in Documentation/RCU/trace.txt Paul E. McKenney
  2013-11-16  0:10   ` [PATCH tip/core/rcu 2/4] rcu: Fix formatting blows in kernel-parameters.txt Paul E. McKenney
  2013-11-16  0:10   ` [PATCH tip/core/rcu 3/4] documentation: Fix circular-buffer example Paul E. McKenney
@ 2013-11-16  0:10   ` Paul E. McKenney
  2013-11-16 16:03     ` Peter Zijlstra
  2013-11-16 11:58   ` David Howells
  3 siblings, 1 reply; 9+ messages in thread
From: Paul E. McKenney @ 2013-11-16  0:10 UTC (permalink / raw)
  To: linux-kernel
  Cc: mingo, laijs, dipankar, akpm, mathieu.desnoyers, josh, niv, tglx,
	peterz, rostedt, dhowells, edumazet, darren, fweisbec, sbw,
	Paul E. McKenney

From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>

This commit replaces full barriers by targeted use of load-acquire and
store-release.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 Documentation/circular-buffers.txt | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/Documentation/circular-buffers.txt b/Documentation/circular-buffers.txt
index a36bed3db4ee..15e54ff50018 100644
--- a/Documentation/circular-buffers.txt
+++ b/Documentation/circular-buffers.txt
@@ -160,6 +160,7 @@ The producer will look something like this:
 	spin_lock(&producer_lock);
 
 	unsigned long head = buffer->head;
+	/* The spin_unlock() and next spin_lock() provide needed ordering. */
 	unsigned long tail = ACCESS_ONCE(buffer->tail);
 
 	if (CIRC_SPACE(head, tail, buffer->size) >= 1) {
@@ -168,9 +169,8 @@ The producer will look something like this:
 
 		produce_item(item);
 
-		smp_wmb(); /* commit the item before incrementing the head */
-
-		ACCESS_ONCE(buffer->head) = (head + 1) & (buffer->size - 1);
+		smp_store_release(buffer->head,
+				  (head + 1) & (buffer->size - 1));
 
 		/* wake_up() will make sure that the head is committed before
 		 * waking anyone up */
@@ -200,21 +200,18 @@ The consumer will look something like this:
 
 	spin_lock(&consumer_lock);
 
-	unsigned long head = ACCESS_ONCE(buffer->head);
+	unsigned long head = smp_load_acquire(buffer->head);
 	unsigned long tail = buffer->tail;
 
 	if (CIRC_CNT(head, tail, buffer->size) >= 1) {
-		/* read index before reading contents at that index */
-		smp_rmb();
 
 		/* extract one item from the buffer */
 		struct item *item = buffer[tail];
 
 		consume_item(item);
 
-		smp_mb(); /* finish reading descriptor before incrementing tail */
-
-		ACCESS_ONCE(buffer->tail) = (tail + 1) & (buffer->size - 1);
+		smp_store_release(buffer->tail,
+				  (tail + 1) & (buffer->size - 1));
 	}
 
 	spin_unlock(&consumer_lock);
@@ -223,15 +220,17 @@ This will instruct the CPU to make sure the index is up to date before reading
 the new item, and then it shall make sure the CPU has finished reading the item
 before it writes the new tail pointer, which will erase the item.
 
-
-Note the use of ACCESS_ONCE() in both algorithms to read the opposition index.
-This prevents the compiler from discarding and reloading its cached value -
-which some compilers will do across smp_read_barrier_depends().  This isn't
-strictly needed if you can be sure that the opposition index will _only_ be
-used the once.  Similarly, ACCESS_ONCE() is used in both algorithms to
-write the thread's index.  This documents the fact that we are writing
-to something that can be read concurrently and also prevents the compiler
-from tearing the store.
+Note the use of ACCESS_ONCE() and smp_load_acquire() to read the
+opposition index.  This prevents the compiler from discarding and
+reloading its cached value - which some compilers will do across
+smp_read_barrier_depends().  This isn't strictly needed if you can
+be sure that the opposition index will _only_ be used the once.
+The smp_load_acquire() additionally forces the CPU to order against
+subsequent memory references.  Similarly, smp_store_release() is used
+in both algorithms to write the thread's index.  This documents the
+fact that we are writing to something that can be read concurrently,
+prevents the compiler from tearing the store, and enforces ordering
+against previous accesses.
 
 
 ===============
-- 
1.8.1.5


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

* Re: [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
  2013-11-16  0:10 ` [PATCH tip/core/rcu 1/4] rcu: Fix typo in Documentation/RCU/trace.txt Paul E. McKenney
                     ` (2 preceding siblings ...)
  2013-11-16  0:10   ` [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release Paul E. McKenney
@ 2013-11-16 11:58   ` David Howells
  2013-11-16 15:40     ` Paul E. McKenney
  3 siblings, 1 reply; 9+ messages in thread
From: David Howells @ 2013-11-16 11:58 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: dhowells, linux-kernel, mingo, laijs, dipankar, akpm,
	mathieu.desnoyers, josh, niv, tglx, peterz, rostedt, edumazet,
	darren, fweisbec, sbw

Paul E. McKenney <paulmck@linux.vnet.ibm.com> wrote:

> -		/* read index before reading contents at that index */

> -		smp_mb(); /* finish reading descriptor before incrementing tail */

I'd rather you didn't remove these comments (assuming they're correct) as
they're pointing out the point of the example.

David

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

* Re: [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
  2013-11-16 11:58   ` David Howells
@ 2013-11-16 15:40     ` Paul E. McKenney
  0 siblings, 0 replies; 9+ messages in thread
From: Paul E. McKenney @ 2013-11-16 15:40 UTC (permalink / raw)
  To: David Howells
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, niv, tglx, peterz, rostedt, edumazet, darren, fweisbec,
	sbw

On Sat, Nov 16, 2013 at 11:58:45AM +0000, David Howells wrote:
> Paul E. McKenney <paulmck@linux.vnet.ibm.com> wrote:
> 
> > -		/* read index before reading contents at that index */
> 
> > -		smp_mb(); /* finish reading descriptor before incrementing tail */
> 
> I'd rather you didn't remove these comments (assuming they're correct) as
> they're pointing out the point of the example.

Ah, good point!  I have added them back just before the smp_load_acquire()
and smp_store_release(), as shown below.  Does that work?

							Thanx, Paul

------------------------------------------------------------------------

diff --git a/Documentation/circular-buffers.txt b/Documentation/circular-buffers.txt
index 15e54ff50018..88951b179262 100644
--- a/Documentation/circular-buffers.txt
+++ b/Documentation/circular-buffers.txt
@@ -200,6 +200,7 @@ The consumer will look something like this:
 
 	spin_lock(&consumer_lock);
 
+	/* Read index before reading contents at that index. */
 	unsigned long head = smp_load_acquire(buffer->head);
 	unsigned long tail = buffer->tail;
 
@@ -210,6 +211,7 @@ The consumer will look something like this:
 
 		consume_item(item);
 
+		/* Finish reading descriptor before incrementing tail. */
 		smp_store_release(buffer->tail,
 				  (tail + 1) & (buffer->size - 1));
 	}


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

* Re: [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
  2013-11-16  0:10   ` [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release Paul E. McKenney
@ 2013-11-16 16:03     ` Peter Zijlstra
  2013-11-16 20:18       ` Paul E. McKenney
  0 siblings, 1 reply; 9+ messages in thread
From: Peter Zijlstra @ 2013-11-16 16:03 UTC (permalink / raw)
  To: Paul E. McKenney
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, niv, tglx, rostedt, dhowells, edumazet, darren, fweisbec,
	sbw

On Fri, Nov 15, 2013 at 04:10:30PM -0800, Paul E. McKenney wrote:
> From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> 
> This commit replaces full barriers by targeted use of load-acquire and
> store-release.

I guess I'd better hurry up merging the patches that introduce these
thingies someplace :-)

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

* Re: [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
  2013-11-16 16:03     ` Peter Zijlstra
@ 2013-11-16 20:18       ` Paul E. McKenney
  0 siblings, 0 replies; 9+ messages in thread
From: Paul E. McKenney @ 2013-11-16 20:18 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: linux-kernel, mingo, laijs, dipankar, akpm, mathieu.desnoyers,
	josh, niv, tglx, rostedt, dhowells, edumazet, darren, fweisbec,
	sbw

On Sat, Nov 16, 2013 at 05:03:40PM +0100, Peter Zijlstra wrote:
> On Fri, Nov 15, 2013 at 04:10:30PM -0800, Paul E. McKenney wrote:
> > From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
> > 
> > This commit replaces full barriers by targeted use of load-acquire and
> > store-release.
> 
> I guess I'd better hurry up merging the patches that introduce these
> thingies someplace :-)

+1 to that!  ;-)

							Thanx, Paul


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

end of thread, other threads:[~2013-11-16 20:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-16  0:10 [PATCH tip/core/rcu 0/4] Documentation changes for 3.14 Paul E. McKenney
2013-11-16  0:10 ` [PATCH tip/core/rcu 1/4] rcu: Fix typo in Documentation/RCU/trace.txt Paul E. McKenney
2013-11-16  0:10   ` [PATCH tip/core/rcu 2/4] rcu: Fix formatting blows in kernel-parameters.txt Paul E. McKenney
2013-11-16  0:10   ` [PATCH tip/core/rcu 3/4] documentation: Fix circular-buffer example Paul E. McKenney
2013-11-16  0:10   ` [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release Paul E. McKenney
2013-11-16 16:03     ` Peter Zijlstra
2013-11-16 20:18       ` Paul E. McKenney
2013-11-16 11:58   ` David Howells
2013-11-16 15:40     ` 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;
as well as URLs for NNTP newsgroup(s).