Lines Matching +full:wait +full:- +full:on +full:- +full:read
1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Task-based RCU implementations.
24 * struct rcu_tasks_percpu - Per-CPU component of definition for a Tasks-RCU-like mechanism.
26 * @lock: Lock protecting per-CPU callback list.
29 * @urgent_gp: Number of additional non-lazy grace periods.
30 * @rtp_n_lock_retries: Rough lock-contention statistic.
58 * struct rcu_tasks - Definition for a Tasks-RCU-like mechanism.
59 * @cbs_wait: RCU wait allowing a new callback to get kthread's attention.
61 * @tasks_gp_mutex: Mutex protecting grace period, needed during mid-boot dead zone.
62 * @gp_func: This flavor's grace-period-wait function.
64 * @gp_sleep: Per-grace-period sleep to prevent CPU-bound looping.
67 * @gp_start: Most recent grace-period start in jiffies.
70 * @n_ipis_fails: Number of IPI-send failures.
71 * @kthread_ptr: This flavor's grace-period/callback-invocation kthread.
73 * @pregp_func: This flavor's pre-grace-period function (optional).
74 * @pertask_func: This flavor's per-task scan function (optional).
75 * @postscan_func: This flavor's post-task scan function (optional).
76 * @holdouts_func: This flavor's holdout-list scan function (optional).
77 * @postgp_func: This flavor's post-grace-period function (optional).
78 * @call_func: This flavor's call_rcu()-equivalent function.
79 * @wait_state: Task state for synchronous grace-period waits (default TASK_UNINTERRUPTIBLE).
83 * @percpu_enqueue_lim: Number of per-CPU callback queues in use for enqueuing.
84 * @percpu_dequeue_lim: Number of per-CPU callback queues in use for dequeuing.
85 * @percpu_dequeue_gpseq: RCU grace-period number to propagate enqueue limit to dequeuers.
87 * @barrier_q_count: Number of queues being waited on.
88 * @barrier_q_completion: Barrier wait/wakeup mechanism.
140 .cbs_wait = __RCUWAIT_INITIALIZER(rt_name.wait), \
153 .barrier_q_seq = (0UL - 50UL) << RCU_SEQ_CTR_SHIFT, \
180 static int rcu_task_enqueue_lim __read_mostly = -1;
193 /* RCU tasks grace-period state for debugging. */
229 /* Record grace-period phase and time. */
232 rtp->gp_state = newstate; in set_tasks_gp_state()
233 rtp->gp_jiffies = jiffies; in set_tasks_gp_state()
240 int i = data_race(rtp->gp_state); // Let KCSAN detect update races in tasks_gp_state_getname()
249 // Initialize per-CPU callback lists for the specified flavor of
267 rtp->rtpcp_array = kcalloc(num_possible_cpus(), sizeof(struct rcu_tasks_percpu *), GFP_KERNEL); in cblist_init_generic()
268 BUG_ON(!rtp->rtpcp_array); in cblist_init_generic()
271 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu); in cblist_init_generic()
276 if (rcu_segcblist_empty(&rtpcp->cblist)) in cblist_init_generic()
277 rcu_segcblist_init(&rtpcp->cblist); in cblist_init_generic()
278 INIT_WORK(&rtpcp->rtp_work, rcu_tasks_invoke_cbs_wq); in cblist_init_generic()
279 rtpcp->cpu = cpu; in cblist_init_generic()
280 rtpcp->rtpp = rtp; in cblist_init_generic()
281 rtpcp->index = index; in cblist_init_generic()
282 rtp->rtpcp_array[index] = rtpcp; in cblist_init_generic()
284 if (!rtpcp->rtp_blkd_tasks.next) in cblist_init_generic()
285 INIT_LIST_HEAD(&rtpcp->rtp_blkd_tasks); in cblist_init_generic()
286 if (!rtpcp->rtp_exit_list.next) in cblist_init_generic()
287 INIT_LIST_HEAD(&rtpcp->rtp_exit_list); in cblist_init_generic()
288 rtpcp->barrier_q_head.next = &rtpcp->barrier_q_head; in cblist_init_generic()
296 if (((rcu_task_cpu_ids - 1) >> shift) >= lim) in cblist_init_generic()
298 WRITE_ONCE(rtp->percpu_enqueue_shift, shift); in cblist_init_generic()
299 WRITE_ONCE(rtp->percpu_dequeue_lim, lim); in cblist_init_generic()
300 smp_store_release(&rtp->percpu_enqueue_lim, lim); in cblist_init_generic()
303 rtp->name, data_race(rtp->percpu_enqueue_shift), data_race(rtp->percpu_enqueue_lim), in cblist_init_generic()
310 return jiffies + rtp->lazy_jiffies; in rcu_tasks_lazy_time()
321 rtp = rtpcp->rtpp; in call_rcu_tasks_generic_timer()
323 if (!rcu_segcblist_empty(&rtpcp->cblist) && rtp->lazy_jiffies) { in call_rcu_tasks_generic_timer()
324 if (!rtpcp->urgent_gp) in call_rcu_tasks_generic_timer()
325 rtpcp->urgent_gp = 1; in call_rcu_tasks_generic_timer()
327 mod_timer(&rtpcp->lazy_timer, rcu_tasks_lazy_time(rtp)); in call_rcu_tasks_generic_timer()
331 rcuwait_wake_up(&rtp->cbs_wait); in call_rcu_tasks_generic_timer()
334 // IRQ-work handler that does deferred wakeup for call_rcu_tasks_generic().
340 rtp = rtpcp->rtpp; in call_rcu_tasks_iw_wakeup()
341 rcuwait_wake_up(&rtp->cbs_wait); in call_rcu_tasks_iw_wakeup()
350 bool havekthread = smp_load_acquire(&rtp->kthread_ptr); in call_rcu_tasks_generic()
357 rhp->next = NULL; in call_rcu_tasks_generic()
358 rhp->func = func; in call_rcu_tasks_generic()
361 ideal_cpu = smp_processor_id() >> READ_ONCE(rtp->percpu_enqueue_shift); in call_rcu_tasks_generic()
362 chosen_cpu = cpumask_next(ideal_cpu - 1, cpu_possible_mask); in call_rcu_tasks_generic()
364 rtpcp = per_cpu_ptr(rtp->rtpcpu, chosen_cpu); in call_rcu_tasks_generic()
368 if (rtpcp->rtp_jiffies != j) { in call_rcu_tasks_generic()
369 rtpcp->rtp_jiffies = j; in call_rcu_tasks_generic()
370 rtpcp->rtp_n_lock_retries = 0; in call_rcu_tasks_generic()
372 if (rcu_task_cb_adjust && ++rtpcp->rtp_n_lock_retries > rcu_task_contend_lim && in call_rcu_tasks_generic()
373 READ_ONCE(rtp->percpu_enqueue_lim) != rcu_task_cpu_ids) in call_rcu_tasks_generic()
377 if (WARN_ON_ONCE(!rcu_segcblist_is_enabled(&rtpcp->cblist))) in call_rcu_tasks_generic()
378 rcu_segcblist_init(&rtpcp->cblist); in call_rcu_tasks_generic()
380 (rcu_segcblist_n_cbs(&rtpcp->cblist) == rcu_task_lazy_lim); in call_rcu_tasks_generic()
381 if (havekthread && !needwake && !timer_pending(&rtpcp->lazy_timer)) { in call_rcu_tasks_generic()
382 if (rtp->lazy_jiffies) in call_rcu_tasks_generic()
383 mod_timer(&rtpcp->lazy_timer, rcu_tasks_lazy_time(rtp)); in call_rcu_tasks_generic()
385 needwake = rcu_segcblist_empty(&rtpcp->cblist); in call_rcu_tasks_generic()
388 rtpcp->urgent_gp = 3; in call_rcu_tasks_generic()
389 rcu_segcblist_enqueue(&rtpcp->cblist, rhp); in call_rcu_tasks_generic()
392 raw_spin_lock_irqsave(&rtp->cbs_gbl_lock, flags); in call_rcu_tasks_generic()
393 if (rtp->percpu_enqueue_lim != rcu_task_cpu_ids) { in call_rcu_tasks_generic()
394 WRITE_ONCE(rtp->percpu_enqueue_shift, 0); in call_rcu_tasks_generic()
395 WRITE_ONCE(rtp->percpu_dequeue_lim, rcu_task_cpu_ids); in call_rcu_tasks_generic()
396 smp_store_release(&rtp->percpu_enqueue_lim, rcu_task_cpu_ids); in call_rcu_tasks_generic()
397 pr_info("Switching %s to per-CPU callback queuing.\n", rtp->name); in call_rcu_tasks_generic()
399 raw_spin_unlock_irqrestore(&rtp->cbs_gbl_lock, flags); in call_rcu_tasks_generic()
403 if (needwake && READ_ONCE(rtp->kthread_ptr)) in call_rcu_tasks_generic()
404 irq_work_queue(&rtpcp->rtp_irq_work); in call_rcu_tasks_generic()
413 rhp->next = rhp; // Mark the callback as having been invoked. in rcu_barrier_tasks_generic_cb()
415 rtp = rtpcp->rtpp; in rcu_barrier_tasks_generic_cb()
416 if (atomic_dec_and_test(&rtp->barrier_q_count)) in rcu_barrier_tasks_generic_cb()
417 complete(&rtp->barrier_q_completion); in rcu_barrier_tasks_generic_cb()
420 // Wait for all in-flight callbacks for the specified RCU Tasks flavor.
427 unsigned long s = rcu_seq_snap(&rtp->barrier_q_seq); in rcu_barrier_tasks_generic()
429 mutex_lock(&rtp->barrier_q_mutex); in rcu_barrier_tasks_generic()
430 if (rcu_seq_done(&rtp->barrier_q_seq, s)) { in rcu_barrier_tasks_generic()
432 mutex_unlock(&rtp->barrier_q_mutex); in rcu_barrier_tasks_generic()
435 rtp->barrier_q_start = jiffies; in rcu_barrier_tasks_generic()
436 rcu_seq_start(&rtp->barrier_q_seq); in rcu_barrier_tasks_generic()
437 init_completion(&rtp->barrier_q_completion); in rcu_barrier_tasks_generic()
438 atomic_set(&rtp->barrier_q_count, 2); in rcu_barrier_tasks_generic()
440 if (cpu >= smp_load_acquire(&rtp->percpu_dequeue_lim)) in rcu_barrier_tasks_generic()
442 rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu); in rcu_barrier_tasks_generic()
443 rtpcp->barrier_q_head.func = rcu_barrier_tasks_generic_cb; in rcu_barrier_tasks_generic()
445 if (rcu_segcblist_entrain(&rtpcp->cblist, &rtpcp->barrier_q_head)) in rcu_barrier_tasks_generic()
446 atomic_inc(&rtp->barrier_q_count); in rcu_barrier_tasks_generic()
449 if (atomic_sub_and_test(2, &rtp->barrier_q_count)) in rcu_barrier_tasks_generic()
450 complete(&rtp->barrier_q_completion); in rcu_barrier_tasks_generic()
451 wait_for_completion(&rtp->barrier_q_completion); in rcu_barrier_tasks_generic()
452 rcu_seq_end(&rtp->barrier_q_seq); in rcu_barrier_tasks_generic()
453 mutex_unlock(&rtp->barrier_q_mutex); in rcu_barrier_tasks_generic()
463 bool gpdone = poll_state_synchronize_rcu(rtp->percpu_dequeue_gpseq); in rcu_tasks_need_gpcb()
469 dequeue_limit = smp_load_acquire(&rtp->percpu_dequeue_lim); in rcu_tasks_need_gpcb()
473 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu); in rcu_tasks_need_gpcb()
476 if (!rcu_segcblist_n_cbs(&rtpcp->cblist)) in rcu_tasks_need_gpcb()
480 n = rcu_segcblist_n_cbs(&rtpcp->cblist); in rcu_tasks_need_gpcb()
486 rcu_segcblist_advance(&rtpcp->cblist, rcu_seq_current(&rtp->tasks_gp_seq)); in rcu_tasks_need_gpcb()
487 (void)rcu_segcblist_accelerate(&rtpcp->cblist, rcu_seq_snap(&rtp->tasks_gp_seq)); in rcu_tasks_need_gpcb()
488 if (rtpcp->urgent_gp > 0 && rcu_segcblist_pend_cbs(&rtpcp->cblist)) { in rcu_tasks_need_gpcb()
489 if (rtp->lazy_jiffies) in rcu_tasks_need_gpcb()
490 rtpcp->urgent_gp--; in rcu_tasks_need_gpcb()
492 } else if (rcu_segcblist_empty(&rtpcp->cblist)) { in rcu_tasks_need_gpcb()
493 rtpcp->urgent_gp = 0; in rcu_tasks_need_gpcb()
495 if (rcu_segcblist_ready_cbs(&rtpcp->cblist)) in rcu_tasks_need_gpcb()
502 // rcu_task_collapse_lim callbacks on CPU 0 and none on any other in rcu_tasks_need_gpcb()
505 // to CPU 0. Note the matching RCU read-side critical section in in rcu_tasks_need_gpcb()
508 raw_spin_lock_irqsave(&rtp->cbs_gbl_lock, flags); in rcu_tasks_need_gpcb()
509 if (rtp->percpu_enqueue_lim > 1) { in rcu_tasks_need_gpcb()
510 WRITE_ONCE(rtp->percpu_enqueue_shift, order_base_2(rcu_task_cpu_ids)); in rcu_tasks_need_gpcb()
511 smp_store_release(&rtp->percpu_enqueue_lim, 1); in rcu_tasks_need_gpcb()
512 rtp->percpu_dequeue_gpseq = get_state_synchronize_rcu(); in rcu_tasks_need_gpcb()
514 pr_info("Starting switch %s to CPU-0 callback queuing.\n", rtp->name); in rcu_tasks_need_gpcb()
516 raw_spin_unlock_irqrestore(&rtp->cbs_gbl_lock, flags); in rcu_tasks_need_gpcb()
519 raw_spin_lock_irqsave(&rtp->cbs_gbl_lock, flags); in rcu_tasks_need_gpcb()
520 if (rtp->percpu_enqueue_lim < rtp->percpu_dequeue_lim) { in rcu_tasks_need_gpcb()
521 WRITE_ONCE(rtp->percpu_dequeue_lim, 1); in rcu_tasks_need_gpcb()
522 pr_info("Completing switch %s to CPU-0 callback queuing.\n", rtp->name); in rcu_tasks_need_gpcb()
524 if (rtp->percpu_dequeue_lim == 1) { in rcu_tasks_need_gpcb()
525 for (cpu = rtp->percpu_dequeue_lim; cpu < rcu_task_cpu_ids; cpu++) { in rcu_tasks_need_gpcb()
528 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu); in rcu_tasks_need_gpcb()
530 WARN_ON_ONCE(rcu_segcblist_n_cbs(&rtpcp->cblist)); in rcu_tasks_need_gpcb()
533 raw_spin_unlock_irqrestore(&rtp->cbs_gbl_lock, flags); in rcu_tasks_need_gpcb()
550 index = rtpcp->index * 2 + 1; in rcu_tasks_invoke_cbs()
552 rtpcp_next = rtp->rtpcp_array[index]; in rcu_tasks_invoke_cbs()
553 if (rtpcp_next->cpu < smp_load_acquire(&rtp->percpu_dequeue_lim)) { in rcu_tasks_invoke_cbs()
554 cpuwq = rcu_cpu_beenfullyonline(rtpcp_next->cpu) ? rtpcp_next->cpu : WORK_CPU_UNBOUND; in rcu_tasks_invoke_cbs()
555 queue_work_on(cpuwq, system_wq, &rtpcp_next->rtp_work); in rcu_tasks_invoke_cbs()
558 rtpcp_next = rtp->rtpcp_array[index]; in rcu_tasks_invoke_cbs()
559 if (rtpcp_next->cpu < smp_load_acquire(&rtp->percpu_dequeue_lim)) { in rcu_tasks_invoke_cbs()
560 cpuwq = rcu_cpu_beenfullyonline(rtpcp_next->cpu) ? rtpcp_next->cpu : WORK_CPU_UNBOUND; in rcu_tasks_invoke_cbs()
561 queue_work_on(cpuwq, system_wq, &rtpcp_next->rtp_work); in rcu_tasks_invoke_cbs()
567 if (rcu_segcblist_empty(&rtpcp->cblist)) in rcu_tasks_invoke_cbs()
570 rcu_segcblist_advance(&rtpcp->cblist, rcu_seq_current(&rtp->tasks_gp_seq)); in rcu_tasks_invoke_cbs()
571 rcu_segcblist_extract_done_cbs(&rtpcp->cblist, &rcl); in rcu_tasks_invoke_cbs()
577 rhp->func(rhp); in rcu_tasks_invoke_cbs()
582 rcu_segcblist_add_len(&rtpcp->cblist, -len); in rcu_tasks_invoke_cbs()
583 (void)rcu_segcblist_accelerate(&rtpcp->cblist, rcu_seq_snap(&rtp->tasks_gp_seq)); in rcu_tasks_invoke_cbs()
593 rtp = rtpcp->rtpp; in rcu_tasks_invoke_cbs_wq()
597 // Wait for one grace period.
602 mutex_lock(&rtp->tasks_gp_mutex); in rcu_tasks_one_gp()
604 // If there were none, wait a bit and start over. in rcu_tasks_one_gp()
608 mutex_unlock(&rtp->tasks_gp_mutex); in rcu_tasks_one_gp()
610 rcuwait_wait_event(&rtp->cbs_wait, in rcu_tasks_one_gp()
613 mutex_lock(&rtp->tasks_gp_mutex); in rcu_tasks_one_gp()
617 // Wait for one grace period. in rcu_tasks_one_gp()
619 rtp->gp_start = jiffies; in rcu_tasks_one_gp()
620 rcu_seq_start(&rtp->tasks_gp_seq); in rcu_tasks_one_gp()
621 rtp->gp_func(rtp); in rcu_tasks_one_gp()
622 rcu_seq_end(&rtp->tasks_gp_seq); in rcu_tasks_one_gp()
627 rcu_tasks_invoke_cbs(rtp, per_cpu_ptr(rtp->rtpcpu, 0)); in rcu_tasks_one_gp()
628 mutex_unlock(&rtp->tasks_gp_mutex); in rcu_tasks_one_gp()
631 // RCU-tasks kthread that detects grace periods and invokes callbacks.
638 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu); in rcu_tasks_kthread()
640 timer_setup(&rtpcp->lazy_timer, call_rcu_tasks_generic_timer, 0); in rcu_tasks_kthread()
641 rtpcp->urgent_gp = 1; in rcu_tasks_kthread()
644 /* Run on housekeeping CPUs by default. Sysadm can move if desired. */ in rcu_tasks_kthread()
646 smp_store_release(&rtp->kthread_ptr, current); // Let GPs start! in rcu_tasks_kthread()
651 * one RCU-tasks grace period and then invokes the callbacks. in rcu_tasks_kthread()
652 * This loop is terminated by the system going down. ;-) in rcu_tasks_kthread()
655 // Wait for one grace period and invoke any callbacks in rcu_tasks_kthread()
660 schedule_timeout_idle(rtp->gp_sleep); in rcu_tasks_kthread()
664 // Wait for a grace period for the specified flavor of Tasks RCU.
669 "synchronize_%s() called too soon", rtp->name)) in synchronize_rcu_tasks_generic()
672 // If the grace-period kthread is running, use it. in synchronize_rcu_tasks_generic()
673 if (READ_ONCE(rtp->kthread_ptr)) { in synchronize_rcu_tasks_generic()
674 wait_rcu_gp_state(rtp->wait_state, rtp->call_func); in synchronize_rcu_tasks_generic()
680 /* Spawn RCU-tasks grace-period kthread. */
685 t = kthread_run(rcu_tasks_kthread, rtp, "%s_kthread", rtp->kname); in rcu_spawn_tasks_kthread_generic()
686 …NCE(IS_ERR(t), "%s: Could not start %s grace-period kthread, OOM is now expected behavior\n", __fu… in rcu_spawn_tasks_kthread_generic()
694 * Print any non-default Tasks RCU settings.
702 …pr_info("\tTasks-RCU CPU stall warnings timeout set to %d (rcu_task_stall_timeout).\n", rcu_task_s… in rcu_tasks_bootup_oddness()
705 …pr_info("\tTasks-RCU CPU stall info multiplier clamped to %d (rcu_task_stall_info_mult).\n", rtsim… in rcu_tasks_bootup_oddness()
721 /* Dump out rcutorture-relevant state common to all RCU-tasks flavors. */
730 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu); in show_rcu_tasks_generic_gp_kthread()
732 if (!data_race(rcu_segcblist_empty(&rtpcp->cblist))) in show_rcu_tasks_generic_gp_kthread()
734 if (data_race(rtpcp->urgent_gp)) in show_rcu_tasks_generic_gp_kthread()
736 if (!data_race(rcu_segcblist_empty(&rtpcp->cblist)) && data_race(rtpcp->urgent_gp)) in show_rcu_tasks_generic_gp_kthread()
742 rtp->kname, in show_rcu_tasks_generic_gp_kthread()
743 tasks_gp_state_getname(rtp), data_race(rtp->gp_state), in show_rcu_tasks_generic_gp_kthread()
744 jiffies - data_race(rtp->gp_jiffies), in show_rcu_tasks_generic_gp_kthread()
745 data_race(rcu_seq_current(&rtp->tasks_gp_seq)), in show_rcu_tasks_generic_gp_kthread()
746 data_race(rtp->n_ipis_fails), data_race(rtp->n_ipis), in show_rcu_tasks_generic_gp_kthread()
747 ".k"[!!data_race(rtp->kthread_ptr)], in show_rcu_tasks_generic_gp_kthread()
751 rtp->lazy_jiffies, in show_rcu_tasks_generic_gp_kthread()
755 /* Dump out more rcutorture-relevant state common to all RCU-tasks flavors. */
765 tt, tf, tst, data_race(rtp->tasks_gp_seq), in rcu_tasks_torture_stats_print_generic()
766 j - data_race(rtp->gp_start), j - data_race(rtp->gp_jiffies), in rcu_tasks_torture_stats_print_generic()
767 data_race(rtp->gp_state), tasks_gp_state_getname(rtp)); in rcu_tasks_torture_stats_print_generic()
769 data_race(rtp->percpu_enqueue_shift), in rcu_tasks_torture_stats_print_generic()
770 data_race(rtp->percpu_enqueue_lim), in rcu_tasks_torture_stats_print_generic()
771 data_race(rtp->percpu_dequeue_lim), in rcu_tasks_torture_stats_print_generic()
772 data_race(rtp->percpu_dequeue_gpseq)); in rcu_tasks_torture_stats_print_generic()
777 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu); in rcu_tasks_torture_stats_print_generic()
779 if (cpumask_available(cm) && !rcu_barrier_cb_is_done(&rtpcp->barrier_q_head)) in rcu_tasks_torture_stats_print_generic()
781 n = rcu_segcblist_n_cbs(&rtpcp->cblist); in rcu_tasks_torture_stats_print_generic()
792 data_race(rtp->barrier_q_seq), j - data_race(rtp->barrier_q_start), in rcu_tasks_torture_stats_print_generic()
793 atomic_read(&rtp->barrier_q_count)); in rcu_tasks_torture_stats_print_generic()
809 // Shared code between task-list-scanning variants of Tasks RCU.
811 /* Wait for one RCU-tasks grace period. */
825 rtp->pregp_func(&holdouts); in rcu_tasks_wait_gp()
828 * There were callbacks, so we need to wait for an RCU-tasks in rcu_tasks_wait_gp()
834 if (rtp->pertask_func) { in rcu_tasks_wait_gp()
837 rtp->pertask_func(t, &holdouts); in rcu_tasks_wait_gp()
842 rtp->postscan_func(&holdouts); in rcu_tasks_wait_gp()
853 // Start off with initial wait and slowly back off to 1 HZ wait. in rcu_tasks_wait_gp()
854 fract = rtp->init_fract; in rcu_tasks_wait_gp()
884 rtp->holdouts_func(&holdouts, needreport, &firstreport); in rcu_tasks_wait_gp()
886 // Print pre-stall informational messages if needed. in rcu_tasks_wait_gp()
892 __func__, rtp->kname, rtp->tasks_gp_seq, j - rtp->gp_start); in rcu_tasks_wait_gp()
897 rtp->postgp_func(rtp); in rcu_tasks_wait_gp()
907 // switch, cond_resched_tasks_rcu_qs(), user-space execution, and idle.
909 // read-side primitives similar to rcu_read_lock() and rcu_read_unlock()
913 // rates from multiple CPUs. If this is required, per-CPU callback lists
916 // The implementation uses rcu_tasks_wait_gp(), which relies on function
922 // Invokes synchronize_rcu() in order to wait for all in-flight
923 // t->on_rq and t->nvcsw transitions to complete. This works because
925 // rcu_tasks_pertask(), invoked on every non-idle task:
926 // For every runnable non-idle task other than the current one, use
931 // Gather per-CPU lists of tasks in do_exit() to ensure that all
935 // will take care of any tasks stuck in the non-preemptible region
939 // for each task on the list. If there is a quiescent state, the
943 // t->on_rq and t->nvcsw transitions are seen by all CPUs and tasks
950 // current task to a per-CPU list of tasks that rcu_tasks_postscan() must
951 // wait on. This is necessary because rcu_tasks_postscan() must wait on
954 // Pre-grace-period update-side code is ordered before the grace
955 // via the raw_spin_lock.*rcu_node(). Pre-grace-period read-side code
960 /* Pre-grace-period preparation. */
964 * Wait for all pre-existing t->on_rq and t->nvcsw transitions in rcu_tasks_pregp_step()
967 * synchronize_rcu(), a read-side critical section that started in rcu_tasks_pregp_step()
972 * memory barrier on the first store to t->rcu_tasks_holdout, in rcu_tasks_pregp_step()
985 if (!READ_ONCE(t->on_rq)) in rcu_tasks_is_holdout()
989 * t->on_rq && !t->se.sched_delayed *could* be considered sleeping but in rcu_tasks_is_holdout()
998 * Idle tasks (or idle injection) within the idle loop are RCU-tasks in rcu_tasks_is_holdout()
1007 /* Idle tasks on offline CPUs are RCU-tasks quiescent states. */ in rcu_tasks_is_holdout()
1014 /* Per-task initial processing. */
1019 t->rcu_tasks_nvcsw = READ_ONCE(t->nvcsw); in rcu_tasks_pertask()
1020 WRITE_ONCE(t->rcu_tasks_holdout, true); in rcu_tasks_pertask()
1021 list_add(&t->rcu_tasks_holdout_list, hop); in rcu_tasks_pertask()
1043 * read side critical sections: in rcu_tasks_postscan()
1049 * 2) An _RCU_ read side starting with the final preempt_disable() in rcu_tasks_postscan()
1065 list_for_each_entry_safe(t, t1, &rtpcp->rtp_exit_list, rcu_tasks_exit_list) { in rcu_tasks_postscan()
1066 if (list_empty(&t->rcu_tasks_holdout_list)) in rcu_tasks_postscan()
1077 list_add(&tmp, &t->rcu_tasks_exit_list); in rcu_tasks_postscan()
1098 if (!READ_ONCE(t->rcu_tasks_holdout) || in check_holdout_task()
1099 t->rcu_tasks_nvcsw != READ_ONCE(t->nvcsw) || in check_holdout_task()
1102 !is_idle_task(t) && READ_ONCE(t->rcu_tasks_idle_cpu) >= 0)) { in check_holdout_task()
1103 WRITE_ONCE(t->rcu_tasks_holdout, false); in check_holdout_task()
1104 list_del_init(&t->rcu_tasks_holdout_list); in check_holdout_task()
1112 pr_err("INFO: rcu_tasks detected stalls on tasks:\n"); in check_holdout_task()
1119 t->rcu_tasks_nvcsw, t->nvcsw, t->rcu_tasks_holdout, in check_holdout_task()
1120 data_race(t->rcu_tasks_idle_cpu), cpu); in check_holdout_task()
1136 /* Finish off the Tasks-RCU grace period. */
1140 * Because ->on_rq and ->nvcsw are not guaranteed to have a full in rcu_tasks_postgp()
1142 * reordering on other CPUs could cause their RCU-tasks read-side in rcu_tasks_postgp()
1144 * However, because these ->nvcsw updates are carried out with in rcu_tasks_postgp()
1146 * needed ordering on all such CPUs. in rcu_tasks_postgp()
1148 * This synchronize_rcu() also confines all ->rcu_tasks_holdout in rcu_tasks_postgp()
1150 * memory barriers for ->rcu_tasks_holdout accesses. in rcu_tasks_postgp()
1156 * read side critical section. in rcu_tasks_postgp()
1169 tasks_gp_state_getname(&rcu_tasks), jiffies - rcu_tasks.gp_jiffies); in tasks_rcu_exit_srcu_stall()
1177 * call_rcu_tasks() - Queue an RCU for invocation task-based grace period
1183 * read-side critical sections have completed. call_rcu_tasks() assumes
1184 * that the read-side critical sections end at a voluntary context
1186 * or transition to usermode execution. As such, there are no read-side
1189 * through a safe state, not so much for data-structure synchronization.
1191 * See the description of call_rcu() for more detailed information on
1201 * synchronize_rcu_tasks - wait until an rcu-tasks grace period has elapsed.
1203 * Control will return to the caller some time after a full rcu-tasks
1205 * executing rcu-tasks read-side critical sections have elapsed. These
1206 * read-side critical sections are delimited by calls to schedule(),
1216 * on memory ordering guarantees.
1225 * rcu_barrier_tasks - Wait for in-flight call_rcu_tasks() callbacks.
1227 * Although the current implementation is guaranteed to wait, it is not
1236 static int rcu_tasks_lazy_ms = -1;
1298 WARN_ON_ONCE(!list_empty(&t->rcu_tasks_exit_list)); in exit_tasks_rcu_start()
1301 t->rcu_tasks_exit_cpu = smp_processor_id(); in exit_tasks_rcu_start()
1303 WARN_ON_ONCE(!rtpcp->rtp_exit_list.next); in exit_tasks_rcu_start()
1304 list_add(&t->rcu_tasks_exit_list, &rtpcp->rtp_exit_list); in exit_tasks_rcu_start()
1311 * non-preemptible, allowing synchronize_rcu() to wait beyond this point.
1319 WARN_ON_ONCE(list_empty(&t->rcu_tasks_exit_list)); in exit_tasks_rcu_finish()
1320 rtpcp = per_cpu_ptr(rcu_tasks.rtpcpu, t->rcu_tasks_exit_cpu); in exit_tasks_rcu_finish()
1322 list_del_init(&t->rcu_tasks_exit_list); in exit_tasks_rcu_finish()
1342 // context switches on all online CPUs, whether idle or not.
1346 // Ordering is provided by the scheduler's context-switch code.
1353 // Wait for one rude RCU-tasks grace period.
1356 rtp->n_ipis += cpumask_weight(cpu_online_mask); in rcu_tasks_rude_wait_gp()
1365 * call_rcu_tasks_rude() - Queue a callback rude task-based grace period
1371 * read-side critical sections have completed. call_rcu_tasks_rude()
1372 * assumes that the read-side critical sections end at context switch,
1374 * usermode execution is schedulable). As such, there are no read-side
1377 * through a safe state, not so much for data-structure synchronization.
1379 * See the description of call_rcu() for more detailed information on
1391 * synchronize_rcu_tasks_rude - wait for a rude rcu-tasks grace period
1393 * Control will return to the caller some time after a rude rcu-tasks
1395 * executing rcu-tasks read-side critical sections have elapsed. These
1396 * read-side critical sections are delimited by calls to schedule(),
1406 * on memory ordering guarantees.
1457 // 1. Has explicit read-side markers to allow finite grace periods
1458 // in the face of in-kernel loops for PREEMPT=n builds.
1461 // CPU-hotplug code paths, similar to the capabilities of SRCU.
1463 // 3. Avoids expensive read-side instructions, having overhead similar
1466 // There are of course downsides. For example, the grace-period code
1476 // The implementation uses rcu_tasks_wait_gp(), which relies on function
1484 // or were preempted within their current RCU Tasks Trace read-side
1486 // Finally, this function re-enables CPU hotplug.
1487 // The ->pertask_func() pointer is NULL, so there is no per-task processing.
1489 // Invokes synchronize_rcu() to wait for late-stage exiting tasks
1493 // for each task on the list. If there is a quiescent state, the
1501 // Pre-grace-period update-side code is ordered before the grace period
1502 // via the ->cbs_lock and barriers in rcu_tasks_kthread(). Pre-grace-period
1503 // read-side code is ordered before the grace period by atomic operations
1504 // on .b.need_qs flag of each task involved in this process, or by scheduler
1505 // context-switch ordering (for locked-down non-running readers).
1520 // The number of detections of task quiescent state relying on
1531 /* Load from ->trc_reader_special.b.need_qs with proper ordering. */
1534 smp_mb(); // Enforce full grace-period ordering. in rcu_ld_need_qs()
1535 return smp_load_acquire(&t->trc_reader_special.b.need_qs); in rcu_ld_need_qs()
1538 /* Store to ->trc_reader_special.b.need_qs with proper ordering. */
1541 smp_store_release(&t->trc_reader_special.b.need_qs, v); in rcu_st_need_qs()
1542 smp_mb(); // Enforce full grace-period ordering. in rcu_st_need_qs()
1546 * Do a cmpxchg() on ->trc_reader_special.b.need_qs, allowing for
1547 * the four-byte operand-size restriction of some platforms.
1553 return cmpxchg(&t->trc_reader_special.b.need_qs, old, new); in rcu_trc_cmpxchg_need_qs()
1558 * If we are the last reader, signal the grace-period kthread.
1559 * Also remove from the per-CPU list of blocked tasks.
1567 // Open-coded full-word version of rcu_ld_need_qs(). in rcu_read_unlock_trace_special()
1568 smp_mb(); // Enforce full grace-period ordering. in rcu_read_unlock_trace_special()
1569 trs = smp_load_acquire(&t->trc_reader_special); in rcu_read_unlock_trace_special()
1571 if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB) && t->trc_reader_special.b.need_mb) in rcu_read_unlock_trace_special()
1572 smp_mb(); // Pairs with update-side barriers. in rcu_read_unlock_trace_special()
1573 // Update .need_qs before ->trc_reader_nesting for irq/NMI handlers. in rcu_read_unlock_trace_special()
1581 rtpcp = per_cpu_ptr(rcu_tasks_trace.rtpcpu, t->trc_blkd_cpu); in rcu_read_unlock_trace_special()
1583 list_del_init(&t->trc_blkd_node); in rcu_read_unlock_trace_special()
1584 WRITE_ONCE(t->trc_reader_special.b.blocked, false); in rcu_read_unlock_trace_special()
1587 WRITE_ONCE(t->trc_reader_nesting, 0); in rcu_read_unlock_trace_special()
1600 t->trc_blkd_cpu = smp_processor_id(); in rcu_tasks_trace_qs_blkd()
1601 if (!rtpcp->rtp_blkd_tasks.next) in rcu_tasks_trace_qs_blkd()
1602 INIT_LIST_HEAD(&rtpcp->rtp_blkd_tasks); in rcu_tasks_trace_qs_blkd()
1603 list_add(&t->trc_blkd_node, &rtpcp->rtp_blkd_tasks); in rcu_tasks_trace_qs_blkd()
1604 WRITE_ONCE(t->trc_reader_special.b.blocked, true); in rcu_tasks_trace_qs_blkd()
1609 /* Add a task to the holdout list, if it is not already on the list. */
1612 if (list_empty(&t->trc_holdout_list)) { in trc_add_holdout()
1614 list_add(&t->trc_holdout_list, bhp); in trc_add_holdout()
1622 if (!list_empty(&t->trc_holdout_list)) { in trc_del_holdout()
1623 list_del_init(&t->trc_holdout_list); in trc_del_holdout()
1625 n_trc_holdouts--; in trc_del_holdout()
1636 // If the task is no longer running on this CPU, leave. in trc_read_check_handler()
1638 goto reset_ipi; // Already on holdout list, so will check later. in trc_read_check_handler()
1640 // If the task is not in a read-side critical section, and in trc_read_check_handler()
1641 // if this is the last reader, awaken the grace-period kthread. in trc_read_check_handler()
1642 nesting = READ_ONCE(t->trc_reader_nesting); in trc_read_check_handler()
1651 // Get here if the task is in a read-side critical section. in trc_read_check_handler()
1652 // Set its state so that it will update state for the grace-period in trc_read_check_handler()
1657 // Allow future IPIs to be sent on CPU and for task. in trc_read_check_handler()
1661 smp_store_release(&texp->trc_ipi_to_cpu, -1); // ^^^ in trc_read_check_handler()
1664 /* Callback function for scheduler to check locked-down task. */
1675 return -EINVAL; in trc_inspect_reader()
1677 // If heavyweight readers are enabled on the remote task, in trc_inspect_reader()
1681 // Check for "running" idle tasks on offline CPUs. in trc_inspect_reader()
1682 if (!rcu_watching_zero_in_eqs(cpu, &t->trc_reader_nesting)) in trc_inspect_reader()
1683 return -EINVAL; // No quiescent state, do it the hard way. in trc_inspect_reader()
1687 // The task is not running, so C-language access is safe. in trc_inspect_reader()
1688 nesting = t->trc_reader_nesting; in trc_inspect_reader()
1694 // If not exiting a read-side critical section, mark as checked in trc_inspect_reader()
1695 // so that the grace-period kthread will remove it from the in trc_inspect_reader()
1702 return -EINVAL; // Reader transitioning, try again later. in trc_inspect_reader()
1704 // The task is in a read-side critical section, so set up its in trc_inspect_reader()
1719 if (smp_load_acquire(&t->trc_ipi_to_cpu) != -1) // Order IPI in trc_wait_for_one_reader()
1725 WARN_ON_ONCE(READ_ONCE(t->trc_reader_nesting)); in trc_wait_for_one_reader()
1737 // If this task is not yet on the holdout list, then we are in in trc_wait_for_one_reader()
1738 // an RCU read-side critical section. Otherwise, the invocation of in trc_wait_for_one_reader()
1751 if (per_cpu(trc_ipi_to_cpu, cpu) || t->trc_ipi_to_cpu >= 0) in trc_wait_for_one_reader()
1755 t->trc_ipi_to_cpu = cpu; in trc_wait_for_one_reader()
1764 t->trc_ipi_to_cpu = -1; in trc_wait_for_one_reader()
1770 * Initialize for first-round processing for the specified task.
1776 // is no idle task for the other CPUs. Also, the grace-period in rcu_tasks_trace_pertask_prep()
1778 // if this task is already on the list. in rcu_tasks_trace_pertask_prep()
1779 if (unlikely(t == NULL) || (t == current && notself) || !list_empty(&t->trc_holdout_list)) in rcu_tasks_trace_pertask_prep()
1783 t->trc_ipi_to_cpu = -1; in rcu_tasks_trace_pertask_prep()
1787 /* Do first-round processing for the specified task. */
1794 /* Initialize for a new RCU-tasks-trace grace period. */
1809 // in CPU-hotplug code paths. in rcu_tasks_trace_pregp_step()
1819 // the grace-period kthread will see that task's read-side in rcu_tasks_trace_pregp_step()
1820 // critical section or the task will see the updater's pre-GP in rcu_tasks_trace_pregp_step()
1835 // current RCU tasks trace read-side critical section. in rcu_tasks_trace_pregp_step()
1839 list_splice_init(&rtpcp->rtp_blkd_tasks, &blkd_tasks); in rcu_tasks_trace_pregp_step()
1843 list_del_init(&t->trc_blkd_node); in rcu_tasks_trace_pregp_step()
1844 list_add(&t->trc_blkd_node, &rtpcp->rtp_blkd_tasks); in rcu_tasks_trace_pregp_step()
1854 // Re-enable CPU hotplug now that the holdout list is populated. in rcu_tasks_trace_pregp_step()
1863 // Wait for late-stage exiting tasks to finish exiting. in rcu_tasks_trace_postscan()
1869 // TRC_NEED_QS_CHECKED in ->trc_reader_special.b.need_qs. in rcu_tasks_trace_postscan()
1885 trc_rdrp->nesting = READ_ONCE(t->trc_reader_nesting); in trc_check_slow_task()
1886 trc_rdrp->ipi_to_cpu = READ_ONCE(t->trc_ipi_to_cpu); in trc_check_slow_task()
1887 trc_rdrp->needqs = rcu_ld_need_qs(t); in trc_check_slow_task()
1899 pr_err("INFO: rcu_tasks_trace detected stalls on tasks:\n"); in show_stalled_task_trace()
1905 t->pid, in show_stalled_task_trace()
1906 ".I"[t->trc_ipi_to_cpu >= 0], in show_stalled_task_trace()
1910 t->pid, in show_stalled_task_trace()
1914 ".B"[!!data_race(t->trc_reader_special.b.blocked)], in show_stalled_task_trace()
1943 if (READ_ONCE(t->trc_ipi_to_cpu) == -1 && in check_all_holdout_tasks_trace()
1948 if (smp_load_acquire(&t->trc_ipi_to_cpu) == -1 && in check_all_holdout_tasks_trace()
1956 // Re-enable CPU hotplug now that the holdout list scan has completed. in check_all_holdout_tasks_trace()
1970 /* Wait for grace period to complete and provide ordering. */
1975 // Wait for any lingering IPI handlers to complete. Note that in rcu_tasks_trace_postgp()
1979 // changes, there will need to be a recheck and/or timed wait. in rcu_tasks_trace_postgp()
1991 union rcu_special trs = READ_ONCE(t->trc_reader_special); in exit_tasks_rcu_finish_trace()
1994 WARN_ON_ONCE(READ_ONCE(t->trc_reader_nesting)); in exit_tasks_rcu_finish_trace()
1998 WRITE_ONCE(t->trc_reader_nesting, 0); in exit_tasks_rcu_finish_trace()
2002 * call_rcu_tasks_trace() - Queue a callback trace task-based grace period
2006 * The callback function will be invoked some time after a trace rcu-tasks
2008 * trace rcu-tasks read-side critical sections have completed. These
2009 * read-side critical sections are delimited by calls to rcu_read_lock_trace()
2012 * See the description of call_rcu() for more detailed information on
2022 * synchronize_rcu_tasks_trace - wait for a trace rcu-tasks grace period
2024 * Control will return to the caller some time after a trace rcu-tasks
2026 * trace rcu-tasks read-side critical sections have elapsed. These read-side
2036 * on memory ordering guarantees.
2040 …race_lock_map), "Illegal synchronize_rcu_tasks_trace() in RCU Tasks Trace read-side critical secti… in synchronize_rcu_tasks_trace()
2046 * rcu_barrier_tasks_trace - Wait for in-flight call_rcu_tasks_trace() callbacks.
2048 * Although the current implementation is guaranteed to wait, it is not
2057 int rcu_tasks_trace_lazy_ms = -1;
2157 pr_info("Callback from %s invoked.\n", rttd->name); in test_rcu_tasks_callback()
2159 rttd->notrun = false; in test_rcu_tasks_callback()
2166 pr_info("Running RCU Tasks wait API self tests\n"); in rcu_tasks_initiate_self_tests()
2173 pr_info("Running RCU Tasks Rude wait API self tests\n"); in rcu_tasks_initiate_self_tests()
2178 pr_info("Running RCU Tasks Trace wait API self tests\n"); in rcu_tasks_initiate_self_tests()
2186 * Return: 0 - test passed
2187 * 1 - test failed, but have not timed out yet
2188 * -1 - test failed and timed out
2201 pr_err("%s has failed boot-time tests.\n", tests[i].name); in rcu_tasks_verify_self_tests()
2202 ret = -1; in rcu_tasks_verify_self_tests()
2273 // Run the self-tests. in rcu_init_tasks_generic()