mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xuewen Yan <xuewen.yan@unisoc.com>
To: <vincent.guittot@linaro.org>, <peterz@infradead.org>,
	<mingo@redhat.com>, <juri.lelli@redhat.com>,
	<dietmar.eggemann@arm.com>, <rostedt@goodmis.org>,
	<bsegall@google.com>, <mgorman@suse.de>, <vschneid@redhat.com>
Cc: <linux-kernel@vger.kernel.org>, <ke.wang@unisoc.com>,
	<di.shen@unisoc.com>, <xuewen.yan94@gmail.com>
Subject: [RFC PATCH V2 3/3] sched: Do not consider the delayed task when cpu is about to enter idle
Date: Mon, 3 Mar 2025 18:52:41 +0800	[thread overview]
Message-ID: <20250303105241.17251-4-xuewen.yan@unisoc.com> (raw)
In-Reply-To: <20250303105241.17251-1-xuewen.yan@unisoc.com>

When there are one task with sched-delayed and one task
which is descheduling, Using nr-running to determine
CPU idle may be incorrect.
For example:
task-A is sched_delayed, task-B is descheduling:
1. before schedule():
   rq-nr-running=2, task-A->on_rq=1; task-B->on_rq=1;
2. after block_task(B):
   rq-nr-running=1, task-A->on_rq=1; task-B->on_rq=0;
3. after pick_next_task(), because the task-A would be dequeued:
   rq-nr-running=0, task-A->on_rq=0; task-B->on_rq=0;

In ttwu_queue_cond, it hope the nr-running to be 0 after
the step 2, however, now the nr-running is not 0.
So sub the nr-delayed-task when checking the rq-nr-running.

Fixes: 152e11f6df29 ("sched/fair: Implement delayed dequeue")
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
---
 kernel/sched/core.c  | 2 +-
 kernel/sched/fair.c  | 5 -----
 kernel/sched/sched.h | 5 +++++
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 67189907214d..6569f220c2fb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3963,7 +3963,7 @@ static inline bool ttwu_queue_cond(struct task_struct *p, int cpu)
 	 * p->on_cpu can be whatever, we've done the dequeue, so
 	 * the wakee has been accounted out of ->nr_running.
 	 */
-	if (!cpu_rq(cpu)->nr_running)
+	if (!(cpu_rq(cpu)->nr_running - cfs_h_nr_delayed(cpu_rq(cpu))))
 		return true;
 
 	return false;
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 8797f6872155..29ee1ce17036 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -7181,11 +7181,6 @@ static bool dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 	return true;
 }
 
-static inline unsigned int cfs_h_nr_delayed(struct rq *rq)
-{
-	return (rq->cfs.h_nr_queued - rq->cfs.h_nr_runnable);
-}
-
 #ifdef CONFIG_SMP
 
 /* Working cpumask for: sched_balance_rq(), sched_balance_newidle(). */
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index c8512a9fb022..3996b0c5c332 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -3609,6 +3609,11 @@ static inline bool is_per_cpu_kthread(struct task_struct *p)
 }
 #endif
 
+static inline unsigned int cfs_h_nr_delayed(struct rq *rq)
+{
+	return (rq->cfs.h_nr_queued - rq->cfs.h_nr_runnable);
+}
+
 extern void swake_up_all_locked(struct swait_queue_head *q);
 extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
 
-- 
2.25.1


  parent reply	other threads:[~2025-03-03 10:53 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 10:52 [RFC PATCH V2 0/3] sched/fair: Fix nr-running vs delayed-dequeue Xuewen Yan
2025-03-03 10:52 ` [RFC PATCH V2 1/3] sched/fair: Fixup-wake_up_sync-vs-DELAYED_DEQUEUE Xuewen Yan
2025-03-19  9:05   ` Tianchen Ding
2025-03-19  9:34   ` Vincent Guittot
2025-05-20  6:00     ` Xuewen Yan
2025-05-21 12:06   ` [tip: sched/core] sched/fair: Fixup wake_up_sync() vs DELAYED_DEQUEUE tip-bot2 for Xuewen Yan
2025-03-03 10:52 ` [RFC PATCH V2 2/3] sched/fair: Do not consider the sched-delayed task when yield Xuewen Yan
2025-03-03 10:52 ` Xuewen Yan [this message]
2025-03-03 12:00 ` [RFC PATCH V2 0/3] sched/fair: Fix nr-running vs delayed-dequeue Peter Zijlstra
2025-03-04  1:56   ` Xuewen Yan
2025-03-05  8:17     ` Vincent Guittot
2025-03-06  7:33       ` Xuewen Yan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250303105241.17251-4-xuewen.yan@unisoc.com \
    --to=xuewen.yan@unisoc.com \
    --cc=bsegall@google.com \
    --cc=di.shen@unisoc.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=ke.wang@unisoc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=xuewen.yan94@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®