SRCU callback parallelization for 4.12
Subsystems (11)
PATCH v3 22/40 srcu: Add grace-period sequence numbers
In reply to Paul E. McKenneyThis commit adds grace-period sequence numbers, which will be used to handle mid-boot grace periods and per-CPU callback lists.
--- include/linux/srcu.h | 1 + kernel/rcu/srcu.c | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-)
include/linux/srcu.h +1 -0
@@ -46,6 +46,7 @@ struct rcu_batch {struct srcu_struct {unsigned long completed; +unsigned long srcu_gp_seq;struct srcu_array __percpu *per_cpu_ref;spinlock_t queue_lock;/* protect ->batch_queue, ->running */ int srcu_state;
kernel/rcu/srcu.c +23 -4
@@ -110,6 +110,7 @@ static inline void rcu_batch_move(struct rcu_batch *to, struct rcu_batch *from)static int init_srcu_struct_fields (struct srcu_struct *sp) { sp->completed =0 ; + sp->srcu_gp_seq =0 ;spin_lock_init (&sp->queue_lock); sp->srcu_state =SRCU_STATE_IDLE ;rcu_batch_init (&sp->batch_queue);
@@ -319,6 +320,15 @@ EXPORT_SYMBOL_GPL(__srcu_read_unlock);#define SYNCHRONIZE_SRCU_EXP_TRYCOUNT 12/* +* Start an SRCU grace period. +*/ +static void srcu_gp_start (struct srcu_struct *sp) +{ +WRITE_ONCE (sp->srcu_state,SRCU_STATE_SCAN1 ); +rcu_seq_start (&sp->srcu_gp_seq); +} + +/* * @@@ Wait until all pre-existing readers complete. Such readers * will have used the index specified by "idx". * the caller should ensures the ->completed is not changed while checking
@@ -355,6 +365,15 @@ static void srcu_flip(struct srcu_struct *sp) }/* +* End an SRCU grace period. +*/ +static void srcu_gp_end (struct srcu_struct *sp) +{ +rcu_seq_end (&sp->srcu_gp_seq); +WRITE_ONCE (sp->srcu_state,SRCU_STATE_DONE ); +} + +/* * Enqueue an SRCU callback on the specified srcu_struct structure, * initiating grace-period processing if it is not already running. *
@@ -392,7 +411,7 @@ void call_srcu(struct srcu_struct *sp, struct rcu_head *head,smp_mb__after_unlock_lock ();/* Caller's prior accesses before GP. */ rcu_batch_queue (&sp->batch_queue, head);if (READ_ONCE (sp->srcu_state) ==SRCU_STATE_IDLE ) { -WRITE_ONCE (sp->srcu_state,SRCU_STATE_SCAN1 ); +srcu_gp_start (sp);queue_delayed_work (system_power_efficient_wq, &sp->work,0 ); }spin_unlock_irqrestore (&sp->queue_lock, flags);
@@ -426,7 +445,7 @@ static void __synchronize_srcu(struct srcu_struct *sp, int trycount)smp_mb__after_unlock_lock ();/* Caller's prior accesses before GP. */ if (READ_ONCE (sp->srcu_state) ==SRCU_STATE_IDLE ) {/* steal the processing owner */ -WRITE_ONCE (sp->srcu_state,SRCU_STATE_SCAN1 ); +srcu_gp_start (sp);rcu_batch_queue (&sp->batch_check0, head);spin_unlock_irq (&sp->queue_lock);/* give the processing owner to work_struct */
@@ -561,7 +580,7 @@ static void srcu_advance_batches(struct srcu_struct *sp, int trycount)*/ if (sp->srcu_state ==SRCU_STATE_DONE ) -WRITE_ONCE (sp->srcu_state,SRCU_STATE_SCAN1 ); +srcu_gp_start (sp);if (sp->srcu_state ==SRCU_STATE_SCAN1 ) { idx =1 ^ (sp->completed &1 );
@@ -608,7 +627,7 @@ static void srcu_advance_batches(struct srcu_struct *sp, int trycount)*/ rcu_batch_move (&sp->batch_done, &sp->batch_check1); -WRITE_ONCE (sp->srcu_state,SRCU_STATE_DONE ); +srcu_gp_end (sp); } }
Signature · 1 line
2.5.2
PATCH v3 28/40 srcu: Make num_rcu_lvl[] array be external
In reply to Paul E. McKenneyThis commit makes the num_rcu_lvl[] array external so that SRCU can make use of it for initializing its upcoming srcu_node tree.
--- kernel/rcu/rcu.h | 1 + kernel/rcu/tree.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
kernel/rcu/rcu.h +1 -0
@@ -195,6 +195,7 @@ extern void resched_cpu(int cpu);#include <linux/rcu_node_tree.h> extern int rcu_num_lvls; +extern int num_rcu_lvl[];extern int rcu_num_nodes;static bool rcu_fanout_exact;static int rcu_fanout_leaf;
kernel/rcu/tree.c +1 -1
@@ -123,7 +123,7 @@ static int rcu_fanout_leaf = RCU_FANOUT_LEAF;module_param (rcu_fanout_leaf, int,0444 );int rcu_num_lvls__read_mostly =RCU_NUM_LVLS ;/* Number of rcu_nodes at specified level. */ -static int num_rcu_lvl[] =NUM_RCU_LVL_INIT ; +int num_rcu_lvl[] =NUM_RCU_LVL_INIT ;int rcu_num_nodes__read_mostly =NUM_RCU_NODES ;/* Total # rcu_nodes in use. */ /* panic() on RCU Stall sysctl. */ int sysctl_panic_on_rcu_stall__read_mostly ;
Signature · 1 line
2.5.2
PATCH v3 13/40 srcu: Abstract multi-tail callback list handling
In reply to Paul E. McKenneyRCU has only one multi-tail callback list, which is implemented via the nxtlist, nxttail, nxtcompleted, qlen_lazy, and qlen fields in the rcu_data structure, and whose operations are open-code throughout the Tree RCU implementation. This has been more or less OK in the past, but upcoming callback-list optimizations in SRCU could really use a multi-tail callback list there as well.
This commit therefore abstracts the multi-tail callback list handling into a new kernel/rcu/rcu_segcblist.h file, and uses this new API. The simple head-and-tail pointer callback list is also abstracted and applied everywhere except for the NOCB callback-offload lists. (Yes, the plan is to apply them there as well, but this commit is already bigger than would be good.)
--- kernel/rcu/rcu_segcblist.h | 625 +++++++++++++++++++++++++++++++++++++++++++++ kernel/rcu/tree.c | 348 ++++++++----------------- kernel/rcu/tree.h | 41 +-- kernel/rcu/tree_plugin.h | 54 ++-- kernel/rcu/tree_trace.c | 21 +- 5 files changed, 780 insertions(+), 309 deletions(-) create mode 100644 kernel/rcu/rcu_segcblist.h
kernel/rcu/rcu_segcblist.h new file +625 -0
@@ -0,0 +1,625 @@ +/* +* RCU segmented callback lists +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, you can access it online at +* http://www.gnu.org/licenses/gpl-2.0.html. +* +* Copyright IBM Corporation, 2017 +* +* Authors: Paul E. McKenney <[email protected]> +*/ + +#ifndef __KERNEL_RCU_SEGCBLIST_H +#define __KERNEL_RCU_SEGCBLIST_H + +/* Simple unsegmented callback lists. */ +struct rcu_cblist { +struct rcu_head *head; +struct rcu_head **tail; +long len; +long len_lazy; +}; + +#define RCU_CBLIST_INITIALIZER (n) { .head = NULL, .tail = &n.head } + +/* Initialize simple callback list. */ +static inline void rcu_cblist_init (struct rcu_cblist *rclp) +{ + rclp->head =NULL ; + rclp->tail = &rclp->head; + rclp->len =0 ; + rclp->len_lazy =0 ; +} + +/* Is simple callback list empty? */ +static inline bool rcu_cblist_empty (struct rcu_cblist *rclp) +{ +return !rclp->head; +} + +/* Return number of callbacks in simple callback list. */ +static inline long rcu_cblist_n_cbs (struct rcu_cblist *rclp) +{ +return rclp->len; +} + +/* Return number of lazy callbacks in simple callback list. */ +static inline long rcu_cblist_n_lazy_cbs (struct rcu_cblist *rclp) +{ +return rclp->len_lazy; +} + +/* +* Debug function to actually count the number of callbacks. +* If the number exceeds the limit specified, return -1. +*/ +static inline long rcu_cblist_count_cbs (struct rcu_cblist *rclp,long lim) +{ +int cnt =0 ; +struct rcu_head **rhpp = &rclp->head; + +for (;;) { +if (!*rhpp) +return cnt; +if (++cnt > lim) +return -1 ; + rhpp = &(*rhpp)->next; + } +} + +/* +* Dequeue the oldest rcu_head structure from the specified callback +* list. This function assumes that the callback is non-lazy, but +* the caller can later invoke rcu_cblist_dequeued_lazy() if it +* finds otherwise (and if it cares about laziness). This allows +* different users to have different ways of determining laziness. +*/ +static inline struct rcu_head *rcu_cblist_dequeue (struct rcu_cblist *rclp) +{ +struct rcu_head *rhp; + + rhp = rclp->head; +if (!rhp) +return NULL ; +prefetch (rhp); + rclp->len--; + rclp->head = rhp->next; +if (!rclp->head) + rclp->tail = &rclp->head; +return rhp; +} + +/* +* Account for the fact that a previously dequeued callback turned out +* to be marked as lazy. +*/ +static inline void rcu_cblist_dequeued_lazy (struct rcu_cblist *rclp) +{ + rclp->len_lazy--; +} + +/* +* Interim function to return rcu_cblist head pointer. Longer term, the +* rcu_cblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head *rcu_cblist_head (struct rcu_cblist *rclp) +{ +return rclp->head; +} + +/* +* Interim function to return rcu_cblist head pointer. Longer term, the +* rcu_cblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head **rcu_cblist_tail (struct rcu_cblist *rclp) +{ +WARN_ON_ONCE (rcu_cblist_empty (rclp)); +return rclp->tail; +} + +/* Complicated segmented callback lists. ;-) */ + +/* +* Index values for segments in rcu_segcblist structure. +* +* The segments are as follows: +* +* [head, *tails[RCU_DONE_TAIL]): +* Callbacks whose grace period has elapsed, and thus can be invoked. +* [*tails[RCU_DONE_TAIL], *tails[RCU_WAIT_TAIL]): +* Callbacks waiting for the current GP from the current CPU's viewpoint. +* [*tails[RCU_WAIT_TAIL], *tails[RCU_NEXT_READY_TAIL]): +* Callbacks that arrived before the next GP started, again from +* the current CPU's viewpoint. These can be handled by the next GP. +* [*tails[RCU_NEXT_READY_TAIL], *tails[RCU_NEXT_TAIL]): +* Callbacks that might have arrived after the next GP started. +* There is some uncertainty as to when a given GP starts and +* ends, but a CPU knows the exact times if it is the one starting +* or ending the GP. Other CPUs know that the previous GP ends +* before the next one starts. +* +* Note that RCU_WAIT_TAIL cannot be empty unless RCU_NEXT_READY_TAIL is also +* empty. +* +* The ->gp_seq[] array contains the grace-period number at which the +* corresponding segment of callbacks will be ready to invoke. A given +* element of this array is meaningful only when the corresponding segment +* is non-empty, and it is never valid for RCU_DONE_TAIL (whose callbacks +* are already ready to invoke) or for RCU_NEXT_TAIL (whose callbacks have +* not yet been assigned a grace-period number). +*/ +#define RCU_DONE_TAIL 0/* Also RCU_WAIT head. */ +#define RCU_WAIT_TAIL 1/* Also RCU_NEXT_READY head. */ +#define RCU_NEXT_READY_TAIL 2/* Also RCU_NEXT head. */ +#define RCU_NEXT_TAIL 3 +#define RCU_CBLIST_NSEGS 4 + +struct rcu_segcblist { +struct rcu_head *head; +struct rcu_head **tails[RCU_CBLIST_NSEGS ]; +unsigned long gp_seq[RCU_CBLIST_NSEGS ]; +long len; +long len_lazy; +}; + +/* +* Initialize an rcu_segcblist structure. +*/ +static inline void rcu_segcblist_init (struct rcu_segcblist *rsclp) +{ +int i; + +BUILD_BUG_ON (RCU_NEXT_TAIL +1 !=ARRAY_SIZE (rsclp->gp_seq)); +BUILD_BUG_ON (ARRAY_SIZE (rsclp->tails) !=ARRAY_SIZE (rsclp->gp_seq)); + rsclp->head =NULL ; +for (i =0 ; i <RCU_CBLIST_NSEGS ; i++) + rsclp->tails[i] = &rsclp->head; + rsclp->len =0 ; + rsclp->len_lazy =0 ; +} + +/* +* Is the specified rcu_segcblist structure empty? +* +* But careful! The fact that the ->head field is NULL does not +* necessarily imply that there are no callbacks associated with +* this structure. When callbacks are being invoked, they are +* removed as a group. If callback invocation must be preempted, +* the remaining callbacks will be added back to the list. Either +* way, the counts are updated later. +* +* So it is often the case that rcu_segcblist_n_cbs() should be used +* instead. +*/ +static inline bool rcu_segcblist_empty (struct rcu_segcblist *rsclp) +{ +return !rsclp->head; +} + +/* Return number of callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_cbs (struct rcu_segcblist *rsclp) +{ +return READ_ONCE (rsclp->len); +} + +/* Return number of lazy callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_lazy_cbs (struct rcu_segcblist *rsclp) +{ +return rsclp->len_lazy; +} + +/* Return number of lazy callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_nonlazy_cbs (struct rcu_segcblist *rsclp) +{ +return rsclp->len - rsclp->len_lazy; +} + +/* +* Is the specified rcu_segcblist enabled, for example, not corresponding +* to an offline or callback-offloaded CPU? +*/ +static inline bool rcu_segcblist_is_enabled (struct rcu_segcblist *rsclp) +{ +return !!rsclp->tails[RCU_NEXT_TAIL ]; +} + +/* +* Disable the specified rcu_segcblist structure, so that callbacks can +* no longer be posted to it. This structure must be empty. +*/ +static inline void rcu_segcblist_disable (struct rcu_segcblist *rsclp) +{ +WARN_ON_ONCE (!rcu_segcblist_empty (rsclp)); +WARN_ON_ONCE (rcu_segcblist_n_cbs (rsclp)); +WARN_ON_ONCE (rcu_segcblist_n_lazy_cbs (rsclp)); + rsclp->tails[RCU_NEXT_TAIL ] =NULL ; +} + +/* +* Is the specified segment of the specified rcu_segcblist structure +* empty of callbacks? +*/ +static inline bool rcu_segcblist_segempty (struct rcu_segcblist *rsclp,int seg) +{ +if (seg ==RCU_DONE_TAIL ) +return &rsclp->head == rsclp->tails[RCU_DONE_TAIL ]; +return rsclp->tails[seg -1 ] == rsclp->tails[seg]; +} + +/* +* Are all segments following the specified segment of the specified +* rcu_segcblist structure empty of callbacks? (The specified +* segment might well contain callbacks.) +*/ +static inline bool rcu_segcblist_restempty (struct rcu_segcblist *rsclp,int seg) +{ +return !*rsclp->tails[seg]; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* are ready to be invoked? +*/ +static inline bool rcu_segcblist_ready_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + &rsclp->head != rsclp->tails[RCU_DONE_TAIL ]; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* are still pending, that is, not yet ready to be invoked? +*/ +static inline bool rcu_segcblist_pend_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + !rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL ); +} + +/* +* Return a pointer to the first callback in the specified rcu_segcblist +* structure. This is useful for diagnostics. +*/ +static inline struct rcu_head * +rcu_segcblist_first_cb (struct rcu_segcblist *rsclp) +{ +if (rcu_segcblist_is_enabled (rsclp)) +return rsclp->head; +return NULL ; +} + +/* +* Return a pointer to the first pending callback in the specified +* rcu_segcblist structure. This is useful just after posting a given +* callback -- if that callback is the first pending callback, then +* you cannot rely on someone else having already started up the required +* grace period. +*/ +static inline struct rcu_head * +rcu_segcblist_first_pend_cb (struct rcu_segcblist *rsclp) +{ +if (rcu_segcblist_is_enabled (rsclp)) +return *rsclp->tails[RCU_DONE_TAIL ]; +return NULL ; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* have not yet been processed beyond having been posted, that is, +* does it contain callbacks in its last segment? +*/ +static inline bool rcu_segcblist_new_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + !rcu_segcblist_restempty (rsclp,RCU_NEXT_READY_TAIL ); +} + +/* +* Enqueue the specified callback onto the specified rcu_segcblist +* structure, updating accounting as needed. Note that the ->len +* field may be accessed locklessly, hence the WRITE_ONCE(). +* The ->len field is used by rcu_barrier() and friends to determine +* if it must post a callback on this structure, and it is OK +* for rcu_barrier() to sometimes post callbacks needlessly, but +* absolutely not OK for it to ever miss posting a callback. +*/ +static inline void rcu_segcblist_enqueue (struct rcu_segcblist *rsclp, +struct rcu_head *rhp,bool lazy) +{ +WRITE_ONCE (rsclp->len, rsclp->len +1 );/* ->len sampled locklessly. */ +if (lazy) + rsclp->len_lazy++; +smp_mb ();/* Ensure counts are updated before callback is enqueued. */ + rhp->next =NULL ; + *rsclp->tails[RCU_NEXT_TAIL ] = rhp; + rsclp->tails[RCU_NEXT_TAIL ] = &rhp->next; +} + +/* +* Extract only the counts from the specified rcu_segcblist structure, +* and place them in the specified rcu_cblist structure. This function +* supports both callback orphaning and invocation, hence the separation +* of counts and callbacks. (Callbacks ready for invocation must be +* orphaned and adopted separately from pending callbacks, but counts +* apply to all callbacks. Locking must be used to make sure that +* both orphaned-callbacks lists are consistent.) +*/ +static inline void rcu_segcblist_extract_count (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ + rclp->len_lazy += rsclp->len_lazy; + rclp->len += rsclp->len; + rsclp->len_lazy =0 ; +WRITE_ONCE (rsclp->len,0 );/* ->len sampled locklessly. */ +} + +/* +* Extract only those callbacks ready to be invoked from the specified +* rcu_segcblist structure and place them in the specified rcu_cblist +* structure. +*/ +static inline void rcu_segcblist_extract_done_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rcu_segcblist_ready_cbs (rsclp)) +return ;/* Nothing to do. */ + *rclp->tail = rsclp->head; + rsclp->head = *rsclp->tails[RCU_DONE_TAIL ]; + *rsclp->tails[RCU_DONE_TAIL ] =NULL ; + rclp->tail = rsclp->tails[RCU_DONE_TAIL ]; +for (i =RCU_CBLIST_NSEGS -1 ; i >=RCU_DONE_TAIL ; i--) +if (rsclp->tails[i] == rsclp->tails[RCU_DONE_TAIL ]) + rsclp->tails[i] = &rsclp->head; +} + +/* +* Extract only those callbacks still pending (not yet ready to be +* invoked) from the specified rcu_segcblist structure and place them in +* the specified rcu_cblist structure. Note that this loses information +* about any callbacks that might have been partway done waiting for +* their grace period. Too bad! They will have to start over. +*/ +static inline void +rcu_segcblist_extract_pend_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rcu_segcblist_pend_cbs (rsclp)) +return ;/* Nothing to do. */ + *rclp->tail = *rsclp->tails[RCU_DONE_TAIL ]; + rclp->tail = rsclp->tails[RCU_NEXT_TAIL ]; + *rsclp->tails[RCU_DONE_TAIL ] =NULL ; +for (i =RCU_DONE_TAIL +1 ; i <RCU_CBLIST_NSEGS ; i++) + rsclp->tails[i] = rsclp->tails[RCU_DONE_TAIL ]; +} + +/* +* Move the entire contents of the specified rcu_segcblist structure, +* counts, callbacks, and all, to the specified rcu_cblist structure. +* @@@ Why do we need this??? Moving early-boot CBs to NOCB lists? +* @@@ Memory barrier needed? (Not if only used at boot time...) +*/ +static inline void rcu_segcblist_extract_all (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +rcu_segcblist_extract_done_cbs (rsclp, rclp); +rcu_segcblist_extract_pend_cbs (rsclp, rclp); +rcu_segcblist_extract_count (rsclp, rclp); +} + +/* +* Insert counts from the specified rcu_cblist structure in the +* specified rcu_segcblist structure. +*/ +static inline void rcu_segcblist_insert_count (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ + rsclp->len_lazy += rclp->len_lazy; +/* ->len sampled locklessly. */ +WRITE_ONCE (rsclp->len, rsclp->len + rclp->len); + rclp->len_lazy =0 ; + rclp->len =0 ; +} + +/* +* Move callbacks from the specified rcu_cblist to the beginning of the +* done-callbacks segment of the specified rcu_segcblist. +*/ +static inline void rcu_segcblist_insert_done_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rclp->head) +return ;/* No callbacks to move. */ + *rclp->tail = rsclp->head; + rsclp->head = rclp->head; +for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) +if (&rsclp->head == rsclp->tails[i]) + rsclp->tails[i] = rclp->tail; +else +break ; + rclp->head =NULL ; + rclp->tail = &rclp->head; +} + +/* +* Move callbacks from the specified rcu_cblist to the end of the +* new-callbacks segment of the specified rcu_segcblist. +*/ +static inline void rcu_segcblist_insert_pend_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +if (!rclp->head) +return ;/* Nothing to do. */ + *rsclp->tails[RCU_NEXT_TAIL ] = rclp->head; + rsclp->tails[RCU_NEXT_TAIL ] = rclp->tail; + rclp->head =NULL ; + rclp->tail = &rclp->head; +} + +/* +* Advance the callbacks in the specified rcu_segcblist structure based +* on the current value passed in for the grace-period counter. +*/ +static inline void rcu_segcblist_advance (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i, j; + +WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); +WARN_ON_ONCE (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )); + +/* +* Find all callbacks whose ->gp_seq numbers indicate that they +* are ready to invoke, and put them into the RCU_DONE_TAIL segment. +*/ +for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) { +if (ULONG_CMP_LT (seq, rsclp->gp_seq[i])) +break ; + rsclp->tails[RCU_DONE_TAIL ] = rsclp->tails[i]; + } + +/* If no callbacks moved, nothing more need be done. */ +if (i ==RCU_WAIT_TAIL ) +return ; + +/* Clean up tail pointers that might have been misordered above. */ +for (j =RCU_WAIT_TAIL ; j < i; j++) + rsclp->tails[j] = rsclp->tails[RCU_DONE_TAIL ]; + +/* +* Callbacks moved, so clean up the misordered ->tails[] pointers +* that now point into the middle of the list of ready-to-invoke +* callbacks. The overall effect is to copy down the later pointers +* into the gap that was created by the now-ready segments. +*/ +for (j =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++, j++) { +if (rsclp->tails[j] == rsclp->tails[RCU_NEXT_TAIL ]) +break ;/* No more callbacks. */ + rsclp->tails[j] = rsclp->tails[i]; + rsclp->gp_seq[j] = rsclp->gp_seq[i]; + } +} + +/* +* "Accelerate" callbacks based on more-accurate grace-period information. +* The reason for this is that RCU does not synchronize the beginnings and +* ends of grace periods, and that callbacks are posted locally. This in +* turn means that the callbacks must be labelled conservatively early +* on, as getting exact information would degrade both performance and +* scalability. When more accurate grace-period information becomes +* available, previously posted callbacks can be "accelerated", marking +* them to complete at the end of the earlier grace period. +* +* This function operates on an rcu_segcblist structure, and also the +* grace-period sequence number at which new callbacks would become +* ready to invoke. +*/ +static inline bool rcu_segcblist_accelerate (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i; + +WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); +WARN_ON_ONCE (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )); + +/* +* Find the segment preceding the oldest segment of callbacks +* whose ->gp_seq[] completion is at or after that passed in via +* "seq", skipping any empty segments. This oldest segment, along +* with any later segments, can be merged in with any newly arrived +* callbacks in the RCU_NEXT_TAIL segment, and assigned "seq" +* as their ->gp_seq[] grace-period completion sequence number. +*/ +for (i =RCU_NEXT_READY_TAIL ; i >RCU_DONE_TAIL ; i--) +if (rsclp->tails[i] != rsclp->tails[i -1 ] && +ULONG_CMP_LT (rsclp->gp_seq[i], seq)) +break ; + +/* +* If all the segments contain callbacks that correspond to +* earlier grace-period sequence numbers than "seq", leave. +* Assuming that the rcu_segcblist structure has enough +* segments in its arrays, this can only happen if some of +* the non-done segments contain callbacks that really are +* ready to invoke. This situation will get straightened +* out by the next call to rcu_segcblist_advance(). +* +* Also advance to the oldest segment of callbacks whose +* ->gp_seq[] completion is at or after that passed in via "seq", +* skipping any empty segments. +*/ +if (++i >=RCU_NEXT_TAIL ) +return false; + +/* +* Merge all later callbacks, including newly arrived callbacks, +* into the segment located by the for-loop above. Assign "seq" +* as the ->gp_seq[] value in order to correctly handle the case +* where there were no pending callbacks in the rcu_segcblist +* structure other than in the RCU_NEXT_TAIL segment. +*/ +for (; i <RCU_NEXT_TAIL ; i++) { + rsclp->tails[i] = rsclp->tails[RCU_NEXT_TAIL ]; + rsclp->gp_seq[i] = seq; + } +return true; +} + +/* +* Scan the specified rcu_segcblist structure for callbacks that need +* a grace period later than the one specified by "seq". We don't look +* at the RCU_DONE_TAIL or RCU_NEXT_TAIL segments because they don't +* have a grace-period sequence number. +*/ +static inline bool rcu_segcblist_future_gp_needed (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i; + +for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) +if (rsclp->tails[i -1 ] != rsclp->tails[i] && +ULONG_CMP_LT (seq, rsclp->gp_seq[i])) +return true; +return false; +} + +/* +* Interim function to return rcu_segcblist head pointer. Longer term, the +* rcu_segcblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head *rcu_segcblist_head (struct rcu_segcblist *rsclp) +{ +return rsclp->head; +} + +/* +* Interim function to return rcu_segcblist head pointer. Longer term, the +* rcu_segcblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head **rcu_segcblist_tail (struct rcu_segcblist *rsclp) +{ +WARN_ON_ONCE (rcu_segcblist_empty (rsclp)); +return rsclp->tails[RCU_NEXT_TAIL ]; +} + +#endif /* __KERNEL_RCU_SEGCBLIST_H */
kernel/rcu/tree.c +112 -236
580 lines not on this page · raw message
kernel/rcu/tree.h +7 -34
61 lines not on this page · raw message
kernel/rcu/tree_plugin.h +25 -29
95 lines not on this page · raw message
kernel/rcu/tree_trace.c +11 -10
@@ -41,6 +41,7 @@#include <linux/mutex.h> #include <linux/debugfs.h> #include <linux/seq_file.h> +#include <linux/prefetch.h> #define RCU_TREE_NONCORE #include "tree.h"
@@ -128,17 +129,15 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp) rdp->dynticks_fqs);seq_printf (m," of=%lu" , rdp->offline_fqs);rcu_nocb_q_lengths (rdp, &ql, &qll); - qll += rdp->qlen_lazy; - ql += rdp->qlen; + qll +=rcu_segcblist_n_lazy_cbs (&rdp->cblist); + ql +=rcu_segcblist_n_cbs (&rdp->cblist);seq_printf (m," ql=%ld/%ld qs=%c%c%c%c" , qll, ql, -".N" [rdp->nxttail[RCU_NEXT_READY_TAIL ] != - rdp->nxttail[RCU_NEXT_TAIL ]], -".R" [rdp->nxttail[RCU_WAIT_TAIL ] != - rdp->nxttail[RCU_NEXT_READY_TAIL ]], -".W" [rdp->nxttail[RCU_DONE_TAIL ] != - rdp->nxttail[RCU_WAIT_TAIL ]], -".D" [&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL ]]); +".N" [!rcu_segcblist_segempty (&rdp->cblist,RCU_NEXT_TAIL )], +".R" [!rcu_segcblist_segempty (&rdp->cblist, +RCU_NEXT_READY_TAIL )], +".W" [!rcu_segcblist_segempty (&rdp->cblist,RCU_WAIT_TAIL )], +".D" [!rcu_segcblist_segempty (&rdp->cblist,RCU_DONE_TAIL )]);#ifdef CONFIG_RCU_BOOST seq_printf(m, " kt=%d/%c ktl=%x", per_cpu(rcu_cpu_has_work, rdp->cpu),
@@ -276,7 +275,9 @@ static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)seq_printf (m,"nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n" , rsp->n_force_qs, rsp->n_force_qs_ngp, rsp->n_force_qs - rsp->n_force_qs_ngp, -READ_ONCE (rsp->n_force_qs_lh), rsp->qlen_lazy, rsp->qlen); +READ_ONCE (rsp->n_force_qs_lh), +rcu_cblist_n_lazy_cbs (&rsp->orphan_done), +rcu_cblist_n_cbs (&rsp->orphan_done));for (rnp = &rsp->node[0 ]; rnp - &rsp->node[0 ] < rcu_num_nodes; rnp++) {if (rnp->level != level) {seq_puts (m,"\n" );
Signature · 1 line
2.5.2
PATCH v3 14/40 srcu: Allow SRCU to access rcu_scheduler_active
In reply to Paul E. McKenneyThis is primarily a code-movement commit in preparation for allowing SRCU to handle early-boot SRCU grace periods.
--- include/linux/rcutiny.h | 6 +++--- kernel/rcu/tiny_plugin.h | 9 +++++---- kernel/rcu/tree.c | 2 +- kernel/rcu/tree_exp.h | 12 ----------- kernel/rcu/update.c | 52 +++++++++++++++++++++++++++++++----------------- 5 files changed, 43 insertions(+), 38 deletions(-)
include/linux/rcutiny.h +3 -3
@@ -217,14 +217,14 @@ static inline void exit_rcu(void) { } -#ifdef CONFIG_DEBUG_LOCK_ALLOC +#if defined(CONFIG_DEBUG_LOCK_ALLOC ) || defined(CONFIG_SRCU )extern int rcu_scheduler_active__read_mostly ;void rcu_scheduler_starting (void ); -#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ +#else /* #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */ static inline void rcu_scheduler_starting (void ) { } -#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ +#endif /* #else #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */ #if defined(CONFIG_DEBUG_LOCK_ALLOC ) || defined(CONFIG_RCU_TRACE )
kernel/rcu/tiny_plugin.h +5 -4
@@ -52,7 +52,7 @@ static struct rcu_ctrlblk rcu_bh_ctrlblk = { RCU_TRACE(.name = "rcu_bh") }; -#ifdef CONFIG_DEBUG_LOCK_ALLOC +#if defined(CONFIG_DEBUG_LOCK_ALLOC ) || defined(CONFIG_SRCU )#include <linux/kernel_stat.h> int rcu_scheduler_active__read_mostly ;
@@ -65,15 +65,16 @@ EXPORT_SYMBOL_GPL(rcu_scheduler_active);* to RCU_SCHEDULER_RUNNING, skipping the RCU_SCHEDULER_INIT stage. * The reason for this is that Tiny RCU does not need kthreads, so does * not have to care about the fact that the scheduler is half-initialized -* at a certain phase of the boot process. +* at a certain phase of the boot process. Unless SRCU is in the mix. */ void __init rcu_scheduler_starting (void ) {WARN_ON (nr_context_switches () >0 ); - rcu_scheduler_active =RCU_SCHEDULER_RUNNING ; + rcu_scheduler_active =IS_ENABLED (CONFIG_SRCU ) + ?RCU_SCHEDULER_INIT :RCU_SCHEDULER_RUNNING ; } -#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ +#endif /* #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */ #ifdef CONFIG_RCU_TRACE
kernel/rcu/tree.c +1 -1
@@ -3974,7 +3974,7 @@ early_initcall(rcu_spawn_gp_kthread);* task is booting the system, and such primitives are no-ops). After this * function is called, any synchronous grace-period primitives are run as * expedited, with the requesting task driving the grace period forward. -* A later core_initcall() rcu_exp_runtime_mode() will switch to full +* A later core_initcall() rcu_set_runtime_mode() will switch to full * runtime RCU functionality. */ void rcu_scheduler_starting (void )
kernel/rcu/tree_exp.h +0 -12
@@ -737,15 +737,3 @@ void synchronize_rcu_expedited(void)EXPORT_SYMBOL_GPL (synchronize_rcu_expedited);#endif /* #else #ifdef CONFIG_PREEMPT_RCU */ - -/* -* Switch to run-time mode once Tree RCU has fully initialized. -*/ -static int __init rcu_exp_runtime_mode (void ) -{ -rcu_test_sync_prims (); - rcu_scheduler_active =RCU_SCHEDULER_RUNNING ; -rcu_test_sync_prims (); -return 0 ; -} -core_initcall (rcu_exp_runtime_mode);
kernel/rcu/update.c +34 -18
70 lines not on this page · raw message
Signature · 1 line
2.5.2
PATCH v3 5/40 rcu: Semicolon inside RCU_TRACE() for rcu.h
In reply to Paul E. McKenneyThe current use of "RCU_TRACE(statement);" can cause odd bugs, especially where "statement" is a local-variable declaration, as it can leave a misplaced ";" in the source code. This commit therefore converts these to "RCU_TRACE(statement;)", which avoids the misplaced ";".
--- kernel/rcu/rcu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/rcu.h +2 -2
@@ -109,12 +109,12 @@ static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head)rcu_lock_acquire (&rcu_callback_map);if (__is_kfree_rcu_offset (offset)) { -RCU_TRACE (trace_rcu_invoke_kfree_callback (rn, head, offset)); + RCU_TRACE(trace_rcu_invoke_kfree_callback(rn, head, offset);)kfree ((void *)head - offset);rcu_lock_release (&rcu_callback_map);return true; }else { -RCU_TRACE (trace_rcu_invoke_callback (rn, head)); + RCU_TRACE(trace_rcu_invoke_callback(rn, head);) head->func(head);rcu_lock_release (&rcu_callback_map);return false;
Signature · 1 line
2.5.2
PATCH v3 7/40 rcu: Semicolon inside RCU_TRACE() for tree.c
In reply to Paul E. McKenneyThe current use of "RCU_TRACE(statement);" can cause odd bugs, especially where "statement" is a local-variable declaration, as it can leave a misplaced ";" in the source code. This commit therefore converts these to "RCU_TRACE(statement;)", which avoids the misplaced ";".
--- kernel/rcu/tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
kernel/rcu/tree.c +4 -4
@@ -2793,14 +2793,14 @@ static void rcu_adopt_orphan_cbs(struct rcu_state *rsp, unsigned long flags)*/ static void rcu_cleanup_dying_cpu (struct rcu_state *rsp) { -RCU_TRACE (unsigned long mask ); - RCU_TRACE(struct rcu_data *rdp = this_cpu_ptr(rsp->rda)); - RCU_TRACE(struct rcu_node *rnp = rdp->mynode); + RCU_TRACE(unsigned long mask;) + RCU_TRACE(struct rcu_data *rdp = this_cpu_ptr(rsp->rda);) + RCU_TRACE(struct rcu_node *rnp = rdp->mynode;)if (!IS_ENABLED (CONFIG_HOTPLUG_CPU ))return ; -RCU_TRACE (mask = rdp->grpmask); + RCU_TRACE(mask = rdp->grpmask;)trace_rcu_grace_period (rsp->name, rnp->gpnum +1 - !!(rnp->qsmask & mask),TPS ("cpuofl" ));
Signature · 1 line
2.5.2
PATCH v3 15/40 srcu: Allow early boot use of synchronize_srcu()
In reply to Paul E. McKenneyThis commit checks for pre-scheduler state, and if that early in the boot process, synchronize_srcu() and friends are no-ops.
--- kernel/rcu/srcu.c | 2 ++ 1 file changed, 2 insertions(+)
kernel/rcu/srcu.c +2 -0
@@ -417,6 +417,8 @@ static void __synchronize_srcu(struct srcu_struct *sp, int trycount)lock_is_held (&rcu_sched_lock_map), "Illegal synchronize_srcu() in same-type SRCU (or in RCU) read-side critical section"); +if (rcu_scheduler_active ==RCU_SCHEDULER_INACTIVE ) +return ;might_sleep ();init_completion (&rcu.completion);
Signature · 1 line
2.5.2
PATCH v3 20/40 srcu: Push srcu_advance_batches() fastpath into common case
In reply to Paul E. McKenneyThis commit simplifies the SRCU state machine by pushing the srcu_advance_batches() idle-SRCU fastpath into the common case. This is done by giving srcu_reschedule() a delay parameter, which is zero in the call from srcu_advance_batches().
This commit is a step towards numbering callbacks in order to efficiently handle per-CPU callback lists.
--- kernel/rcu/srcu.c | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-)
kernel/rcu/srcu.c +7 -20
@@ -399,8 +399,7 @@ void call_srcu(struct srcu_struct *sp, struct rcu_head *head, }EXPORT_SYMBOL_GPL (call_srcu); -static void srcu_advance_batches (struct srcu_struct *sp,int trycount); -static void srcu_reschedule (struct srcu_struct *sp); +static void srcu_reschedule (struct srcu_struct *sp,unsigned long delay);/* * Helper function for synchronize_srcu() and synchronize_srcu_expedited().
@@ -409,7 +408,6 @@ static void __synchronize_srcu(struct srcu_struct *sp, int trycount) {struct rcu_synchronize rcu;struct rcu_head *head = &rcu.head; -bool done = false; RCU_LOCKDEP_WARN(lock_is_held(&sp->dep_map) || lock_is_held(&rcu_bh_lock_map) ||
@@ -431,25 +429,15 @@ static void __synchronize_srcu(struct srcu_struct *sp, int trycount) sp->running = true;rcu_batch_queue (&sp->batch_check0, head);spin_unlock_irq (&sp->queue_lock); - -srcu_advance_batches (sp, trycount); -if (!rcu_batch_empty (&sp->batch_done)) { -BUG_ON (sp->batch_done.head != head); -rcu_batch_dequeue (&sp->batch_done); - done = true; - }/* give the processing owner to work_struct */ -srcu_reschedule (sp); +srcu_reschedule (sp,0 ); }else {rcu_batch_queue (&sp->batch_queue, head);spin_unlock_irq (&sp->queue_lock); } -if (!done) { -wait_for_completion (&rcu.completion); -smp_mb ();/* Caller's later accesses after GP. */ - } - +wait_for_completion (&rcu.completion); +smp_mb ();/* Caller's later accesses after GP. */ }/**
@@ -639,7 +627,7 @@ static void srcu_invoke_callbacks(struct srcu_struct *sp)* Finished one round of SRCU grace period. Start another if there are * more SRCU callbacks queued, otherwise put SRCU into not-running state. */ -static void srcu_reschedule (struct srcu_struct *sp) +static void srcu_reschedule (struct srcu_struct *sp,unsigned long delay) {bool pending = true;
@@ -653,8 +641,7 @@ static void srcu_reschedule(struct srcu_struct *sp) }if (pending) -queue_delayed_work (system_power_efficient_wq, - &sp->work,SRCU_INTERVAL ); +queue_delayed_work (system_power_efficient_wq, &sp->work, delay); }/*
@@ -669,6 +656,6 @@ void process_srcu(struct work_struct *work)srcu_collect_new (sp);srcu_advance_batches (sp,1 );srcu_invoke_callbacks (sp); -srcu_reschedule (sp); +srcu_reschedule (sp,SRCU_INTERVAL ); }EXPORT_SYMBOL_GPL (process_srcu);
Signature · 1 line
2.5.2
PATCH v3 39/40 srcu: Expedite srcu_schedule_cbs_snp() callback invocation
In reply to Paul E. McKenneyAlthough Tree SRCU does reduce delays when there is at least one synchronize_srcu_expedited() invocation pending, srcu_schedule_cbs_snp() still waits for SRCU_INTERVAL before invoking callbacks. Since synchronize_srcu_expedited() now posts a callback and waits for that callback to do a wakeup, this destroys the expedited nature of synchronize_srcu_expedited(). This destruction became apparent to Marc Zyngier in the guise of a guest-OS bootup slowdown from five seconds to no fewer than forty seconds.
This commit therefore invokes callbacks immediately at the end of the grace period when there is at least one synchronize_srcu_expedited() invocation pending. This brought Marc's guest-OS bootup times back into the realm of reason.
--- kernel/rcu/srcutree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/rcu/srcutree.c +2 -1
@@ -442,7 +442,8 @@ static void srcu_schedule_cbs_snp(struct srcu_struct *sp, struct srcu_node *snp)int cpu;for (cpu = snp->grplo; cpu <= snp->grphi; cpu++) -srcu_schedule_cbs_sdp (per_cpu_ptr (sp->sda, cpu),SRCU_INTERVAL ); +srcu_schedule_cbs_sdp (per_cpu_ptr (sp->sda, cpu), +atomic_read (&sp->srcu_exp_cnt) ?0 :SRCU_INTERVAL ); }/*
Signature · 1 line
2.5.2
PATCH v3 37/40 srcu: Introduce CLASSIC_SRCU Kconfig option
In reply to Paul E. McKenneyThe TREE_SRCU rewrite is large and a bit on the non-simple side, so this commit helps reduce risk by allowing the old v4.11 SRCU algorithm to be selected using a new CLASSIC_SRCU Kconfig option that depends on RCU_EXPERT. The default is to use the new TREE_SRCU and TINY_SRCU algorithms, in order to help get these the testing that they need. However, if your users do not require the update-side scalability that is to be provided by TREE_SRCU, select RCU_EXPERT and then CLASSIC_SRCU to revert back to the old classic SRCU algorithm.
--- include/linux/srcu.h | 2 + include/linux/srcuclassic.h | 101 ++++++++ init/Kconfig | 21 +- kernel/rcu/Makefile | 3 +- kernel/rcu/rcutorture.c | 2 +- kernel/rcu/srcu.c | 347 ++++++++++++++----------- kernel/rcu/srcutree.c | 613 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 934 insertions(+), 155 deletions(-) create mode 100644 include/linux/srcuclassic.h create mode 100644 kernel/rcu/srcutree.c
include/linux/srcu.h +2 -0
@@ -60,6 +60,8 @@ int init_srcu_struct(struct srcu_struct *sp);#include <linux/srcutiny.h> #elif defined(CONFIG_TREE_SRCU )#include <linux/srcutree.h> +#elif defined(CONFIG_CLASSIC_SRCU ) +#include <linux/srcuclassic.h> #else #error "Unknown SRCU implementation specified to kernel configuration"#endif
include/linux/srcuclassic.h new file +101 -0
101 lines not on this page · raw message
init/Kconfig +19 -2
@@ -526,15 +526,32 @@ config SRCU permits arbitrary sleeping or blocking within RCU read-side critical sections. +config CLASSIC_SRCU + bool "Use v4.11 classic SRCU implementation" + default n + depends on RCU_EXPERT && SRCU + help + This option selects the traditional well-tested classic SRCU + implementation from v4.11, as might be desired for enterprise + Linux distributions. Without this option, the shiny new + Tiny SRCU and Tree SRCU implementations are used instead. + At some point, it is hoped that Tiny SRCU and Tree SRCU + will accumulate enough test time and confidence to allow + Classic SRCU to be dropped entirely. + + Say Y if you need a rock-solid SRCU. + + Say N if you would like help test Tree SRCU. + config TINY_SRCU bool - default y if TINY_RCU + default y if TINY_RCU && !CLASSIC_SRCU help This option selects the single-CPU non-preemptible version of SRCU. config TREE_SRCU bool - default y if !TINY_RCU + default y if !TINY_RCU && !CLASSIC_SRCU help This option selects the full-fledged version of SRCU.
kernel/rcu/Makefile +2 -1
@@ -3,7 +3,8 @@ KCOV_INSTRUMENT := n obj-y += update.o sync.o -obj-$(CONFIG_TREE_SRCU) += srcu.o +obj-$(CONFIG_CLASSIC_SRCU) += srcu.o +obj-$(CONFIG_TREE_SRCU) += srcutree.o obj-$(CONFIG_TINY_SRCU) += srcutiny.o obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o obj-$(CONFIG_RCU_PERF_TEST) += rcuperf.o
kernel/rcu/rcutorture.c +1 -1
@@ -562,7 +562,7 @@ static void srcu_torture_stats(void)int __maybe_unused cpu;int idx; -#ifdef CONFIG_TREE_SRCU +#if defined(CONFIG_TREE_SRCU ) || defined(CONFIG_CLASSIC_SRCU ) idx = srcu_ctlp->completed &0x1 ;pr_alert ("%s%s Tree SRCU per-CPU(idx=%d):" , torture_type,TORTURE_FLAG , idx);
kernel/rcu/srcu.c +196 -151
497 lines not on this page · raw message
kernel/rcu/srcutree.c new file +613 -0
613 lines not on this page · raw message
Signature · 1 line
2.5.2
PATCH v3 26/40 rcu: Remove redundant levelcnt[] array from rcu_init_one()
In reply to Paul E. McKenneyThe levelcnt[] array is identical to num_rcu_lvl[], so this commit removes levelcnt[].
--- kernel/rcu/tree.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
kernel/rcu/tree.c +3 -6
@@ -3961,7 +3961,6 @@ static void __init rcu_init_one(struct rcu_state *rsp)static struct lock_class_key rcu_node_class[RCU_NUM_LVLS ];static struct lock_class_key rcu_fqs_class[RCU_NUM_LVLS ]; -int levelcnt[RCU_NUM_LVLS ];/* # nodes in each level. */ int levelspread[RCU_NUM_LVLS ];/* kids/node in each level. */ int cpustride =1 ;int i;
@@ -3976,18 +3975,16 @@ static void __init rcu_init_one(struct rcu_state *rsp)/* Initialize the level-tracking arrays. */ -for (i =0 ; i < rcu_num_lvls; i++) - levelcnt[i] = num_rcu_lvl[i];for (i =1 ; i < rcu_num_lvls; i++) - rsp->level[i] = rsp->level[i -1 ] + levelcnt[i -1 ]; -rcu_init_levelspread (levelspread, levelcnt); + rsp->level[i] = rsp->level[i -1 ] + num_rcu_lvl[i -1 ]; +rcu_init_levelspread (levelspread, num_rcu_lvl);/* Initialize the elements themselves, starting from the leaves. */ for (i = rcu_num_lvls -1 ; i >=0 ; i--) { cpustride *= levelspread[i]; rnp = rsp->level[i]; -for (j =0 ; j < levelcnt[i]; j++, rnp++) { +for (j =0 ; j < num_rcu_lvl[i]; j++, rnp++) {raw_spin_lock_init (&ACCESS_PRIVATE (rnp, lock));lockdep_set_class_and_name (&ACCESS_PRIVATE (rnp, lock), &rcu_node_class[i], buf[i]);
Signature · 1 line
2.5.2
PATCH v3 38/40 srcu: Parallelize callback handling
In reply to Paul E. McKenneyPeter Zijlstra proposed using SRCU to reduce mmap_sem contention [1,2], however, there are workloads that could result in a high volume of concurrent invocations of call_srcu(), which with current SRCU would result in excessive lock contention on the srcu_struct structure's ->queue_lock, which protects SRCU's callback lists. This commit therefore moves SRCU to per-CPU callback lists, thus greatly reducing contention.
Because a given SRCU instance no longer has a single centralized callback list, starting grace periods and invoking callbacks are both more complex than in the single-list Classic SRCU implementation. Starting grace periods and handling callbacks are now handled using an srcu_node tree that is in some ways similar to the rcu_node trees used by RCU-bh, RCU-preempt, and RCU-sched (for example, the srcu_node tree shape is controlled by exactly the same Kconfig options and boot parameters that control the shape of the rcu_node tree).
In addition, the old per-CPU srcu_array structure is now named srcu_data and contains an rcu_segcblist structure named ->srcu_cblist for its callbacks (and a spinlock to protect this). The srcu_struct gets an srcu_gp_seq that is used to associate callback segments with the corresponding completion-time grace-period number. These completion-time grace-period numbers are propagated up the srcu_node tree so that the grace-period workqueue handler can determine whether additional grace periods are needed on the one hand and where to look for callbacks that are ready to be invoked.
The srcu_barrier() function must now wait on all instances of the per-CPU ->srcu_cblist. Because each ->srcu_cblist is protected by ->lock, srcu_barrier() can remotely add the needed callbacks. In theory, it could also remotely start grace periods, but in practice doing so is complex and racy. And interestingly enough, it is never necessary for srcu_barrier() to start a grace period because srcu_barrier() only enqueues a callback when a callback is already present--and it turns out that a grace period has to have already been started for this pre-existing callback. Furthermore, it is only the callback that srcu_barrier() needs to wait on, not any particular grace period. Therefore, a new rcu_segcblist_entrain() function enqueues the srcu_barrier() function's callback into the same segment occupied by the last pre-existing callback in the list. The special case where all the pre-existing callbacks are on a different list (because they are in the process of being invoked) is handled by enqueuing srcu_barrier()'s callback into the RCU_DONE_TAIL segment, relying on the done-callbacks check that takes place after all callbacks are inovked.
Note that the readers use the same algorithm as before. Note that there is a separate srcu_idx that tells the readers what counter to increment. This unfortunately cannot be combined with srcu_gp_seq because they need to be incremented at different times.
This commit introduces some ugly #ifdefs in rcutorture. These will go away when I feel good enough about Tree SRCU to ditch Classic SRCU.
Some crude performance comparisons, courtesy of a quickly hacked rcuperf asynchronous-grace-period capability:
Callback Queuing Overhead ------------------------- # CPUS Classic SRCU Tree SRCU ------ ------------ --------- 2 0.349 us 0.342 us 16 31.66 us 0.4 us 41 --------- 0.417 us
The times are the 90th percentiles, a statistic that was chosen to reject the overheads of the occasional srcu_barrier() call needed to avoid OOMing the test machine. The rcuperf test hangs when running Classic SRCU at 41 CPUs, hence the line of dashes. Despite the hacks to both the rcuperf code and that statistics, this is a convincing demonstration of Tree SRCU's performance and scalability advantages.
[1] https://lwn.net/Articles/309030/
[2] https://patchwork.kernel.org/patch/5108281/
--- include/linux/rcu_segcblist.h | 42 ++- include/linux/srcutree.h | 80 ++++-- kernel/rcu/rcutorture.c | 20 +- kernel/rcu/srcutree.c | 639 +++++++++++++++++++++++++++++++++--------- kernel/rcu/tree.c | 6 + kernel/rcu/tree.h | 8 + 6 files changed, 645 insertions(+), 150 deletions(-)
include/linux/rcu_segcblist.h +38 -4
@@ -402,6 +402,37 @@ static inline void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp, }/* +* Entrain the specified callback onto the specified rcu_segcblist at +* the end of the last non-empty segment. If the entire rcu_segcblist +* is empty, make no change, but return false. +* +* This is intended for use by rcu_barrier()-like primitives, -not- +* for normal grace-period use. IMPORTANT: The callback you enqueue +* will wait for all prior callbacks, NOT necessarily for a grace +* period. You have been warned. +*/ +static inline bool rcu_segcblist_entrain (struct rcu_segcblist *rsclp, +struct rcu_head *rhp,bool lazy) +{ +int i; + +if (rcu_segcblist_n_cbs (rsclp) ==0 ) +return false; +WRITE_ONCE (rsclp->len, rsclp->len +1 ); +if (lazy) + rsclp->len_lazy++; +smp_mb ();/* Ensure counts are updated before callback is entrained. */ + rhp->next =NULL ; +for (i =RCU_NEXT_TAIL ; i >RCU_DONE_TAIL ; i--) +if (rsclp->tails[i] != rsclp->tails[i -1 ]) +break ; + *rsclp->tails[i] = rhp; +for (; i <=RCU_NEXT_TAIL ; i++) + rsclp->tails[i] = &rhp->next; +return true; +} + +/* * Extract only the counts from the specified rcu_segcblist structure, * and place them in the specified rcu_cblist structure. This function * supports both callback orphaning and invocation, hence the separation
@@ -537,7 +568,8 @@ static inline void rcu_segcblist_advance(struct rcu_segcblist *rsclp,int i, j;WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); -WARN_ON_ONCE (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )); +if (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )) +return ;/* * Find all callbacks whose ->gp_seq numbers indicate that they
@@ -582,8 +614,9 @@ static inline void rcu_segcblist_advance(struct rcu_segcblist *rsclp,* them to complete at the end of the earlier grace period. * * This function operates on an rcu_segcblist structure, and also the -* grace-period sequence number at which new callbacks would become -* ready to invoke. +* grace-period sequence number seq at which new callbacks would become +* ready to invoke. Returns true if there are callbacks that won't be +* ready to invoke until seq, false otherwise. */ static inline bool rcu_segcblist_accelerate (struct rcu_segcblist *rsclp,unsigned long seq)
@@ -591,7 +624,8 @@ static inline bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp,int i;WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); -WARN_ON_ONCE (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )); +if (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )) +return false;/* * Find the segment preceding the oldest segment of callbacks
include/linux/srcutree.h +64 -16
107 lines not on this page · raw message
kernel/rcu/rcutorture.c +19 -1
@@ -563,17 +563,30 @@ static void srcu_torture_stats(void)int idx;#if defined(CONFIG_TREE_SRCU ) || defined(CONFIG_CLASSIC_SRCU ) +#ifdef CONFIG_TREE_SRCU + idx = srcu_ctlp->srcu_idx &0x1 ; +#else /* #ifdef CONFIG_TREE_SRCU */ idx = srcu_ctlp->completed &0x1 ; +#endif /* #else #ifdef CONFIG_TREE_SRCU */ pr_alert ("%s%s Tree SRCU per-CPU(idx=%d):" , torture_type,TORTURE_FLAG , idx);for_each_possible_cpu (cpu) {unsigned long l0, l1;unsigned long u0, u1;long c0, c1; -struct srcu_array *counts =per_cpu_ptr (srcu_ctlp->per_cpu_ref, cpu); +#ifdef CONFIG_TREE_SRCU +struct srcu_data *counts; + counts =per_cpu_ptr (srcu_ctlp->sda, cpu); + u0 = counts->srcu_unlock_count[!idx]; + u1 = counts->srcu_unlock_count[idx]; +#else /* #ifdef CONFIG_TREE_SRCU */ +struct srcu_array *counts; + + counts =per_cpu_ptr (srcu_ctlp->per_cpu_ref, cpu); u0 = counts->unlock_count[!idx]; u1 = counts->unlock_count[idx]; +#endif /* #else #ifdef CONFIG_TREE_SRCU */ /* * Make sure that a lock is always counted if the corresponding
@@ -581,8 +594,13 @@ static void srcu_torture_stats(void)*/ smp_rmb (); +#ifdef CONFIG_TREE_SRCU + l0 = counts->srcu_lock_count[!idx]; + l1 = counts->srcu_lock_count[idx]; +#else /* #ifdef CONFIG_TREE_SRCU */ l0 = counts->lock_count[!idx]; l1 = counts->lock_count[idx]; +#endif /* #else #ifdef CONFIG_TREE_SRCU */ c0 = l0 - u0; c1 = l1 - u1;
kernel/rcu/srcutree.c +510 -129
877 lines not on this page · raw message
kernel/rcu/tree.c +6 -0
@@ -3776,12 +3776,16 @@ int rcutree_online_cpu(unsigned int cpu) {sync_sched_exp_online_cleanup (cpu);rcutree_affinity_setting (cpu,-1 ); +if (IS_ENABLED (CONFIG_TREE_SRCU )) +srcu_online_cpu (cpu);return 0 ; }int rcutree_offline_cpu (unsigned int cpu) {rcutree_affinity_setting (cpu, cpu); +if (IS_ENABLED (CONFIG_TREE_SRCU )) +srcu_offline_cpu (cpu);return 0 ; }
@@ -4157,6 +4161,8 @@ void __init rcu_init(void)for_each_online_cpu (cpu) {rcutree_prepare_cpu (cpu);rcu_cpu_starting (cpu); +if (IS_ENABLED (CONFIG_TREE_SRCU )) +srcu_online_cpu (cpu); } }
kernel/rcu/tree.h +8 -0
@@ -541,6 +541,14 @@ static bool rcu_nohz_full_cpu(struct rcu_state *rsp);static void rcu_dynticks_task_enter (void );static void rcu_dynticks_task_exit (void ); +#ifdef CONFIG_SRCU +void srcu_online_cpu (unsigned int cpu); +void srcu_offline_cpu (unsigned int cpu); +#else /* #ifdef CONFIG_SRCU */ +void srcu_online_cpu (unsigned int cpu) { } +void srcu_offline_cpu (unsigned int cpu) { } +#endif /* #else #ifdef CONFIG_SRCU */ +#endif /* #ifndef RCU_TREE_NONCORE */ #ifdef CONFIG_RCU_TRACE
Signature · 1 line
2.5.2
PATCH v3 25/40 srcu: Move rcu_init_levelspread() to rcu_tree_node.h
In reply to Paul E. McKenneyThis commit moves the rcu_init_levelspread() function from kernel/rcu/tree.c to kernel/rcu/rcu.h so that SRCU can access it. This is another step towards enabling SRCU to create its own combining tree. This commit is code-movement only, give or take knock-on adjustments.
--- include/linux/rcu_node_tree.h | 3 --- kernel/rcu/rcu.h | 36 ++++++++++++++++++++++++++++++++++++ kernel/rcu/srcu.c | 1 + kernel/rcu/tree.c | 25 ------------------------- kernel/rcu/tree_trace.c | 1 + 5 files changed, 38 insertions(+), 28 deletions(-)
include/linux/rcu_node_tree.h +0 -3
@@ -96,7 +96,4 @@# error "CONFIG_RCU_FANOUT insufficient for NR_CPUS"#endif /* #if (NR_CPUS) <= RCU_FANOUT_1 */ -extern int rcu_num_lvls; -extern int rcu_num_nodes; -#endif /* __LINUX_RCU_NODE_TREE_H */
kernel/rcu/rcu.h +36 -0
@@ -190,4 +190,40 @@ void rcu_test_sync_prims(void);*/ extern void resched_cpu (int cpu); +#if defined(SRCU ) || !defined(TINY_RCU ) + +#include <linux/rcu_node_tree.h> + +extern int rcu_num_lvls; +extern int rcu_num_nodes; +static bool rcu_fanout_exact; +static int rcu_fanout_leaf; + +/* +* Compute the per-level fanout, either using the exact fanout specified +* or balancing the tree, depending on the rcu_fanout_exact boot parameter. +*/ +static inline void rcu_init_levelspread (int *levelspread,const int *levelcnt) +{ +int i; + +if (rcu_fanout_exact) { + levelspread[rcu_num_lvls -1 ] = rcu_fanout_leaf; +for (i = rcu_num_lvls -2 ; i >=0 ; i--) + levelspread[i] =RCU_FANOUT ; + }else { +int ccur; +int cprv; + + cprv = nr_cpu_ids; +for (i = rcu_num_lvls -1 ; i >=0 ; i--) { + ccur = levelcnt[i]; + levelspread[i] = (cprv + ccur -1 ) / ccur; + cprv = ccur; + } + } +} + +#endif /* #if defined(SRCU) || !defined(TINY_RCU) */ +#endif /* __LINUX_RCU_H */
kernel/rcu/srcu.c +1 -0
@@ -36,6 +36,7 @@#include <linux/delay.h> #include <linux/srcu.h> +#include <linux/rcu_node_tree.h> #include "rcu.h" static int init_srcu_struct_fields (struct srcu_struct *sp)
kernel/rcu/tree.c +0 -25
@@ -3952,31 +3952,6 @@ void rcu_scheduler_starting(void) }/* -* Compute the per-level fanout, either using the exact fanout specified -* or balancing the tree, depending on the rcu_fanout_exact boot parameter. -*/ -static void __init rcu_init_levelspread (int *levelspread,const int *levelcnt) -{ -int i; - -if (rcu_fanout_exact) { - levelspread[rcu_num_lvls -1 ] = rcu_fanout_leaf; -for (i = rcu_num_lvls -2 ; i >=0 ; i--) - levelspread[i] =RCU_FANOUT ; - }else { -int ccur; -int cprv; - - cprv = nr_cpu_ids; -for (i = rcu_num_lvls -1 ; i >=0 ; i--) { - ccur = levelcnt[i]; - levelspread[i] = (cprv + ccur -1 ) / ccur; - cprv = ccur; - } - } -} - -/* * Helper function for rcu_init() that initializes one rcu_state structure. */ static void __init rcu_init_one (struct rcu_state *rsp)
kernel/rcu/tree_trace.c +1 -0
@@ -45,6 +45,7 @@#define RCU_TREE_NONCORE #include "tree.h" +#include "rcu.h" static int r_open (struct inode *inode,struct file *file,const struct seq_operations *op)
Signature · 1 line
2.5.2
PATCH v3 17/40 srcu: Move rcu_seq_start() and friends to rcu.h
In reply to Paul E. McKenneyThis commit moves rcu_seq_start(), rcu_seq_end(), rcu_seq_snap(), and rcu_seq_done() from kernel/rcu/tree.c to kernel/rcu/rcu.h. This will allow SRCU to use these functions, which in turn will allow SRCU to move from a single global callback queue to a per-CPU callback queue.
--- kernel/rcu/rcu.h | 40 ++++++++++++++++++++++++++++++++++++++++ kernel/rcu/tree.c | 35 ----------------------------------- 2 files changed, 40 insertions(+), 35 deletions(-)
kernel/rcu/rcu.h +40 -0
@@ -56,6 +56,46 @@#define DYNTICK_TASK_EXIT_IDLE (DYNTICK_TASK_NEST_VALUE + \ DYNTICK_TASK_FLAG) + +/* +* Grace-period counter management. +*/ + +/* Adjust sequence number for start of update-side operation. */ +static inline void rcu_seq_start (unsigned long *sp) +{ +WRITE_ONCE (*sp, *sp +1 ); +smp_mb ();/* Ensure update-side operation after counter increment. */ +WARN_ON_ONCE (!(*sp &0x1 )); +} + +/* Adjust sequence number for end of update-side operation. */ +static inline void rcu_seq_end (unsigned long *sp) +{ +smp_mb ();/* Ensure update-side operation before counter increment. */ +WRITE_ONCE (*sp, *sp +1 ); +WARN_ON_ONCE (*sp &0x1 ); +} + +/* Take a snapshot of the update side's sequence number. */ +static inline unsigned long rcu_seq_snap (unsigned long *sp) +{ +unsigned long s; + + s = (READ_ONCE (*sp) +3 ) & ~0x1 ; +smp_mb ();/* Above access must not bleed into critical section. */ +return s; +} + +/* +* Given a snapshot from rcu_seq_snap(), determine whether or not a +* full update-side operation has occurred. +*/ +static inline bool rcu_seq_done (unsigned long *sp,unsigned long s) +{ +return ULONG_CMP_GE (READ_ONCE (*sp), s); +} +/* * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally * by call_rcu() and rcu callback execution, and are therefore not part of the
kernel/rcu/tree.c +0 -35
@@ -3409,41 +3409,6 @@ void cond_synchronize_sched(unsigned long oldstate) }EXPORT_SYMBOL_GPL (cond_synchronize_sched); -/* Adjust sequence number for start of update-side operation. */ -static void rcu_seq_start (unsigned long *sp) -{ -WRITE_ONCE (*sp, *sp +1 ); -smp_mb ();/* Ensure update-side operation after counter increment. */ -WARN_ON_ONCE (!(*sp &0x1 )); -} - -/* Adjust sequence number for end of update-side operation. */ -static void rcu_seq_end (unsigned long *sp) -{ -smp_mb ();/* Ensure update-side operation before counter increment. */ -WRITE_ONCE (*sp, *sp +1 ); -WARN_ON_ONCE (*sp &0x1 ); -} - -/* Take a snapshot of the update side's sequence number. */ -static unsigned long rcu_seq_snap (unsigned long *sp) -{ -unsigned long s; - - s = (READ_ONCE (*sp) +3 ) & ~0x1 ; -smp_mb ();/* Above access must not bleed into critical section. */ -return s; -} - -/* -* Given a snapshot from rcu_seq_snap(), determine whether or not a -* full update-side operation has occurred. -*/ -static bool rcu_seq_done (unsigned long *sp,unsigned long s) -{ -return ULONG_CMP_GE (READ_ONCE (*sp), s); -} -/* * Check to see if there is any immediate RCU-related work to be done * by the current CPU, for the specified type of RCU, returning 1 if so.
Signature · 1 line
2.5.2
PATCH v3 3/40 srcu: Consolidate batch checking into rcu_all_batches_empty()
In reply to Paul E. McKenneyThe srcu_reschedule() function invokes rcu_batch_empty() on each of the four rcu_batch structures in the srcu_struct in question twice. Given that this check will also be needed in cleanup_srcu_struct(), this commit consolidates these four checks into a new rcu_all_batches_empty() function.
--- kernel/rcu/srcu.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-)
kernel/rcu/srcu.c +13 -8
@@ -65,6 +65,17 @@ static inline bool rcu_batch_empty(struct rcu_batch *b) }/* +* Are all batches empty for the specified srcu_struct? +*/ +static inline bool rcu_all_batches_empty (struct srcu_struct *sp) +{ +return rcu_batch_empty (&sp->batch_done) && +rcu_batch_empty (&sp->batch_check1) && +rcu_batch_empty (&sp->batch_check0) && +rcu_batch_empty (&sp->batch_queue); +} + +/* * Remove the callback at the head of the specified rcu_batch structure * and return a pointer to it, or return NULL if the structure is empty. */
@@ -619,15 +630,9 @@ static void srcu_reschedule(struct srcu_struct *sp) {bool pending = true; -if (rcu_batch_empty (&sp->batch_done) && -rcu_batch_empty (&sp->batch_check1) && -rcu_batch_empty (&sp->batch_check0) && -rcu_batch_empty (&sp->batch_queue)) { +if (rcu_all_batches_empty (sp)) {spin_lock_irq (&sp->queue_lock); -if (rcu_batch_empty (&sp->batch_done) && -rcu_batch_empty (&sp->batch_check1) && -rcu_batch_empty (&sp->batch_check0) && -rcu_batch_empty (&sp->batch_queue)) { +if (rcu_all_batches_empty (sp)) { sp->running = false; pending = false; }
Signature · 1 line
2.5.2
PATCH v3 6/40 rcu: Semicolon inside RCU_TRACE() for Tiny RCU
In reply to Paul E. McKenneyThe current use of "RCU_TRACE(statement);" can cause odd bugs, especially where "statement" is a local-variable declaration, as it can leave a misplaced ";" in the source code. This commit therefore converts these to "RCU_TRACE(statement;)", which avoids the misplaced ";".
--- kernel/rcu/tiny.c | 20 ++++++++++---------- kernel/rcu/tiny_plugin.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-)
kernel/rcu/tiny.c +10 -10
@@ -79,7 +79,7 @@ EXPORT_SYMBOL(__rcu_is_watching);*/ static int rcu_qsctr_help (struct rcu_ctrlblk *rcp) { -RCU_TRACE (reset_cpu_stall_ticks (rcp)); + RCU_TRACE(reset_cpu_stall_ticks(rcp);)if (rcp->donetail != rcp->curtail) { rcp->donetail = rcp->curtail;return 1 ;
@@ -125,7 +125,7 @@ void rcu_bh_qs(void)*/ void rcu_check_callbacks (int user) { -RCU_TRACE (check_cpu_stalls ()); + RCU_TRACE(check_cpu_stalls();)if (user)rcu_sched_qs ();else if (!in_softirq ())
@@ -143,7 +143,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)const char *rn =NULL ;struct rcu_head *next, *list;unsigned long flags; - RCU_TRACE(int cb_count = 0); + RCU_TRACE(int cb_count = 0;)/* Move the ready-to-invoke callbacks to a local list. */ local_irq_save (flags);
@@ -152,7 +152,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)local_irq_restore (flags);return ; } -RCU_TRACE (trace_rcu_batch_start (rcp->name,0 , rcp->qlen,-1 )); + RCU_TRACE(trace_rcu_batch_start(rcp->name, 0, rcp->qlen, -1);) list = rcp->rcucblist; rcp->rcucblist = *rcp->donetail; *rcp->donetail =NULL ;
@@ -162,7 +162,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)local_irq_restore (flags);/* Invoke the callbacks on the local list. */ -RCU_TRACE (rn = rcp->name); + RCU_TRACE(rn = rcp->name;)while (list) { next = list->next;prefetch (next);
@@ -171,9 +171,9 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)__rcu_reclaim (rn, list);local_bh_enable (); list = next; -RCU_TRACE (cb_count++); + RCU_TRACE(cb_count++;) } -RCU_TRACE (rcu_trace_sub_qlen (rcp, cb_count)); + RCU_TRACE(rcu_trace_sub_qlen(rcp, cb_count);) RCU_TRACE(trace_rcu_batch_end(rcp->name, cb_count, 0, need_resched(), is_idle_task(current),
@@ -221,7 +221,7 @@ static void __call_rcu(struct rcu_head *head,local_irq_save (flags); *rcp->curtail = head; rcp->curtail = &head->next; -RCU_TRACE (rcp->qlen++); + RCU_TRACE(rcp->qlen++;)local_irq_restore (flags);if (unlikely (is_idle_task (current))) {
@@ -254,8 +254,8 @@ EXPORT_SYMBOL_GPL(call_rcu_bh);void __init rcu_init (void ) {open_softirq (RCU_SOFTIRQ , rcu_process_callbacks); -RCU_TRACE (reset_cpu_stall_ticks (&rcu_sched_ctrlblk)); -RCU_TRACE (reset_cpu_stall_ticks (&rcu_bh_ctrlblk)); + RCU_TRACE(reset_cpu_stall_ticks(&rcu_sched_ctrlblk);) + RCU_TRACE(reset_cpu_stall_ticks(&rcu_bh_ctrlblk);)rcu_early_boot_tests (); }
kernel/rcu/tiny_plugin.h +2 -2
@@ -162,8 +162,8 @@ static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)static void check_cpu_stalls (void ) { -RCU_TRACE (check_cpu_stall (&rcu_bh_ctrlblk)); -RCU_TRACE (check_cpu_stall (&rcu_sched_ctrlblk)); + RCU_TRACE(check_cpu_stall(&rcu_bh_ctrlblk);) + RCU_TRACE(check_cpu_stall(&rcu_sched_ctrlblk);) }#endif /* #ifdef CONFIG_RCU_TRACE */
Signature · 1 line
2.5.2
PATCH v3 33/40 srcu: Crude control of expedited grace periods
In reply to Paul E. McKenneySRCU's implementation of expedited grace periods has always assumed that the SRCU instance is idle when the expedited request arrives. This commit improves this a bit by maintaining a count of the number of outstanding expedited requests, thus allowing prior non-expedited grace periods accommodate these requests by shifting to expedited mode. However, any non-expedited wait already in progress will still wait for the full duration.
Improved control of expedited grace periods is planned, but one step at a time.
--- include/linux/srcu.h | 1 + kernel/rcu/srcu.c | 84 ++++++++++++++++++++++++++++------------------------ 2 files changed, 47 insertions(+), 38 deletions(-)
include/linux/srcu.h +1 -0
@@ -42,6 +42,7 @@ struct srcu_array {struct srcu_struct {unsigned long completed;unsigned long srcu_gp_seq; +atomic_t srcu_exp_cnt;struct srcu_array __percpu *per_cpu_ref;spinlock_t queue_lock;/* protect ->srcu_cblist */ struct rcu_segcblist srcu_cblist;
kernel/rcu/srcu.c +46 -38
168 lines not on this page · raw message
Signature · 1 line
2.5.2
PATCH v3 23/40 srcu: Use rcu_segcblist to track SRCU callbacks
In reply to Paul E. McKenneyThis commit switches SRCU from custom-built callback queues to the new rcu_segcblist structure. This change associates grace-period sequence numbers with groups of callbacks, which will be needed for efficient processing of per-CPU callbacks.
--- include/linux/rcu_segcblist.h | 678 ++++++++++++++++++++++++++++++++++++++++++ include/linux/srcu.h | 24 +- kernel/rcu/rcu.h | 6 + kernel/rcu/rcu_segcblist.h | 670 ----------------------------------------- kernel/rcu/srcu.c | 159 ++-------- kernel/rcu/tree.h | 2 +- 6 files changed, 721 insertions(+), 818 deletions(-) create mode 100644 include/linux/rcu_segcblist.h delete mode 100644 kernel/rcu/rcu_segcblist.h
include/linux/rcu_segcblist.h new file +678 -0
@@ -0,0 +1,678 @@ +/* +* RCU segmented callback lists +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, you can access it online at +* http://www.gnu.org/licenses/gpl-2.0.html. +* +* Copyright IBM Corporation, 2017 +* +* Authors: Paul E. McKenney <[email protected]> +*/ + +#ifndef __KERNEL_RCU_SEGCBLIST_H +#define __KERNEL_RCU_SEGCBLIST_H + +/* Simple unsegmented callback lists. */ +struct rcu_cblist { +struct rcu_head *head; +struct rcu_head **tail; +long len; +long len_lazy; +}; + +#define RCU_CBLIST_INITIALIZER (n) { .head = NULL, .tail = &n.head } + +/* Initialize simple callback list. */ +static inline void rcu_cblist_init (struct rcu_cblist *rclp) +{ + rclp->head =NULL ; + rclp->tail = &rclp->head; + rclp->len =0 ; + rclp->len_lazy =0 ; +} + +/* Is simple callback list empty? */ +static inline bool rcu_cblist_empty (struct rcu_cblist *rclp) +{ +return !rclp->head; +} + +/* Return number of callbacks in simple callback list. */ +static inline long rcu_cblist_n_cbs (struct rcu_cblist *rclp) +{ +return rclp->len; +} + +/* Return number of lazy callbacks in simple callback list. */ +static inline long rcu_cblist_n_lazy_cbs (struct rcu_cblist *rclp) +{ +return rclp->len_lazy; +} + +/* +* Debug function to actually count the number of callbacks. +* If the number exceeds the limit specified, return -1. +*/ +static inline long rcu_cblist_count_cbs (struct rcu_cblist *rclp,long lim) +{ +int cnt =0 ; +struct rcu_head **rhpp = &rclp->head; + +for (;;) { +if (!*rhpp) +return cnt; +if (++cnt > lim) +return -1 ; + rhpp = &(*rhpp)->next; + } +} + +/* +* Dequeue the oldest rcu_head structure from the specified callback +* list. This function assumes that the callback is non-lazy, but +* the caller can later invoke rcu_cblist_dequeued_lazy() if it +* finds otherwise (and if it cares about laziness). This allows +* different users to have different ways of determining laziness. +*/ +static inline struct rcu_head *rcu_cblist_dequeue (struct rcu_cblist *rclp) +{ +struct rcu_head *rhp; + + rhp = rclp->head; +if (!rhp) +return NULL ; + rclp->len--; + rclp->head = rhp->next; +if (!rclp->head) + rclp->tail = &rclp->head; +return rhp; +} + +/* +* Account for the fact that a previously dequeued callback turned out +* to be marked as lazy. +*/ +static inline void rcu_cblist_dequeued_lazy (struct rcu_cblist *rclp) +{ + rclp->len_lazy--; +} + +/* +* Interim function to return rcu_cblist head pointer. Longer term, the +* rcu_cblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head *rcu_cblist_head (struct rcu_cblist *rclp) +{ +return rclp->head; +} + +/* +* Interim function to return rcu_cblist head pointer. Longer term, the +* rcu_cblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head **rcu_cblist_tail (struct rcu_cblist *rclp) +{ +WARN_ON_ONCE (rcu_cblist_empty (rclp)); +return rclp->tail; +} + +/* Complicated segmented callback lists. ;-) */ + +/* +* Index values for segments in rcu_segcblist structure. +* +* The segments are as follows: +* +* [head, *tails[RCU_DONE_TAIL]): +* Callbacks whose grace period has elapsed, and thus can be invoked. +* [*tails[RCU_DONE_TAIL], *tails[RCU_WAIT_TAIL]): +* Callbacks waiting for the current GP from the current CPU's viewpoint. +* [*tails[RCU_WAIT_TAIL], *tails[RCU_NEXT_READY_TAIL]): +* Callbacks that arrived before the next GP started, again from +* the current CPU's viewpoint. These can be handled by the next GP. +* [*tails[RCU_NEXT_READY_TAIL], *tails[RCU_NEXT_TAIL]): +* Callbacks that might have arrived after the next GP started. +* There is some uncertainty as to when a given GP starts and +* ends, but a CPU knows the exact times if it is the one starting +* or ending the GP. Other CPUs know that the previous GP ends +* before the next one starts. +* +* Note that RCU_WAIT_TAIL cannot be empty unless RCU_NEXT_READY_TAIL is also +* empty. +* +* The ->gp_seq[] array contains the grace-period number at which the +* corresponding segment of callbacks will be ready to invoke. A given +* element of this array is meaningful only when the corresponding segment +* is non-empty, and it is never valid for RCU_DONE_TAIL (whose callbacks +* are already ready to invoke) or for RCU_NEXT_TAIL (whose callbacks have +* not yet been assigned a grace-period number). +*/ +#define RCU_DONE_TAIL 0/* Also RCU_WAIT head. */ +#define RCU_WAIT_TAIL 1/* Also RCU_NEXT_READY head. */ +#define RCU_NEXT_READY_TAIL 2/* Also RCU_NEXT head. */ +#define RCU_NEXT_TAIL 3 +#define RCU_CBLIST_NSEGS 4 + +struct rcu_segcblist { +struct rcu_head *head; +struct rcu_head **tails[RCU_CBLIST_NSEGS ]; +unsigned long gp_seq[RCU_CBLIST_NSEGS ]; +long len; +long len_lazy; +}; + +#define RCU_SEGCBLIST_INITIALIZER (n) \ +{ \ + .head = NULL, \ + .tails[RCU_DONE_TAIL] = &n.head, \ + .tails[RCU_WAIT_TAIL] = &n.head, \ + .tails[RCU_NEXT_READY_TAIL] = &n.head, \ + .tails[RCU_NEXT_TAIL] = &n.head, \ +} + +/* +* Initialize an rcu_segcblist structure. +*/ +static inline void rcu_segcblist_init (struct rcu_segcblist *rsclp) +{ +int i; + +BUILD_BUG_ON (RCU_NEXT_TAIL +1 !=ARRAY_SIZE (rsclp->gp_seq)); +BUILD_BUG_ON (ARRAY_SIZE (rsclp->tails) !=ARRAY_SIZE (rsclp->gp_seq)); + rsclp->head =NULL ; +for (i =0 ; i <RCU_CBLIST_NSEGS ; i++) + rsclp->tails[i] = &rsclp->head; + rsclp->len =0 ; + rsclp->len_lazy =0 ; +} + +/* +* Is the specified rcu_segcblist structure empty? +* +* But careful! The fact that the ->head field is NULL does not +* necessarily imply that there are no callbacks associated with +* this structure. When callbacks are being invoked, they are +* removed as a group. If callback invocation must be preempted, +* the remaining callbacks will be added back to the list. Either +* way, the counts are updated later. +* +* So it is often the case that rcu_segcblist_n_cbs() should be used +* instead. +*/ +static inline bool rcu_segcblist_empty (struct rcu_segcblist *rsclp) +{ +return !rsclp->head; +} + +/* Return number of callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_cbs (struct rcu_segcblist *rsclp) +{ +return READ_ONCE (rsclp->len); +} + +/* Return number of lazy callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_lazy_cbs (struct rcu_segcblist *rsclp) +{ +return rsclp->len_lazy; +} + +/* Return number of lazy callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_nonlazy_cbs (struct rcu_segcblist *rsclp) +{ +return rsclp->len - rsclp->len_lazy; +} + +/* +* Is the specified rcu_segcblist enabled, for example, not corresponding +* to an offline or callback-offloaded CPU? +*/ +static inline bool rcu_segcblist_is_enabled (struct rcu_segcblist *rsclp) +{ +return !!rsclp->tails[RCU_NEXT_TAIL ]; +} + +/* +* Disable the specified rcu_segcblist structure, so that callbacks can +* no longer be posted to it. This structure must be empty. +*/ +static inline void rcu_segcblist_disable (struct rcu_segcblist *rsclp) +{ +WARN_ON_ONCE (!rcu_segcblist_empty (rsclp)); +WARN_ON_ONCE (rcu_segcblist_n_cbs (rsclp)); +WARN_ON_ONCE (rcu_segcblist_n_lazy_cbs (rsclp)); + rsclp->tails[RCU_NEXT_TAIL ] =NULL ; +} + +/* +* Is the specified segment of the specified rcu_segcblist structure +* empty of callbacks? +*/ +static inline bool rcu_segcblist_segempty (struct rcu_segcblist *rsclp,int seg) +{ +if (seg ==RCU_DONE_TAIL ) +return &rsclp->head == rsclp->tails[RCU_DONE_TAIL ]; +return rsclp->tails[seg -1 ] == rsclp->tails[seg]; +} + +/* +* Are all segments following the specified segment of the specified +* rcu_segcblist structure empty of callbacks? (The specified +* segment might well contain callbacks.) +*/ +static inline bool rcu_segcblist_restempty (struct rcu_segcblist *rsclp,int seg) +{ +return !*rsclp->tails[seg]; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* are ready to be invoked? +*/ +static inline bool rcu_segcblist_ready_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + &rsclp->head != rsclp->tails[RCU_DONE_TAIL ]; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* are still pending, that is, not yet ready to be invoked? +*/ +static inline bool rcu_segcblist_pend_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + !rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL ); +} + +/* +* Dequeue and return the first ready-to-invoke callback. If there +* are no ready-to-invoke callbacks, return NULL. Disables interrupts +* to avoid interference. Does not protect from interference from other +* CPUs or tasks. +*/ +static inline struct rcu_head * +rcu_segcblist_dequeue (struct rcu_segcblist *rsclp) +{ +unsigned long flags; +int i; +struct rcu_head *rhp; + +local_irq_save (flags); +if (!rcu_segcblist_ready_cbs (rsclp)) { +local_irq_restore (flags); +return NULL ; + } + rhp = rsclp->head; +BUG_ON (!rhp); + rsclp->head = rhp->next; +for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) { +if (rsclp->tails[i] != &rhp->next) +break ; + rsclp->tails[i] = &rsclp->head; + } +smp_mb ();/* Dequeue before decrement for rcu_barrier(). */ +WRITE_ONCE (rsclp->len, rsclp->len -1 ); +local_irq_restore (flags); +return rhp; +} + +/* +* Account for the fact that a previously dequeued callback turned out +* to be marked as lazy. +*/ +static inline void rcu_segcblist_dequeued_lazy (struct rcu_segcblist *rsclp) +{ +unsigned long flags; + +local_irq_save (flags); + rsclp->len_lazy--; +local_irq_restore (flags); +} + +/* +* Return a pointer to the first callback in the specified rcu_segcblist +* structure. This is useful for diagnostics. +*/ +static inline struct rcu_head * +rcu_segcblist_first_cb (struct rcu_segcblist *rsclp) +{ +if (rcu_segcblist_is_enabled (rsclp)) +return rsclp->head; +return NULL ; +} + +/* +* Return a pointer to the first pending callback in the specified +* rcu_segcblist structure. This is useful just after posting a given +* callback -- if that callback is the first pending callback, then +* you cannot rely on someone else having already started up the required +* grace period. +*/ +static inline struct rcu_head * +rcu_segcblist_first_pend_cb (struct rcu_segcblist *rsclp) +{ +if (rcu_segcblist_is_enabled (rsclp)) +return *rsclp->tails[RCU_DONE_TAIL ]; +return NULL ; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* have not yet been processed beyond having been posted, that is, +* does it contain callbacks in its last segment? +*/ +static inline bool rcu_segcblist_new_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + !rcu_segcblist_restempty (rsclp,RCU_NEXT_READY_TAIL ); +} + +/* +* Enqueue the specified callback onto the specified rcu_segcblist +* structure, updating accounting as needed. Note that the ->len +* field may be accessed locklessly, hence the WRITE_ONCE(). +* The ->len field is used by rcu_barrier() and friends to determine +* if it must post a callback on this structure, and it is OK +* for rcu_barrier() to sometimes post callbacks needlessly, but +* absolutely not OK for it to ever miss posting a callback. +*/ +static inline void rcu_segcblist_enqueue (struct rcu_segcblist *rsclp, +struct rcu_head *rhp,bool lazy) +{ +WRITE_ONCE (rsclp->len, rsclp->len +1 );/* ->len sampled locklessly. */ +if (lazy) + rsclp->len_lazy++; +smp_mb ();/* Ensure counts are updated before callback is enqueued. */ + rhp->next =NULL ; + *rsclp->tails[RCU_NEXT_TAIL ] = rhp; + rsclp->tails[RCU_NEXT_TAIL ] = &rhp->next; +} + +/* +* Extract only the counts from the specified rcu_segcblist structure, +* and place them in the specified rcu_cblist structure. This function +* supports both callback orphaning and invocation, hence the separation +* of counts and callbacks. (Callbacks ready for invocation must be +* orphaned and adopted separately from pending callbacks, but counts +* apply to all callbacks. Locking must be used to make sure that +* both orphaned-callbacks lists are consistent.) +*/ +static inline void rcu_segcblist_extract_count (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ + rclp->len_lazy += rsclp->len_lazy; + rclp->len += rsclp->len; + rsclp->len_lazy =0 ; +WRITE_ONCE (rsclp->len,0 );/* ->len sampled locklessly. */ +} + +/* +* Extract only those callbacks ready to be invoked from the specified +* rcu_segcblist structure and place them in the specified rcu_cblist +* structure. +*/ +static inline void rcu_segcblist_extract_done_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rcu_segcblist_ready_cbs (rsclp)) +return ;/* Nothing to do. */ + *rclp->tail = rsclp->head; + rsclp->head = *rsclp->tails[RCU_DONE_TAIL ]; + *rsclp->tails[RCU_DONE_TAIL ] =NULL ; + rclp->tail = rsclp->tails[RCU_DONE_TAIL ]; +for (i =RCU_CBLIST_NSEGS -1 ; i >=RCU_DONE_TAIL ; i--) +if (rsclp->tails[i] == rsclp->tails[RCU_DONE_TAIL ]) + rsclp->tails[i] = &rsclp->head; +} + +/* +* Extract only those callbacks still pending (not yet ready to be +* invoked) from the specified rcu_segcblist structure and place them in +* the specified rcu_cblist structure. Note that this loses information +* about any callbacks that might have been partway done waiting for +* their grace period. Too bad! They will have to start over. +*/ +static inline void +rcu_segcblist_extract_pend_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rcu_segcblist_pend_cbs (rsclp)) +return ;/* Nothing to do. */ + *rclp->tail = *rsclp->tails[RCU_DONE_TAIL ]; + rclp->tail = rsclp->tails[RCU_NEXT_TAIL ]; + *rsclp->tails[RCU_DONE_TAIL ] =NULL ; +for (i =RCU_DONE_TAIL +1 ; i <RCU_CBLIST_NSEGS ; i++) + rsclp->tails[i] = rsclp->tails[RCU_DONE_TAIL ]; +} + +/* +* Move the entire contents of the specified rcu_segcblist structure, +* counts, callbacks, and all, to the specified rcu_cblist structure. +* @@@ Why do we need this??? Moving early-boot CBs to NOCB lists? +* @@@ Memory barrier needed? (Not if only used at boot time...) +*/ +static inline void rcu_segcblist_extract_all (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +rcu_segcblist_extract_done_cbs (rsclp, rclp); +rcu_segcblist_extract_pend_cbs (rsclp, rclp); +rcu_segcblist_extract_count (rsclp, rclp); +} + +/* +* Insert counts from the specified rcu_cblist structure in the +* specified rcu_segcblist structure. +*/ +static inline void rcu_segcblist_insert_count (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ + rsclp->len_lazy += rclp->len_lazy; +/* ->len sampled locklessly. */ +WRITE_ONCE (rsclp->len, rsclp->len + rclp->len); + rclp->len_lazy =0 ; + rclp->len =0 ; +} + +/* +* Move callbacks from the specified rcu_cblist to the beginning of the +* done-callbacks segment of the specified rcu_segcblist. +*/ +static inline void rcu_segcblist_insert_done_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rclp->head) +return ;/* No callbacks to move. */ + *rclp->tail = rsclp->head; + rsclp->head = rclp->head; +for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) +if (&rsclp->head == rsclp->tails[i]) + rsclp->tails[i] = rclp->tail; +else +break ; + rclp->head =NULL ; + rclp->tail = &rclp->head; +} + +/* +* Move callbacks from the specified rcu_cblist to the end of the +* new-callbacks segment of the specified rcu_segcblist. +*/ +static inline void rcu_segcblist_insert_pend_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +if (!rclp->head) +return ;/* Nothing to do. */ + *rsclp->tails[RCU_NEXT_TAIL ] = rclp->head; + rsclp->tails[RCU_NEXT_TAIL ] = rclp->tail; + rclp->head =NULL ; + rclp->tail = &rclp->head; +} + +/* +* Advance the callbacks in the specified rcu_segcblist structure based +* on the current value passed in for the grace-period counter. +*/ +static inline void rcu_segcblist_advance (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i, j; + +WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); +WARN_ON_ONCE (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )); + +/* +* Find all callbacks whose ->gp_seq numbers indicate that they +* are ready to invoke, and put them into the RCU_DONE_TAIL segment. +*/ +for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) { +if (ULONG_CMP_LT (seq, rsclp->gp_seq[i])) +break ; + rsclp->tails[RCU_DONE_TAIL ] = rsclp->tails[i]; + } + +/* If no callbacks moved, nothing more need be done. */ +if (i ==RCU_WAIT_TAIL ) +return ; + +/* Clean up tail pointers that might have been misordered above. */ +for (j =RCU_WAIT_TAIL ; j < i; j++) + rsclp->tails[j] = rsclp->tails[RCU_DONE_TAIL ]; + +/* +* Callbacks moved, so clean up the misordered ->tails[] pointers +* that now point into the middle of the list of ready-to-invoke +* callbacks. The overall effect is to copy down the later pointers +* into the gap that was created by the now-ready segments. +*/ +for (j =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++, j++) { +if (rsclp->tails[j] == rsclp->tails[RCU_NEXT_TAIL ]) +break ;/* No more callbacks. */ + rsclp->tails[j] = rsclp->tails[i]; + rsclp->gp_seq[j] = rsclp->gp_seq[i]; + } +} + +/* +* "Accelerate" callbacks based on more-accurate grace-period information. +* The reason for this is that RCU does not synchronize the beginnings and +* ends of grace periods, and that callbacks are posted locally. This in +* turn means that the callbacks must be labelled conservatively early +* on, as getting exact information would degrade both performance and +* scalability. When more accurate grace-period information becomes +* available, previously posted callbacks can be "accelerated", marking +* them to complete at the end of the earlier grace period. +* +* This function operates on an rcu_segcblist structure, and also the +* grace-period sequence number at which new callbacks would become +* ready to invoke. +*/ +static inline bool rcu_segcblist_accelerate (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i; + +WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); +WARN_ON_ONCE (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )); + +/* +* Find the segment preceding the oldest segment of callbacks +* whose ->gp_seq[] completion is at or after that passed in via +* "seq", skipping any empty segments. This oldest segment, along +* with any later segments, can be merged in with any newly arrived +* callbacks in the RCU_NEXT_TAIL segment, and assigned "seq" +* as their ->gp_seq[] grace-period completion sequence number. +*/ +for (i =RCU_NEXT_READY_TAIL ; i >RCU_DONE_TAIL ; i--) +if (rsclp->tails[i] != rsclp->tails[i -1 ] && +ULONG_CMP_LT (rsclp->gp_seq[i], seq)) +break ; + +/* +* If all the segments contain callbacks that correspond to +* earlier grace-period sequence numbers than "seq", leave. +* Assuming that the rcu_segcblist structure has enough +* segments in its arrays, this can only happen if some of +* the non-done segments contain callbacks that really are +* ready to invoke. This situation will get straightened +* out by the next call to rcu_segcblist_advance(). +* +* Also advance to the oldest segment of callbacks whose +* ->gp_seq[] completion is at or after that passed in via "seq", +* skipping any empty segments. +*/ +if (++i >=RCU_NEXT_TAIL ) +return false; + +/* +* Merge all later callbacks, including newly arrived callbacks, +* into the segment located by the for-loop above. Assign "seq" +* as the ->gp_seq[] value in order to correctly handle the case +* where there were no pending callbacks in the rcu_segcblist +* structure other than in the RCU_NEXT_TAIL segment. +*/ +for (; i <RCU_NEXT_TAIL ; i++) { + rsclp->tails[i] = rsclp->tails[RCU_NEXT_TAIL ]; + rsclp->gp_seq[i] = seq; + } +return true; +} + +/* +* Scan the specified rcu_segcblist structure for callbacks that need +* a grace period later than the one specified by "seq". We don't look +* at the RCU_DONE_TAIL or RCU_NEXT_TAIL segments because they don't +* have a grace-period sequence number. +*/ +static inline bool rcu_segcblist_future_gp_needed (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i; + +for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) +if (rsclp->tails[i -1 ] != rsclp->tails[i] && +ULONG_CMP_LT (seq, rsclp->gp_seq[i])) +return true; +return false; +} + +/* +* Interim function to return rcu_segcblist head pointer. Longer term, the +* rcu_segcblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head *rcu_segcblist_head (struct rcu_segcblist *rsclp) +{ +return rsclp->head; +} + +/* +* Interim function to return rcu_segcblist head pointer. Longer term, the +* rcu_segcblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head **rcu_segcblist_tail (struct rcu_segcblist *rsclp) +{ +WARN_ON_ONCE (rcu_segcblist_empty (rsclp)); +return rsclp->tails[RCU_NEXT_TAIL ]; +} + +#endif /* __KERNEL_RCU_SEGCBLIST_H */
include/linux/srcu.h +5 -19
@@ -22,7 +22,7 @@* Lai Jiangshan <[email protected]> * * For detailed explanation of Read-Copy Update mechanism see - -* Documentation/RCU/ *.txt +* Documentation/RCU/ *.txt * */
@@ -32,31 +32,20 @@#include <linux/mutex.h> #include <linux/rcupdate.h> #include <linux/workqueue.h> +#include <linux/rcu_segcblist.h> struct srcu_array {unsigned long lock_count[2 ];unsigned long unlock_count[2 ]; }; -struct rcu_batch { -struct rcu_head *head, **tail; -}; - -#define RCU_BATCH_INIT (name) { NULL, &(name.head) } -struct srcu_struct {unsigned long completed;unsigned long srcu_gp_seq;struct srcu_array __percpu *per_cpu_ref; -spinlock_t queue_lock;/* protect ->batch_queue, ->running */ +spinlock_t queue_lock;/* protect ->srcu_cblist, ->srcu_state */ int srcu_state; -/* callbacks just queued */ -struct rcu_batch batch_queue; -/* callbacks try to do the first check_zero */ -struct rcu_batch batch_check0; -/* callbacks done with the first check_zero and the flip */ -struct rcu_batch batch_check1; -struct rcu_batch batch_done; +struct rcu_segcblist srcu_cblist;struct delayed_work work;#ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map;
@@ -97,10 +86,7 @@ void process_srcu(struct work_struct *work); .per_cpu_ref = &name##_srcu_array, \ .queue_lock = __SPIN_LOCK_UNLOCKED(name.queue_lock), \ .srcu_state = SRCU_STATE_IDLE, \ - .batch_queue = RCU_BATCH_INIT(name.batch_queue), \ - .batch_check0 = RCU_BATCH_INIT(name.batch_check0), \ - .batch_check1 = RCU_BATCH_INIT(name.batch_check1), \ - .batch_done = RCU_BATCH_INIT(name.batch_done), \ + .srcu_cblist = RCU_SEGCBLIST_INITIALIZER(name.srcu_cblist),\ .work =__DELAYED_WORK_INITIALIZER (name.work, process_srcu,0 ),\ __SRCU_DEP_MAP_INIT(name) \ }
kernel/rcu/rcu.h +6 -0
@@ -87,6 +87,12 @@ static inline unsigned long rcu_seq_snap(unsigned long *sp)return s; } +/* Return the current value the update side's sequence number, no ordering. */ +static inline unsigned long rcu_seq_current (unsigned long *sp) +{ +return READ_ONCE (*sp); +} +/* * Given a snapshot from rcu_seq_snap(), determine whether or not a * full update-side operation has occurred.
kernel/rcu/rcu_segcblist.h deleted +0 -670
670 lines not on this page · raw message
kernel/rcu/srcu.c +31 -128
254 lines not on this page · raw message
kernel/rcu/tree.h +1 -1
@@ -30,7 +30,7 @@#include <linux/seqlock.h> #include <linux/swait.h> #include <linux/stop_machine.h> -#include "rcu_segcblist.h" +#include <linux/rcu_segcblist.h> /* * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and
Signature · 1 line
2.5.2
PATCH v3 36/40 srcutorture: Print Tiny SRCU reader statistics
In reply to Paul E. McKenneyThe srcu_torture_stats() function is adapted to the specific srcu_struct layout traditionally used by SRCU. This commit therefore adds support for Tiny SRCU.
--- kernel/rcu/rcutorture.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
kernel/rcu/rcutorture.c +11 -4
@@ -559,11 +559,12 @@ static void srcu_torture_barrier(void)static void srcu_torture_stats (void ) { -#ifdef CONFIG_TREE_SRCU -int cpu; -int idx = srcu_ctlp->completed &0x1 ; +int __maybe_unused cpu; +int idx; -pr_alert ("%s%s per-CPU(idx=%d):" , +#ifdef CONFIG_TREE_SRCU + idx = srcu_ctlp->completed &0x1 ; +pr_alert ("%s%s Tree SRCU per-CPU(idx=%d):" , torture_type,TORTURE_FLAG , idx);for_each_possible_cpu (cpu) {unsigned long l0, l1;
@@ -588,6 +589,12 @@ static void srcu_torture_stats(void) pr_cont(" %d(%ld,%ld)", cpu, c0, c1); }pr_cont ("\n" ); +#elif defined(CONFIG_TINY_SRCU) + idx =READ_ONCE (srcu_ctlp->srcu_idx) &0x1 ; +pr_alert ("%s%s Tiny SRCU per-CPU(idx=%d): (%d,%d)\n" , + torture_type,TORTURE_FLAG , idx, +READ_ONCE (srcu_ctlp->srcu_lock_nesting[!idx]), +READ_ONCE (srcu_ctlp->srcu_lock_nesting[idx]));#endif }
Signature · 1 line
2.5.2
PATCH v3 29/40 srcu: Fix bogus try_check_zero() comment
In reply to Paul E. McKenney--- kernel/rcu/srcu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/rcu/srcu.c +3 -4
@@ -260,10 +260,9 @@ static void srcu_gp_start(struct srcu_struct *sp) }/* -* @@@ Wait until all pre-existing readers complete. Such readers -* will have used the index specified by "idx". -* the caller should ensures the ->completed is not changed while checking -* and idx = (->completed & 1) ^ 1 +* Wait until all readers counted by array index idx complete, but loop +* a maximum of trycount times. The caller must ensure that ->completed +* is not changed while checking. */ static bool try_check_zero (struct srcu_struct *sp,int idx,int trycount) {
Signature · 1 line
2.5.2
PATCH v3 10/40 rcu: Eliminate flavor scan in rcu_momentary_dyntick_idle()
In reply to Paul E. McKenneyThe rcu_momentary_dyntick_idle() function scans the RCU flavors, checking that one of them still needs a quiescent state before doing an expensive atomic operation on the ->dynticks counter. However, this check reduces overhead only after a rare race condition, and increases complexity. This commit therefore removes the scan and the mechanism enabling the scan.
--- .../Design/Data-Structures/Data-Structures.html | 4 +- kernel/rcu/tree.c | 62 +++++----------------- kernel/rcu/tree.h | 3 +- 3 files changed, 15 insertions(+), 54 deletions(-)
Documentation/RCU/Design/Data-Structures/Data-Structures.html +2 -2
@@ -1104,7 +1104,7 @@ Its fields are as follows: 1 int dynticks_nesting; 2 int dynticks_nmi_nesting; 3 atomic_t dynticks; - 4 int rcu_sched_qs_mask; + 4 bool rcu_need_heavy_qs; 5 unsigned long rcu_qs_ctr; </pre>
@@ -1124,7 +1124,7 @@ CPU's transitions to and from dyntick-idle mode, so that this counter has an even value when the CPU is in dyntick-idle mode and an odd value otherwise. -</p><p>The <tt>->rcu_sched_qs_mask</tt> field is used +</p><p>The <tt>->rcu_need_heavy_qs</tt> field is used to record the fact that the RCU core code would really like to see a quiescent state from the corresponding CPU, so much so that it is willing to call for heavy-weight dyntick-counter operations.
kernel/rcu/tree.c +12 -50
115 lines not on this page · raw message
kernel/rcu/tree.h +1 -2
@@ -113,7 +113,7 @@ struct rcu_dynticks {/* Process level is worth LLONG_MAX/2. */ int dynticks_nmi_nesting;/* Track NMI nesting level. */ atomic_t dynticks;/* Even value for idle, else odd. */ -int rcu_sched_qs_mask;/* GP old, need heavy quiescent state. */ +bool rcu_need_heavy_qs;/* GP old, need heavy quiescent state. */ unsigned long rcu_qs_ctr;/* Light universal quiescent state ctr. */ #ifdef CONFIG_NO_HZ_FULL_SYSIDLE long long dynticks_idle_nesting;
@@ -484,7 +484,6 @@ struct rcu_state {struct rcu_node *level[RCU_NUM_LVLS +1 ];/* Hierarchy levels (+1 to */ /* shut bogus gcc warning) */ -u8 flavor_mask;/* bit in flavor mask. */ struct rcu_data __percpu *rda;/* pointer of percu rcu_data. */ call_rcu_func_t call;/* call_rcu() flavor. */ int ncpus;/* # CPUs seen so far. */
Signature · 1 line
2.5.2
PATCH v3 9/40 rcu: Pull rcu_qs_ctr into rcu_dynticks structure
In reply to Paul E. McKenneyThe rcu_qs_ctr variable is yet another isolated per-CPU variable, so this commit pulls it into the pre-existing rcu_dynticks per-CPU structure.
--- .../RCU/Design/Data-Structures/Data-Structures.html | 12 ++++++++++-- kernel/rcu/tree.c | 15 ++++++--------- kernel/rcu/tree.h | 3 ++- kernel/rcu/tree_trace.c | 4 +--- 4 files changed, 19 insertions(+), 15 deletions(-)
Documentation/RCU/Design/Data-Structures/Data-Structures.html +10 -2
@@ -1105,6 +1105,7 @@ Its fields are as follows: 2 int dynticks_nmi_nesting; 3 atomic_t dynticks; 4 int rcu_sched_qs_mask; + 5 unsigned long rcu_qs_ctr; </pre> <p>The <tt>->dynticks_nesting</tt> field counts the
@@ -1123,12 +1124,19 @@ CPU's transitions to and from dyntick-idle mode, so that this counter has an even value when the CPU is in dyntick-idle mode and an odd value otherwise. -</p><p>Finally, the <tt>->rcu_sched_qs_mask</tt> field is used +</p><p>The <tt>->rcu_sched_qs_mask</tt> field is used to record the fact that the RCU core code would really like to -see a quiescent state from the corresponding CPU. +see a quiescent state from the corresponding CPU, so much so that +it is willing to call for heavy-weight dyntick-counter operations. This flag is checked by RCU's context-switch and <tt>cond_resched()</tt> code, which provide a momentary idle sojourn in response. +</p><p>Finally the <tt>->rcu_qs_ctr</tt> field is used to record +quiescent states from <tt>cond_resched()</tt>. +Because <tt>cond_resched()</tt> can execute quite frequently, this +must be quite lightweight, as in a non-atomic increment of this +per-CPU field. + <table> <tr><th> </th></tr> <tr><th align="left">Quick Quiz:</th></tr>
kernel/rcu/tree.c +6 -9
@@ -436,9 +436,6 @@ bool rcu_eqs_special_set(int cpu)return true; } -DEFINE_PER_CPU_SHARED_ALIGNED(unsigned long, rcu_qs_ctr); -EXPORT_PER_CPU_SYMBOL_GPL (rcu_qs_ctr); -/* * Let the RCU core know that this CPU has gone through the scheduler, * which is a quiescent state. This is called when the need for a
@@ -542,7 +539,7 @@ void rcu_all_qs(void)rcu_sched_qs ();preempt_enable (); } -this_cpu_inc (rcu_qs_ctr); +this_cpu_inc (rcu_dynticks.rcu_qs_ctr);barrier ();/* Avoid RCU read-side critical sections leaking up. */ }EXPORT_SYMBOL_GPL (rcu_all_qs);
@@ -1315,7 +1312,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,*/ rnp = rdp->mynode;if (time_after (jiffies, rdp->rsp->gp_start + jtsq) && -READ_ONCE (rdp->rcu_qs_ctr_snap) !=per_cpu (rcu_qs_ctr, rdp->cpu) && +READ_ONCE (rdp->rcu_qs_ctr_snap) !=per_cpu (rcu_dynticks.rcu_qs_ctr, rdp->cpu) &&READ_ONCE (rdp->gpnum) == rnp->gpnum && !rdp->gpwrap) {trace_rcu_fqs (rdp->rsp->name, rdp->gpnum, rdp->cpu,TPS ("rqc" ));return 1 ;
@@ -2024,7 +2021,7 @@ static bool __note_gp_changes(struct rcu_state *rsp, struct rcu_node *rnp,trace_rcu_grace_period (rsp->name, rdp->gpnum,TPS ("cpustart" )); need_gp = !!(rnp->qsmask & rdp->grpmask); rdp->cpu_no_qs.b.norm = need_gp; - rdp->rcu_qs_ctr_snap =__this_cpu_read (rcu_qs_ctr); + rdp->rcu_qs_ctr_snap =__this_cpu_read (rcu_dynticks.rcu_qs_ctr); rdp->core_needs_qs = need_gp;zero_cpu_stall_ticks (rdp);WRITE_ONCE (rdp->gpwrap, false);
@@ -2622,7 +2619,7 @@ rcu_report_qs_rdp(int cpu, struct rcu_state *rsp, struct rcu_data *rdp)* within the current grace period. */ rdp->cpu_no_qs.b.norm = true;/* need qs for new gp. */ - rdp->rcu_qs_ctr_snap =__this_cpu_read (rcu_qs_ctr); + rdp->rcu_qs_ctr_snap =__this_cpu_read (rcu_dynticks.rcu_qs_ctr);raw_spin_unlock_irqrestore_rcu_node (rnp, flags);return ; }
@@ -3620,7 +3617,7 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)/* Is the RCU core waiting for a quiescent state from this CPU? */ if (rcu_scheduler_fully_active && rdp->core_needs_qs && rdp->cpu_no_qs.b.norm && - rdp->rcu_qs_ctr_snap ==__this_cpu_read (rcu_qs_ctr)) { + rdp->rcu_qs_ctr_snap ==__this_cpu_read (rcu_dynticks.rcu_qs_ctr)) { rdp->n_rp_core_needs_qs++; }else if (rdp->core_needs_qs && !rdp->cpu_no_qs.b.norm) { rdp->n_rp_report_qs++;
@@ -3933,7 +3930,7 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp) rdp->gpnum = rnp->completed;/* Make CPU later note any new GP. */ rdp->completed = rnp->completed; rdp->cpu_no_qs.b.norm = true; - rdp->rcu_qs_ctr_snap =per_cpu (rcu_qs_ctr, cpu); + rdp->rcu_qs_ctr_snap =per_cpu (rcu_dynticks.rcu_qs_ctr, cpu); rdp->core_needs_qs = false;trace_rcu_grace_period (rsp->name, rdp->gpnum,TPS ("cpuonl" ));raw_spin_unlock_irqrestore_rcu_node (rnp, flags);
kernel/rcu/tree.h +2 -1
@@ -113,7 +113,8 @@ struct rcu_dynticks {/* Process level is worth LLONG_MAX/2. */ int dynticks_nmi_nesting;/* Track NMI nesting level. */ atomic_t dynticks;/* Even value for idle, else odd. */ -int rcu_sched_qs_mask;/* GP old, need quiescent state. */ +int rcu_sched_qs_mask;/* GP old, need heavy quiescent state. */ +unsigned long rcu_qs_ctr;/* Light universal quiescent state ctr. */ #ifdef CONFIG_NO_HZ_FULL_SYSIDLE long long dynticks_idle_nesting;/* irq/process nesting level from idle. */
kernel/rcu/tree_trace.c +1 -3
@@ -45,8 +45,6 @@#define RCU_TREE_NONCORE #include "tree.h" -DECLARE_PER_CPU_SHARED_ALIGNED(unsigned long, rcu_qs_ctr); -static int r_open (struct inode *inode,struct file *file,const struct seq_operations *op) {
@@ -121,7 +119,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)cpu_is_offline (rdp->cpu) ?'!' :' ' ,ulong2long (rdp->completed),ulong2long (rdp->gpnum), rdp->cpu_no_qs.b.norm, - rdp->rcu_qs_ctr_snap ==per_cpu (rcu_qs_ctr, rdp->cpu), + rdp->rcu_qs_ctr_snap ==per_cpu (rdp->dynticks->rcu_qs_ctr, rdp->cpu), rdp->core_needs_qs); seq_printf(m, " dt=%d/%llx/%d df=%lu", rcu_dynticks_snap(rdp->dynticks),
Signature · 1 line
2.5.2
PATCH v3 4/40 srcu: Check for tardy grace-period activity in cleanup_srcu_struct()
In reply to Paul E. McKenneyUsers of SRCU are obliged to complete all grace-period activity before invoking cleanup_srcu_struct(). This means that all calls to either synchronize_srcu() or synchronize_srcu_expedited() must have returned, and all calls to call_srcu() must have returned, and the last call to call_srcu() must have been followed by a call to srcu_barrier(). Furthermore, the caller must have done something to prevent any further calls to synchronize_srcu(), synchronize_srcu_expedited(), and call_srcu().
Therefore, if there has ever been an invocation of call_srcu() on the srcu_struct in question, the sequence of events must be as follows:
1. Prevent any further calls to call_srcu(). 2. Wait for any pre-existing call_srcu() invocations to return. 3. Invoke srcu_barrier(). 4. It is now safe to invoke cleanup_srcu_struct().
On the other hand, if there has ever been a call to synchronize_srcu() or synchronize_srcu_expedited(), the sequence of events must be as follows:
1. Prevent any further calls to synchronize_srcu() or synchronize_srcu_expedited().
2. Wait for any pre-existing synchronize_srcu() or synchronize_srcu_expedited() invocations to return.
3. It is now safe to invoke cleanup_srcu_struct().
If there have been calls to all both types of functions (call_srcu() and either of synchronize_srcu() and synchronize_srcu_expedited()), then the caller must do the first three steps of the call_srcu() procedure above and the first two steps of the synchronize_s*() procedure above, and only then invoke cleanup_srcu_struct().
Note that cleanup_srcu_struct() does some probabilistic checks for the caller failing to follow these procedures, in which case cleanup_srcu_struct() does WARN_ON() and avoids freeing the per-CPU structures associated with the specified srcu_struct structure.
--- kernel/rcu/srcu.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
kernel/rcu/srcu.c +13 -2
@@ -254,13 +254,24 @@ static bool srcu_readers_active(struct srcu_struct *sp)* cleanup_srcu_struct - deconstruct a sleep-RCU structure * @sp: structure to clean up. * -* Must invoke this after you are finished using a given srcu_struct that -* was initialized via init_srcu_struct(), else you leak memory. +* Must invoke this only after you are finished using a given srcu_struct +* that was initialized via init_srcu_struct(). This code does some +* probabalistic checking, spotting late uses of srcu_read_lock(), +* synchronize_srcu(), synchronize_srcu_expedited(), and call_srcu(). +* If any such late uses are detected, the per-CPU memory associated with +* the srcu_struct is simply leaked and WARN_ON() is invoked. If the +* caller frees the srcu_struct itself, a use-after-free crash will likely +* ensue, but at least there will be a warning printed. */ void cleanup_srcu_struct (struct srcu_struct *sp) {if (WARN_ON (srcu_readers_active (sp)))return ;/* Leakage unless caller handles error. */ +if (WARN_ON (!rcu_all_batches_empty (sp))) +return ;/* Leakage unless caller handles error. */ +flush_delayed_work (&sp->work); +if (WARN_ON (sp->running)) +return ;/* Caller forgot to stop doing call_srcu()? */ free_percpu (sp->per_cpu_ref); sp->per_cpu_ref =NULL ; }
Signature · 1 line
2.5.2
PATCH v3 27/40 srcu: Move rcu_node traversal macros to rcu.h
In reply to Paul E. McKenneyThis commit moves rcu_for_each_node_breadth_first(), rcu_for_each_nonleaf_node_breadth_first(), and rcu_for_each_leaf_node() from kernel/rcu/tree.h to kernel/rcu/rcu.h so that SRCU can access them. This commit is code-movement only.
--- kernel/rcu/rcu.h | 35 +++++++++++++++++++++++++++++++++++ kernel/rcu/tree.h | 35 ----------------------------------- 2 files changed, 35 insertions(+), 35 deletions(-)
kernel/rcu/rcu.h +35 -0
@@ -224,6 +224,41 @@ static inline void rcu_init_levelspread(int *levelspread, const int *levelcnt) } } +/* +* Do a full breadth-first scan of the rcu_node structures for the +* specified rcu_state structure. +*/ +#define rcu_for_each_node_breadth_first (rsp, rnp) \ + for ((rnp) = &(rsp)->node[0]; \ + (rnp) < &(rsp)->node[rcu_num_nodes]; (rnp)++) + +/* +* Do a breadth-first scan of the non-leaf rcu_node structures for the +* specified rcu_state structure. Note that if there is a singleton +* rcu_node tree with but one rcu_node structure, this loop is a no-op. +*/ +#define rcu_for_each_nonleaf_node_breadth_first (rsp, rnp) \ + for ((rnp) = &(rsp)->node[0]; \ + (rnp) < (rsp)->level[rcu_num_lvls - 1]; (rnp)++) + +/* +* Scan the leaves of the rcu_node hierarchy for the specified rcu_state +* structure. Note that if there is a singleton rcu_node tree with but +* one rcu_node structure, this loop -will- visit the rcu_node structure. +* It is still a leaf node, even if it is also the root node. +*/ +#define rcu_for_each_leaf_node (rsp, rnp) \ + for ((rnp) = (rsp)->level[rcu_num_lvls - 1]; \ + (rnp) < &(rsp)->node[rcu_num_nodes]; (rnp)++) + +/* +* Iterate over all possible CPUs in a leaf RCU node. +*/ +#define for_each_leaf_node_possible_cpu (rnp, cpu) \ + for ((cpu) = cpumask_next(rnp->grplo - 1, cpu_possible_mask); \ + cpu <= rnp->grphi; \ + cpu = cpumask_next((cpu), cpu_possible_mask)) +#endif /* #if defined(SRCU) || !defined(TINY_RCU) */ #endif /* __LINUX_RCU_H */
kernel/rcu/tree.h +0 -35
@@ -193,41 +193,6 @@ struct rcu_node {#define leaf_node_cpu_bit (rnp, cpu) (1UL << ((cpu) - (rnp)->grplo))/* -* Do a full breadth-first scan of the rcu_node structures for the -* specified rcu_state structure. -*/ -#define rcu_for_each_node_breadth_first (rsp, rnp) \ - for ((rnp) = &(rsp)->node[0]; \ - (rnp) < &(rsp)->node[rcu_num_nodes]; (rnp)++) - -/* -* Do a breadth-first scan of the non-leaf rcu_node structures for the -* specified rcu_state structure. Note that if there is a singleton -* rcu_node tree with but one rcu_node structure, this loop is a no-op. -*/ -#define rcu_for_each_nonleaf_node_breadth_first (rsp, rnp) \ - for ((rnp) = &(rsp)->node[0]; \ - (rnp) < (rsp)->level[rcu_num_lvls - 1]; (rnp)++) - -/* -* Scan the leaves of the rcu_node hierarchy for the specified rcu_state -* structure. Note that if there is a singleton rcu_node tree with but -* one rcu_node structure, this loop -will- visit the rcu_node structure. -* It is still a leaf node, even if it is also the root node. -*/ -#define rcu_for_each_leaf_node (rsp, rnp) \ - for ((rnp) = (rsp)->level[rcu_num_lvls - 1]; \ - (rnp) < &(rsp)->node[rcu_num_nodes]; (rnp)++) - -/* -* Iterate over all possible CPUs in a leaf RCU node. -*/ -#define for_each_leaf_node_possible_cpu (rnp, cpu) \ - for ((cpu) = cpumask_next(rnp->grplo - 1, cpu_possible_mask); \ - cpu <= rnp->grphi; \ - cpu = cpumask_next((cpu), cpu_possible_mask)) - -/* * Union to allow "aggregate OR" operation on the need for a quiescent * state by the normal and expedited grace periods. */
Signature · 1 line
2.5.2
Re: [PATCH v3 tip/core/rcu 05/40] rcu: Semicolon inside RCU_TRACE() for rcu.h
In reply to Paul E. McKenneyQuoted 4 lines · Paul E. McKenney
The current use of "
RCU_TRACE(statement);" can cause odd bugs, especially where "statement" is a local-variable declaration, as it can leave a misplaced ";" in the source code. This commit therefore converts these to "RCU_TRACE(statement;)", which avoids the misplaced ";".
Perhaps instead the single RCU_TRACE macro should be split into RCU_TRACE_DECLARE and RCU_TRACE, and then RCU_TRACE should use do {} while (0)
powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
In reply to Paul E. McKenneyQuoted 5 lines · Paul E. McKenney
include/linux/srcutree.h +0
-0@@ -24,25 +24,75 @@
...
Quoted 18 lines
include/linux/srcutree.h +11
-6+/* +* Per-SRCU-domain structure, similar in function to rcu_state. +*/ struct srcu_struct { -unsigned long completed; -unsigned long srcu_gp_seq; -atomic_t srcu_exp_cnt; -struct srcu_array __percpu *per_cpu_ref; -spinlock_t queue_lock;/* protect ->srcu_cblist */ -struct rcu_segcblist srcu_cblist; +struct srcu_node node[NUM_RCU_NODES ];/* Combining tree. */ +struct srcu_node *level[RCU_NUM_LVLS +1 ]; +/* First node at each level. */ +struct mutex srcu_cb_mutex;/* Serialize CB preparation. */ +spinlock_t gp_lock;/* protect ->srcu_cblist */ +struct mutex srcu_gp_mutex;/* Serialize GP work. */ +unsigned int srcu_idx;/* Current rdr array element. */ +unsigned long srcu_gp_seq;/* Grace-period seq #. */
include/linux/srcutree.h line 88
Quoted 10 lines
include/linux/srcutree.h +10
-0+unsigned long srcu_gp_seq_needed;/* Latest gp_seq needed. */ +atomic_t srcu_exp_cnt;/* # ongoing expedited GPs. */ +struct srcu_data __percpu *sda;/* Per-CPU srcu_data array. */ +unsigned long srcu_barrier_seq;/* srcu_barrier seq #. */ +struct mutex srcu_barrier_mutex;/* Serialize barrier ops. */ +struct completion srcu_barrier_completion; +/* Awaken barrier rq at end. */ +atomic_t srcu_barrier_cpu_cnt;/* # CPUs not yet posting a */ +/* callback for the barrier */ +/* operation. */
This change seems to have had the non-obvious effect of breaking the powerpc KVM build.
Because struct kvm contains two srcu_structs which are located before the kvm_arch struct, the increase in size of srcu_struct has caused the offset from the start of struct kvm to kvm_arch to be too big for some of our asm.
struct kvm {
spinlock_t mmu_lock;
struct mutex slots_lock;
struct mm_struct *mm; /* userspace tied to this vm */
struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM];
struct srcu_struct srcu;
struct srcu_struct irq_srcu;
...
struct kvm_arch arch;Example error:
arch/powerpc/kvm/book3s_hv_rmhandlers.S:617: Error: operand out of range (0x000000000000b328 is not between 0xffffffffffff8000 and 0x0000000000007fff)
Where line 617 is:
lwz r7,KVM_LPID(r9)
And the KVM_LPID constant comes from asm-offsets.s. The diff of old vs new is:
-->KVM_LPID 17752 offsetof(struct kvm, arch.lpid) #
+->KVM_LPID 45864 offsetof(struct kvm, arch.lpid) #
We can probably just fix it by changing the asm to keep the address of kvm_arch in a register, and then offset from that.
cheers
Re: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
Quoted 65 lines · Michael Ellerman
Quoted 5 lines · Paul E. McKenney
include/linux/srcutree.h +0
-0@@ -24,25 +24,75 @@...
Quoted 18 lines
include/linux/srcutree.h +11
-6+/* +* Per-SRCU-domain structure, similar in function to rcu_state. +*/ struct srcu_struct { -unsigned long completed; -unsigned long srcu_gp_seq; -atomic_t srcu_exp_cnt; -struct srcu_array __percpu *per_cpu_ref; -spinlock_t queue_lock;/* protect ->srcu_cblist */ -struct rcu_segcblist srcu_cblist; +struct srcu_node node[NUM_RCU_NODES ];/* Combining tree. */ +struct srcu_node *level[RCU_NUM_LVLS +1 ]; +/* First node at each level. */ +struct mutex srcu_cb_mutex;/* Serialize CB preparation. */ +spinlock_t gp_lock;/* protect ->srcu_cblist */ +struct mutex srcu_gp_mutex;/* Serialize GP work. */ +unsigned int srcu_idx;/* Current rdr array element. */ +unsigned long srcu_gp_seq;/* Grace-period seq #. */ include/linux/srcutree.h line 88
Quoted 10 lines
include/linux/srcutree.h +10
-0+unsigned long srcu_gp_seq_needed;/* Latest gp_seq needed. */ +atomic_t srcu_exp_cnt;/* # ongoing expedited GPs. */ +struct srcu_data __percpu *sda;/* Per-CPU srcu_data array. */ +unsigned long srcu_barrier_seq;/* srcu_barrier seq #. */ +struct mutex srcu_barrier_mutex;/* Serialize barrier ops. */ +struct completion srcu_barrier_completion; +/* Awaken barrier rq at end. */ +atomic_t srcu_barrier_cpu_cnt;/* # CPUs not yet posting a */ +/* callback for the barrier */ +/* operation. */ This change seems to have had the non-obvious effect of breaking the powerpc KVM build.
Because struct kvm contains two
srcu_structswhich are located before thekvm_archstruct, the increase in size ofsrcu_structhas caused the offset from the start of struct kvm tokvm_archto be too big for some of our asm.struct kvm { spinlock_t mmu_lock; struct mutex slots_lock; struct mm_struct *mm; /* userspace tied to this vm */ struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM]; struct srcu_struct srcu; struct srcu_struct irq_srcu; ... struct kvm_arch arch;Example error:
arch/powerpc/kvm/book3s_hv_rmhandlers.S:617: Error: operand out of range (0x000000000000b328is not between0xffffffffffff8000and0x0000000000007fff)Where line 617 is:
lwz r7,KVM_LPID(r9)And the
KVM_LPIDconstant comes from asm-offsets.s. The diff of old vs new is:
Quoted 6 lines
-->KVM_LPID 17752
offsetof(struct kvm, arch.lpid)#
+->KVM_LPID 45864offsetof(struct kvm, arch.lpid)#We can probably just fix it by changing the asm to keep the address of
kvm_archin a register, and then offset from that.
Ouch!
What do you need from me?
Thanx, Paul
Paolo Bonzini
maintainerRe: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
In reply to Michael EllermanQuoted 65 lines · Michael Ellerman
Quoted 5 lines · Paul E. McKenney
include/linux/srcutree.h +0
-0@@ -24,25 +24,75 @@...
Quoted 18 lines
include/linux/srcutree.h +11
-6+/* +* Per-SRCU-domain structure, similar in function to rcu_state. +*/ struct srcu_struct { -unsigned long completed; -unsigned long srcu_gp_seq; -atomic_t srcu_exp_cnt; -struct srcu_array __percpu *per_cpu_ref; -spinlock_t queue_lock;/* protect ->srcu_cblist */ -struct rcu_segcblist srcu_cblist; +struct srcu_node node[NUM_RCU_NODES ];/* Combining tree. */ +struct srcu_node *level[RCU_NUM_LVLS +1 ]; +/* First node at each level. */ +struct mutex srcu_cb_mutex;/* Serialize CB preparation. */ +spinlock_t gp_lock;/* protect ->srcu_cblist */ +struct mutex srcu_gp_mutex;/* Serialize GP work. */ +unsigned int srcu_idx;/* Current rdr array element. */ +unsigned long srcu_gp_seq;/* Grace-period seq #. */ include/linux/srcutree.h line 88
Quoted 10 lines
include/linux/srcutree.h +10
-0+unsigned long srcu_gp_seq_needed;/* Latest gp_seq needed. */ +atomic_t srcu_exp_cnt;/* # ongoing expedited GPs. */ +struct srcu_data __percpu *sda;/* Per-CPU srcu_data array. */ +unsigned long srcu_barrier_seq;/* srcu_barrier seq #. */ +struct mutex srcu_barrier_mutex;/* Serialize barrier ops. */ +struct completion srcu_barrier_completion; +/* Awaken barrier rq at end. */ +atomic_t srcu_barrier_cpu_cnt;/* # CPUs not yet posting a */ +/* callback for the barrier */ +/* operation. */ This change seems to have had the non-obvious effect of breaking the powerpc KVM build.
Because struct kvm contains two
srcu_structswhich are located before thekvm_archstruct, the increase in size ofsrcu_structhas caused the offset from the start of struct kvm tokvm_archto be too big for some of our asm.struct kvm { spinlock_t mmu_lock; struct mutex slots_lock; struct mm_struct *mm; /* userspace tied to this vm */ struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM]; struct srcu_struct srcu; struct srcu_struct irq_srcu; ... struct kvm_arch arch;Example error:
arch/powerpc/kvm/book3s_hv_rmhandlers.S:617: Error: operand out of range (0x000000000000b328is not between0xffffffffffff8000and0x0000000000007fff)Where line 617 is:
lwz r7,KVM_LPID(r9)And the
KVM_LPIDconstant comes from asm-offsets.s. The diff of old vs new is:
Quoted 6 lines
-->KVM_LPID 17752
offsetof(struct kvm, arch.lpid)#
+->KVM_LPID 45864offsetof(struct kvm, arch.lpid)#We can probably just fix it by changing the asm to keep the address of
kvm_archin a register, and then offset from that.
Michael, if you want to move the two srcu structs at the end of struct kvm, that would be fine by me. Please send a patch yourself so you can test it on PPC. Thanks,
Paolo
Re: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
Quoted 72 lines · Paolo Bonzini
Quoted 69 lines · Michael Ellerman
Quoted 5 lines · Paul E. McKenney
include/linux/srcutree.h +0
-0@@ -24,25 +24,75 @@...
Quoted 18 lines
include/linux/srcutree.h +11
-6+/* +* Per-SRCU-domain structure, similar in function to rcu_state. +*/ struct srcu_struct { -unsigned long completed; -unsigned long srcu_gp_seq; -atomic_t srcu_exp_cnt; -struct srcu_array __percpu *per_cpu_ref; -spinlock_t queue_lock;/* protect ->srcu_cblist */ -struct rcu_segcblist srcu_cblist; +struct srcu_node node[NUM_RCU_NODES ];/* Combining tree. */ +struct srcu_node *level[RCU_NUM_LVLS +1 ]; +/* First node at each level. */ +struct mutex srcu_cb_mutex;/* Serialize CB preparation. */ +spinlock_t gp_lock;/* protect ->srcu_cblist */ +struct mutex srcu_gp_mutex;/* Serialize GP work. */ +unsigned int srcu_idx;/* Current rdr array element. */ +unsigned long srcu_gp_seq;/* Grace-period seq #. */ include/linux/srcutree.h line 88
Quoted 10 lines
include/linux/srcutree.h +10
-0+unsigned long srcu_gp_seq_needed;/* Latest gp_seq needed. */ +atomic_t srcu_exp_cnt;/* # ongoing expedited GPs. */ +struct srcu_data __percpu *sda;/* Per-CPU srcu_data array. */ +unsigned long srcu_barrier_seq;/* srcu_barrier seq #. */ +struct mutex srcu_barrier_mutex;/* Serialize barrier ops. */ +struct completion srcu_barrier_completion; +/* Awaken barrier rq at end. */ +atomic_t srcu_barrier_cpu_cnt;/* # CPUs not yet posting a */ +/* callback for the barrier */ +/* operation. */ This change seems to have had the non-obvious effect of breaking the powerpc KVM build.
Because struct kvm contains two
srcu_structswhich are located before thekvm_archstruct, the increase in size ofsrcu_structhas caused the offset from the start of struct kvm tokvm_archto be too big for some of our asm.struct kvm { spinlock_t mmu_lock; struct mutex slots_lock; struct mm_struct *mm; /* userspace tied to this vm */ struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM]; struct srcu_struct srcu; struct srcu_struct irq_srcu; ... struct kvm_arch arch;Example error:
arch/powerpc/kvm/book3s_hv_rmhandlers.S:617: Error: operand out of range (0x000000000000b328is not between0xffffffffffff8000and0x0000000000007fff)Where line 617 is:
lwz r7,KVM_LPID(r9)And the
KVM_LPIDconstant comes from asm-offsets.s. The diff of old vs new is:-->KVM_LPID 17752
offsetof(struct kvm, arch.lpid)#
+->KVM_LPID 45864offsetof(struct kvm, arch.lpid)#
Quoted 6 lines
Quoted 2 lines
We can probably just fix it by changing the asm to keep the address of
kvm_archin a register, and then offset from that.Michael, if you want to move the two srcu structs at the end of struct kvm, that would be fine by me. Please send a patch yourself so you can test it on PPC. Thanks,
On the off-chance that it is at all helpful, I have added the commit shown below to -rcu. If it helps, I am happy to push this, but am just as happy to drop it in favor of some other fix. If at all possible, I would like to get this into the upcoming merge window.
Thanx, Paul
Michael Ellerman
Tested-byRe: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
Quoted 6 lines · Paul E. McKenney
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Michael Ellerman
"Paul E. McKenney" <[email protected]> writes:
This change seems to have had the non-obvious effect of breaking the powerpc KVM build.
...
Quoted 7 lines
Quoted 4 lines
Michael, if you want to move the two srcu structs at the end of struct kvm, that would be fine by me. Please send a patch yourself so you can test it on PPC. Thanks,
On the off-chance that it is at all helpful, I have added the commit shown below to -rcu.
As shown below :)
Quoted 3 lines
If it helps, I am happy to push this, but am just as happy to drop it in favor of some other fix. If at all possible, I would like to get this into the upcoming merge window.
Thanks, this looks perfect to me, and if you're happy to put it on top of your tree that would limit the breakage to a smaller history window, so that would be ideal.
cheers
Quoted 1 line
From
a19a6617e2817e485ccc2f7cc5a97bd7ff769b87Mon Sep 17 00:00:00 2001
From: "Paul E. McKenney" <[email protected]>
Date: Thu, 20 Apr 2017 17:30:06 -0700
Subject: kvm: Move srcu_struct fields to end of struct kvm
Parallelizing SRCU callback handling increased the size of srcu_struct, which moved the kvm_arch field within the kvm struct out of reach of powerpc's current assembly code, resulting in the following sort of build error:
arch/powerpc/kvm/book3s_hv_rmhandlers.S:617: Error: operand out of range (0x000000000000b328 is not between 0xffffffffffff8000 and 0x0000000000007fff)
This commit moves the srcu_struct fields in the kvm structure to follow the kvm_arch field, which again allows powerpc's assembly code to reach it.
--- include/linux/kvm_host.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/kvm_host.h +2 -2
@@ -375,8 +375,6 @@ struct kvm {struct mutex slots_lock;struct mm_struct *mm;/* userspace tied to this vm */ struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM ]; -struct srcu_struct srcu; -struct srcu_struct irq_srcu;struct kvm_vcpu *vcpus[KVM_MAX_VCPUS ];/*
@@ -429,6 +427,8 @@ struct kvm {struct list_head devices;struct dentry *debugfs_dentry;struct kvm_stat_data **debugfs_stat_data; +struct srcu_struct srcu; +struct srcu_struct irq_srcu; };#define kvm_err (fmt, ...) \
Signature · 1 line
cgit v1.1
Re: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
In reply to Paolo BonziniQuoted 3 lines · Paolo Bonzini
Michael, if you want to move the two srcu structs at the end of struct kvm, that would be fine by me. Please send a patch yourself so you can test it on PPC. Thanks,
Paul beat me to it :)
I've confirmed it fixes the build break and the resulting kernel can boot a KVM guest happily.
cheers
Re: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
In reply to Michael EllermanQuoted 22 lines · Michael Ellerman
Quoted 6 lines · Paul E. McKenney
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Michael Ellerman
"Paul E. McKenney" <[email protected]> writes:
This change seems to have had the non-obvious effect of breaking the powerpc KVM build.
...
Quoted 7 lines
Quoted 4 lines
Michael, if you want to move the two srcu structs at the end of struct kvm, that would be fine by me. Please send a patch yourself so you can test it on PPC. Thanks,
On the off-chance that it is at all helpful, I have added the commit shown below to -rcu.
As shown below :)
Quoted 3 lines
If it helps, I am happy to push this, but am just as happy to drop it in favor of some other fix. If at all possible, I would like to get this into the upcoming merge window.
Quoted 5 lines
Thanks, this looks perfect to me, and if you're happy to put it on top of your tree that would limit the breakage to a smaller history window, so that would be ideal.
Tested-by Michael Ellerman <[email protected]>
Thank you, Michael!
Paolo, does this look good to you? My upstream maintainer will be much more likely to take this with your ack. ;-)
Thanx, Paul
Quoted 52 lines
cheers
Quoted 1 line
From
a19a6617e2817e485ccc2f7cc5a97bd7ff769b87Mon Sep 17 00:00:00 2001From: "Paul E. McKenney" <[email protected]>
Date: Thu, 20 Apr 2017 17:30:06 -0700
Subject: kvm: Movesrcu_structfields to end of struct kvmParallelizing SRCU callback handling increased the size of
srcu_struct, which moved thekvm_archfield within the kvm struct out of reach of powerpc's current assembly code, resulting in the following sort of build error:
arch/powerpc/kvm/book3s_hv_rmhandlers.S:617: Error: operand out of range (0x000000000000b328is not between0xffffffffffff8000and0x0000000000007fff)This commit moves the
srcu_structfields in the kvm structure to follow thekvm_archfield, which again allows powerpc's assembly code to reach it.Reported-by Stephen Rothwell <[email protected]>Reported-by Michael Ellerman <[email protected]>Reported-by kbuild test robot <[email protected]>Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>--- include/linux/kvm_host.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/kvm_host.h +2
-2@@ -375,8 +375,6 @@ struct kvm {struct mutex slots_lock;struct mm_struct *mm;/* userspace tied to this vm */ struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM ]; -struct srcu_struct srcu; -struct srcu_struct irq_srcu;struct kvm_vcpu *vcpus[KVM_MAX_VCPUS ];/* @@ -429,6 +427,8 @@ struct kvm {struct list_head devices;struct dentry *debugfs_dentry;struct kvm_stat_data **debugfs_stat_data; +struct srcu_struct srcu; +struct srcu_struct irq_srcu; };#define kvm_err (fmt, ...) \Signature · 1 line
cgit v1.1
Re: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
Quoted 9 lines · Paul E. McKenney
Quoted 5 lines
Thanks, this looks perfect to me, and if you're happy to put it on top of your tree that would limit the breakage to a smaller history window, so that would be ideal.
Tested-by Michael Ellerman <[email protected]>Thank you, Michael!
Paolo, does this look good to you? My upstream maintainer will be much more likely to take this with your ack. ;-)
Sure,
since I don't expect conflicts between whoever applies this patch and the KVM tree.
Paolo
Paul E. McKenney
AppliedRe: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
Quoted 13 lines · Paolo Bonzini
Quoted 9 lines · Paul E. McKenney
Quoted 5 lines
Thanks, this looks perfect to me, and if you're happy to put it on top of your tree that would limit the breakage to a smaller history window, so that would be ideal.
Tested-by Michael Ellerman <[email protected]>Thank you, Michael!
Paolo, does this look good to you? My upstream maintainer will be much more likely to take this with your ack. ;-)
Quoted 6 lines
Sure,
Acked-by Paolo Bonzini <[email protected]>since I don't expect conflicts between whoever applies this patch and the KVM tree.
Applied, thank you!
Thanx, Paul
Re: powerpc KVM build break in linux-next (was Re: [PATCH tip/core/rcu 40/40] srcu: Parallelize callback handling)
Quoted 12 lines · Paul E. McKenney
Quoted 11 lines · Paolo Bonzini
Quoted 9 lines · Paul E. McKenney
Quoted 5 lines
Thanks, this looks perfect to me, and if you're happy to put it on top of your tree that would limit the breakage to a smaller history window, so that would be ideal.
Tested-by Michael Ellerman <[email protected]>Thank you, Michael!
Paolo, does this look good to you? My upstream maintainer will be much more likely to take this with your ack. ;-)
Quoted 8 lines
Quoted 6 lines
Sure,
Acked-by Paolo Bonzini <[email protected]>since I don't expect conflicts between whoever applies this patch and the KVM tree.
Applied, thank you!
Thanks all.
cheers
Re: [PATCH v3 tip/core/rcu 05/40] rcu: Semicolon inside RCU_TRACE() for rcu.h
In reply to Joe PerchesQuoted 9 lines · Joe Perches
Quoted 4 lines · Paul E. McKenney
The current use of "
RCU_TRACE(statement);" can cause odd bugs, especially where "statement" is a local-variable declaration, as it can leave a misplaced ";" in the source code. This commit therefore converts these to "RCU_TRACE(statement;)", which avoids the misplaced ";".Perhaps instead the single
RCU_TRACEmacro should be split intoRCU_TRACE_DECLAREandRCU_TRACE, and thenRCU_TRACEshould use do {} while (0)
Cute trick, but I am having a hard time getting very excited either way. Thoughts from others?
Thanx, Paul
Steven Rostedt
reviewerRe: [PATCH v3 tip/core/rcu 05/40] rcu: Semicolon inside RCU_TRACE() for rcu.h
In reply to Paul E. McKenneyQuoted 16 lines · On Wed, 19 Apr 2017 09:58:02 -0700 "Paul E. McKenney"…
The current use of "
RCU_TRACE(statement);" can cause odd bugs, especially where "statement" is a local-variable declaration, as it can leave a misplaced ";" in the source code. This commit therefore converts these to "RCU_TRACE(statement;)", which avoids the misplaced ";".Reported-by Josh Triplett <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/rcu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/rcu.h +0
-0
kernel/rcu/rcu.h static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head) · line 112
Quoted 5 lines
kernel/rcu/rcu.h +1
-1@@ -109,12 +109,12 @@ static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head)rcu_lock_acquire (&rcu_callback_map);if (__is_kfree_rcu_offset (offset)) { -RCU_TRACE (trace_rcu_invoke_kfree_callback (rn, head, offset)); + RCU_TRACE(trace_rcu_invoke_kfree_callback(rn, head, offset);)
I have to ask. Why is this a RCU_TRACE() anyway? tracepoints use jump labels, and this is basically a nop here when tracing is off.
-- Steve
Quoted 9 lines
kernel/rcu/rcu.h +1
-1kfree ((void *)head - offset);rcu_lock_release (&rcu_callback_map);return true; }else { -RCU_TRACE (trace_rcu_invoke_callback (rn, head)); + RCU_TRACE(trace_rcu_invoke_callback(rn, head);) head->func(head);rcu_lock_release (&rcu_callback_map);return false;
Re: [PATCH v3 tip/core/rcu 05/40] rcu: Semicolon inside RCU_TRACE() for rcu.h
Quoted 20 lines · Steven Rostedt
Quoted 17 lines · On Wed, 19 Apr 2017 09:58:02 -0700 "Paul E. McKenney"…
The current use of "
RCU_TRACE(statement);" can cause odd bugs, especially where "statement" is a local-variable declaration, as it can leave a misplaced ";" in the source code. This commit therefore converts these to "RCU_TRACE(statement;)", which avoids the misplaced ";".Reported-by Josh Triplett <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>--- kernel/rcu/rcu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/rcu.h +0
-0@@ -109,12 +109,12 @@ static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head)
Quoted 7 lines
kernel/rcu/rcu.h static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head) · line 112
Quoted 4 lines
kernel/rcu/rcu.h +1
-1rcu_lock_acquire (&rcu_callback_map);if (__is_kfree_rcu_offset (offset)) { -RCU_TRACE (trace_rcu_invoke_kfree_callback (rn, head, offset)); + RCU_TRACE(trace_rcu_invoke_kfree_callback(rn, head, offset);)I have to ask. Why is this a
RCU_TRACE()anyway? tracepoints use jump labels, and this is basically a nop here when tracing is off.
Because otherwise the build breaks if CONFIG_RCU_TRACE=n. So it is not the tracepoints themselves, but their helper functions. Worse, the variables declared for them. Even worse, in Tiny RCU, the fields in structures that are used only for tracing.
I freely admit that there might be a better way to structure this, give or take the Tiny RCU structure fields.
Thanx, Paul
Quoted 13 lines
-- Steve
Quoted 9 lines
kernel/rcu/rcu.h +1
-1kfree ((void *)head - offset);rcu_lock_release (&rcu_callback_map);return true; }else { -RCU_TRACE (trace_rcu_invoke_callback (rn, head)); + RCU_TRACE(trace_rcu_invoke_callback(rn, head);) head->func(head);rcu_lock_release (&rcu_callback_map);return false;
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
In reply to Paul E. McKenneyQuoted 8 lines · Paul E. McKenney
Currently, a call to
schedule()acts as a Tasks RCU quiescent state only if a context switch actually takes place. However, just the call toschedule()guarantees that the calling task has moved off of whatever tracing trampoline that it might have been one previously. This commit therefore plumbs schedule()'s "preempt" parameter intorcu_note_context_switch(), which then records the Tasks RCU quiescent state, but only if this call toschedule()was -not- due to a preemption.
Quoted 6 lines
To avoid adding overhead to the common-case context-switch path, this commit hides the
rcu_note_context_switch()check under an existing non-common-case check.Suggested-by Steven Rostedt <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>
Hey Paul,
I'm seeing the following on the latest -next kernel, and suspect it's caused bit this patch:
------------[ cut here ]------------ WARNING: CPU: 0 PID: 6974 at kernel/rcu/tree_plugin.h:329 rcu_preempt_note_context_switch kernel/rcu/tree_plugin.h:329 [inline] WARNING: CPU: 0 PID: 6974 at kernel/rcu/tree_plugin.h:329 rcu_note_context_switch+0x16c/0x2210 kernel/rcu/tree.c:458 Kernel panic - not syncing: panic_on_warn set ... CPU: 0 PID: 6974 Comm: syz-fuzzer Not tainted 4.13.0-next-20170908+ #246 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.1-1ubuntu1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:16 [inline] dump_stack+0x11d/0x1e5 lib/dump_stack.c:52 panic+0x1bc/0x3b7 kernel/panic.c:181 __warn+0x1c4/0x1d9 kernel/panic.c:542 report_bug+0x211/0x2d0 lib/bug.c:183 fixup_bug+0x3f/0x90 arch/x86/kernel/traps.c:178 do_trap_no_signal arch/x86/kernel/traps.c:212 [inline] do_trap+0x260/0x390 arch/x86/kernel/traps.c:261 do_error_trap+0x133/0x380 arch/x86/kernel/traps.c:298 do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:311 invalid_op+0x18/0x20 arch/x86/entry/entry_64.S:905 RIP: 0010:rcu_preempt_note_context_switch kernel/rcu/tree_plugin.h:329 [inline] RIP: 0010:rcu_note_context_switch+0x16c/0x2210 kernel/rcu/tree.c:458 RSP: 0018:ffff88003b2debc8 EFLAGS: 00010002 RAX: 0000000000000001 RBX: 1ffff1000765bd85 RCX: 0000000000000000 RDX: 1ffff100075d7882 RSI: ffffffffb5c7da20 RDI: ffff88003aebc410 RBP: ffff88003b2def30 R08: dffffc0000000000 R09: 0000000000000001 R10: 0000000000000000 R11: 0000000000000000 R12: ffff88003b2def08 R13: 0000000000000000 R14: ffff88003aebc040 R15: ffff88003aebc040 __schedule+0x201/0x2240 kernel/sched/core.c:3292 schedule+0x113/0x460 kernel/sched/core.c:3421 kvm_async_pf_task_wait+0x43f/0x940 arch/x86/kernel/kvm.c:158 do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136 sprintf+0xbe/0xf0 lib/vsprintf.c:2386 proc_self_get_link+0xfb/0x1c0 fs/proc/self.c:23 get_link fs/namei.c:1047 [inline] link_path_walk+0x1041/0x1490 fs/namei.c:2127 path_openat+0x2d0/0x3600 fs/namei.c:3527 do_filp_open+0x263/0x3c0 fs/namei.c:3562 do_sys_open+0x515/0x6f0 fs/open.c:1059 SYSC_openat fs/open.c:1086 [inline] SyS_openat+0x30/0x40 fs/open.c:1080 do_syscall_64+0x26a/0x800 arch/x86/entry/common.c:287 entry_SYSCALL64_slow_path+0x25/0x25 RIP: 0033:0x4889da RSP: 002b:000000c4261eb8f0 EFLAGS: 00000206 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00000000004889da RDX: 0000000000000002 RSI: 000000c42338d2c0 RDI: ffffffffffffff9c RBP: 000000c4261eb980 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000 R13: 00000000ffffffee R14: 00000000000012c0 R15: 0000000000000100
Dumping ftrace buffer:
(ftrace buffer empty)
Kernel Offset: 0x30000000 from 0xffffffff81000000 (relocation range:
0xffffffff80000000-0xffffffffbfffffff)
Rebooting in 86400 seconds..
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
Quoted 14 lines · Sasha Levin
Quoted 12 lines · Paul E. McKenney
Currently, a call to
schedule()acts as a Tasks RCU quiescent state only if a context switch actually takes place. However, just the call toschedule()guarantees that the calling task has moved off of whatever tracing trampoline that it might have been one previously. This commit therefore plumbs schedule()'s "preempt" parameter intorcu_note_context_switch(), which then records the Tasks RCU quiescent state, but only if this call toschedule()was -not- due to a preemption.To avoid adding overhead to the common-case context-switch path, this commit hides the
rcu_note_context_switch()check under an existing non-common-case check.
Quoted 7 lines
Quoted 2 lines
Suggested-by Steven Rostedt <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>Hey Paul,
I'm seeing the following on the latest -next kernel, and suspect it's caused bit this patch:
Hmmm... kernel/rcu/tree_plugin.h:329 thinks that someone slept (as opposed to was preempted) in an RCU read-side critical section.
If this is reproducible, could you please enable lockdep if you are not already doing so?
Thanx, Paul
Quoted 67 lines
------------[ cut here ]------------ WARNING: CPU: 0 PID: 6974 at kernel/rcu/tree_plugin.h:329 rcu_preempt_note_context_switch kernel/rcu/tree_plugin.h:329 [inline] WARNING: CPU: 0 PID: 6974 at kernel/rcu/tree_plugin.h:329 rcu_note_context_switch+0x16c/0x2210 kernel/rcu/tree.c:458 Kernel panic - not syncing: panic_on_warn set ... CPU: 0 PID: 6974 Comm: syz-fuzzer Not tainted 4.13.0-next-20170908+ #246 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.1-1ubuntu1 04/01/2014 Call Trace: __dump_stack lib/dump_stack.c:16 [inline] dump_stack+0x11d/0x1e5 lib/dump_stack.c:52 panic+0x1bc/0x3b7 kernel/panic.c:181 __warn+0x1c4/0x1d9 kernel/panic.c:542 report_bug+0x211/0x2d0 lib/bug.c:183 fixup_bug+0x3f/0x90 arch/x86/kernel/traps.c:178 do_trap_no_signal arch/x86/kernel/traps.c:212 [inline] do_trap+0x260/0x390 arch/x86/kernel/traps.c:261 do_error_trap+0x133/0x380 arch/x86/kernel/traps.c:298 do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:311 invalid_op+0x18/0x20 arch/x86/entry/entry_64.S:905 RIP: 0010:rcu_preempt_note_context_switch kernel/rcu/tree_plugin.h:329 [inline] RIP: 0010:rcu_note_context_switch+0x16c/0x2210 kernel/rcu/tree.c:458 RSP: 0018:ffff88003b2debc8 EFLAGS: 00010002 RAX: 0000000000000001 RBX: 1ffff1000765bd85 RCX: 0000000000000000 RDX: 1ffff100075d7882 RSI: ffffffffb5c7da20 RDI: ffff88003aebc410 RBP: ffff88003b2def30 R08: dffffc0000000000 R09: 0000000000000001 R10: 0000000000000000 R11: 0000000000000000 R12: ffff88003b2def08 R13: 0000000000000000 R14: ffff88003aebc040 R15: ffff88003aebc040 __schedule+0x201/0x2240 kernel/sched/core.c:3292 schedule+0x113/0x460 kernel/sched/core.c:3421 kvm_async_pf_task_wait+0x43f/0x940 arch/x86/kernel/kvm.c:158 do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136 sprintf+0xbe/0xf0 lib/vsprintf.c:2386 proc_self_get_link+0xfb/0x1c0 fs/proc/self.c:23 get_link fs/namei.c:1047 [inline] link_path_walk+0x1041/0x1490 fs/namei.c:2127 path_openat+0x2d0/0x3600 fs/namei.c:3527 do_filp_open+0x263/0x3c0 fs/namei.c:3562 do_sys_open+0x515/0x6f0 fs/open.c:1059 SYSC_openat fs/open.c:1086 [inline] SyS_openat+0x30/0x40 fs/open.c:1080 do_syscall_64+0x26a/0x800 arch/x86/entry/common.c:287 entry_SYSCALL64_slow_path+0x25/0x25 RIP: 0033:0x4889da RSP: 002b:000000c4261eb8f0 EFLAGS: 00000206 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00000000004889da RDX: 0000000000000002 RSI: 000000c42338d2c0 RDI: ffffffffffffff9c RBP: 000000c4261eb980 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000 R13: 00000000ffffffee R14: 00000000000012c0 R15: 0000000000000100Dumping ftrace buffer:
(ftrace buffer empty)
Kernel Offset:0x30000000from0xffffffff81000000(relocation range:
0xffffffff80000000-0xffffffffbfffffff)
Rebooting in 86400 seconds..
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
Quoted 20 lines · Paul E. McKenney
Quoted 19 lines · Sasha Levin
Quoted 8 lines · Paul E. McKenney
Currently, a call to
schedule()acts as a Tasks RCU quiescent state only if a context switch actually takes place. However, just the call toschedule()guarantees that the calling task has moved off of whatever tracing trampoline that it might have been one previously. This commit therefore plumbs schedule()'s "preempt" parameter intorcu_note_context_switch(), which then records the Tasks RCU quiescent state, but only if this call toschedule()was -not- due to a preemption.Quoted 6 lines
To avoid adding overhead to the common-case context-switch path, this commit hides the
rcu_note_context_switch()check under an existing non-common-case check.Suggested-by Steven Rostedt <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>Hey Paul,
Quoted 8 lines
Quoted 2 lines
I'm seeing the following on the latest -next kernel, and suspect it's caused bit this patch:
Hmmm...
kernel/rcu/tree_plugin.h:329thinks that someone slept (as opposed to was preempted) in an RCU read-side critical section.If this is reproducible, could you please enable lockdep if you are not already doing so?
lockdep was on, as far as I can tell.
It happened once in ~3 weeks of fuzzing, so not sure how easily I can reproduce.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
Quoted 27 lines · Alexander (Sasha Levin)
Quoted 26 lines · Paul E. McKenney
Quoted 14 lines · Sasha Levin
Quoted 12 lines · Paul E. McKenney
Currently, a call to
schedule()acts as a Tasks RCU quiescent state only if a context switch actually takes place. However, just the call toschedule()guarantees that the calling task has moved off of whatever tracing trampoline that it might have been one previously. This commit therefore plumbs schedule()'s "preempt" parameter intorcu_note_context_switch(), which then records the Tasks RCU quiescent state, but only if this call toschedule()was -not- due to a preemption.To avoid adding overhead to the common-case context-switch path, this commit hides the
rcu_note_context_switch()check under an existing non-common-case check.Quoted 7 lines
Quoted 2 lines
Suggested-by Steven Rostedt <[email protected]>Signed-off-by Paul E. McKenney <[email protected]>Hey Paul,
I'm seeing the following on the latest -next kernel, and suspect it's caused bit this patch:
Hmmm...
kernel/rcu/tree_plugin.h:329thinks that someone slept (as opposed to was preempted) in an RCU read-side critical section.
Quoted 6 lines
Quoted 2 lines
If this is reproducible, could you please enable lockdep if you are not already doing so?
lockdep was on, as far as I can tell.
It happened once in ~3 weeks of fuzzing, so not sure how easily I can reproduce.
Oh, wait... Looking at the stack trace:
Quoted 12 lines
Call Trace: __dump_stack lib/dump_stack.c:16 [inline] dump_stack+0x11d/0x1e5 lib/dump_stack.c:52 panic+0x1bc/0x3b7 kernel/panic.c:181 __warn+0x1c4/0x1d9 kernel/panic.c:542 report_bug+0x211/0x2d0 lib/bug.c:183 fixup_bug+0x3f/0x90 arch/x86/kernel/traps.c:178 do_trap_no_signal arch/x86/kernel/traps.c:212 [inline] do_trap+0x260/0x390 arch/x86/kernel/traps.c:261 do_error_trap+0x133/0x380 arch/x86/kernel/traps.c:298 do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:311 invalid_op+0x18/0x20 arch/x86/entry/entry_64.S:905
Quoted 8 lines
RIP: 0010:rcu_preempt_note_context_switch kernel/rcu/tree_plugin.h:329 [inline] RIP: 0010:rcu_note_context_switch+0x16c/0x2210 kernel/rcu/tree.c:458 RSP: 0018:ffff88003b2debc8 EFLAGS: 00010002 RAX: 0000000000000001 RBX: 1ffff1000765bd85 RCX: 0000000000000000 RDX: 1ffff100075d7882 RSI: ffffffffb5c7da20 RDI: ffff88003aebc410 RBP: ffff88003b2def30 R08: dffffc0000000000 R09: 0000000000000001 R10: 0000000000000000 R11: 0000000000000000 R12: ffff88003b2def08 R13: 0000000000000000 R14: ffff88003aebc040 R15: ffff88003aebc040
Up to here is all about the kernel complaining.
Quoted 3 lines
__schedule+0x201/0x2240 kernel/sched/core.c:3292 schedule+0x113/0x460 kernel/sched/core.c:3421 kvm_async_pf_task_wait+0x43f/0x940 arch/x86/kernel/kvm.c:158
It is kvm_async_pf_task_wait() that calls schedule(), but it carefully sets state to make that legal. Except...
Quoted 10 lines
do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136
We took a page fault in vsnprintf() while doing link_path_walk(), which looks to be within an RCU read-side critical section.
Maybe the page fault confused lockdep?
Sigh. It is going to be a real pain if all printk()s need to be outside of RCU read-side critical sections due to the possibility of page faults...
Thanx, Paul
Quoted 18 lines
sprintf+0xbe/0xf0 lib/vsprintf.c:2386 proc_self_get_link+0xfb/0x1c0 fs/proc/self.c:23 get_link fs/namei.c:1047 [inline] link_path_walk+0x1041/0x1490 fs/namei.c:2127 path_openat+0x2d0/0x3600 fs/namei.c:3527 do_filp_open+0x263/0x3c0 fs/namei.c:3562 do_sys_open+0x515/0x6f0 fs/open.c:1059 SYSC_openat fs/open.c:1086 [inline] SyS_openat+0x30/0x40 fs/open.c:1080 do_syscall_64+0x26a/0x800 arch/x86/entry/common.c:287 entry_SYSCALL64_slow_path+0x25/0x25 RIP: 0033:0x4889da RSP: 002b:000000c4261eb8f0 EFLAGS: 00000206 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00000000004889da RDX: 0000000000000002 RSI: 000000c42338d2c0 RDI: ffffffffffffff9c RBP: 000000c4261eb980 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000 R13: 00000000ffffffee R14: 00000000000012c0 R15: 0000000000000100
Quoted 5 lines
Dumping ftrace buffer:
(ftrace buffer empty)
Kernel Offset:0x30000000from0xffffffff81000000(relocation range:
0xffffffff80000000-0xffffffffbfffffff)
Rebooting in 86400 seconds..
So kvm_async_pf_task_wait() does a schedule(), and it carefully
Peter Zijlstra
maintainerRe: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
In reply to Levin, Alexander (Sasha Levin)Quoted 4 lines · Alexander (Sasha Levin)
Quoted 2 lines · Paul E. McKenney
Hmmm...
kernel/rcu/tree_plugin.h:329thinks that someone slept (as opposed to was preempted) in an RCU read-side critical section.
Sasha, was this on one of those kernels that did a printk() from scheduler context?
Peter Zijlstra
maintainerRe: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
In reply to Paul E. McKenneyQuoted 11 lines · Paul E. McKenney
Quoted 10 lines
do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136
Quoted 8 lines
We took a page fault in
vsnprintf()while doinglink_path_walk(), which looks to be within an RCU read-side critical section.Maybe the page fault confused lockdep?
Sigh. It is going to be a real pain if all printk()s need to be outside of RCU read-side critical sections due to the possibility of page faults...
printk() _should_ not fault AFAIK. If it does, you've done something dodgy.
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
In reply to Peter ZijlstraQuoted 8 lines · Peter Zijlstra
Quoted 4 lines · Alexander (Sasha Levin)
Quoted 2 lines · Paul E. McKenney
Hmmm...
kernel/rcu/tree_plugin.h:329thinks that someone slept (as opposed to was preempted) in an RCU read-side critical section.Sasha, was this on one of those kernels that did a
printk()from scheduler context?
No, it was an older kernel (about a month old -next), I also didn't do any CPU hotplug in this set of tests.
Signature · 2 lines
Thanks, Sasha
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
In reply to Peter ZijlstraQuoted 15 lines · Peter Zijlstra
Quoted 14 lines · Paul E. McKenney
Quoted 10 lines
do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136We took a page fault in
vsnprintf()while doinglink_path_walk(), which looks to be within an RCU read-side critical section.
Quoted 8 lines
Quoted 5 lines
Maybe the page fault confused lockdep?
Sigh. It is going to be a real pain if all printk()s need to be outside of RCU read-side critical sections due to the possibility of page faults...
printk()_should_ not fault AFAIK. If it does, you've done something dodgy.
And we really do have a page fault there. Perhaps the fault of the caller of printk(), printing some memory that is, as you say, dodgy?
Thanx, Paul
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
In reply to Paul E. McKenneyOn Thu, Sep 28, 2017 at 04:05:14PM +0000, Paul E. McKenney wrote:
[...]
Quoted 18 lines
Quoted 3 lines
__schedule+0x201/0x2240 kernel/sched/core.c:3292 schedule+0x113/0x460 kernel/sched/core.c:3421 kvm_async_pf_task_wait+0x43f/0x940 arch/x86/kernel/kvm.c:158It is
kvm_async_pf_task_wait()that callsschedule(), but it carefully sets state to make that legal. Except...Quoted 10 lines
do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136
Quoted 9 lines
We took a page fault in
vsnprintf()while doinglink_path_walk(), which looks to be within an RCU read-side critical section.Maybe the page fault confused lockdep?
Sigh. It is going to be a real pain if all printk()s need to be outside of RCU read-side critical sections due to the possibility of page faults...
Does this mean whenever we get a page fault in a RCU read-side critical section, we may hit this?
Could we simply avoid to schedule() in kvm_async_pf_task_wait() if the fault process is in a RCU read-side critical section as follow?
arch/x86/kernel/kvm.c +1 -1
@@ -140,7 +140,7 @@ void kvm_async_pf_task_wait(u32 token) n.token = token; n.cpu =smp_processor_id (); - n.halted =is_idle_task (current) ||preempt_count () >1 ; + n.halted =is_idle_task (current) ||preempt_count () >1 ||rcu_preempt_depth ();init_swait_queue_head (&n.wq);hlist_add_head (&n.link, &b->list);raw_spin_unlock (&b->lock);
(Add KVM folks and list Cced)
Regards,
Boqun
Quoted 1 line
Thanx, Paul
[...]
Paolo Bonzini
maintainerRe: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
Quoted 50 lines · Boqun Feng
On Thu, Sep 28, 2017 at 04:05:14PM +0000, Paul E. McKenney wrote:
[...]Quoted 18 lines
Quoted 3 lines
__schedule+0x201/0x2240 kernel/sched/core.c:3292 schedule+0x113/0x460 kernel/sched/core.c:3421 kvm_async_pf_task_wait+0x43f/0x940 arch/x86/kernel/kvm.c:158It is
kvm_async_pf_task_wait()that callsschedule(), but it carefully sets state to make that legal. Except...Quoted 10 lines
do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136Quoted 9 lines
We took a page fault in
vsnprintf()while doinglink_path_walk(), which looks to be within an RCU read-side critical section.Maybe the page fault confused lockdep?
Sigh. It is going to be a real pain if all printk()s need to be outside of RCU read-side critical sections due to the possibility of page faults...
Does this mean whenever we get a page fault in a RCU read-side critical section, we may hit this?
Could we simply avoid to
schedule()inkvm_async_pf_task_wait()if the fault process is in a RCU read-side critical section as follow?arch/x86/kernel/kvm.c +1
-1@@ -140,7 +140,7 @@ void kvm_async_pf_task_wait(u32 token) n.token = token; n.cpu =smp_processor_id (); - n.halted =is_idle_task (current) ||preempt_count () >1 ; + n.halted =is_idle_task (current) ||preempt_count () >1 ||rcu_preempt_depth ();init_swait_queue_head (&n.wq);hlist_add_head (&n.link, &b->list);raw_spin_unlock (&b->lock);
Quoted 1 line
(Add KVM folks and list Cced)
Yes, that would work. Mind to send it as a proper patch?
Thanks,
Paolo
Quoted 6 lines
Regards,
BoqunQuoted 1 line
Thanx, Paul
[...]
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
Quoted 51 lines · Paolo Bonzini
Quoted 50 lines · Boqun Feng
On Thu, Sep 28, 2017 at 04:05:14PM +0000, Paul E. McKenney wrote:
[...]Quoted 18 lines
Quoted 3 lines
__schedule+0x201/0x2240 kernel/sched/core.c:3292 schedule+0x113/0x460 kernel/sched/core.c:3421 kvm_async_pf_task_wait+0x43f/0x940 arch/x86/kernel/kvm.c:158It is
kvm_async_pf_task_wait()that callsschedule(), but it carefully sets state to make that legal. Except...Quoted 10 lines
do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136Quoted 9 lines
We took a page fault in
vsnprintf()while doinglink_path_walk(), which looks to be within an RCU read-side critical section.Maybe the page fault confused lockdep?
Sigh. It is going to be a real pain if all printk()s need to be outside of RCU read-side critical sections due to the possibility of page faults...
Does this mean whenever we get a page fault in a RCU read-side critical section, we may hit this?
Could we simply avoid to
schedule()inkvm_async_pf_task_wait()if the fault process is in a RCU read-side critical section as follow?arch/x86/kernel/kvm.c +1
-1@@ -140,7 +140,7 @@ void kvm_async_pf_task_wait(u32 token) n.token = token; n.cpu =smp_processor_id (); - n.halted =is_idle_task (current) ||preempt_count () >1 ; + n.halted =is_idle_task (current) ||preempt_count () >1 ||rcu_preempt_depth ();init_swait_queue_head (&n.wq);hlist_add_head (&n.link, &b->list);raw_spin_unlock (&b->lock);
Quoted 4 lines
Quoted 1 line
(Add KVM folks and list Cced)
Yes, that would work. Mind to send it as a proper patch?
I'd love to ;-) In a minute.
Regards,
Boqun
Quoted 12 lines
Thanks,
Paolo
Quoted 6 lines
Regards,
BoqunQuoted 1 line
Thanx, Paul
[...]
Peter Zijlstra
maintainerRe: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
In reply to Paolo BonziniQuoted 20 lines · Paolo Bonzini
Quoted 20 lines
Does this mean whenever we get a page fault in a RCU read-side critical section, we may hit this?
Could we simply avoid to
schedule()inkvm_async_pf_task_wait()if the fault process is in a RCU read-side critical section as follow?arch/x86/kernel/kvm.c +1
-1@@ -140,7 +140,7 @@ void kvm_async_pf_task_wait(u32 token) n.token = token; n.cpu =smp_processor_id (); - n.halted =is_idle_task (current) ||preempt_count () >1 ; + n.halted =is_idle_task (current) ||preempt_count () >1 ||rcu_preempt_depth ();init_swait_queue_head (&n.wq);hlist_add_head (&n.link, &b->list);raw_spin_unlock (&b->lock);
Quoted 3 lines
Quoted 1 line
(Add KVM folks and list Cced)
Yes, that would work. Mind to send it as a proper patch?
I'm confused, why would we do an ASYNC PF at all here? Thing is, a printk() shouldn't trigger a major fault _ever_. At worst it triggers something like a vmalloc minor fault. And I'm thinking we should not do the whole ASYNC machinery for minor faults.
Paolo Bonzini
maintainerRe: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
Quoted 21 lines · Peter Zijlstra
Quoted 20 lines · Paolo Bonzini
Quoted 20 lines
Does this mean whenever we get a page fault in a RCU read-side critical section, we may hit this?
Could we simply avoid to
schedule()inkvm_async_pf_task_wait()if the fault process is in a RCU read-side critical section as follow?arch/x86/kernel/kvm.c +1
-1@@ -140,7 +140,7 @@ void kvm_async_pf_task_wait(u32 token) n.token = token; n.cpu =smp_processor_id (); - n.halted =is_idle_task (current) ||preempt_count () >1 ; + n.halted =is_idle_task (current) ||preempt_count () >1 ||rcu_preempt_depth ();init_swait_queue_head (&n.wq);hlist_add_head (&n.link, &b->list);raw_spin_unlock (&b->lock);
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
(Add KVM folks and list Cced)
Yes, that would work. Mind to send it as a proper patch?
I'm confused, why would we do an ASYNC PF at all here? Thing is, a
printk()shouldn't trigger a major fault _ever_. At worst it triggers something like a vmalloc minor fault. And I'm thinking we should not do the whole ASYNC machinery for minor faults.
Async page faults are page faults _on the host_ side, and you cannot control what the host pages out. Of course the hypervisor filters out some cases itself (e.g. IF=0) but in general you could get one at any time.
Paolo
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
Quoted 26 lines · Paolo Bonzini
Quoted 25 lines · Peter Zijlstra
Quoted 23 lines · Paolo Bonzini
Quoted 20 lines
Does this mean whenever we get a page fault in a RCU read-side critical section, we may hit this?
Could we simply avoid to
schedule()inkvm_async_pf_task_wait()if the fault process is in a RCU read-side critical section as follow?arch/x86/kernel/kvm.c +1
-1@@ -140,7 +140,7 @@ void kvm_async_pf_task_wait(u32 token) n.token = token; n.cpu =smp_processor_id (); - n.halted =is_idle_task (current) ||preempt_count () >1 ; + n.halted =is_idle_task (current) ||preempt_count () >1 ||rcu_preempt_depth ();init_swait_queue_head (&n.wq);hlist_add_head (&n.link, &b->list);raw_spin_unlock (&b->lock);Quoted 1 line
(Add KVM folks and list Cced)
Yes, that would work. Mind to send it as a proper patch?
Quoted 8 lines
Quoted 4 lines
I'm confused, why would we do an ASYNC PF at all here? Thing is, a
printk()shouldn't trigger a major fault _ever_. At worst it triggers something like a vmalloc minor fault. And I'm thinking we should not do the whole ASYNC machinery for minor faults.Async page faults are page faults
_onthehost_side, and you cannot control what the host pages out. Of course the hypervisor filters out some cases itself (e.g. IF=0) but in general you could get one at any time.
Just to make sure I am understanding this... You take a page fault on the host, and this causes a schedule() on the guest? Or did I lose the thread here?
Thanx, Paul
Re: [PATCH v3 tip/core/rcu 40/40] rcu: Make non-preemptive schedule be Tasks RCU quiescent state
In reply to Paolo BonziniQuoted 43 lines · Paolo Bonzini
Quoted 42 lines · Boqun Feng
On Thu, Sep 28, 2017 at 04:05:14PM +0000, Paul E. McKenney wrote:
[...]Quoted 18 lines
Quoted 3 lines
__schedule+0x201/0x2240 kernel/sched/core.c:3292 schedule+0x113/0x460 kernel/sched/core.c:3421 kvm_async_pf_task_wait+0x43f/0x940 arch/x86/kernel/kvm.c:158It is
kvm_async_pf_task_wait()that callsschedule(), but it carefully sets state to make that legal. Except...Quoted 10 lines
do_async_page_fault+0x72/0x90 arch/x86/kernel/kvm.c:271 async_page_fault+0x22/0x30 arch/x86/entry/entry_64.S:1069 RIP: 0010:format_decode+0x240/0x830 lib/vsprintf.c:1996 RSP: 0018:ffff88003b2df520 EFLAGS: 00010283 RAX: 000000000000003f RBX: ffffffffb5d1e141 RCX: ffff88003b2df670 RDX: 0000000000000001 RSI: dffffc0000000000 RDI: ffffffffb5d1e140 RBP: ffff88003b2df560 R08: dffffc0000000000 R09: 0000000000000000 R10: ffff88003b2df718 R11: 0000000000000000 R12: ffff88003b2df5d8 R13: 0000000000000064 R14: ffffffffb5d1e140 R15: 0000000000000000 vsnprintf+0x173/0x1700 lib/vsprintf.c:2136Quoted 9 lines
We took a page fault in
vsnprintf()while doinglink_path_walk(), which looks to be within an RCU read-side critical section.Maybe the page fault confused lockdep?
Sigh. It is going to be a real pain if all printk()s need to be outside of RCU read-side critical sections due to the possibility of page faults...
Does this mean whenever we get a page fault in a RCU read-side critical section, we may hit this?
Could we simply avoid to
schedule()inkvm_async_pf_task_wait()if the fault process is in a RCU read-side critical section as follow?arch/x86/kernel/kvm.c +0
-0@@ -140,7 +140,7 @@ void kvm_async_pf_task_wait(u32 token)
Quoted 7 lines
arch/x86/kernel/kvm.c void kvm_async_pf_task_wait(u32 token) · line 146
Quoted 7 lines
arch/x86/kernel/kvm.c +1
-1n.token = token; n.cpu =smp_processor_id (); - n.halted =is_idle_task (current) ||preempt_count () >1 ; + n.halted =is_idle_task (current) ||preempt_count () >1 ||rcu_preempt_depth ();init_swait_queue_head (&n.wq);hlist_add_head (&n.link, &b->list);raw_spin_unlock (&b->lock);
This works for PREEMPT=y kernels, but can silently break RCU read-side critical sections on PREEMPT=n kernels.
Quoted 3 lines
Quoted 1 line
(Add KVM folks and list Cced)
Yes, that would work. Mind to send it as a proper patch?
Just out of curiosity, why is printk() being passed something that can page fault?
Thanx, Paul