Skip to content

Commit 126c209

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
sched: Add rq::ttwu_pending
In preparation of removing rq->wake_list, replace the !list_empty(rq->wake_list) with rq->ttwu_pending. This is not fully equivalent as this new variable is racy. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4b44a21 commit 126c209

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

kernel/sched/core.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,13 +2275,21 @@ static int ttwu_remote(struct task_struct *p, int wake_flags)
22752275
void sched_ttwu_pending(void)
22762276
{
22772277
struct rq *rq = this_rq();
2278-
struct llist_node *llist = llist_del_all(&rq->wake_list);
2278+
struct llist_node *llist;
22792279
struct task_struct *p, *t;
22802280
struct rq_flags rf;
22812281

2282+
llist = llist_del_all(&rq->wake_list);
22822283
if (!llist)
22832284
return;
22842285

2286+
/*
2287+
* rq::ttwu_pending racy indication of out-standing wakeups.
2288+
* Races such that false-negatives are possible, since they
2289+
* are shorter lived that false-positives would be.
2290+
*/
2291+
WRITE_ONCE(rq->ttwu_pending, 0);
2292+
22852293
rq_lock_irqsave(rq, &rf);
22862294
update_rq_clock(rq);
22872295

@@ -2318,6 +2326,7 @@ static void __ttwu_queue_wakelist(struct task_struct *p, int cpu, int wake_flags
23182326

23192327
p->sched_remote_wakeup = !!(wake_flags & WF_MIGRATED);
23202328

2329+
WRITE_ONCE(rq->ttwu_pending, 1);
23212330
if (llist_add(&p->wake_entry, &rq->wake_list)) {
23222331
if (!set_nr_if_polling(rq->idle))
23232332
smp_call_function_single_async(cpu, &rq->wake_csd);
@@ -4705,7 +4714,7 @@ int idle_cpu(int cpu)
47054714
return 0;
47064715

47074716
#ifdef CONFIG_SMP
4708-
if (!llist_empty(&rq->wake_list))
4717+
if (rq->ttwu_pending)
47094718
return 0;
47104719
#endif
47114720

kernel/sched/debug.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ do { \
638638

639639
P(nr_running);
640640
P(nr_switches);
641-
P(nr_load_updates);
642641
P(nr_uninterruptible);
643642
PN(next_balance);
644643
SEQ_printf(m, " .%-30s: %ld\n", "curr->pid", (long)(task_pid_nr(rq->curr)));

kernel/sched/fair.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8590,7 +8590,7 @@ static int idle_cpu_without(int cpu, struct task_struct *p)
85908590
*/
85918591

85928592
#ifdef CONFIG_SMP
8593-
if (!llist_empty(&rq->wake_list))
8593+
if (rq->ttwu_pending)
85948594
return 0;
85958595
#endif
85968596

kernel/sched/sched.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,9 @@ struct rq {
895895
atomic_t nohz_flags;
896896
#endif /* CONFIG_NO_HZ_COMMON */
897897

898-
unsigned long nr_load_updates;
898+
#ifdef CONFIG_SMP
899+
unsigned int ttwu_pending;
900+
#endif
899901
u64 nr_switches;
900902

901903
#ifdef CONFIG_UCLAMP_TASK

0 commit comments

Comments
 (0)