1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Read-Copy Update mechanism for mutual exclusion (tree-based version) 4 * Internal non-public definitions that provide either classic 5 * or preemptible semantics. 6 * 7 * Copyright Red Hat, 2009 8 * Copyright IBM Corporation, 2009 9 * Copyright SUSE, 2021 10 * 11 * Author: Ingo Molnar <mingo@elte.hu> 12 * Paul E. McKenney <paulmck@linux.ibm.com> 13 * Frederic Weisbecker <frederic@kernel.org> 14 */ 15 16 #ifdef CONFIG_RCU_NOCB_CPU 17 static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */ 18 static bool __read_mostly rcu_nocb_poll; /* Offload kthread are to poll. */ 19 20 static inline bool rcu_current_is_nocb_kthread(struct rcu_data *rdp) 21 { 22 /* Race on early boot between thread creation and assignment */ 23 if (!rdp->nocb_cb_kthread || !rdp->nocb_gp_kthread) 24 return true; 25 26 if (current == rdp->nocb_cb_kthread || current == rdp->nocb_gp_kthread) 27 if (in_task()) 28 return true; 29 return false; 30 } 31 32 /* 33 * Offload callback processing from the boot-time-specified set of CPUs 34 * specified by rcu_nocb_mask. For the CPUs in the set, there are kthreads 35 * created that pull the callbacks from the corresponding CPU, wait for 36 * a grace period to elapse, and invoke the callbacks. These kthreads 37 * are organized into GP kthreads, which manage incoming callbacks, wait for 38 * grace periods, and awaken CB kthreads, and the CB kthreads, which only 39 * invoke callbacks. Each GP kthread invokes its own CBs. The no-CBs CPUs 40 * do a wake_up() on their GP kthread when they insert a callback into any 41 * empty list, unless the rcu_nocb_poll boot parameter has been specified, 42 * in which case each kthread actively polls its CPU. (Which isn't so great 43 * for energy efficiency, but which does reduce RCU's overhead on that CPU.) 44 * 45 * This is intended to be used in conjunction with Frederic Weisbecker's 46 * adaptive-idle work, which would seriously reduce OS jitter on CPUs 47 * running CPU-bound user-mode computations. 48 * 49 * Offloading of callbacks can also be used as an energy-efficiency 50 * measure because CPUs with no RCU callbacks queued are more aggressive 51 * about entering dyntick-idle mode. 52 */ 53 54 55 /* 56 * Parse the boot-time rcu_nocb_mask CPU list from the kernel parameters. 57 * If the list is invalid, a warning is emitted and all CPUs are offloaded. 58 */ 59 static int __init rcu_nocb_setup(char *str) 60 { 61 alloc_bootmem_cpumask_var(&rcu_nocb_mask); 62 if (*str == '=') { 63 if (cpulist_parse(++str, rcu_nocb_mask)) { 64 pr_warn("rcu_nocbs= bad CPU range, all CPUs set\n"); 65 cpumask_setall(rcu_nocb_mask); 66 } 67 } 68 rcu_state.nocb_is_setup = true; 69 return 1; 70 } 71 __setup("rcu_nocbs", rcu_nocb_setup); 72 73 static int __init parse_rcu_nocb_poll(char *arg) 74 { 75 rcu_nocb_poll = true; 76 return 1; 77 } 78 __setup("rcu_nocb_poll", parse_rcu_nocb_poll); 79 80 /* 81 * Don't bother bypassing ->cblist if the call_rcu() rate is low. 82 * After all, the main point of bypassing is to avoid lock contention 83 * on ->nocb_lock, which only can happen at high call_rcu() rates. 84 */ 85 static int nocb_nobypass_lim_per_jiffy = 16 * 1000 / HZ; 86 module_param(nocb_nobypass_lim_per_jiffy, int, 0); 87 88 /* 89 * Acquire the specified rcu_data structure's ->nocb_bypass_lock. If the 90 * lock isn't immediately available, perform minimal sanity check. 91 */ 92 static void rcu_nocb_bypass_lock(struct rcu_data *rdp) 93 __acquires(&rdp->nocb_bypass_lock) 94 { 95 lockdep_assert_irqs_disabled(); 96 if (raw_spin_trylock(&rdp->nocb_bypass_lock)) 97 return; 98 /* 99 * Contention expected only when local enqueue collide with 100 * remote flush from kthreads. 101 */ 102 WARN_ON_ONCE(smp_processor_id() != rdp->cpu); 103 raw_spin_lock(&rdp->nocb_bypass_lock); 104 } 105 106 /* 107 * Conditionally acquire the specified rcu_data structure's 108 * ->nocb_bypass_lock. 109 */ 110 static bool rcu_nocb_bypass_trylock(struct rcu_data *rdp) 111 { 112 lockdep_assert_irqs_disabled(); 113 return raw_spin_trylock(&rdp->nocb_bypass_lock); 114 } 115 116 /* 117 * Release the specified rcu_data structure's ->nocb_bypass_lock. 118 */ 119 static void rcu_nocb_bypass_unlock(struct rcu_data *rdp) 120 __releases(&rdp->nocb_bypass_lock) 121 { 122 lockdep_assert_irqs_disabled(); 123 raw_spin_unlock(&rdp->nocb_bypass_lock); 124 } 125 126 /* 127 * Acquire the specified rcu_data structure's ->nocb_lock, but only 128 * if it corresponds to a no-CBs CPU. 129 */ 130 static void rcu_nocb_lock(struct rcu_data *rdp) 131 { 132 lockdep_assert_irqs_disabled(); 133 if (!rcu_rdp_is_offloaded(rdp)) 134 return; 135 raw_spin_lock(&rdp->nocb_lock); 136 } 137 138 /* 139 * Release the specified rcu_data structure's ->nocb_lock, but only 140 * if it corresponds to a no-CBs CPU. 141 */ 142 static void rcu_nocb_unlock(struct rcu_data *rdp) 143 { 144 if (rcu_rdp_is_offloaded(rdp)) { 145 lockdep_assert_irqs_disabled(); 146 raw_spin_unlock(&rdp->nocb_lock); 147 } 148 } 149 150 /* 151 * Release the specified rcu_data structure's ->nocb_lock and restore 152 * interrupts, but only if it corresponds to a no-CBs CPU. 153 */ 154 static void rcu_nocb_unlock_irqrestore(struct rcu_data *rdp, 155 unsigned long flags) 156 { 157 if (rcu_rdp_is_offloaded(rdp)) { 158 lockdep_assert_irqs_disabled(); 159 raw_spin_unlock_irqrestore(&rdp->nocb_lock, flags); 160 } else { 161 local_irq_restore(flags); 162 } 163 } 164 165 /* Lockdep check that ->cblist may be safely accessed. */ 166 static void rcu_lockdep_assert_cblist_protected(struct rcu_data *rdp) 167 { 168 lockdep_assert_irqs_disabled(); 169 if (rcu_rdp_is_offloaded(rdp)) 170 lockdep_assert_held(&rdp->nocb_lock); 171 } 172 173 /* 174 * Wake up any no-CBs CPUs' kthreads that were waiting on the just-ended 175 * grace period. 176 */ 177 static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq) 178 { 179 swake_up_all(sq); 180 } 181 182 static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp) 183 { 184 return &rnp->nocb_gp_wq[rcu_seq_ctr(rnp->gp_seq) & 0x1]; 185 } 186 187 static void rcu_init_one_nocb(struct rcu_node *rnp) 188 { 189 init_swait_queue_head(&rnp->nocb_gp_wq[0]); 190 init_swait_queue_head(&rnp->nocb_gp_wq[1]); 191 } 192 193 /* Clear any pending deferred wakeup timer (nocb_gp_lock must be held). */ 194 static void nocb_defer_wakeup_cancel(struct rcu_data *rdp_gp) 195 { 196 if (rdp_gp->nocb_defer_wakeup > RCU_NOCB_WAKE_NOT) { 197 WRITE_ONCE(rdp_gp->nocb_defer_wakeup, RCU_NOCB_WAKE_NOT); 198 timer_delete(&rdp_gp->nocb_timer); 199 } 200 } 201 202 static bool __wake_nocb_gp(struct rcu_data *rdp_gp, 203 struct rcu_data *rdp, 204 unsigned long flags) 205 __releases(rdp_gp->nocb_gp_lock) 206 { 207 bool needwake = false; 208 209 if (!READ_ONCE(rdp_gp->nocb_gp_kthread)) { 210 raw_spin_unlock_irqrestore(&rdp_gp->nocb_gp_lock, flags); 211 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 212 TPS("AlreadyAwake")); 213 return false; 214 } 215 216 nocb_defer_wakeup_cancel(rdp_gp); 217 218 if (READ_ONCE(rdp_gp->nocb_gp_sleep)) { 219 WRITE_ONCE(rdp_gp->nocb_gp_sleep, false); 220 needwake = true; 221 } 222 raw_spin_unlock_irqrestore(&rdp_gp->nocb_gp_lock, flags); 223 if (needwake) { 224 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("DoWake")); 225 swake_up_one(&rdp_gp->nocb_gp_wq); 226 } 227 228 return needwake; 229 } 230 231 /* 232 * Kick the GP kthread for this NOCB group. 233 */ 234 static bool wake_nocb_gp(struct rcu_data *rdp) 235 { 236 unsigned long flags; 237 struct rcu_data *rdp_gp = rdp->nocb_gp_rdp; 238 239 raw_spin_lock_irqsave(&rdp_gp->nocb_gp_lock, flags); 240 return __wake_nocb_gp(rdp_gp, rdp, flags); 241 } 242 243 #ifdef CONFIG_RCU_LAZY 244 /* 245 * LAZY_FLUSH_JIFFIES decides the maximum amount of time that 246 * can elapse before lazy callbacks are flushed. Lazy callbacks 247 * could be flushed much earlier for a number of other reasons 248 * however, LAZY_FLUSH_JIFFIES will ensure no lazy callbacks are 249 * left unsubmitted to RCU after those many jiffies. 250 */ 251 #define LAZY_FLUSH_JIFFIES (10 * HZ) 252 static unsigned long jiffies_lazy_flush = LAZY_FLUSH_JIFFIES; 253 254 // To be called only from test code. 255 void rcu_set_jiffies_lazy_flush(unsigned long jif) 256 { 257 jiffies_lazy_flush = jif; 258 } 259 EXPORT_SYMBOL(rcu_set_jiffies_lazy_flush); 260 261 unsigned long rcu_get_jiffies_lazy_flush(void) 262 { 263 return jiffies_lazy_flush; 264 } 265 EXPORT_SYMBOL(rcu_get_jiffies_lazy_flush); 266 #endif 267 268 /* 269 * Arrange to wake the GP kthread for this NOCB group at some future 270 * time when it is safe to do so. 271 */ 272 static void wake_nocb_gp_defer(struct rcu_data *rdp, int waketype, 273 const char *reason) 274 { 275 unsigned long flags; 276 struct rcu_data *rdp_gp = rdp->nocb_gp_rdp; 277 278 raw_spin_lock_irqsave(&rdp_gp->nocb_gp_lock, flags); 279 280 /* 281 * Bypass wakeup overrides previous deferments. In case of 282 * callback storms, no need to wake up too early. 283 */ 284 if (waketype == RCU_NOCB_WAKE_LAZY && 285 rdp_gp->nocb_defer_wakeup == RCU_NOCB_WAKE_NOT) { 286 mod_timer(&rdp_gp->nocb_timer, jiffies + rcu_get_jiffies_lazy_flush()); 287 WRITE_ONCE(rdp_gp->nocb_defer_wakeup, waketype); 288 } else if (waketype == RCU_NOCB_WAKE_BYPASS) { 289 mod_timer(&rdp_gp->nocb_timer, jiffies + 2); 290 WRITE_ONCE(rdp_gp->nocb_defer_wakeup, waketype); 291 } else { 292 if (rdp_gp->nocb_defer_wakeup < RCU_NOCB_WAKE) 293 mod_timer(&rdp_gp->nocb_timer, jiffies + 1); 294 if (rdp_gp->nocb_defer_wakeup < waketype) 295 WRITE_ONCE(rdp_gp->nocb_defer_wakeup, waketype); 296 } 297 298 raw_spin_unlock_irqrestore(&rdp_gp->nocb_gp_lock, flags); 299 300 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, reason); 301 } 302 303 /* 304 * Flush the ->nocb_bypass queue into ->cblist, enqueuing rhp if non-NULL. 305 * However, if there is a callback to be enqueued and if ->nocb_bypass 306 * proves to be initially empty, just return false because the no-CB GP 307 * kthread may need to be awakened in this case. 308 * 309 * Return true if there was something to be flushed and it succeeded, otherwise 310 * false. 311 * 312 * Note that this function always returns true if rhp is NULL. 313 */ 314 static bool rcu_nocb_do_flush_bypass(struct rcu_data *rdp, struct rcu_head *rhp_in, 315 unsigned long j, bool lazy) 316 { 317 struct rcu_cblist rcl; 318 struct rcu_head *rhp = rhp_in; 319 320 WARN_ON_ONCE(!rcu_rdp_is_offloaded(rdp)); 321 rcu_lockdep_assert_cblist_protected(rdp); 322 lockdep_assert_held(&rdp->nocb_bypass_lock); 323 if (rhp && !rcu_cblist_n_cbs(&rdp->nocb_bypass)) { 324 raw_spin_unlock(&rdp->nocb_bypass_lock); 325 return false; 326 } 327 /* Note: ->cblist.len already accounts for ->nocb_bypass contents. */ 328 if (rhp) 329 rcu_segcblist_inc_len(&rdp->cblist); /* Must precede enqueue. */ 330 331 /* 332 * If the new CB requested was a lazy one, queue it onto the main 333 * ->cblist so that we can take advantage of the grace-period that will 334 * happen regardless. But queue it onto the bypass list first so that 335 * the lazy CB is ordered with the existing CBs in the bypass list. 336 */ 337 if (lazy && rhp) { 338 rcu_cblist_enqueue(&rdp->nocb_bypass, rhp); 339 rhp = NULL; 340 } 341 rcu_cblist_flush_enqueue(&rcl, &rdp->nocb_bypass, rhp); 342 WRITE_ONCE(rdp->lazy_len, 0); 343 344 rcu_segcblist_insert_pend_cbs(&rdp->cblist, &rcl); 345 WRITE_ONCE(rdp->nocb_bypass_first, j); 346 rcu_nocb_bypass_unlock(rdp); 347 return true; 348 } 349 350 /* 351 * Flush the ->nocb_bypass queue into ->cblist, enqueuing rhp if non-NULL. 352 * However, if there is a callback to be enqueued and if ->nocb_bypass 353 * proves to be initially empty, just return false because the no-CB GP 354 * kthread may need to be awakened in this case. 355 * 356 * Note that this function always returns true if rhp is NULL. 357 */ 358 static bool rcu_nocb_flush_bypass(struct rcu_data *rdp, struct rcu_head *rhp, 359 unsigned long j, bool lazy) 360 { 361 if (!rcu_rdp_is_offloaded(rdp)) 362 return true; 363 rcu_lockdep_assert_cblist_protected(rdp); 364 rcu_nocb_bypass_lock(rdp); 365 return rcu_nocb_do_flush_bypass(rdp, rhp, j, lazy); 366 } 367 368 /* 369 * If the ->nocb_bypass_lock is immediately available, flush the 370 * ->nocb_bypass queue into ->cblist. 371 */ 372 static void rcu_nocb_try_flush_bypass(struct rcu_data *rdp, unsigned long j) 373 { 374 rcu_lockdep_assert_cblist_protected(rdp); 375 if (!rcu_rdp_is_offloaded(rdp) || 376 !rcu_nocb_bypass_trylock(rdp)) 377 return; 378 WARN_ON_ONCE(!rcu_nocb_do_flush_bypass(rdp, NULL, j, false)); 379 } 380 381 /* 382 * See whether it is appropriate to use the ->nocb_bypass list in order 383 * to control contention on ->nocb_lock. A limited number of direct 384 * enqueues are permitted into ->cblist per jiffy. If ->nocb_bypass 385 * is non-empty, further callbacks must be placed into ->nocb_bypass, 386 * otherwise rcu_barrier() breaks. Use rcu_nocb_flush_bypass() to switch 387 * back to direct use of ->cblist. However, ->nocb_bypass should not be 388 * used if ->cblist is empty, because otherwise callbacks can be stranded 389 * on ->nocb_bypass because we cannot count on the current CPU ever again 390 * invoking call_rcu(). The general rule is that if ->nocb_bypass is 391 * non-empty, the corresponding no-CBs grace-period kthread must not be 392 * in an indefinite sleep state. 393 * 394 * Finally, it is not permitted to use the bypass during early boot, 395 * as doing so would confuse the auto-initialization code. Besides 396 * which, there is no point in worrying about lock contention while 397 * there is only one CPU in operation. 398 */ 399 static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp, 400 bool *was_alldone, unsigned long flags, 401 bool lazy) 402 { 403 unsigned long c; 404 unsigned long cur_gp_seq; 405 unsigned long j = jiffies; 406 long ncbs = rcu_cblist_n_cbs(&rdp->nocb_bypass); 407 bool bypass_is_lazy = (ncbs == READ_ONCE(rdp->lazy_len)); 408 409 lockdep_assert_irqs_disabled(); 410 411 // Pure softirq/rcuc based processing: no bypassing, no 412 // locking. 413 if (!rcu_rdp_is_offloaded(rdp)) { 414 *was_alldone = !rcu_segcblist_pend_cbs(&rdp->cblist); 415 return false; 416 } 417 418 // Don't use ->nocb_bypass during early boot. 419 if (rcu_scheduler_active != RCU_SCHEDULER_RUNNING) { 420 rcu_nocb_lock(rdp); 421 WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass)); 422 *was_alldone = !rcu_segcblist_pend_cbs(&rdp->cblist); 423 return false; 424 } 425 426 // If we have advanced to a new jiffy, reset counts to allow 427 // moving back from ->nocb_bypass to ->cblist. 428 if (j == rdp->nocb_nobypass_last) { 429 c = rdp->nocb_nobypass_count + 1; 430 } else { 431 WRITE_ONCE(rdp->nocb_nobypass_last, j); 432 c = rdp->nocb_nobypass_count - nocb_nobypass_lim_per_jiffy; 433 if (ULONG_CMP_LT(rdp->nocb_nobypass_count, 434 nocb_nobypass_lim_per_jiffy)) 435 c = 0; 436 else if (c > nocb_nobypass_lim_per_jiffy) 437 c = nocb_nobypass_lim_per_jiffy; 438 } 439 WRITE_ONCE(rdp->nocb_nobypass_count, c); 440 441 // If there hasn't yet been all that many ->cblist enqueues 442 // this jiffy, tell the caller to enqueue onto ->cblist. But flush 443 // ->nocb_bypass first. 444 // Lazy CBs throttle this back and do immediate bypass queuing. 445 if (rdp->nocb_nobypass_count < nocb_nobypass_lim_per_jiffy && !lazy) { 446 rcu_nocb_lock(rdp); 447 *was_alldone = !rcu_segcblist_pend_cbs(&rdp->cblist); 448 if (*was_alldone) 449 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 450 TPS("FirstQ")); 451 452 WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, j, false)); 453 WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass)); 454 return false; // Caller must enqueue the callback. 455 } 456 457 // If ->nocb_bypass has been used too long or is too full, 458 // flush ->nocb_bypass to ->cblist. 459 if ((ncbs && !bypass_is_lazy && j != READ_ONCE(rdp->nocb_bypass_first)) || 460 (ncbs && bypass_is_lazy && 461 (time_after(j, READ_ONCE(rdp->nocb_bypass_first) + rcu_get_jiffies_lazy_flush()))) || 462 ncbs >= qhimark) { 463 rcu_nocb_lock(rdp); 464 *was_alldone = !rcu_segcblist_pend_cbs(&rdp->cblist); 465 466 if (!rcu_nocb_flush_bypass(rdp, rhp, j, lazy)) { 467 if (*was_alldone) 468 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 469 TPS("FirstQ")); 470 WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass)); 471 return false; // Caller must enqueue the callback. 472 } 473 if (j != rdp->nocb_gp_adv_time && 474 rcu_segcblist_nextgp(&rdp->cblist, &cur_gp_seq) && 475 rcu_seq_done(&rdp->mynode->gp_seq, cur_gp_seq)) { 476 rcu_advance_cbs_nowake(rdp->mynode, rdp); 477 rdp->nocb_gp_adv_time = j; 478 } 479 480 // The flush succeeded and we moved CBs into the regular list. 481 // Don't wait for the wake up timer as it may be too far ahead. 482 // Wake up the GP thread now instead, if the cblist was empty. 483 __call_rcu_nocb_wake(rdp, *was_alldone, flags); 484 485 return true; // Callback already enqueued. 486 } 487 488 // We need to use the bypass. 489 rcu_nocb_bypass_lock(rdp); 490 ncbs = rcu_cblist_n_cbs(&rdp->nocb_bypass); 491 rcu_segcblist_inc_len(&rdp->cblist); /* Must precede enqueue. */ 492 rcu_cblist_enqueue(&rdp->nocb_bypass, rhp); 493 494 if (lazy) 495 WRITE_ONCE(rdp->lazy_len, rdp->lazy_len + 1); 496 497 if (!ncbs) { 498 WRITE_ONCE(rdp->nocb_bypass_first, j); 499 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("FirstBQ")); 500 } 501 rcu_nocb_bypass_unlock(rdp); 502 503 // A wake up of the grace period kthread or timer adjustment 504 // needs to be done only if: 505 // 1. Bypass list was fully empty before (this is the first 506 // bypass list entry), or: 507 // 2. Both of these conditions are met: 508 // a. The bypass list previously had only lazy CBs, and: 509 // b. The new CB is non-lazy. 510 if (!ncbs || (bypass_is_lazy && !lazy)) { 511 // No-CBs GP kthread might be indefinitely asleep, if so, wake. 512 rcu_nocb_lock(rdp); // Rare during call_rcu() flood. 513 if (!rcu_segcblist_pend_cbs(&rdp->cblist)) { 514 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 515 TPS("FirstBQwake")); 516 __call_rcu_nocb_wake(rdp, true, flags); 517 } else { 518 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 519 TPS("FirstBQnoWake")); 520 rcu_nocb_unlock(rdp); 521 } 522 } 523 return true; // Callback already enqueued. 524 } 525 526 /* 527 * Awaken the no-CBs grace-period kthread if needed due to it legitimately 528 * being asleep. 529 */ 530 static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_alldone, 531 unsigned long flags) 532 __releases(rdp->nocb_lock) 533 { 534 long bypass_len; 535 long lazy_len; 536 long len; 537 struct task_struct *t; 538 539 // If we are being polled or there is no kthread, just leave. 540 t = READ_ONCE(rdp->nocb_gp_kthread); 541 if (rcu_nocb_poll || !t) { 542 rcu_nocb_unlock(rdp); 543 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 544 TPS("WakeNotPoll")); 545 return; 546 } 547 // Need to actually to a wakeup. 548 len = rcu_segcblist_n_cbs(&rdp->cblist); 549 bypass_len = rcu_cblist_n_cbs(&rdp->nocb_bypass); 550 lazy_len = READ_ONCE(rdp->lazy_len); 551 if (was_alldone) { 552 rdp->qlen_last_fqs_check = len; 553 rcu_nocb_unlock(rdp); 554 // Only lazy CBs in bypass list 555 if (lazy_len && bypass_len == lazy_len) { 556 wake_nocb_gp_defer(rdp, RCU_NOCB_WAKE_LAZY, 557 TPS("WakeLazy")); 558 } else if (!irqs_disabled_flags(flags)) { 559 /* ... if queue was empty ... */ 560 wake_nocb_gp(rdp); 561 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 562 TPS("WakeEmpty")); 563 } else { 564 wake_nocb_gp_defer(rdp, RCU_NOCB_WAKE, 565 TPS("WakeEmptyIsDeferred")); 566 } 567 568 return; 569 } 570 571 rcu_nocb_unlock(rdp); 572 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("WakeNot")); 573 } 574 575 static void call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *head, 576 rcu_callback_t func, unsigned long flags, bool lazy) 577 { 578 bool was_alldone; 579 580 if (!rcu_nocb_try_bypass(rdp, head, &was_alldone, flags, lazy)) { 581 /* Not enqueued on bypass but locked, do regular enqueue */ 582 rcutree_enqueue(rdp, head, func); 583 __call_rcu_nocb_wake(rdp, was_alldone, flags); /* unlocks */ 584 } 585 } 586 587 static void nocb_gp_toggle_rdp(struct rcu_data *rdp_gp, struct rcu_data *rdp) 588 { 589 struct rcu_segcblist *cblist = &rdp->cblist; 590 unsigned long flags; 591 592 /* 593 * Locking orders future de-offloaded callbacks enqueue against previous 594 * handling of this rdp. Ie: Make sure rcuog is done with this rdp before 595 * deoffloaded callbacks can be enqueued. 596 */ 597 raw_spin_lock_irqsave(&rdp->nocb_lock, flags); 598 if (!rcu_segcblist_test_flags(cblist, SEGCBLIST_OFFLOADED)) { 599 /* 600 * Offloading. Set our flag and notify the offload worker. 601 * We will handle this rdp until it ever gets de-offloaded. 602 */ 603 list_add_tail(&rdp->nocb_entry_rdp, &rdp_gp->nocb_head_rdp); 604 rcu_segcblist_set_flags(cblist, SEGCBLIST_OFFLOADED); 605 } else { 606 /* 607 * De-offloading. Clear our flag and notify the de-offload worker. 608 * We will ignore this rdp until it ever gets re-offloaded. 609 */ 610 list_del(&rdp->nocb_entry_rdp); 611 rcu_segcblist_clear_flags(cblist, SEGCBLIST_OFFLOADED); 612 } 613 raw_spin_unlock_irqrestore(&rdp->nocb_lock, flags); 614 } 615 616 static void nocb_gp_sleep(struct rcu_data *my_rdp, int cpu) 617 { 618 trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Sleep")); 619 swait_event_interruptible_exclusive(my_rdp->nocb_gp_wq, 620 !READ_ONCE(my_rdp->nocb_gp_sleep)); 621 trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("EndSleep")); 622 } 623 624 /* 625 * No-CBs GP kthreads come here to wait for additional callbacks to show up 626 * or for grace periods to end. 627 */ 628 static void nocb_gp_wait(struct rcu_data *my_rdp) 629 { 630 bool bypass = false; 631 int __maybe_unused cpu = my_rdp->cpu; 632 unsigned long cur_gp_seq; 633 unsigned long flags; 634 bool gotcbs = false; 635 unsigned long j = jiffies; 636 bool lazy = false; 637 bool needwait_gp = false; // This prevents actual uninitialized use. 638 bool needwake; 639 bool needwake_gp; 640 struct rcu_data *rdp, *rdp_toggling = NULL; 641 struct rcu_node *rnp; 642 unsigned long wait_gp_seq = 0; // Suppress "use uninitialized" warning. 643 bool wasempty = false; 644 645 /* 646 * Each pass through the following loop checks for CBs and for the 647 * nearest grace period (if any) to wait for next. The CB kthreads 648 * and the global grace-period kthread are awakened if needed. 649 */ 650 WARN_ON_ONCE(my_rdp->nocb_gp_rdp != my_rdp); 651 /* 652 * An rcu_data structure is removed from the list after its 653 * CPU is de-offloaded and added to the list before that CPU is 654 * (re-)offloaded. If the following loop happens to be referencing 655 * that rcu_data structure during the time that the corresponding 656 * CPU is de-offloaded and then immediately re-offloaded, this 657 * loop's rdp pointer will be carried to the end of the list by 658 * the resulting pair of list operations. This can cause the loop 659 * to skip over some of the rcu_data structures that were supposed 660 * to have been scanned. Fortunately a new iteration through the 661 * entire loop is forced after a given CPU's rcu_data structure 662 * is added to the list, so the skipped-over rcu_data structures 663 * won't be ignored for long. 664 */ 665 list_for_each_entry(rdp, &my_rdp->nocb_head_rdp, nocb_entry_rdp) { 666 long bypass_ncbs; 667 bool flush_bypass = false; 668 long lazy_ncbs; 669 670 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("Check")); 671 rcu_nocb_lock_irqsave(rdp, flags); 672 lockdep_assert_held(&rdp->nocb_lock); 673 bypass_ncbs = rcu_cblist_n_cbs(&rdp->nocb_bypass); 674 lazy_ncbs = READ_ONCE(rdp->lazy_len); 675 676 if (bypass_ncbs && (lazy_ncbs == bypass_ncbs) && 677 (time_after(j, READ_ONCE(rdp->nocb_bypass_first) + rcu_get_jiffies_lazy_flush()) || 678 bypass_ncbs > 2 * qhimark)) { 679 flush_bypass = true; 680 } else if (bypass_ncbs && (lazy_ncbs != bypass_ncbs) && 681 (time_after(j, READ_ONCE(rdp->nocb_bypass_first) + 1) || 682 bypass_ncbs > 2 * qhimark)) { 683 flush_bypass = true; 684 } else if (!bypass_ncbs && rcu_segcblist_empty(&rdp->cblist)) { 685 rcu_nocb_unlock_irqrestore(rdp, flags); 686 continue; /* No callbacks here, try next. */ 687 } 688 689 if (flush_bypass) { 690 // Bypass full or old, so flush it. 691 (void)rcu_nocb_try_flush_bypass(rdp, j); 692 bypass_ncbs = rcu_cblist_n_cbs(&rdp->nocb_bypass); 693 lazy_ncbs = READ_ONCE(rdp->lazy_len); 694 } 695 696 if (bypass_ncbs) { 697 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 698 bypass_ncbs == lazy_ncbs ? TPS("Lazy") : TPS("Bypass")); 699 if (bypass_ncbs == lazy_ncbs) 700 lazy = true; 701 else 702 bypass = true; 703 } 704 rnp = rdp->mynode; 705 706 // Advance callbacks if helpful and low contention. 707 needwake_gp = false; 708 if (!rcu_segcblist_restempty(&rdp->cblist, 709 RCU_NEXT_READY_TAIL) || 710 (rcu_segcblist_nextgp(&rdp->cblist, &cur_gp_seq) && 711 rcu_seq_done(&rnp->gp_seq, cur_gp_seq))) { 712 raw_spin_lock_rcu_node(rnp); /* irqs disabled. */ 713 needwake_gp = rcu_advance_cbs(rnp, rdp); 714 wasempty = rcu_segcblist_restempty(&rdp->cblist, 715 RCU_NEXT_READY_TAIL); 716 raw_spin_unlock_rcu_node(rnp); /* irqs disabled. */ 717 } 718 // Need to wait on some grace period? 719 WARN_ON_ONCE(wasempty && 720 !rcu_segcblist_restempty(&rdp->cblist, 721 RCU_NEXT_READY_TAIL)); 722 if (rcu_segcblist_nextgp(&rdp->cblist, &cur_gp_seq)) { 723 if (!needwait_gp || 724 ULONG_CMP_LT(cur_gp_seq, wait_gp_seq)) 725 wait_gp_seq = cur_gp_seq; 726 needwait_gp = true; 727 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, 728 TPS("NeedWaitGP")); 729 } 730 if (rcu_segcblist_ready_cbs(&rdp->cblist)) { 731 needwake = rdp->nocb_cb_sleep; 732 WRITE_ONCE(rdp->nocb_cb_sleep, false); 733 } else { 734 needwake = false; 735 } 736 rcu_nocb_unlock_irqrestore(rdp, flags); 737 if (needwake) { 738 swake_up_one(&rdp->nocb_cb_wq); 739 gotcbs = true; 740 } 741 if (needwake_gp) 742 rcu_gp_kthread_wake(); 743 } 744 745 my_rdp->nocb_gp_bypass = bypass; 746 my_rdp->nocb_gp_gp = needwait_gp; 747 my_rdp->nocb_gp_seq = needwait_gp ? wait_gp_seq : 0; 748 749 // At least one child with non-empty ->nocb_bypass, so set 750 // timer in order to avoid stranding its callbacks. 751 if (!rcu_nocb_poll) { 752 // If bypass list only has lazy CBs. Add a deferred lazy wake up. 753 if (lazy && !bypass) { 754 wake_nocb_gp_defer(my_rdp, RCU_NOCB_WAKE_LAZY, 755 TPS("WakeLazyIsDeferred")); 756 // Otherwise add a deferred bypass wake up. 757 } else if (bypass) { 758 wake_nocb_gp_defer(my_rdp, RCU_NOCB_WAKE_BYPASS, 759 TPS("WakeBypassIsDeferred")); 760 } 761 } 762 763 if (rcu_nocb_poll) { 764 /* Polling, so trace if first poll in the series. */ 765 if (gotcbs) 766 trace_rcu_nocb_wake(rcu_state.name, cpu, TPS("Poll")); 767 if (list_empty(&my_rdp->nocb_head_rdp)) { 768 raw_spin_lock_irqsave(&my_rdp->nocb_gp_lock, flags); 769 if (!my_rdp->nocb_toggling_rdp) 770 WRITE_ONCE(my_rdp->nocb_gp_sleep, true); 771 raw_spin_unlock_irqrestore(&my_rdp->nocb_gp_lock, flags); 772 /* Wait for any offloading rdp */ 773 nocb_gp_sleep(my_rdp, cpu); 774 } else { 775 schedule_timeout_idle(1); 776 } 777 } else if (!needwait_gp) { 778 /* Wait for callbacks to appear. */ 779 nocb_gp_sleep(my_rdp, cpu); 780 } else { 781 rnp = my_rdp->mynode; 782 trace_rcu_this_gp(rnp, my_rdp, wait_gp_seq, TPS("StartWait")); 783 swait_event_interruptible_exclusive( 784 rnp->nocb_gp_wq[rcu_seq_ctr(wait_gp_seq) & 0x1], 785 rcu_seq_done(&rnp->gp_seq, wait_gp_seq) || 786 !READ_ONCE(my_rdp->nocb_gp_sleep)); 787 trace_rcu_this_gp(rnp, my_rdp, wait_gp_seq, TPS("EndWait")); 788 } 789 790 if (!rcu_nocb_poll) { 791 raw_spin_lock_irqsave(&my_rdp->nocb_gp_lock, flags); 792 // (De-)queue an rdp to/from the group if its nocb state is changing 793 rdp_toggling = my_rdp->nocb_toggling_rdp; 794 if (rdp_toggling) 795 my_rdp->nocb_toggling_rdp = NULL; 796 797 nocb_defer_wakeup_cancel(my_rdp); 798 WRITE_ONCE(my_rdp->nocb_gp_sleep, true); 799 raw_spin_unlock_irqrestore(&my_rdp->nocb_gp_lock, flags); 800 } else { 801 rdp_toggling = READ_ONCE(my_rdp->nocb_toggling_rdp); 802 if (rdp_toggling) { 803 /* 804 * Paranoid locking to make sure nocb_toggling_rdp is well 805 * reset *before* we (re)set SEGCBLIST_KTHREAD_GP or we could 806 * race with another round of nocb toggling for this rdp. 807 * Nocb locking should prevent from that already but we stick 808 * to paranoia, especially in rare path. 809 */ 810 raw_spin_lock_irqsave(&my_rdp->nocb_gp_lock, flags); 811 my_rdp->nocb_toggling_rdp = NULL; 812 raw_spin_unlock_irqrestore(&my_rdp->nocb_gp_lock, flags); 813 } 814 } 815 816 if (rdp_toggling) { 817 nocb_gp_toggle_rdp(my_rdp, rdp_toggling); 818 swake_up_one(&rdp_toggling->nocb_state_wq); 819 } 820 821 my_rdp->nocb_gp_seq = -1; 822 WARN_ON(signal_pending(current)); 823 } 824 825 /* 826 * No-CBs grace-period-wait kthread. There is one of these per group 827 * of CPUs, but only once at least one CPU in that group has come online 828 * at least once since boot. This kthread checks for newly posted 829 * callbacks from any of the CPUs it is responsible for, waits for a 830 * grace period, then awakens all of the rcu_nocb_cb_kthread() instances 831 * that then have callback-invocation work to do. 832 */ 833 static int rcu_nocb_gp_kthread(void *arg) 834 { 835 struct rcu_data *rdp = arg; 836 837 for (;;) { 838 WRITE_ONCE(rdp->nocb_gp_loops, rdp->nocb_gp_loops + 1); 839 nocb_gp_wait(rdp); 840 cond_resched_tasks_rcu_qs(); 841 } 842 return 0; 843 } 844 845 static inline bool nocb_cb_wait_cond(struct rcu_data *rdp) 846 { 847 return !READ_ONCE(rdp->nocb_cb_sleep) || kthread_should_park(); 848 } 849 850 /* 851 * Invoke any ready callbacks from the corresponding no-CBs CPU, 852 * then, if there are no more, wait for more to appear. 853 */ 854 static void nocb_cb_wait(struct rcu_data *rdp) 855 { 856 struct rcu_segcblist *cblist = &rdp->cblist; 857 unsigned long cur_gp_seq; 858 unsigned long flags; 859 bool needwake_gp = false; 860 struct rcu_node *rnp = rdp->mynode; 861 862 swait_event_interruptible_exclusive(rdp->nocb_cb_wq, 863 nocb_cb_wait_cond(rdp)); 864 if (kthread_should_park()) { 865 /* 866 * kthread_park() must be preceded by an rcu_barrier(). 867 * But yet another rcu_barrier() might have sneaked in between 868 * the barrier callback execution and the callbacks counter 869 * decrement. 870 */ 871 if (rdp->nocb_cb_sleep) { 872 rcu_nocb_lock_irqsave(rdp, flags); 873 WARN_ON_ONCE(rcu_segcblist_n_cbs(&rdp->cblist)); 874 rcu_nocb_unlock_irqrestore(rdp, flags); 875 kthread_parkme(); 876 } 877 } else if (READ_ONCE(rdp->nocb_cb_sleep)) { 878 WARN_ON(signal_pending(current)); 879 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("WokeEmpty")); 880 } 881 882 WARN_ON_ONCE(!rcu_rdp_is_offloaded(rdp)); 883 884 local_irq_save(flags); 885 rcu_momentary_eqs(); 886 local_irq_restore(flags); 887 /* 888 * Disable BH to provide the expected environment. Also, when 889 * transitioning to/from NOCB mode, a self-requeuing callback might 890 * be invoked from softirq. A short grace period could cause both 891 * instances of this callback would execute concurrently. 892 */ 893 local_bh_disable(); 894 rcu_do_batch(rdp); 895 local_bh_enable(); 896 lockdep_assert_irqs_enabled(); 897 rcu_nocb_lock_irqsave(rdp, flags); 898 if (rcu_segcblist_nextgp(cblist, &cur_gp_seq) && 899 rcu_seq_done(&rnp->gp_seq, cur_gp_seq) && 900 raw_spin_trylock_rcu_node(rnp)) { /* irqs already disabled. */ 901 needwake_gp = rcu_advance_cbs(rdp->mynode, rdp); 902 raw_spin_unlock_rcu_node(rnp); /* irqs remain disabled. */ 903 } 904 905 if (!rcu_segcblist_ready_cbs(cblist)) { 906 WRITE_ONCE(rdp->nocb_cb_sleep, true); 907 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("CBSleep")); 908 } else { 909 WRITE_ONCE(rdp->nocb_cb_sleep, false); 910 } 911 912 rcu_nocb_unlock_irqrestore(rdp, flags); 913 if (needwake_gp) 914 rcu_gp_kthread_wake(); 915 } 916 917 /* 918 * Per-rcu_data kthread, but only for no-CBs CPUs. Repeatedly invoke 919 * nocb_cb_wait() to do the dirty work. 920 */ 921 static int rcu_nocb_cb_kthread(void *arg) 922 { 923 struct rcu_data *rdp = arg; 924 925 // Each pass through this loop does one callback batch, and, 926 // if there are no more ready callbacks, waits for them. 927 for (;;) { 928 nocb_cb_wait(rdp); 929 cond_resched_tasks_rcu_qs(); 930 } 931 return 0; 932 } 933 934 /* Is a deferred wakeup of rcu_nocb_kthread() required? */ 935 static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp, int level) 936 { 937 return READ_ONCE(rdp->nocb_defer_wakeup) >= level; 938 } 939 940 /* Do a deferred wakeup of rcu_nocb_kthread(). */ 941 static bool do_nocb_deferred_wakeup_common(struct rcu_data *rdp_gp, 942 struct rcu_data *rdp, int level, 943 unsigned long flags) 944 __releases(rdp_gp->nocb_gp_lock) 945 { 946 int ret; 947 948 if (!rcu_nocb_need_deferred_wakeup(rdp_gp, level)) { 949 raw_spin_unlock_irqrestore(&rdp_gp->nocb_gp_lock, flags); 950 return false; 951 } 952 953 ret = __wake_nocb_gp(rdp_gp, rdp, flags); 954 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("DeferredWake")); 955 956 return ret; 957 } 958 959 /* Do a deferred wakeup of rcu_nocb_kthread() from a timer handler. */ 960 static void do_nocb_deferred_wakeup_timer(struct timer_list *t) 961 { 962 unsigned long flags; 963 struct rcu_data *rdp = timer_container_of(rdp, t, nocb_timer); 964 965 WARN_ON_ONCE(rdp->nocb_gp_rdp != rdp); 966 trace_rcu_nocb_wake(rcu_state.name, rdp->cpu, TPS("Timer")); 967 968 raw_spin_lock_irqsave(&rdp->nocb_gp_lock, flags); 969 do_nocb_deferred_wakeup_common(rdp, rdp, RCU_NOCB_WAKE_BYPASS, flags); 970 } 971 972 /* 973 * Do a deferred wakeup of rcu_nocb_kthread() from fastpath. 974 * This means we do an inexact common-case check. Note that if 975 * we miss, ->nocb_timer will eventually clean things up. 976 */ 977 static bool do_nocb_deferred_wakeup(struct rcu_data *rdp) 978 { 979 unsigned long flags; 980 struct rcu_data *rdp_gp = rdp->nocb_gp_rdp; 981 982 if (!rdp_gp || !rcu_nocb_need_deferred_wakeup(rdp_gp, RCU_NOCB_WAKE)) 983 return false; 984 985 raw_spin_lock_irqsave(&rdp_gp->nocb_gp_lock, flags); 986 return do_nocb_deferred_wakeup_common(rdp_gp, rdp, RCU_NOCB_WAKE, flags); 987 } 988 989 void rcu_nocb_flush_deferred_wakeup(void) 990 { 991 do_nocb_deferred_wakeup(this_cpu_ptr(&rcu_data)); 992 } 993 EXPORT_SYMBOL_GPL(rcu_nocb_flush_deferred_wakeup); 994 995 static int rcu_nocb_queue_toggle_rdp(struct rcu_data *rdp) 996 { 997 struct rcu_data *rdp_gp = rdp->nocb_gp_rdp; 998 bool wake_gp = false; 999 unsigned long flags; 1000 1001 raw_spin_lock_irqsave(&rdp_gp->nocb_gp_lock, flags); 1002 // Queue this rdp for add/del to/from the list to iterate on rcuog 1003 WRITE_ONCE(rdp_gp->nocb_toggling_rdp, rdp); 1004 if (rdp_gp->nocb_gp_sleep) { 1005 rdp_gp->nocb_gp_sleep = false; 1006 wake_gp = true; 1007 } 1008 raw_spin_unlock_irqrestore(&rdp_gp->nocb_gp_lock, flags); 1009 1010 return wake_gp; 1011 } 1012 1013 static bool rcu_nocb_rdp_deoffload_wait_cond(struct rcu_data *rdp) 1014 { 1015 unsigned long flags; 1016 bool ret; 1017 1018 /* 1019 * Locking makes sure rcuog is done handling this rdp before deoffloaded 1020 * enqueue can happen. Also it keeps the SEGCBLIST_OFFLOADED flag stable 1021 * while the ->nocb_lock is held. 1022 */ 1023 raw_spin_lock_irqsave(&rdp->nocb_lock, flags); 1024 ret = !rcu_segcblist_test_flags(&rdp->cblist, SEGCBLIST_OFFLOADED); 1025 raw_spin_unlock_irqrestore(&rdp->nocb_lock, flags); 1026 1027 return ret; 1028 } 1029 1030 static int rcu_nocb_rdp_deoffload(struct rcu_data *rdp) 1031 { 1032 unsigned long flags; 1033 int wake_gp; 1034 struct rcu_data *rdp_gp = rdp->nocb_gp_rdp; 1035 1036 /* CPU must be offline, unless it's early boot */ 1037 WARN_ON_ONCE(cpu_online(rdp->cpu) && rdp->cpu != raw_smp_processor_id()); 1038 1039 pr_info("De-offloading %d\n", rdp->cpu); 1040 1041 /* Flush all callbacks from segcblist and bypass */ 1042 rcu_barrier(); 1043 1044 /* 1045 * Make sure the rcuoc kthread isn't in the middle of a nocb locked 1046 * sequence while offloading is deactivated, along with nocb locking. 1047 */ 1048 if (rdp->nocb_cb_kthread) 1049 kthread_park(rdp->nocb_cb_kthread); 1050 1051 rcu_nocb_lock_irqsave(rdp, flags); 1052 WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass)); 1053 WARN_ON_ONCE(rcu_segcblist_n_cbs(&rdp->cblist)); 1054 rcu_nocb_unlock_irqrestore(rdp, flags); 1055 1056 wake_gp = rcu_nocb_queue_toggle_rdp(rdp); 1057 1058 mutex_lock(&rdp_gp->nocb_gp_kthread_mutex); 1059 1060 if (rdp_gp->nocb_gp_kthread) { 1061 if (wake_gp) 1062 wake_up_process(rdp_gp->nocb_gp_kthread); 1063 1064 swait_event_exclusive(rdp->nocb_state_wq, 1065 rcu_nocb_rdp_deoffload_wait_cond(rdp)); 1066 } else { 1067 /* 1068 * No kthread to clear the flags for us or remove the rdp from the nocb list 1069 * to iterate. Do it here instead. Locking doesn't look stricly necessary 1070 * but we stick to paranoia in this rare path. 1071 */ 1072 raw_spin_lock_irqsave(&rdp->nocb_lock, flags); 1073 rcu_segcblist_clear_flags(&rdp->cblist, SEGCBLIST_OFFLOADED); 1074 raw_spin_unlock_irqrestore(&rdp->nocb_lock, flags); 1075 1076 list_del(&rdp->nocb_entry_rdp); 1077 } 1078 1079 mutex_unlock(&rdp_gp->nocb_gp_kthread_mutex); 1080 1081 return 0; 1082 } 1083 1084 int rcu_nocb_cpu_deoffload(int cpu) 1085 { 1086 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); 1087 int ret = 0; 1088 1089 cpus_read_lock(); 1090 mutex_lock(&rcu_state.nocb_mutex); 1091 if (rcu_rdp_is_offloaded(rdp)) { 1092 if (!cpu_online(cpu)) { 1093 ret = rcu_nocb_rdp_deoffload(rdp); 1094 if (!ret) 1095 cpumask_clear_cpu(cpu, rcu_nocb_mask); 1096 } else { 1097 pr_info("NOCB: Cannot CB-deoffload online CPU %d\n", rdp->cpu); 1098 ret = -EINVAL; 1099 } 1100 } 1101 mutex_unlock(&rcu_state.nocb_mutex); 1102 cpus_read_unlock(); 1103 1104 return ret; 1105 } 1106 EXPORT_SYMBOL_GPL(rcu_nocb_cpu_deoffload); 1107 1108 static bool rcu_nocb_rdp_offload_wait_cond(struct rcu_data *rdp) 1109 { 1110 unsigned long flags; 1111 bool ret; 1112 1113 raw_spin_lock_irqsave(&rdp->nocb_lock, flags); 1114 ret = rcu_segcblist_test_flags(&rdp->cblist, SEGCBLIST_OFFLOADED); 1115 raw_spin_unlock_irqrestore(&rdp->nocb_lock, flags); 1116 1117 return ret; 1118 } 1119 1120 static int rcu_nocb_rdp_offload(struct rcu_data *rdp) 1121 { 1122 int wake_gp; 1123 1124 WARN_ON_ONCE(cpu_online(rdp->cpu)); 1125 /* 1126 * For now we only support re-offload, ie: the rdp must have been 1127 * offloaded on boot first. 1128 */ 1129 if (!rdp->nocb_gp_rdp) 1130 return -EINVAL; 1131 1132 if (WARN_ON_ONCE(!rdp->nocb_gp_kthread)) 1133 return -EINVAL; 1134 1135 pr_info("Offloading %d\n", rdp->cpu); 1136 1137 WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass)); 1138 WARN_ON_ONCE(rcu_segcblist_n_cbs(&rdp->cblist)); 1139 1140 wake_gp = rcu_nocb_queue_toggle_rdp(rdp); 1141 if (wake_gp) 1142 wake_up_process(rdp->nocb_gp_kthread); 1143 1144 swait_event_exclusive(rdp->nocb_state_wq, 1145 rcu_nocb_rdp_offload_wait_cond(rdp)); 1146 1147 kthread_unpark(rdp->nocb_cb_kthread); 1148 1149 return 0; 1150 } 1151 1152 int rcu_nocb_cpu_offload(int cpu) 1153 { 1154 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); 1155 int ret = 0; 1156 1157 cpus_read_lock(); 1158 mutex_lock(&rcu_state.nocb_mutex); 1159 if (!rcu_rdp_is_offloaded(rdp)) { 1160 if (!cpu_online(cpu)) { 1161 ret = rcu_nocb_rdp_offload(rdp); 1162 if (!ret) 1163 cpumask_set_cpu(cpu, rcu_nocb_mask); 1164 } else { 1165 pr_info("NOCB: Cannot CB-offload online CPU %d\n", rdp->cpu); 1166 ret = -EINVAL; 1167 } 1168 } 1169 mutex_unlock(&rcu_state.nocb_mutex); 1170 cpus_read_unlock(); 1171 1172 return ret; 1173 } 1174 EXPORT_SYMBOL_GPL(rcu_nocb_cpu_offload); 1175 1176 #ifdef CONFIG_RCU_LAZY 1177 static unsigned long 1178 lazy_rcu_shrink_count(struct shrinker *shrink, struct shrink_control *sc) 1179 { 1180 int cpu; 1181 unsigned long count = 0; 1182 1183 if (WARN_ON_ONCE(!cpumask_available(rcu_nocb_mask))) 1184 return 0; 1185 1186 /* Protect rcu_nocb_mask against concurrent (de-)offloading. */ 1187 if (!mutex_trylock(&rcu_state.nocb_mutex)) 1188 return 0; 1189 1190 /* Snapshot count of all CPUs */ 1191 for_each_cpu(cpu, rcu_nocb_mask) { 1192 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); 1193 1194 count += READ_ONCE(rdp->lazy_len); 1195 } 1196 1197 mutex_unlock(&rcu_state.nocb_mutex); 1198 1199 return count ? count : SHRINK_EMPTY; 1200 } 1201 1202 static unsigned long 1203 lazy_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) 1204 { 1205 int cpu; 1206 unsigned long flags; 1207 unsigned long count = 0; 1208 1209 if (WARN_ON_ONCE(!cpumask_available(rcu_nocb_mask))) 1210 return 0; 1211 /* 1212 * Protect against concurrent (de-)offloading. Otherwise nocb locking 1213 * may be ignored or imbalanced. 1214 */ 1215 if (!mutex_trylock(&rcu_state.nocb_mutex)) { 1216 /* 1217 * But really don't insist if nocb_mutex is contended since we 1218 * can't guarantee that it will never engage in a dependency 1219 * chain involving memory allocation. The lock is seldom contended 1220 * anyway. 1221 */ 1222 return 0; 1223 } 1224 1225 /* Snapshot count of all CPUs */ 1226 for_each_cpu(cpu, rcu_nocb_mask) { 1227 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); 1228 int _count; 1229 1230 if (WARN_ON_ONCE(!rcu_rdp_is_offloaded(rdp))) 1231 continue; 1232 1233 if (!READ_ONCE(rdp->lazy_len)) 1234 continue; 1235 1236 rcu_nocb_lock_irqsave(rdp, flags); 1237 /* 1238 * Recheck under the nocb lock. Since we are not holding the bypass 1239 * lock we may still race with increments from the enqueuer but still 1240 * we know for sure if there is at least one lazy callback. 1241 */ 1242 _count = READ_ONCE(rdp->lazy_len); 1243 if (!_count) { 1244 rcu_nocb_unlock_irqrestore(rdp, flags); 1245 continue; 1246 } 1247 rcu_nocb_try_flush_bypass(rdp, jiffies); 1248 rcu_nocb_unlock_irqrestore(rdp, flags); 1249 wake_nocb_gp(rdp); 1250 sc->nr_to_scan -= _count; 1251 count += _count; 1252 if (sc->nr_to_scan <= 0) 1253 break; 1254 } 1255 1256 mutex_unlock(&rcu_state.nocb_mutex); 1257 1258 return count ? count : SHRINK_STOP; 1259 } 1260 #endif // #ifdef CONFIG_RCU_LAZY 1261 1262 void __init rcu_init_nohz(void) 1263 { 1264 int cpu; 1265 struct rcu_data *rdp; 1266 const struct cpumask *cpumask = NULL; 1267 struct shrinker * __maybe_unused lazy_rcu_shrinker; 1268 1269 #if defined(CONFIG_NO_HZ_FULL) 1270 if (tick_nohz_full_running && !cpumask_empty(tick_nohz_full_mask)) 1271 cpumask = tick_nohz_full_mask; 1272 #endif 1273 1274 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_DEFAULT_ALL) && 1275 !rcu_state.nocb_is_setup && !cpumask) 1276 cpumask = cpu_possible_mask; 1277 1278 if (cpumask) { 1279 if (!cpumask_available(rcu_nocb_mask)) { 1280 if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) { 1281 pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n"); 1282 return; 1283 } 1284 } 1285 1286 cpumask_or(rcu_nocb_mask, rcu_nocb_mask, cpumask); 1287 rcu_state.nocb_is_setup = true; 1288 } 1289 1290 if (!rcu_state.nocb_is_setup) 1291 return; 1292 1293 #ifdef CONFIG_RCU_LAZY 1294 lazy_rcu_shrinker = shrinker_alloc(0, "rcu-lazy"); 1295 if (!lazy_rcu_shrinker) { 1296 pr_err("Failed to allocate lazy_rcu shrinker!\n"); 1297 } else { 1298 lazy_rcu_shrinker->count_objects = lazy_rcu_shrink_count; 1299 lazy_rcu_shrinker->scan_objects = lazy_rcu_shrink_scan; 1300 1301 shrinker_register(lazy_rcu_shrinker); 1302 } 1303 #endif // #ifdef CONFIG_RCU_LAZY 1304 1305 if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) { 1306 pr_info("\tNote: kernel parameter 'rcu_nocbs=', 'nohz_full', or 'isolcpus=' contains nonexistent CPUs.\n"); 1307 cpumask_and(rcu_nocb_mask, cpu_possible_mask, 1308 rcu_nocb_mask); 1309 } 1310 if (cpumask_empty(rcu_nocb_mask)) 1311 pr_info("\tOffload RCU callbacks from CPUs: (none).\n"); 1312 else 1313 pr_info("\tOffload RCU callbacks from CPUs: %*pbl.\n", 1314 cpumask_pr_args(rcu_nocb_mask)); 1315 if (rcu_nocb_poll) 1316 pr_info("\tPoll for callbacks from no-CBs CPUs.\n"); 1317 1318 for_each_cpu(cpu, rcu_nocb_mask) { 1319 rdp = per_cpu_ptr(&rcu_data, cpu); 1320 if (rcu_segcblist_empty(&rdp->cblist)) 1321 rcu_segcblist_init(&rdp->cblist); 1322 rcu_segcblist_set_flags(&rdp->cblist, SEGCBLIST_OFFLOADED); 1323 } 1324 rcu_organize_nocb_kthreads(); 1325 } 1326 1327 /* Initialize per-rcu_data variables for no-CBs CPUs. */ 1328 static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp) 1329 { 1330 init_swait_queue_head(&rdp->nocb_cb_wq); 1331 init_swait_queue_head(&rdp->nocb_gp_wq); 1332 init_swait_queue_head(&rdp->nocb_state_wq); 1333 raw_spin_lock_init(&rdp->nocb_lock); 1334 raw_spin_lock_init(&rdp->nocb_bypass_lock); 1335 raw_spin_lock_init(&rdp->nocb_gp_lock); 1336 timer_setup(&rdp->nocb_timer, do_nocb_deferred_wakeup_timer, 0); 1337 rcu_cblist_init(&rdp->nocb_bypass); 1338 WRITE_ONCE(rdp->lazy_len, 0); 1339 mutex_init(&rdp->nocb_gp_kthread_mutex); 1340 } 1341 1342 /* 1343 * If the specified CPU is a no-CBs CPU that does not already have its 1344 * rcuo CB kthread, spawn it. Additionally, if the rcuo GP kthread 1345 * for this CPU's group has not yet been created, spawn it as well. 1346 */ 1347 static void rcu_spawn_cpu_nocb_kthread(int cpu) 1348 { 1349 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu); 1350 struct rcu_data *rdp_gp; 1351 struct task_struct *t; 1352 struct sched_param sp; 1353 1354 if (!rcu_scheduler_fully_active || !rcu_state.nocb_is_setup) 1355 return; 1356 1357 /* If there already is an rcuo kthread, then nothing to do. */ 1358 if (rdp->nocb_cb_kthread) 1359 return; 1360 1361 /* If we didn't spawn the GP kthread first, reorganize! */ 1362 sp.sched_priority = kthread_prio; 1363 rdp_gp = rdp->nocb_gp_rdp; 1364 mutex_lock(&rdp_gp->nocb_gp_kthread_mutex); 1365 if (!rdp_gp->nocb_gp_kthread) { 1366 t = kthread_run(rcu_nocb_gp_kthread, rdp_gp, 1367 "rcuog/%d", rdp_gp->cpu); 1368 if (WARN_ONCE(IS_ERR(t), "%s: Could not start rcuo GP kthread, OOM is now expected behavior\n", __func__)) { 1369 mutex_unlock(&rdp_gp->nocb_gp_kthread_mutex); 1370 goto err; 1371 } 1372 WRITE_ONCE(rdp_gp->nocb_gp_kthread, t); 1373 if (kthread_prio) 1374 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp); 1375 } 1376 mutex_unlock(&rdp_gp->nocb_gp_kthread_mutex); 1377 1378 /* Spawn the kthread for this CPU. */ 1379 t = kthread_create(rcu_nocb_cb_kthread, rdp, 1380 "rcuo%c/%d", rcu_state.abbr, cpu); 1381 if (WARN_ONCE(IS_ERR(t), "%s: Could not start rcuo CB kthread, OOM is now expected behavior\n", __func__)) 1382 goto err; 1383 1384 if (rcu_rdp_is_offloaded(rdp)) 1385 wake_up_process(t); 1386 else 1387 kthread_park(t); 1388 1389 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_CB_BOOST) && kthread_prio) 1390 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp); 1391 1392 WRITE_ONCE(rdp->nocb_cb_kthread, t); 1393 WRITE_ONCE(rdp->nocb_gp_kthread, rdp_gp->nocb_gp_kthread); 1394 return; 1395 1396 err: 1397 /* 1398 * No need to protect against concurrent rcu_barrier() 1399 * because the number of callbacks should be 0 for a non-boot CPU, 1400 * therefore rcu_barrier() shouldn't even try to grab the nocb_lock. 1401 * But hold nocb_mutex to avoid nocb_lock imbalance from shrinker. 1402 */ 1403 WARN_ON_ONCE(system_state > SYSTEM_BOOTING && rcu_segcblist_n_cbs(&rdp->cblist)); 1404 mutex_lock(&rcu_state.nocb_mutex); 1405 if (rcu_rdp_is_offloaded(rdp)) { 1406 rcu_nocb_rdp_deoffload(rdp); 1407 cpumask_clear_cpu(cpu, rcu_nocb_mask); 1408 } 1409 mutex_unlock(&rcu_state.nocb_mutex); 1410 } 1411 1412 /* How many CB CPU IDs per GP kthread? Default of -1 for sqrt(nr_cpu_ids). */ 1413 static int rcu_nocb_gp_stride = -1; 1414 module_param(rcu_nocb_gp_stride, int, 0444); 1415 1416 /* 1417 * Initialize GP-CB relationships for all no-CBs CPU. 1418 */ 1419 static void __init rcu_organize_nocb_kthreads(void) 1420 { 1421 int cpu; 1422 bool firsttime = true; 1423 bool gotnocbs = false; 1424 bool gotnocbscbs = true; 1425 int ls = rcu_nocb_gp_stride; 1426 int nl = 0; /* Next GP kthread. */ 1427 struct rcu_data *rdp; 1428 struct rcu_data *rdp_gp = NULL; /* Suppress misguided gcc warn. */ 1429 1430 if (!cpumask_available(rcu_nocb_mask)) 1431 return; 1432 if (ls == -1) { 1433 ls = nr_cpu_ids / int_sqrt(nr_cpu_ids); 1434 rcu_nocb_gp_stride = ls; 1435 } 1436 1437 /* 1438 * Each pass through this loop sets up one rcu_data structure. 1439 * Should the corresponding CPU come online in the future, then 1440 * we will spawn the needed set of rcu_nocb_kthread() kthreads. 1441 */ 1442 for_each_possible_cpu(cpu) { 1443 rdp = per_cpu_ptr(&rcu_data, cpu); 1444 if (rdp->cpu >= nl) { 1445 /* New GP kthread, set up for CBs & next GP. */ 1446 gotnocbs = true; 1447 nl = DIV_ROUND_UP(rdp->cpu + 1, ls) * ls; 1448 rdp_gp = rdp; 1449 INIT_LIST_HEAD(&rdp->nocb_head_rdp); 1450 if (dump_tree) { 1451 if (!firsttime) 1452 pr_cont("%s\n", gotnocbscbs 1453 ? "" : " (self only)"); 1454 gotnocbscbs = false; 1455 firsttime = false; 1456 pr_alert("%s: No-CB GP kthread CPU %d:", 1457 __func__, cpu); 1458 } 1459 } else { 1460 /* Another CB kthread, link to previous GP kthread. */ 1461 gotnocbscbs = true; 1462 if (dump_tree) 1463 pr_cont(" %d", cpu); 1464 } 1465 rdp->nocb_gp_rdp = rdp_gp; 1466 if (cpumask_test_cpu(cpu, rcu_nocb_mask)) 1467 list_add_tail(&rdp->nocb_entry_rdp, &rdp_gp->nocb_head_rdp); 1468 } 1469 if (gotnocbs && dump_tree) 1470 pr_cont("%s\n", gotnocbscbs ? "" : " (self only)"); 1471 } 1472 1473 /* 1474 * Bind the current task to the offloaded CPUs. If there are no offloaded 1475 * CPUs, leave the task unbound. Splat if the bind attempt fails. 1476 */ 1477 void rcu_bind_current_to_nocb(void) 1478 { 1479 if (cpumask_available(rcu_nocb_mask) && !cpumask_empty(rcu_nocb_mask)) 1480 WARN_ON(sched_setaffinity(current->pid, rcu_nocb_mask)); 1481 } 1482 EXPORT_SYMBOL_GPL(rcu_bind_current_to_nocb); 1483 1484 // The ->on_cpu field is available only in CONFIG_SMP=y, so... 1485 #ifdef CONFIG_SMP 1486 static char *show_rcu_should_be_on_cpu(struct task_struct *tsp) 1487 { 1488 return tsp && task_is_running(tsp) && !tsp->on_cpu ? "!" : ""; 1489 } 1490 #else // #ifdef CONFIG_SMP 1491 static char *show_rcu_should_be_on_cpu(struct task_struct *tsp) 1492 { 1493 return ""; 1494 } 1495 #endif // #else #ifdef CONFIG_SMP 1496 1497 /* 1498 * Dump out nocb grace-period kthread state for the specified rcu_data 1499 * structure. 1500 */ 1501 static void show_rcu_nocb_gp_state(struct rcu_data *rdp) 1502 { 1503 struct rcu_node *rnp = rdp->mynode; 1504 1505 pr_info("nocb GP %d %c%c%c%c%c %c[%c%c] %c%c:%ld rnp %d:%d %lu %c CPU %d%s\n", 1506 rdp->cpu, 1507 "kK"[!!rdp->nocb_gp_kthread], 1508 "lL"[raw_spin_is_locked(&rdp->nocb_gp_lock)], 1509 "dD"[!!rdp->nocb_defer_wakeup], 1510 "tT"[timer_pending(&rdp->nocb_timer)], 1511 "sS"[!!rdp->nocb_gp_sleep], 1512 ".W"[swait_active(&rdp->nocb_gp_wq)], 1513 ".W"[swait_active(&rnp->nocb_gp_wq[0])], 1514 ".W"[swait_active(&rnp->nocb_gp_wq[1])], 1515 ".B"[!!rdp->nocb_gp_bypass], 1516 ".G"[!!rdp->nocb_gp_gp], 1517 (long)rdp->nocb_gp_seq, 1518 rnp->grplo, rnp->grphi, READ_ONCE(rdp->nocb_gp_loops), 1519 rdp->nocb_gp_kthread ? task_state_to_char(rdp->nocb_gp_kthread) : '.', 1520 rdp->nocb_gp_kthread ? (int)task_cpu(rdp->nocb_gp_kthread) : -1, 1521 show_rcu_should_be_on_cpu(rdp->nocb_gp_kthread)); 1522 } 1523 1524 /* Dump out nocb kthread state for the specified rcu_data structure. */ 1525 static void show_rcu_nocb_state(struct rcu_data *rdp) 1526 { 1527 char bufd[22]; 1528 char bufw[45]; 1529 char bufr[45]; 1530 char bufn[22]; 1531 char bufb[22]; 1532 struct rcu_data *nocb_next_rdp; 1533 struct rcu_segcblist *rsclp = &rdp->cblist; 1534 bool waslocked; 1535 bool wassleep; 1536 1537 if (rdp->nocb_gp_rdp == rdp) 1538 show_rcu_nocb_gp_state(rdp); 1539 1540 if (!rcu_segcblist_is_offloaded(&rdp->cblist)) 1541 return; 1542 1543 nocb_next_rdp = list_next_or_null_rcu(&rdp->nocb_gp_rdp->nocb_head_rdp, 1544 &rdp->nocb_entry_rdp, 1545 typeof(*rdp), 1546 nocb_entry_rdp); 1547 1548 sprintf(bufd, "%ld", rsclp->seglen[RCU_DONE_TAIL]); 1549 sprintf(bufw, "%ld(%ld)", rsclp->seglen[RCU_WAIT_TAIL], rsclp->gp_seq[RCU_WAIT_TAIL]); 1550 sprintf(bufr, "%ld(%ld)", rsclp->seglen[RCU_NEXT_READY_TAIL], 1551 rsclp->gp_seq[RCU_NEXT_READY_TAIL]); 1552 sprintf(bufn, "%ld", rsclp->seglen[RCU_NEXT_TAIL]); 1553 sprintf(bufb, "%ld", rcu_cblist_n_cbs(&rdp->nocb_bypass)); 1554 pr_info(" CB %d^%d->%d %c%c%c%c%c F%ld L%ld C%d %c%s%c%s%c%s%c%s%c%s q%ld %c CPU %d%s\n", 1555 rdp->cpu, rdp->nocb_gp_rdp->cpu, 1556 nocb_next_rdp ? nocb_next_rdp->cpu : -1, 1557 "kK"[!!rdp->nocb_cb_kthread], 1558 "bB"[raw_spin_is_locked(&rdp->nocb_bypass_lock)], 1559 "lL"[raw_spin_is_locked(&rdp->nocb_lock)], 1560 "sS"[!!rdp->nocb_cb_sleep], 1561 ".W"[swait_active(&rdp->nocb_cb_wq)], 1562 jiffies - rdp->nocb_bypass_first, 1563 jiffies - rdp->nocb_nobypass_last, 1564 rdp->nocb_nobypass_count, 1565 ".D"[rcu_segcblist_ready_cbs(rsclp)], 1566 rcu_segcblist_segempty(rsclp, RCU_DONE_TAIL) ? "" : bufd, 1567 ".W"[!rcu_segcblist_segempty(rsclp, RCU_WAIT_TAIL)], 1568 rcu_segcblist_segempty(rsclp, RCU_WAIT_TAIL) ? "" : bufw, 1569 ".R"[!rcu_segcblist_segempty(rsclp, RCU_NEXT_READY_TAIL)], 1570 rcu_segcblist_segempty(rsclp, RCU_NEXT_READY_TAIL) ? "" : bufr, 1571 ".N"[!rcu_segcblist_segempty(rsclp, RCU_NEXT_TAIL)], 1572 rcu_segcblist_segempty(rsclp, RCU_NEXT_TAIL) ? "" : bufn, 1573 ".B"[!!rcu_cblist_n_cbs(&rdp->nocb_bypass)], 1574 !rcu_cblist_n_cbs(&rdp->nocb_bypass) ? "" : bufb, 1575 rcu_segcblist_n_cbs(&rdp->cblist), 1576 rdp->nocb_cb_kthread ? task_state_to_char(rdp->nocb_cb_kthread) : '.', 1577 rdp->nocb_cb_kthread ? (int)task_cpu(rdp->nocb_cb_kthread) : -1, 1578 show_rcu_should_be_on_cpu(rdp->nocb_cb_kthread)); 1579 1580 /* It is OK for GP kthreads to have GP state. */ 1581 if (rdp->nocb_gp_rdp == rdp) 1582 return; 1583 1584 waslocked = raw_spin_is_locked(&rdp->nocb_gp_lock); 1585 wassleep = swait_active(&rdp->nocb_gp_wq); 1586 if (!rdp->nocb_gp_sleep && !waslocked && !wassleep) 1587 return; /* Nothing untoward. */ 1588 1589 pr_info(" nocb GP activity on CB-only CPU!!! %c%c%c %c\n", 1590 "lL"[waslocked], 1591 "dD"[!!rdp->nocb_defer_wakeup], 1592 "sS"[!!rdp->nocb_gp_sleep], 1593 ".W"[wassleep]); 1594 } 1595 1596 #else /* #ifdef CONFIG_RCU_NOCB_CPU */ 1597 1598 /* No ->nocb_lock to acquire. */ 1599 static void rcu_nocb_lock(struct rcu_data *rdp) 1600 { 1601 } 1602 1603 /* No ->nocb_lock to release. */ 1604 static void rcu_nocb_unlock(struct rcu_data *rdp) 1605 { 1606 } 1607 1608 /* No ->nocb_lock to release. */ 1609 static void rcu_nocb_unlock_irqrestore(struct rcu_data *rdp, 1610 unsigned long flags) 1611 { 1612 local_irq_restore(flags); 1613 } 1614 1615 /* Lockdep check that ->cblist may be safely accessed. */ 1616 static void rcu_lockdep_assert_cblist_protected(struct rcu_data *rdp) 1617 { 1618 lockdep_assert_irqs_disabled(); 1619 } 1620 1621 static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq) 1622 { 1623 } 1624 1625 static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp) 1626 { 1627 return NULL; 1628 } 1629 1630 static void rcu_init_one_nocb(struct rcu_node *rnp) 1631 { 1632 } 1633 1634 static bool wake_nocb_gp(struct rcu_data *rdp) 1635 { 1636 return false; 1637 } 1638 1639 static bool rcu_nocb_flush_bypass(struct rcu_data *rdp, struct rcu_head *rhp, 1640 unsigned long j, bool lazy) 1641 { 1642 return true; 1643 } 1644 1645 static void call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *head, 1646 rcu_callback_t func, unsigned long flags, bool lazy) 1647 { 1648 WARN_ON_ONCE(1); /* Should be dead code! */ 1649 } 1650 1651 static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_empty, 1652 unsigned long flags) 1653 { 1654 WARN_ON_ONCE(1); /* Should be dead code! */ 1655 } 1656 1657 static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp) 1658 { 1659 } 1660 1661 static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp, int level) 1662 { 1663 return false; 1664 } 1665 1666 static bool do_nocb_deferred_wakeup(struct rcu_data *rdp) 1667 { 1668 return false; 1669 } 1670 1671 static void rcu_spawn_cpu_nocb_kthread(int cpu) 1672 { 1673 } 1674 1675 static void show_rcu_nocb_state(struct rcu_data *rdp) 1676 { 1677 } 1678 1679 #endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */ 1680