Skip to content

Commit 176f8f7

Browse files
committed
rcu: Make TASKS_RCU handle nohz_full= CPUs
Currently TASKS_RCU would ignore a CPU running a task in nohz_full= usermode execution. There would be neither a context switch nor a scheduling-clock interrupt to tell TASKS_RCU that the task in question had passed through a quiescent state. The grace period would therefore extend indefinitely. This commit therefore makes RCU's dyntick-idle subsystem record the task_struct structure of the task that is running in dyntick-idle mode on each CPU. The TASKS_RCU grace period can then access this information and record a quiescent state on behalf of any CPU running in dyntick-idle usermode. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 84a8f44 commit 176f8f7

6 files changed

Lines changed: 27 additions & 2 deletions

File tree

‎include/linux/init_task.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ extern struct group_info init_groups;
121121
#define INIT_TASK_RCU_TASKS(tsk) \
122122
.rcu_tasks_holdout = false, \
123123
.rcu_tasks_holdout_list = \
124-
LIST_HEAD_INIT(tsk.rcu_tasks_holdout_list),
124+
LIST_HEAD_INIT(tsk.rcu_tasks_holdout_list), \
125+
.rcu_tasks_idle_cpu = -1,
125126
#else
126127
#define INIT_TASK_RCU_TASKS(tsk)
127128
#endif

‎include/linux/sched.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,7 @@ struct task_struct {
12741274
unsigned long rcu_tasks_nvcsw;
12751275
bool rcu_tasks_holdout;
12761276
struct list_head rcu_tasks_holdout_list;
1277+
int rcu_tasks_idle_cpu;
12771278
#endif /* #ifdef CONFIG_TASKS_RCU */
12781279

12791280
#if defined(CONFIG_SCHEDSTATS) || defined(CONFIG_TASK_DELAY_ACCT)
@@ -2020,6 +2021,7 @@ static inline void rcu_copy_process(struct task_struct *p)
20202021
#ifdef CONFIG_TASKS_RCU
20212022
p->rcu_tasks_holdout = false;
20222023
INIT_LIST_HEAD(&p->rcu_tasks_holdout_list);
2024+
p->rcu_tasks_idle_cpu = -1;
20232025
#endif /* #ifdef CONFIG_TASKS_RCU */
20242026
}
20252027

‎kernel/rcu/tree.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
526526
atomic_inc(&rdtp->dynticks);
527527
smp_mb__after_atomic(); /* Force ordering with next sojourn. */
528528
WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
529+
rcu_dynticks_task_enter();
529530

530531
/*
531532
* It is illegal to enter an extended quiescent state while
@@ -642,6 +643,7 @@ void rcu_irq_exit(void)
642643
static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
643644
int user)
644645
{
646+
rcu_dynticks_task_exit();
645647
smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
646648
atomic_inc(&rdtp->dynticks);
647649
/* CPUs seeing atomic_inc() must see later RCU read-side crit sects */

‎kernel/rcu/tree.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,8 @@ static void rcu_sysidle_report_gp(struct rcu_state *rsp, int isidle,
605605
static void rcu_bind_gp_kthread(void);
606606
static void rcu_sysidle_init_percpu_data(struct rcu_dynticks *rdtp);
607607
static bool rcu_nohz_full_cpu(struct rcu_state *rsp);
608+
static void rcu_dynticks_task_enter(void);
609+
static void rcu_dynticks_task_exit(void);
608610

609611
#endif /* #ifndef RCU_TREE_NONCORE */
610612

‎kernel/rcu/tree_plugin.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,3 +3036,19 @@ static void rcu_bind_gp_kthread(void)
30363036
housekeeping_affine(current);
30373037
#endif /* #else #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
30383038
}
3039+
3040+
/* Record the current task on dyntick-idle entry. */
3041+
static void rcu_dynticks_task_enter(void)
3042+
{
3043+
#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
3044+
ACCESS_ONCE(current->rcu_tasks_idle_cpu) = smp_processor_id();
3045+
#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
3046+
}
3047+
3048+
/* Record no current task on dyntick-idle exit. */
3049+
static void rcu_dynticks_task_exit(void)
3050+
{
3051+
#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
3052+
ACCESS_ONCE(current->rcu_tasks_idle_cpu) = -1;
3053+
#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
3054+
}

‎kernel/rcu/update.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ static void check_holdout_task(struct task_struct *t,
463463
{
464464
if (!ACCESS_ONCE(t->rcu_tasks_holdout) ||
465465
t->rcu_tasks_nvcsw != ACCESS_ONCE(t->nvcsw) ||
466-
!ACCESS_ONCE(t->on_rq)) {
466+
!ACCESS_ONCE(t->on_rq) ||
467+
(IS_ENABLED(CONFIG_NO_HZ_FULL) &&
468+
!is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
467469
ACCESS_ONCE(t->rcu_tasks_holdout) = false;
468470
list_del_rcu(&t->rcu_tasks_holdout_list);
469471
put_task_struct(t);

0 commit comments

Comments
 (0)