rcu: Support for lazy callbacks on !CONFIG_RCU_NOCB_CPU
Subsystems (3)
Frederic Weisbecker
maintainercover rcu: Support for lazy callbacks on !CONFIG_RCU_NOCB_CPU
Hi,
Here is a first attempt at providing support for lazy callbacks on non-offloaded CPUs. I have measured interesting results on my machine when it is mostly idle (just an idle ssh connection kept alive) with a gain of +10% idle time. This needs more serious testing though, especially to make sure that no performance regression is introduced.
Also I have only mildly tested on NOCB (eg: no rcutorture yet), so I might have broken something.
Finally it's also possible that the idle time improvement is due to me introducing a bug :)
The patches 1-5 can be considered independently from the rest.
Frederic Weisbecker (9):
rcu: Assume IRQS disabled from rcu_report_dead()
rcu: Use rcu_segcblist_segempty() instead of open coding it
rcu: Rename jiffies_till_flush to jiffies_lazy_flush
rcu: Introduce lazy queue's own qhimark
rcu: Add rcutree.lazy_enabled boot parameter rcu/nocb: Rename was_alldone to was_pending
rcu: Implement lazyness on the main segcblist level
rcu: Make segcblist flags test strict
rcu: Support lazy callbacks with CONFIG_RCU_NOCB=n
.../admin-guide/kernel-parameters.txt | 5 + include/linux/rcu_segcblist.h | 13 +- kernel/rcu/Kconfig | 2 +- kernel/rcu/rcu.h | 8 +- kernel/rcu/rcu_segcblist.c | 44 ++- kernel/rcu/rcu_segcblist.h | 32 +- kernel/rcu/rcuscale.c | 6 +- kernel/rcu/tree.c | 272 +++++++++++++++-- kernel/rcu/tree.h | 9 +- kernel/rcu/tree_nocb.h | 285 +++++------------- 10 files changed, 425 insertions(+), 251 deletions(-)
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 1/9 rcu: Assume IRQS disabled from rcu_report_dead()
rcu_report_dead() is the last RCU word from the CPU down through the hotplug path. It is called in the idle loop right before the CPU shuts down for good. Because it removes the CPU from the grace period state machine and reports an ultimate quiescent state if necessary, no further use of RCU is allowed. Therefore it is expected that IRQs are disabled upon calling this function and are not to be re-enabled again until the CPU shuts down.
Remove the IRQs disablement from that function and verify instead that it is actually called with IRQs disabled as it is expected at that special point in the idle path.
--- kernel/rcu/tree.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/rcu/tree.c +6 -4
@@ -4476,11 +4476,16 @@ void rcu_cpu_starting(unsigned int cpu)*/ void rcu_report_dead (unsigned int cpu) { -unsigned long flags, seq_flags; +unsigned long flags;unsigned long mask;struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);struct rcu_node *rnp = rdp->mynode;/* Outgoing CPU's rdp & rnp. */ +/* +* IRQS must be disabled from now on and until the CPU dies, or an interrupt +* may introduce a new READ-side while it is actually off the QS masks. +*/ +lockdep_assert_irqs_disabled ();// Do any dangling deferred wakeups. do_nocb_deferred_wakeup (rdp);
@@ -4488,7 +4493,6 @@ void rcu_report_dead(unsigned int cpu)/* Remove outgoing CPU from mask in the leaf rcu_node structure. */ mask = rdp->grpmask; -local_irq_save (seq_flags);arch_spin_lock (&rcu_state.ofl_lock);raw_spin_lock_irqsave_rcu_node (rnp, flags);/* Enforce GP memory-order guarantee. */ rdp->rcu_ofl_gp_seq =READ_ONCE (rcu_state.gp_seq);
@@ -4502,8 +4506,6 @@ void rcu_report_dead(unsigned int cpu)WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext & ~mask);raw_spin_unlock_irqrestore_rcu_node (rnp, flags);arch_spin_unlock (&rcu_state.ofl_lock); -local_irq_restore (seq_flags); - rdp->cpu_started = false; }
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 2/9 rcu: Use rcu_segcblist_segempty() instead of open coding it
In reply to Frederic WeisbeckerThis makes the code more readable.
--- kernel/rcu/rcu_segcblist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/rcu/rcu_segcblist.c +2 -2
@@ -368,7 +368,7 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,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 ]) +if (!rcu_segcblist_segempty (rsclp, i))break ;rcu_segcblist_inc_seglen (rsclp, i);WRITE_ONCE (*rsclp->tails[i], rhp);
@@ -551,7 +551,7 @@ bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long 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 ] && +if (!rcu_segcblist_segempty (rsclp, i) &&ULONG_CMP_LT (rsclp->gp_seq[i], seq))break ;
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 3/9 rcu: Rename jiffies_till_flush to jiffies_lazy_flush
In reply to Frederic WeisbeckerThe variable name jiffies_till_flush is too generic and therefore:
* It may shadow a global variable
* It doesn't tell on what it operates
Make the name more precise, along with the related APIs.
--- kernel/rcu/rcu.h | 8 ++++---- kernel/rcu/rcuscale.c | 6 +++--- kernel/rcu/tree_nocb.h | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-)
kernel/rcu/rcu.h +4 -4
@@ -526,11 +526,11 @@ enum rcutorture_type { };#if defined(CONFIG_RCU_LAZY ) -unsigned long rcu_lazy_get_jiffies_till_flush (void ); -void rcu_lazy_set_jiffies_till_flush (unsigned long j); +unsigned long rcu_get_jiffies_lazy_flush (void ); +void rcu_set_jiffies_lazy_flush (unsigned long j);#else -static inline unsigned long rcu_lazy_get_jiffies_till_flush (void ) {return 0 ; } -static inline void rcu_lazy_set_jiffies_till_flush (unsigned long j) { } +static inline unsigned long rcu_get_jiffies_lazy_flush (void ) {return 0 ; } +static inline void rcu_set_jiffies_lazy_flush (unsigned long j) { }#endif #if defined(CONFIG_TREE_RCU )
kernel/rcu/rcuscale.c +3 -3
@@ -725,9 +725,9 @@ kfree_scale_init(void)if (kfree_by_call_rcu) {/* do a test to check the timeout. */ - orig_jif =rcu_lazy_get_jiffies_till_flush (); + orig_jif =rcu_get_jiffies_lazy_flush (); -rcu_lazy_set_jiffies_till_flush (2 *HZ ); +rcu_set_jiffies_lazy_flush (2 *HZ );rcu_barrier (); jif_start = jiffies;
@@ -736,7 +736,7 @@ kfree_scale_init(void)smp_cond_load_relaxed (&rcu_lazy_test1_cb_called,VAL ==1 ); -rcu_lazy_set_jiffies_till_flush (orig_jif); +rcu_set_jiffies_lazy_flush (orig_jif);if (WARN_ON_ONCE (jiffies_at_lazy_cb - jif_start <2 *HZ )) {pr_alert ("ERROR: call_rcu() CBs are not being lazy as expected!\n" );
kernel/rcu/tree_nocb.h +10 -10
@@ -264,21 +264,21 @@ static bool wake_nocb_gp(struct rcu_data *rdp, bool force)* left unsubmitted to RCU after those many jiffies. */ #define LAZY_FLUSH_JIFFIES (10 * HZ) -static unsigned long jiffies_till_flush =LAZY_FLUSH_JIFFIES ; +static unsigned long jiffies_lazy_flush =LAZY_FLUSH_JIFFIES ;#ifdef CONFIG_RCU_LAZY // To be called only from test code. -void rcu_lazy_set_jiffies_till_flush (unsigned long jif) +void rcu_lazy_set_jiffies_lazy_flush (unsigned long jif) { - jiffies_till_flush = jif; + jiffies_lazy_flush = jif; } -EXPORT_SYMBOL (rcu_lazy_set_jiffies_till_flush); +EXPORT_SYMBOL (rcu_lazy_set_jiffies_lazy_flush); -unsigned long rcu_lazy_get_jiffies_till_flush (void ) +unsigned long rcu_lazy_get_jiffies_lazy_flush (void ) { -return jiffies_till_flush; +return jiffies_lazy_flush; } -EXPORT_SYMBOL (rcu_lazy_get_jiffies_till_flush); +EXPORT_SYMBOL (rcu_lazy_get_jiffies_lazy_flush);#endif /*
@@ -299,7 +299,7 @@ static void wake_nocb_gp_defer(struct rcu_data *rdp, int waketype,*/ if (waketype ==RCU_NOCB_WAKE_LAZY && rdp->nocb_defer_wakeup ==RCU_NOCB_WAKE_NOT ) { -mod_timer (&rdp_gp->nocb_timer, jiffies + jiffies_till_flush); +mod_timer (&rdp_gp->nocb_timer, jiffies + jiffies_lazy_flush);WRITE_ONCE (rdp_gp->nocb_defer_wakeup, waketype); }else if (waketype ==RCU_NOCB_WAKE_BYPASS ) {mod_timer (&rdp_gp->nocb_timer, jiffies +2 );
@@ -482,7 +482,7 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,// flush ->nocb_bypass to ->cblist. if ((ncbs && !bypass_is_lazy && j !=READ_ONCE (rdp->nocb_bypass_first)) || (ncbs && bypass_is_lazy && - (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_till_flush))) || + (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_lazy_flush))) || ncbs >= qhimark) {rcu_nocb_lock (rdp); *was_alldone = !rcu_segcblist_pend_cbs (&rdp->cblist);
@@ -723,7 +723,7 @@ static void nocb_gp_wait(struct rcu_data *my_rdp) lazy_ncbs =READ_ONCE (rdp->lazy_len);if (bypass_ncbs && (lazy_ncbs == bypass_ncbs) && - (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_till_flush) || + (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_lazy_flush) || bypass_ncbs >2 * qhimark)) { flush_bypass = true; } else if (bypass_ncbs && (lazy_ncbs != bypass_ncbs) &&
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 4/9 rcu: Introduce lazy queue's own qhimark
In reply to Frederic WeisbeckerThe lazy and the regular bypass queues share the same thresholds in terms of number of callbacks after which a flush to the main list is
performed: 10 000 callbacks.
However lazy and regular bypass don't have the same purposes and neither should their respective thresholds:
* The bypass queue stands for relieving the main queue in case of a callback storm. It makes sense to allow a high number of callbacks to pile up before flushing to the main queue, especially as the life cycle for this queue is very short (1 jiffy).
* The lazy queue aims to spare wake ups and reduce the number of grace periods. There it doesn't make sense to allow a huge number of callbacks before flushing so as not to introduce memory pressure, especially as the life cycle for this queue is very long (10 seconds)
For those reasons, set the default threshold for the lazy queue to 100.
--- kernel/rcu/tree.c | 2 ++ kernel/rcu/tree_nocb.h | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-)
kernel/rcu/tree.c +2 -0
@@ -379,6 +379,8 @@ static int rcu_is_cpu_rrupt_from_idle(void)static long blimit =DEFAULT_RCU_BLIMIT ;#define DEFAULT_RCU_QHIMARK 10000 // If this many pending, ignore blimit.static long qhimark =DEFAULT_RCU_QHIMARK ; +#define DEFAULT_RCU_QHIMARK_LAZY 100 // If this many pending, flush. +static long qhimark_lazy =DEFAULT_RCU_QHIMARK_LAZY ;#define DEFAULT_RCU_QLOMARK 100 // Once only this many pending, use blimit.static long qlowmark =DEFAULT_RCU_QLOMARK ;#define DEFAULT_RCU_QOVLD_MULT 2
kernel/rcu/tree_nocb.h +4 -5
@@ -480,10 +480,9 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,// If ->nocb_bypass has been used too long or is too full, // flush ->nocb_bypass to ->cblist. -if ((ncbs && !bypass_is_lazy && j !=READ_ONCE (rdp->nocb_bypass_first)) || - (ncbs && bypass_is_lazy && - (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_lazy_flush))) || - ncbs >= qhimark) { +if (ncbs && + ((!bypass_is_lazy && ((j !=READ_ONCE (rdp->nocb_bypass_first)) || ncbs >= qhimark)) || + (bypass_is_lazy && (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_lazy_flush) || ncbs >= qhimark_lazy)))) {rcu_nocb_lock (rdp); *was_alldone = !rcu_segcblist_pend_cbs (&rdp->cblist);
@@ -724,7 +723,7 @@ static void nocb_gp_wait(struct rcu_data *my_rdp)if (bypass_ncbs && (lazy_ncbs == bypass_ncbs) && (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_lazy_flush) || - bypass_ncbs >2 * qhimark)) { + bypass_ncbs >2 * qhimark_lazy)) { flush_bypass = true; } else if (bypass_ncbs && (lazy_ncbs != bypass_ncbs) && (time_after(j, READ_ONCE(rdp->nocb_bypass_first) + 1) ||
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 5/9 rcu: Add rcutree.lazy_enabled boot parameter
In reply to Frederic WeisbeckerAllow to overwrite the arbitrary default number of lazy callbacks threshold that is currently set to 100. This allows for tuning between powersaving, throughtput and memory consumption expectations. As a bonus, setting this value to 0 disables lazy callbacks.
--- Documentation/admin-guide/kernel-parameters.txt | 5 +++++ kernel/rcu/tree.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -4798,6 +4798,11 @@ Set threshold of queued RCU callbacks beyond which batch limiting is disabled. + rcutree.qhimark_lazy = [KNL] + Set threshold of queued lazy RCU callbacks beyond which + batch must be flushed to the main queue. If set to 0, + disable lazy queue. + rcutree.qlowmark= [KNL] Set threshold of queued RCU callbacks below which batch limiting is re-enabled.
kernel/rcu/tree.c +2 -1
@@ -390,6 +390,7 @@ static long qovld_calc = -1; // No pre-initialization lock acquisitions!module_param (blimit, long,0444 );module_param (qhimark, long,0444 ); +module_param (qhimark_lazy, long,0444 );module_param (qlowmark, long,0444 );module_param (qovld, long,0444 );
@@ -2655,7 +2656,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)kasan_record_aux_stack_noalloc (head);local_irq_save (flags); rdp =this_cpu_ptr (&rcu_data); - lazy = lazy_in && !rcu_async_should_hurry (); + lazy = lazy_in && qhimark_lazy && !rcu_async_should_hurry ();/* Add the callback to our list. */ if (unlikely (!rcu_segcblist_is_enabled (&rdp->cblist))) {
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 6/9 rcu/nocb: Rename was_alldone to was_pending
In reply to Frederic WeisbeckerUpon enqueuing on an offloaded rdp, RCU checks if the queue was previsouly only made of done callbacks and relies on that information in order to determine if the rcuog kthread needs to be woken up.
In order to prepare for moving the lazy callbacks from the bypass queue to the main queue, track instead if there are pending callbacks. For now the meaning of "having pending callbacks" is just the reverse of "having only done callbacks". However lazy callbacks will be ignored from the pending queue in a further patch.
--- kernel/rcu/tree.c | 14 +++++++------- kernel/rcu/tree.h | 2 +- kernel/rcu/tree_nocb.h | 28 ++++++++++++++-------------- 3 files changed, 22 insertions(+), 22 deletions(-)
kernel/rcu/tree.c +7 -7
@@ -2633,7 +2633,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)unsigned long flags;bool lazy;struct rcu_data *rdp; -bool was_alldone; +bool was_pending;/* Misaligned rcu_head! */ WARN_ON_ONCE ((unsigned long )head & (sizeof (void *) -1 ));
@@ -2670,7 +2670,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in) }check_cb_ovld (rdp); -if (rcu_nocb_try_bypass (rdp, head, &was_alldone, flags, lazy)) +if (rcu_nocb_try_bypass (rdp, head, &was_pending, flags, lazy))return ;// Enqueued onto ->nocb_bypass, so just leave. // If no-CBs CPU gets here, rcu_nocb_try_bypass() acquired ->nocb_lock. rcu_segcblist_enqueue (&rdp->cblist, head);
@@ -2686,7 +2686,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)/* Go handle any RCU core processing required. */ if (unlikely (rcu_rdp_is_offloaded (rdp))) { -__call_rcu_nocb_wake (rdp, was_alldone, flags);/* unlocks */ +__call_rcu_nocb_wake (rdp, was_pending, flags);/* unlocks */ }else {__call_rcu_core (rdp, head, flags);local_irq_restore (flags);
@@ -3936,8 +3936,8 @@ static void rcu_barrier_entrain(struct rcu_data *rdp) {unsigned long gseq =READ_ONCE (rcu_state.barrier_sequence);unsigned long lseq =READ_ONCE (rdp->barrier_seq_snap); +bool nocb_no_pending = false;bool wake_nocb = false; -bool was_alldone = false;lockdep_assert_held (&rcu_state.barrier_lock);if (rcu_seq_state (lseq) || !rcu_seq_state (gseq) ||rcu_seq_ctr (lseq) !=rcu_seq_ctr (gseq))
@@ -3951,9 +3951,9 @@ static void rcu_barrier_entrain(struct rcu_data *rdp)* queue. This way we don't wait for bypass timer that can reach seconds * if it's fully lazy. */ - was_alldone =rcu_rdp_is_offloaded (rdp) && !rcu_segcblist_pend_cbs (&rdp->cblist); + nocb_no_pending =rcu_rdp_is_offloaded (rdp) && !rcu_segcblist_pend_cbs (&rdp->cblist);WARN_ON_ONCE (!rcu_nocb_flush_bypass (rdp,NULL , jiffies, false)); - wake_nocb = was_alldone &&rcu_segcblist_pend_cbs (&rdp->cblist); + wake_nocb = nocb_no_pending &&rcu_segcblist_pend_cbs (&rdp->cblist);if (rcu_segcblist_entrain (&rdp->cblist, &rdp->barrier_head)) {atomic_inc (&rcu_state.barrier_cpu_count); }else {
@@ -4549,7 +4549,7 @@ void rcutree_migrate_callbacks(int cpu)check_cb_ovld_locked (my_rdp, my_rnp);if (rcu_rdp_is_offloaded (my_rdp)) {raw_spin_unlock_rcu_node (my_rnp);/* irqs remain disabled. */ -__call_rcu_nocb_wake (my_rdp, true, flags); +__call_rcu_nocb_wake (my_rdp, false, flags); }else {rcu_nocb_unlock (my_rdp);/* irqs remain disabled. */ raw_spin_unlock_irqrestore_rcu_node (my_rnp, flags);
kernel/rcu/tree.h +1 -1
@@ -464,7 +464,7 @@ static bool wake_nocb_gp(struct rcu_data *rdp, bool force);static bool rcu_nocb_flush_bypass (struct rcu_data *rdp,struct rcu_head *rhp,unsigned long j,bool lazy);static bool rcu_nocb_try_bypass (struct rcu_data *rdp,struct rcu_head *rhp, -bool *was_alldone,unsigned long flags, +bool *was_pending,unsigned long flags,bool lazy);static void __call_rcu_nocb_wake (struct rcu_data *rdp,bool was_empty,unsigned long flags);
kernel/rcu/tree_nocb.h +14 -14
@@ -413,7 +413,7 @@ static void rcu_nocb_try_flush_bypass(struct rcu_data *rdp, unsigned long j)* there is only one CPU in operation. */ static bool rcu_nocb_try_bypass (struct rcu_data *rdp,struct rcu_head *rhp, -bool *was_alldone,unsigned long flags, +bool *was_pending,unsigned long flags,bool lazy) {unsigned long c;
@@ -427,7 +427,7 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,// Pure softirq/rcuc based processing: no bypassing, no // locking. if (!rcu_rdp_is_offloaded (rdp)) { - *was_alldone = !rcu_segcblist_pend_cbs (&rdp->cblist); + *was_pending =rcu_segcblist_pend_cbs (&rdp->cblist);return false; }
@@ -435,7 +435,7 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,// locking. if (!rcu_segcblist_completely_offloaded (&rdp->cblist)) {rcu_nocb_lock (rdp); - *was_alldone = !rcu_segcblist_pend_cbs (&rdp->cblist); + *was_pending =rcu_segcblist_pend_cbs (&rdp->cblist);return false;/* Not offloaded, no bypassing. */ }
@@ -443,7 +443,7 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,if (rcu_scheduler_active !=RCU_SCHEDULER_RUNNING ) {rcu_nocb_lock (rdp);WARN_ON_ONCE (rcu_cblist_n_cbs (&rdp->nocb_bypass)); - *was_alldone = !rcu_segcblist_pend_cbs (&rdp->cblist); + *was_pending =rcu_segcblist_pend_cbs (&rdp->cblist);return false; }
@@ -468,8 +468,8 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,// Lazy CBs throttle this back and do immediate bypass queuing. if (rdp->nocb_nobypass_count < nocb_nobypass_lim_per_jiffy && !lazy) {rcu_nocb_lock (rdp); - *was_alldone = !rcu_segcblist_pend_cbs (&rdp->cblist); -if (*was_alldone) + *was_pending =rcu_segcblist_pend_cbs (&rdp->cblist); +if (!*was_pending)trace_rcu_nocb_wake (rcu_state.name, rdp->cpu,TPS ("FirstQ" ));
@@ -484,10 +484,10 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp, ((!bypass_is_lazy && ((j != READ_ONCE(rdp->nocb_bypass_first)) || ncbs >= qhimark)) || (bypass_is_lazy && (time_after(j, READ_ONCE(rdp->nocb_bypass_first) + jiffies_lazy_flush) || ncbs >= qhimark_lazy)))) {rcu_nocb_lock (rdp); - *was_alldone = !rcu_segcblist_pend_cbs (&rdp->cblist); + *was_pending =rcu_segcblist_pend_cbs (&rdp->cblist);if (!rcu_nocb_flush_bypass (rdp, rhp, j, lazy)) { -if (*was_alldone) +if (!*was_pending)trace_rcu_nocb_wake (rcu_state.name, rdp->cpu,TPS ("FirstQ" ));WARN_ON_ONCE (rcu_cblist_n_cbs (&rdp->nocb_bypass));
@@ -503,7 +503,7 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,// The flush succeeded and we moved CBs into the regular list. // Don't wait for the wake up timer as it may be too far ahead. // Wake up the GP thread now instead, if the cblist was empty. -__call_rcu_nocb_wake (rdp, *was_alldone, flags); +__call_rcu_nocb_wake (rdp, *was_pending, flags);return true;// Callback already enqueued. }
@@ -539,7 +539,7 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,if (!rcu_segcblist_pend_cbs (&rdp->cblist)) {trace_rcu_nocb_wake (rcu_state.name, rdp->cpu,TPS ("FirstBQwake" )); -__call_rcu_nocb_wake (rdp, true, flags); +__call_rcu_nocb_wake (rdp, false, flags); }else {trace_rcu_nocb_wake (rcu_state.name, rdp->cpu,TPS ("FirstBQnoWake" ));
@@ -555,7 +555,7 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,* * If warranted, also wake up the kthread servicing this CPUs queues. */ -static void __call_rcu_nocb_wake (struct rcu_data *rdp,bool was_alldone, +static void __call_rcu_nocb_wake (struct rcu_data *rdp,bool was_pending,unsigned long flags) __releases(rdp->nocb_lock) {
@@ -578,7 +578,7 @@ static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone, len =rcu_segcblist_n_cbs (&rdp->cblist); bypass_len =rcu_cblist_n_cbs (&rdp->nocb_bypass); lazy_len =READ_ONCE (rdp->lazy_len); -if (was_alldone) { +if (!was_pending) { rdp->qlen_last_fqs_check = len;// Only lazy CBs in bypass list if (lazy_len && bypass_len == lazy_len) {
@@ -1767,12 +1767,12 @@ static bool rcu_nocb_flush_bypass(struct rcu_data *rdp, struct rcu_head *rhp, }static bool rcu_nocb_try_bypass (struct rcu_data *rdp,struct rcu_head *rhp, -bool *was_alldone,unsigned long flags,bool lazy) +bool *was_pending,unsigned long flags,bool lazy) {return false; } -static void __call_rcu_nocb_wake (struct rcu_data *rdp,bool was_empty, +static void __call_rcu_nocb_wake (struct rcu_data *rdp,bool was_pending,unsigned long flags) {WARN_ON_ONCE (1 );/* Should be dead code! */
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 8/9 rcu: Make segcblist flags test strict
In reply to Frederic WeisbeckerWhile testing several flags at once, make sure that all of them verify the test. This will be necessary to check if an rdp is (de-)offloading.
--- kernel/rcu/rcu_segcblist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcu_segcblist.h +1 -1
@@ -70,7 +70,7 @@ static inline void rcu_segcblist_clear_flags(struct rcu_segcblist *rsclp,static inline bool rcu_segcblist_test_flags (struct rcu_segcblist *rsclp,int flags) { -return READ_ONCE (rsclp->flags) & flags; +return (READ_ONCE (rsclp->flags) & flags) == flags; }/*
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 7/9 rcu: Implement lazyness on the main segcblist level
In reply to Frederic WeisbeckerThe lazy queue is currently implemented by the bypass list which only exists on CONFIG_RCU_NOCB=y with offloaded rdp.
Supporting the lazy queue on non offloaded rdp will require a different approach based on the main per-cpu segmented callback list. And ideally most of the lazy infrastructure behind offloaded and non-offloaded should be made generic and consolidated.
Therefore in order to prepare for supporting lazy callbacks on non-offloaded rdp, switch the lazy callbacks infrastructure from the bypass list to the main segmented callback list.
Lazy callbacks are then enqueued like any other callbacks to the RCU_NEXT_TAIL segment and a SEGCBLIST_NEXT_TAIL_LAZY flag tells if that segment is completely lazy or not. A lazy queue gets ignored by acceleration, unless it can piggyback with the acceleration of existing callbacks in RCU_NEXT_READY_TAIL or RCU_WAIT_TAIL. If anything this introduces a tiny optimization as compared to the bypass list.
As for the offloaded implementation specifics, the rcuog kthread is only woken up if the RCU_NEXT_TAIL segment is not lazy.
--- include/linux/rcu_segcblist.h | 13 +-- kernel/rcu/rcu_segcblist.c | 42 ++++++++-- kernel/rcu/rcu_segcblist.h | 21 ++++- kernel/rcu/tree.c | 98 ++++++++++++++++++++-- kernel/rcu/tree.h | 8 +- kernel/rcu/tree_nocb.h | 154 ++++++++++++++-------------------- 6 files changed, 221 insertions(+), 115 deletions(-)
include/linux/rcu_segcblist.h +7 -6
@@ -196,12 +196,13 @@ struct rcu_cblist {* | rcuc kthread, without holding nocb_lock. | * ---------------------------------------------------------------------------- */ -#define SEGCBLIST_ENABLED BIT(0) -#define SEGCBLIST_RCU_CORE BIT(1) -#define SEGCBLIST_LOCKING BIT(2) -#define SEGCBLIST_KTHREAD_CB BIT(3) -#define SEGCBLIST_KTHREAD_GP BIT(4) -#define SEGCBLIST_OFFLOADED BIT(5) +#define SEGCBLIST_ENABLED BIT(0) +#define SEGCBLIST_RCU_CORE BIT(1) +#define SEGCBLIST_LOCKING BIT(2) +#define SEGCBLIST_KTHREAD_CB BIT(3) +#define SEGCBLIST_KTHREAD_GP BIT(4) +#define SEGCBLIST_OFFLOADED BIT(5) +#define SEGCBLIST_NEXT_TAIL_LAZY BIT(6)struct rcu_segcblist {struct rcu_head *head;
kernel/rcu/rcu_segcblist.c +36 -6
73 lines not on this page · raw message
kernel/rcu/rcu_segcblist.h +20 -1
@@ -104,6 +104,24 @@ static inline bool rcu_segcblist_completely_offloaded(struct rcu_segcblist *rsclreturn false; } +static inline bool rcu_segcblist_next_is_lazy (struct rcu_segcblist *rsclp) +{ +if (IS_ENABLED (CONFIG_RCU_LAZY ) && +rcu_segcblist_test_flags (rsclp,SEGCBLIST_NEXT_TAIL_LAZY )) +return true; + +return false; +} + +/* Return number of callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_cbs_lazy (struct rcu_segcblist *rsclp) +{ +if (rcu_segcblist_next_is_lazy (rsclp)) +return rcu_segcblist_get_seglen (rsclp,RCU_NEXT_TAIL ); +else +return 0 ; +} +/* * Are all segments following the specified segment of the specified * rcu_segcblist structure empty of callbacks? (The specified
@@ -132,9 +150,10 @@ void rcu_segcblist_disable(struct rcu_segcblist *rsclp);void rcu_segcblist_offload (struct rcu_segcblist *rsclp,bool offload);bool rcu_segcblist_ready_cbs (struct rcu_segcblist *rsclp);bool rcu_segcblist_pend_cbs (struct rcu_segcblist *rsclp); +bool rcu_segcblist_pend_cbs_nolazy (struct rcu_segcblist *rsclp);struct rcu_head *rcu_segcblist_first_cb (struct rcu_segcblist *rsclp);struct rcu_head *rcu_segcblist_first_pend_cb (struct rcu_segcblist *rsclp); -bool rcu_segcblist_nextgp (struct rcu_segcblist *rsclp,unsigned long *lp); +bool rcu_segcblist_nextgp_nolazy (struct rcu_segcblist *rsclp,unsigned long *lp);void rcu_segcblist_enqueue (struct rcu_segcblist *rsclp,struct rcu_head *rhp); bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
kernel/rcu/tree.c +91 -7
151 lines not on this page · raw message
kernel/rcu/tree.h +3 -5
@@ -281,8 +281,7 @@ struct rcu_data {unsigned long last_sched_clock;/* Jiffies of last rcu_sched_clock_irq(). */ struct rcu_snap_record snap_record;/* Snapshot of core stats at half of */ /* the first RCU stall timeout */ - -long lazy_len;/* Length of buffered lazy callbacks. */ +unsigned long lazy_firstq;int cpu; };
@@ -462,10 +461,9 @@ static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq);static void rcu_init_one_nocb (struct rcu_node *rnp);static bool wake_nocb_gp (struct rcu_data *rdp,bool force);static bool rcu_nocb_flush_bypass (struct rcu_data *rdp,struct rcu_head *rhp, -unsigned long j,bool lazy); +unsigned long j);static bool rcu_nocb_try_bypass (struct rcu_data *rdp,struct rcu_head *rhp, -bool *was_pending,unsigned long flags, -bool lazy); +bool *was_pending,unsigned long flags,bool lazy);static void __call_rcu_nocb_wake (struct rcu_data *rdp,bool was_empty,unsigned long flags);static int rcu_nocb_need_deferred_wakeup (struct rcu_data *rdp,int level);
kernel/rcu/tree_nocb.h +64 -90
378 lines not on this page · raw message
Signature · 1 line
2.40.1
Frederic Weisbecker
maintainerPATCH 9/9 rcu: Support lazy callbacks with CONFIG_RCU_NOCB_CPU=n
In reply to Frederic WeisbeckerSupport the lazy queue with CONFIG_RCU_NOCB_CPU=n or CONFIG_RCU_NOCB=y with non-offloaded rdp. This reuses most of the lazy infrastructure.
The major difference is the addition of a dedicated per-CPU timer which runs as long as the queue is lazy to make sure that lazy callbacks eventually expire. It's worth noting that the timer is not cancelled when the lazy queue is accelerated (reset) for performance reasons. It may therefore run spuriously though the delay is long enough (10 secs) for it to go mostly unnoticed. Nohz_full CPUs shouldn't suffer from that since they rely on the NOCB implementation.
Some interesting numbers have been observed on a mostly idle system. The test runs 100 times "sleep 10" on an 8 CPU machine and computes an average of the idle time spent on all CPUs per C-state before and after this patch. The following displays the improvement:
Before the patch:
POLL: 0.000006 C1: 0.001064 C1E: 0.000777 C3: 0.000457 C6: 2.711224 C7s: 47.484802 Total: 50.198330
After the patch:
POLL: 0.000011 C1: 0.001088 C1E: 0.000874 C3: 0.000545 C6: 3.234707 C7s: 53.101949 Total: 56.339175
Diff:
POLL: +0.000005 (+43.73%) C1: +0.000024 (+2.25%) C1E: +0.000097 (+11.11%) C3: +0.000088 (+16.16%) C6: +0.523482 (+16.18%) C7s: +5.617148 (+10.58%) Total +6.140844 (+10.90%)
It's worth noting that the above may depend on the idle load (here an idle ssh connection is probably the source of some periodic lazy callbacks queued that get batched, hence the improvement). And more important further testing is mandatory to ensure that this doesn't introduce a performance regression on busy loads.
--- kernel/rcu/Kconfig | 2 +- kernel/rcu/rcu_segcblist.h | 9 +++ kernel/rcu/tree.c | 153 +++++++++++++++++++++++++++++++++++-- kernel/rcu/tree.h | 1 + kernel/rcu/tree_nocb.h | 110 +++----------------------- 5 files changed, 167 insertions(+), 108 deletions(-)
kernel/rcu/Kconfig +1 -1
@@ -308,7 +308,7 @@ config TASKS_TRACE_RCU_READ_MB config RCU_LAZY bool "RCU callback lazy invocation functionality" - depends on RCU_NOCB_CPU + depends on TREE_RCU default n help To save power, batch RCU callbacks and flush after delay, memory
kernel/rcu/rcu_segcblist.h +9 -0
@@ -104,6 +104,15 @@ static inline bool rcu_segcblist_completely_offloaded(struct rcu_segcblist *rsclreturn false; } +static inline bool rcu_segcblist_nocb_transitioning (struct rcu_segcblist *rsclp) +{ +if (IS_ENABLED (CONFIG_RCU_NOCB_CPU ) && +rcu_segcblist_test_flags (rsclp,SEGCBLIST_LOCKING |SEGCBLIST_RCU_CORE )) +return true; + +return false; +} +static inline bool rcu_segcblist_next_is_lazy (struct rcu_segcblist *rsclp) { if (IS_ENABLED(CONFIG_RCU_LAZY) &&
kernel/rcu/tree.c +147 -6
219 lines not on this page · raw message
kernel/rcu/tree.h +1 -0
@@ -282,6 +282,7 @@ struct rcu_data {struct rcu_snap_record snap_record;/* Snapshot of core stats at half of */ /* the first RCU stall timeout */ unsigned long lazy_firstq; +struct timer_list lazy_timer;int cpu; };
kernel/rcu/tree_nocb.h +9 -101
140 lines not on this page · raw message
Signature · 1 line
2.40.1
kernel test robot
build botRe: [PATCH 3/9] rcu: Rename jiffies_till_flush to jiffies_lazy_flush
In reply to Frederic Weisbeckerkernel test robot noticed the following build errors:
Hi Frederic,
kernel test robot noticed the following build errors:
[auto build test ERROR on paulmck-rcu/dev]
[also build test ERROR on linus/master v6.4-rc4 next-20230601] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Frederic-Weisbecker/rcu-Assume-IRQS-disabled-from-rcu_report_dead/20230531-182004 base: https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git dev patch link: https://lore.kernel.org/r/20230531101736.12981-4-frederic%40kernel.org patch subject: [PATCH 3/9] rcu: Rename jiffies_till_flush to jiffies_lazy_flush config: mips-allmodconfig (https://download.01.org/0day-ci/archive/20230602/[email protected]/config) compiler: mips-linux-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c07a1bea9df8b80429d4e24052d83de94f5ee160
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Frederic-Weisbecker/rcu-Assume-IRQS-disabled-from-rcu_report_dead/20230531-182004 git checkout c07a1bea9df8b80429d4e24052d83de94f5ee160
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=mips olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=mips SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "rcu_get_jiffies_lazy_flush" [kernel/rcu/rcuscale.ko] undefined! >> ERROR: modpost: "rcu_set_jiffies_lazy_flush" [kernel/rcu/rcuscale.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 3/9] rcu: Rename jiffies_till_flush to jiffies_lazy_flush
In reply to Frederic Weisbeckerkernel test robot noticed the following build warnings:
Hi Frederic,
kernel test robot noticed the following build warnings:
[auto build test WARNING on paulmck-rcu/dev]
[also build test WARNING on linus/master v6.4-rc4 next-20230601] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Frederic-Weisbecker/rcu-Assume-IRQS-disabled-from-rcu_report_dead/20230531-182004 base: https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git dev patch link: https://lore.kernel.org/r/20230531101736.12981-4-frederic%40kernel.org patch subject: [PATCH 3/9] rcu: Rename jiffies_till_flush to jiffies_lazy_flush config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20230602/[email protected]/config) compiler: arceb-elf-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c07a1bea9df8b80429d4e24052d83de94f5ee160
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Frederic-Weisbecker/rcu-Assume-IRQS-disabled-from-rcu_report_dead/20230531-182004 git checkout c07a1bea9df8b80429d4e24052d83de94f5ee160
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arc SHELL=/bin/bash kernel/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from kernel/rcu/tree.c:5018:
>> kernel/rcu/tree_nocb.h:271:6: warning: no previous prototype for 'rcu_lazy_set_jiffies_lazy_flush' [-Wmissing-prototypes]
271 | void rcu_lazy_set_jiffies_lazy_flush(unsigned long jif)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> kernel/rcu/tree_nocb.h:277:15: warning: no previous prototype for 'rcu_lazy_get_jiffies_lazy_flush' [-Wmissing-prototypes] 277 | unsigned long rcu_lazy_get_jiffies_lazy_flush(void)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/rcu_lazy_set_jiffies_lazy_flush +271 kernel/rcu/tree_nocb.h
268
269 #ifdef CONFIG_RCU_LAZY
270 // To be called only from test code.
> 271 void rcu_lazy_set_jiffies_lazy_flush(unsigned long jif)
272 {
273 jiffies_lazy_flush = jif;
274 }
275 EXPORT_SYMBOL(rcu_lazy_set_jiffies_lazy_flush);
276
> 277 unsigned long rcu_lazy_get_jiffies_lazy_flush(void) 278 {
279 return jiffies_lazy_flush;
280 }
281 EXPORT_SYMBOL(rcu_lazy_get_jiffies_lazy_flush);
282 #endif
283
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH 3/9] rcu: Rename jiffies_till_flush to jiffies_lazy_flush
In reply to Frederic Weisbeckerkernel test robot noticed the following build errors:
Hi Frederic,
kernel test robot noticed the following build errors:
[auto build test ERROR on paulmck-rcu/dev]
[also build test ERROR on linus/master v6.4-rc4 next-20230601] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Frederic-Weisbecker/rcu-Assume-IRQS-disabled-from-rcu_report_dead/20230531-182004 base: https://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git dev patch link: https://lore.kernel.org/r/20230531101736.12981-4-frederic%40kernel.org patch subject: [PATCH 3/9] rcu: Rename jiffies_till_flush to jiffies_lazy_flush config: arm-allyesconfig (https://download.01.org/0day-ci/archive/20230602/[email protected]/config) compiler: arm-linux-gnueabi-gcc (GCC) 12.3.0
reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c07a1bea9df8b80429d4e24052d83de94f5ee160
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Frederic-Weisbecker/rcu-Assume-IRQS-disabled-from-rcu_report_dead/20230531-182004 git checkout c07a1bea9df8b80429d4e24052d83de94f5ee160
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arm olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
arm-linux-gnueabi-ld: kernel/rcu/rcuscale.o: in function `kfree_scale_init':
rcuscale.c:(.init.text+0xec): undefined reference to `rcu_get_jiffies_lazy_flush'
>> arm-linux-gnueabi-ld: rcuscale.c:(.init.text+0x104): undefined reference to `rcu_set_jiffies_lazy_flush'
arm-linux-gnueabi-ld: rcuscale.c:(.init.text+0x170): undefined reference to `rcu_set_jiffies_lazy_flush'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH 1/9] rcu: Assume IRQS disabled from rcu_report_dead()
In reply to Frederic WeisbeckerQuoted 40 lines · Frederic Weisbecker
rcu_report_dead()is the last RCU word from the CPU down through the hotplug path. It is called in the idle loop right before the CPU shuts down for good. Because it removes the CPU from the grace period state machine and reports an ultimate quiescent state if necessary, no further use of RCU is allowed. Therefore it is expected that IRQs are disabled upon calling this function and are not to be re-enabled again until the CPU shuts down.Remove the IRQs disablement from that function and verify instead that it is actually called with IRQs disabled as it is expected at that special point in the idle path.
Signed-off-by Frederic Weisbecker <[email protected]>--- kernel/rcu/tree.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)kernel/rcu/tree.c +6
-1@@ -4476,11 +4476,16 @@ void rcu_cpu_starting(unsigned int cpu)*/ void rcu_report_dead (unsigned int cpu) { -unsigned long flags, seq_flags; +unsigned long flags;unsigned long mask;struct rcu_data *rdp =per_cpu_ptr (&rcu_data, cpu);struct rcu_node *rnp = rdp->mynode;/* Outgoing CPU's rdp & rnp. */ +/* +* IRQS must be disabled from now on and until the CPU dies, or an interrupt +* may introduce a new READ-side while it is actually off the QS masks. +*/ +lockdep_assert_irqs_disabled ();// Do any dangling deferred wakeups. do_nocb_deferred_wakeup (rdp);
kernel/rcu/tree.c void rcu_report_dead(unsigned int cpu) · line 4491
Quoted 4 lines
kernel/rcu/tree.c +0
-1@@ -4488,7 +4493,6 @@ void rcu_report_dead(unsigned int cpu)/* Remove outgoing CPU from mask in the leaf rcu_node structure. */ mask = rdp->grpmask; -local_irq_save (seq_flags);
True, IRQs should be disabled here. The idle loop disables irqs before calling cpuhp_report_idle_dead() which calls rcu_report_dead().
I was curious about this path called from cpu_die_early() in ARM, in which case it is an existing bug if it did not already disable interrupts. So your lockdep check is a good thing in that regard.
For this patch:
thanks,
- Joel
Quoted 15 lines
kernel/rcu/tree.c +0
-2arch_spin_lock (&rcu_state.ofl_lock);raw_spin_lock_irqsave_rcu_node (rnp, flags);/* Enforce GP memory-order guarantee. */ rdp->rcu_ofl_gp_seq =READ_ONCE (rcu_state.gp_seq);@@ -4502,8 +4506,6 @@ void rcu_report_dead(unsigned int cpu)WRITE_ONCE (rnp->qsmaskinitnext, rnp->qsmaskinitnext & ~mask);raw_spin_unlock_irqrestore_rcu_node (rnp, flags);arch_spin_unlock (&rcu_state.ofl_lock); -local_irq_restore (seq_flags); - rdp->cpu_started = false; }Signature · 1 line
2.40.1
Re: [PATCH 2/9] rcu: Use rcu_segcblist_segempty() instead of open coding it
In reply to Frederic WeisbeckerQuoted 13 lines · Frederic Weisbecker
This makes the code more readable.
Signed-off-by Frederic Weisbecker <[email protected]>--- kernel/rcu/rcu_segcblist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/rcu_segcblist.c +0
-0
kernel/rcu/rcu_segcblist.c bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp, · line 371
Quoted 5 lines
kernel/rcu/rcu_segcblist.c +1
-1@@ -368,7 +368,7 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,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 ]) +if (!rcu_segcblist_segempty (rsclp, i))
Hopefully the compiler optimizer will be smart enough to remove this from the inlined code ;-):
if (seg == RCU_DONE_TAIL)
return &rsclp->head == rsclp->tails[RCU_DONE_TAIL];
Otherwise it appears to be no functional change for this and the below change, and straightforward so for this patch:
thanks,
- Joel
Quoted 15 lines
kernel/rcu/rcu_segcblist.c +1
-2break ;rcu_segcblist_inc_seglen (rsclp, i);WRITE_ONCE (*rsclp->tails[i], rhp);@@ -551,7 +551,7 @@ bool rcu_segcblist_accelerate(struct rcu_segcblist *rsclp, unsigned long 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 ] && +if (!rcu_segcblist_segempty (rsclp, i) &&ULONG_CMP_LT (rsclp->gp_seq[i], seq))break ; --2.40.1
Re: [PATCH 4/9] rcu: Introduce lazy queue's own qhimark
In reply to Frederic WeisbeckerQuoted 11 lines · Frederic Weisbecker
The lazy and the regular bypass queues share the same thresholds in terms of number of callbacks after which a flush to the main list is
performed: 10 000 callbacks.However lazy and regular bypass don't have the same purposes and neither should their respective thresholds:
* The bypass queue stands for relieving the main queue in case of a callback storm. It makes sense to allow a high number of callbacks to pile up before flushing to the main queue, especially as the life cycle for this queue is very short (1 jiffy).
Sure.
Quoted 6 lines
* The lazy queue aims to spare wake ups and reduce the number of grace periods. There it doesn't make sense to allow a huge number of callbacks before flushing so as not to introduce memory pressure, especially as the life cycle for this queue is very long (10 seconds).
It does make sense as we have a shrinker, and it is better to avoid RCU disturbing the system unwantedly when there's lots of memory lying around.
Quoted 3 lines
For those reasons, set the default threshold for the lazy queue to 100.
I am OK with splitting the qhimark, but this lazy default is too low. In typical workloads on ChromeOS, we see 1000s of callback even when CPU utilization is low. So considering that, we would be flushing all the time.
Eventually I want the mm subsystem to tell us when flushing is needed so we could flush sooner at that time if really needed, but for now we have a shrinker so it should be OK. Is there a reason the shrinker does not work for you?
thanks,
- Joel
Quoted 50 lines
Signed-off-by Frederic Weisbecker <[email protected]>--- kernel/rcu/tree.c | 2 ++ kernel/rcu/tree_nocb.h | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-)kernel/rcu/tree.c +2
-0@@ -379,6 +379,8 @@ static int rcu_is_cpu_rrupt_from_idle(void)static long blimit =DEFAULT_RCU_BLIMIT ;#define DEFAULT_RCU_QHIMARK 10000 // If this many pending, ignore blimit.static long qhimark =DEFAULT_RCU_QHIMARK ; +#define DEFAULT_RCU_QHIMARK_LAZY 100 // If this many pending, flush. +static long qhimark_lazy =DEFAULT_RCU_QHIMARK_LAZY ;#define DEFAULT_RCU_QLOMARK 100 // Once only this many pending, use blimit.static long qlowmark =DEFAULT_RCU_QLOMARK ;#define DEFAULT_RCU_QOVLD_MULT 2kernel/rcu/tree_nocb.h +4
-5@@ -480,10 +480,9 @@ static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,// If ->nocb_bypass has been used too long or is too full, // flush ->nocb_bypass to ->cblist. -if ((ncbs && !bypass_is_lazy && j !=READ_ONCE (rdp->nocb_bypass_first)) || - (ncbs && bypass_is_lazy && - (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_lazy_flush))) || - ncbs >= qhimark) { +if (ncbs && + ((!bypass_is_lazy && ((j !=READ_ONCE (rdp->nocb_bypass_first)) || ncbs >= qhimark)) || + (bypass_is_lazy && (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_lazy_flush) || ncbs >= qhimark_lazy)))) {rcu_nocb_lock (rdp); *was_alldone = !rcu_segcblist_pend_cbs (&rdp->cblist);@@ -724,7 +723,7 @@ static void nocb_gp_wait(struct rcu_data *my_rdp)if (bypass_ncbs && (lazy_ncbs == bypass_ncbs) && (time_after (j,READ_ONCE (rdp->nocb_bypass_first) + jiffies_lazy_flush) || - bypass_ncbs >2 * qhimark)) { + bypass_ncbs >2 * qhimark_lazy)) { flush_bypass = true; } else if (bypass_ncbs && (lazy_ncbs != bypass_ncbs) && (time_after(j, READ_ONCE(rdp->nocb_bypass_first) + 1) ||Signature · 1 line
2.40.1
RE: [PATCH 5/9] rcu: Add rcutree.lazy_enabled boot parameter
In reply to Frederic WeisbeckerQuoted 4 lines
From: Frederic Weisbecker <[email protected]>
Sent: Wednesday, May 31, 2023 6:18 PM
...
Subject: [PATCH 5/9] rcu: Add rcutree.lazy_enabled boot parameter
I didn't find the 'lazy_enabled' variable in the patch series. Did you say rcutree. qhimark_lazy?
-Qiuxu
Quoted 54 lines
Allow to overwrite the arbitrary default number of lazy callbacks threshold that is currently set to 100. This allows for tuning between powersaving, throughtput and memory consumption expectations. As a bonus, setting this value to 0 disables lazy callbacks.
Signed-off-by Frederic Weisbecker <[email protected]>--- Documentation/admin-guide/kernel-parameters.txt | 5 +++++ kernel/rcu/tree.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-)Documentation/admin-guide/kernel-parameters.txt +2
-0@@ -4798,6 +4798,11 @@ Set threshold of queued RCU callbacks beyond which batch limiting is disabled. + rcutree.qhimark_lazy = [KNL] + Set threshold of queued lazy RCU callbacks beyondwhich
Documentation/admin-guide/kernel-parameters.txt +3
-0+ batch must be flushed to the main queue. If set to 0, + disable lazy queue. + rcutree.qlowmark= [KNL] Set threshold of queued RCU callbacks below which batch limiting is re-enabled.kernel/rcu/tree.c index renamed from kernel/rcu/tree.c +0
-0
9b98d87fa22e..e33c0d889216100644kernel/rcu/tree.c +0
-0@@ -390,6 +390,7 @@ static long qovld_calc = -1; // No pre-initialization lock acquisitions!
module_param(blimit, long, 0444);
module_param(qhimark, long, 0444);kernel/rcu/tree.c +2
-1+module_param (qhimark_lazy, long,0444 );module_param (qlowmark, long,0444 );module_param (qovld, long,0444 );@@ -2655,7 +2656,7 @@ __call_rcu_common(struct rcu_head *head, rcu_callback_t func, bool lazy_in)kasan_record_aux_stack_noalloc (head );local_irq_save (flags); rdp =this_cpu_ptr (&rcu_data); - lazy = lazy_in && !rcu_async_should_hurry (); + lazy = lazy_in && qhimark_lazy && !rcu_async_should_hurry ();/* Add the callback to our list. */ if (unlikely(!rcu_segcblist_is_enabled(&rdp->cblist))) {
--
2.40.1
RE: [PATCH 2/9] rcu: Use rcu_segcblist_segempty() instead of open coding it
In reply to Frederic WeisbeckerThis patch LGTM. Thanks!
Quoted 44 lines
From: Frederic Weisbecker <[email protected]>
Sent: Wednesday, May 31, 2023 6:17 PM
To: Paul E . McKenney <[email protected]>
Cc: LKML <[email protected]>; Frederic Weisbecker <[email protected]>; rcu <[email protected]>; Uladzislau Rezki <[email protected]>; Neeraj Upadhyay <[email protected]>; Joel Fernandes <[email protected]>; Giovanni Gherdovich <[email protected]>
Subject: [PATCH 2/9] rcu: Usercu_segcblist_segempty()instead of open coding itThis makes the code more readable.
Signed-off-by Frederic Weisbecker <[email protected]>--- kernel/rcu/rcu_segcblist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/rcu/rcu_segcblist.c index renamed from kernel/rcu/rcu_segcblist.c +0
-0
f71fac422c8f..1693ea22ef1b100644kernel/rcu/rcu_segcblist.c +1
-1@@ -368,7 +368,7 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,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 ]) +if (!rcu_segcblist_segempty (rsclp, i))break ;rcu_segcblist_inc_seglen (rsclp, i);kernel/rcu/rcu_segcblist.c +1
-2WRITE_ONCE (*rsclp->tails[i], rhp);@@ -551,7 +551,7 @@ bool rcu_segcblist_accelerate(struct rcu_segcblist*rsclp, unsigned long 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 ] && +if (!rcu_segcblist_segempty (rsclp, i) &&ULONG_CMP_LT (rsclp->gp_seq[i], seq))break ; --2.40.1
Frederic Weisbecker
maintainerRe: [PATCH 2/9] rcu: Use rcu_segcblist_segempty() instead of open coding it
In reply to Joel FernandesQuoted 9 lines · Joel Fernandes
Quoted 8 lines · Frederic Weisbecker
This makes the code more readable.
Signed-off-by Frederic Weisbecker <[email protected]>--- kernel/rcu/rcu_segcblist.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 15 lines
kernel/rcu/rcu_segcblist.c bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp, · line 371
Quoted 10 lines
kernel/rcu/rcu_segcblist.c +1
-1@@ -368,7 +368,7 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,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 ]) +if (!rcu_segcblist_segempty (rsclp, i))Hopefully the compiler optimizer will be smart enough to remove this from the inlined code ;-):
if (seg ==RCU_DONE_TAIL)
return&rsclp->head== rsclp->tails[RCU_DONE_TAIL];
I'm counting on that indeed :-)
Quoted 4 lines
Otherwise it appears to be no functional change for this and the below change, and straightforward so for this patch:
Reviewed-by Joel Fernandes (Google) <[email protected]>
Thanks.
Frederic Weisbecker
maintainerQuoted 7 lines · Frederic Weisbecker
Hi,
Here is a first attempt at providing support for lazy callbacks on non-offloaded CPUs. I have measured interesting results on my machine when it is mostly idle (just an idle ssh connection kept alive) with a gain of +10% idle time. This needs more serious testing though, especially to make sure that no performance regression is introduced.
So after refining my measurements, it actually doesn't seem to bring much.
Here's what I measured (it's an average after 100 runs):
* 0.01% more idle time during a "sleep 10"
* introduce 3% performance regression during an "scp" on the tools directory of the kernel source.
* Brings less than 1% performance improvement with a "make" on tools/perf
It only brings unconditional improvement when rcu boost is enabled (callbacks offloaded to rcuc) but still below 1%.
The reason for the performance penalty is unclear, I initially thought it was due to the batch execution delaying other softirqs vectors but it doesn't look that way after all.
So for now I'm only going to re-iterate the cleanups in the beginning of the patchset and I'll wait for a good reason before ever proceeding with the rest.
Thanks.
Frederic Weisbecker
maintainerRe: [PATCH 5/9] rcu: Add rcutree.lazy_enabled boot parameter
In reply to Zhuo, QiuxuQuoted 7 lines · Qiuxu
Quoted 4 lines
From: Frederic Weisbecker <[email protected]>
Sent: Wednesday, May 31, 2023 6:18 PM
...
Subject: [PATCH 5/9] rcu: Add rcutree.lazy_enabled boot parameterI didn't find the '
lazy_enabled' variable in the patch series. Did you say rcutree.qhimark_lazy?
Indeed :-)
Thanks.
Frederic Weisbecker
maintainerRe: [PATCH 4/9] rcu: Introduce lazy queue's own qhimark
In reply to Joel FernandesQuoted 29 lines · Joel Fernandes
Quoted 11 lines · Frederic Weisbecker
The lazy and the regular bypass queues share the same thresholds in terms of number of callbacks after which a flush to the main list is
performed: 10 000 callbacks.However lazy and regular bypass don't have the same purposes and neither should their respective thresholds:
* The bypass queue stands for relieving the main queue in case of a callback storm. It makes sense to allow a high number of callbacks to pile up before flushing to the main queue, especially as the life cycle for this queue is very short (1 jiffy).
Sure.
Quoted 6 lines
* The lazy queue aims to spare wake ups and reduce the number of grace periods. There it doesn't make sense to allow a huge number of callbacks before flushing so as not to introduce memory pressure, especially as the life cycle for this queue is very long (10 seconds).
It does make sense as we have a shrinker, and it is better to avoid RCU disturbing the system unwantedly when there's lots of memory lying around.
Quoted 3 lines
For those reasons, set the default threshold for the lazy queue to 100.
Quoted 8 lines
I am OK with splitting the qhimark, but this lazy default is too low. In typical workloads on ChromeOS, we see 1000s of callback even when CPU utilization is low. So considering that, we would be flushing all the time.
Eventually I want the mm subsystem to tell us when flushing is needed so we could flush sooner at that time if really needed, but for now we have a shrinker so it should be OK. Is there a reason the shrinker does not work for you?
So you mean dynamically adapting the lazy qhimark on top of shrinker calls, right? That would make sense indeed.
Thanks.