All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chen Yu <yu.c.chen@intel.com>
To: Tim Chen <tim.c.chen@linux.intel.com>
Cc: Chen Yu <chen.yu@linux.dev>,
	Zhan Xusheng <zhanxusheng1024@gmail.com>, <peterz@infradead.org>,
	<mingo@redhat.com>, <juri.lelli@redhat.com>,
	<vincent.guittot@linaro.org>, <dietmar.eggemann@arm.com>,
	<rostedt@goodmis.org>, <bsegall@google.com>, <mgorman@suse.de>,
	<vschneid@redhat.com>, <kprateek.nayak@amd.com>,
	<linux-kernel@vger.kernel.org>, <zhanxusheng@xiaomi.com>
Subject: Re: sched/fair: which tasks should nr_pref_llc_running be compared against?
Date: Thu, 3 Sep 2026 23:21:13 +0800	[thread overview]
Message-ID: <apmQaelH5Y7czrOM@fengwei-dev> (raw)
In-Reply-To: <06ed8af87506f858176a81a4c29acf92d24b6dc7.camel@linux.intel.com>

On Tue, Sep 01, 2026 at 01:42:58PM -0700, Tim Chen wrote:
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 8dff37059faf..84c068f1deec 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1549,7 +1549,13 @@ static void account_llc_enqueue(struct rq *rq, struct task_struct *p)
>  
>  	pref_llc_queued = (pref_llc == task_llc(p));
>  	rq->nr_llc_running++;
> -	rq->nr_pref_llc_running += pref_llc_queued;

Since the logic in
account_llc_enqueue()/account_llc_dequeue()/
account_llc_delayed()/account_llc_requeue_delayed() are very
similar, can we introduce one helper for them:
static void account_llc_pref_running(struct rq *rq, struct task_struct *p, int delta)
{
       if (p->pref_llc_queued && !p->se.sched_delayed)
               rq->nr_pref_llc_running += delta;
}

> +	/*
> +	 * If the task is being migrated while delay dequeued, keep it out
> +	 * of the runnable-domain nr_pref_llc_running; clear_delayed() ->
> +	 * account_llc_requeue_delayed() re-adds it when it wakes.
> +	 */
> +	if (!p->se.sched_delayed)
> +		rq->nr_pref_llc_running += pref_llc_queued;
>

put after p->pref_llc_queued = pref_llc_queued;
account_llc_pref_running(rq, p, 1)

>  	/*
>  	 * Record whether p is enqueued on its preferred
> @@ -1583,7 +1589,14 @@ static void account_llc_dequeue(struct rq *rq, struct task_struct *p)
>  
>  	rq->nr_llc_running--;
>  	if (p->pref_llc_queued) {
> -		rq->nr_pref_llc_running--;
> +		/*
> +		 * If the task is being finally dequeued while still delayed,
> +		 * set_delayed() already removed it from nr_pref_llc_running;
> +		 * skip here to avoid underflow. Clearing pref_llc_queued also
> +		 * stops the subsequent clear_delayed() from re-adding it.
> +		 */
> +		if (!p->se.sched_delayed)
> +			rq->nr_pref_llc_running--;

account_llc_pref_running(rq, p, -1)

> +static void account_llc_delayed(struct rq *rq, struct task_struct *p)
> +{
> +	if (p->pref_llc_queued)
> +		rq->nr_pref_llc_running--;
> +}
> +
> +/* A delay-dequeued task becoming runnable again rejoins the count. */
> +static void account_llc_requeue_delayed(struct rq *rq, struct task_struct *p)
> +{
> +	if (p->pref_llc_queued)
> +		rq->nr_pref_llc_running++;
> +}
> +

Do not need above anymore.

>  
> +static void account_llc_delayed(struct rq *rq, struct task_struct *p) {}
> +
> +static void account_llc_requeue_delayed(struct rq *rq, struct task_struct *p) {}
> +
>  #endif /* CONFIG_SCHED_CACHE */
>  
>  /*
> @@ -6392,6 +6427,13 @@ static void set_delayed(struct sched_entity *se)
>  	if (!entity_is_task(se))
>  		return;
>  
> +	/*
> +	 * A delayed task is queued but no longer runnable. Drop it from
> +	 * nr_pref_llc_running so that counter keeps runnable semantics and
> +	 * stays comparable with h_nr_runnable in alb_break_llc().
> +	 */
> +	account_llc_delayed(rq_of(cfs_rq_of(se)), task_of(se));
> +

Added before the se->sched_delayed is set:
account_llc_pref_running(rq_of(cfs_rq_of(se)), task_of(se), -1);
se->sched_delayed = 1;

>  	for_each_sched_entity(se) {
>  		struct cfs_rq *cfs_rq = cfs_rq_of(se);
>  
> @@ -6412,6 +6454,13 @@ static void clear_delayed(struct sched_entity *se)
>  	if (!entity_is_task(se))
>  		return;
>  
> +	/*
> +	 * Re-add on wake (requeue_delayed_entity). On the final delayed
> +	 * dequeue, account_llc_dequeue() has already cleared pref_llc_queued,
> +	 * so this correctly does nothing.
> +	 */
> +	account_llc_requeue_delayed(rq_of(cfs_rq_of(se)), task_of(se));
> +

account_llc_pref_running(rq_of(cfs_rq_of(se)), task_of(se), 1);

thanks,
Chenyu
>  	for_each_sched_entity(se) {
>  		struct cfs_rq *cfs_rq = cfs_rq_of(se);
>  
> -- 
> 2.32.0
> 
> 
> 

  reply	other threads:[~2026-09-03 15:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 13:50 sched/fair: which tasks should nr_pref_llc_running be compared against? Zhan Xusheng
2026-08-27 20:57 ` Tim Chen
2026-08-28  2:20   ` [PATCH] sched/cache: Keep nr_pref_llc_running in the runnable domain Zhan Xusheng
2026-08-28 17:08     ` Tim Chen
2026-08-30  8:17   ` sched/fair: which tasks should nr_pref_llc_running be compared against? Chen Yu
2026-09-01 20:42     ` Tim Chen
2026-09-03 15:21       ` Chen Yu [this message]
2026-09-04 20:53         ` Tim Chen
2026-09-09 11:40           ` Chen Yu
2026-09-09 17:47             ` Tim Chen
2026-09-10 10:47               ` Chen Yu

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=apmQaelH5Y7czrOM@fengwei-dev \
    --to=yu.c.chen@intel.com \
    --cc=bsegall@google.com \
    --cc=chen.yu@linux.dev \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tim.c.chen@linux.intel.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=zhanxusheng1024@gmail.com \
    --cc=zhanxusheng@xiaomi.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.