Documentation changes for 3.14
Subsystems (2)
cover Documentation changes for 3.14
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(-)
PATCH 1/4 rcu: Fix typo in Documentation/RCU/trace.txt
From: "Paul E. McKenney" <[email protected]>
--- Documentation/RCU/trace.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/RCU/trace.txt +1 -1
@@ -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
Signature · 1 line
1.8.1.5
PATCH 2/4 rcu: Fix formatting blows in kernel-parameters.txt
From: "Paul E. McKenney" <[email protected]>
--- Documentation/kernel-parameters.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
Documentation/kernel-parameters.txt +4 -5
@@ -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
Signature · 1 line
1.8.1.5
PATCH 3/4 documentation: Fix circular-buffer example.
In reply to Paul E. McKenneyFrom: "Paul E. McKenney" <[email protected]>
The code sample in Documentation/circular-buffers.txt appears to have a few ordering bugs. This patch therefore applies the needed fixes.
--- Documentation/circular-buffers.txt | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
Documentation/circular-buffers.txt +15 -7
@@ -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. ===============
Signature · 1 line
1.8.1.5
PATCH 4/4 documentation: Update circular buffer for load-acquire/store-release
In reply to Paul E. McKenneyFrom: "Paul E. McKenney" <[email protected]>
This commit replaces full barriers by targeted use of load-acquire and store-release.
--- Documentation/circular-buffers.txt | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
Documentation/circular-buffers.txt +17 -18
@@ -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. ===============
Signature · 1 line
1.8.1.5
Re: [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
Documentation/circular-buffers.txt The consumer will look something like this: · line 215
Quoted 3 lines · Paul E. McKenney
Documentation/circular-buffers.txt +0
-2- /* 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
Re: [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
Quoted 8 lines · David Howells
Review
Quoted 3 lines · Paul E. McKenney
(quoted diff) +0
-2- /* 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
------------------------------------------------------------------------
Documentation/circular-buffers.txt +2 -0
@@ -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)); }
Re: [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
In reply to Paul E. McKenneyQuoted 4 lines · Paul E. McKenney
From: "Paul E. McKenney" <[email protected]>
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 :-)
Re: [PATCH tip/core/rcu 4/4] documentation: Update circular buffer for load-acquire/store-release
Quoted 8 lines · Peter Zijlstra
Quoted 4 lines · Paul E. McKenney
From: "Paul E. McKenney" <[email protected]>
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