mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tim Chen <tim.c.chen@linux.intel.com>
To: Chen Yu <yu.c.chen@intel.com>, Kayra Cizmeci <kayracizmeci@gmail.com>
Cc: brauner@kernel.org, bsegall@google.com, dietmar.eggemann@arm.com,
	 imv4bel@gmail.com, jack@suse.cz, juri.lelli@redhat.com,
	kees@kernel.org,  kprateek.nayak@amd.com,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, mgorman@suse.de,  mingo@redhat.com,
	peterz@infradead.org, qyousef@layalina.io,
	 ricardo.neri-calderon@linux.intel.com, rostedt@goodmis.org,
	srikar@linux.ibm.com, 	sshegde@linux.ibm.com,
	vincent.guittot@linaro.org, vineethr@linux.ibm.com,
		viro@zeniv.linux.org.uk, vschneid@redhat.com,
	wanglu.priv@gmail.com, 	yi1.lai@intel.com,
	zhanxusheng1024@gmail.com, zhanxusheng@xiaomi.com,
		ziqianlu@bytedance.com, chen.yu@linux.dev
Subject: Re: [PATCH 1/4] sched/cache: Keep nr_pref_llc_running in the runnable domain
Date: Mon, 14 Sep 2026 15:25:05 -0700	[thread overview]
Message-ID: <025bdcdef34170b1ffcc673c6b59cb51abc8fef5.camel@linux.intel.com> (raw)
In-Reply-To: <aqdVpO66OfmHvvqB@chenyu-dev>

On Mon, 2026-09-14 at 10:02 +0800, Chen Yu wrote:
> Hi Kayra,
> 
> On Fri, Sep 11, 2026 at 01:03:30AM +0300, Kayra Cizmeci wrote:
> > Hello Tim,
> > 
> > > So moving the accounting next to (or after) the h_nr_runnable update
> > > would make task_pref_llc_runnable() return false and skip the
> > > decrement, leaving nr_pref_llc_running too high.
> > 
> > What I really wanted wasn't getting the accounting next to or after the h_nr_runnable. 
> > If we are updating h_nr_runnable in some way that means we don't need
> > its check since it's already getting updated. And if it's getting updated
> > that means on that branch we know how our check should behave since we 
> > are a subset of it. We can skip the delayed check on that way since we are
> > trying to behave as h_nr_runnable's subset.
> > 
> > >        if (entity_is_task(se))
> > >                pref_llc_running_dec(...);      /* sched_delayed still 0 */
> > >        se->sched_delayed = 1;
> > >        ...
> > >        for_each_sched_entity(se)
> > >                cfs_rq->h_nr_runnable--;        /* sched_delayed already 1 */
> > 
> > For example:
> > 
> > In this code the h_nr_runnable is updated the same way regarding what is sched_delayed.
> > That means if we want to behave as a subset of it, we don't need the check delayed,
> > since we check the delayed to be a subset but if h_nr_runnable is decreasing/increasing
> > we should look into our checks.
> > 
> 
> I had a try according to your suggestion. It seems that the code becomes more complex
> and brings more headache :-( due to several corner cases. The current version is a simpler
> version with less code IMO. But I agree it looks a little hard to catch up with, so I added
> some comments around account_llc_dequeue() and adjusted the code sequence of clear_delayed()
> to make it easier to understand. Tim, could you please help check if this makes sense?
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index e64d9ad7a108..89311bbadfac 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -1609,8 +1609,58 @@ static void account_llc_dequeue(struct rq *rq, struct task_struct *p)
>  	if (p->pref_llc_queued) {
>  		/*
>  		 * Skipped if still delayed (set_delayed() already removed it);
> -		 * clearing pref_llc_queued below also stops clear_delayed()
> -		 * from re-adding it.
> +		 *
> +		 * The nr_pref_llc_running varies with h_nr_runnable, it involves
> +		 * set_delayed(), clear_delayed(), account_llc_enqueued() and account_llc_dequeue().
> +		 * The following shows two typical cases of how nr_pref_llc_running is maintained
> +		 * during enqueue/dequeue.
> +		 *
> +		 * case 1 - wakeup a delayed task

I assume both CPU0 and CPU1 in preferred LLC, and task woken on
CPU1.  Should say so.

> +		 *
> +		 * CPU0                                       CPU1
> +		 * __dequeue_task [fake dequeue]
> +		 *   set_delayed
> +		 *     rq0->nr_pref_llc_running--
> +		 *     p->se.sched_delayed = 1
> +		 *
> +		 *                                     try_to_wake_up(p)
> +		 *                                       enqueue_task_fair
> +		 *                                         requeue_delayed_entity
> +		 *                                           clear_delayed
> +		 *                                             rq0->nr_pref_llc_running++

							       rq1->nr_pref_llc_running++
> +		 *
> +		 *
> +		 * case 2 - LB for delayed task

LB for delayed task from a preferred LLC to a non-preferred LLC.

> +		 *
> +		 * CPU0                                       CPU1
> +		 * __dequeue_task [fake dequeue]
> +		 *   set_delayed
> +		 *     rq0->nr_pref_llc_running--
> +		 *     p->se.sched_delayed = 1
> +		 *
> +		 *
> +		 *                                     --------- load balance ---------
> +		 *                                     detach_task(p, rq0, migrate_load)
> +		 *                                       account_llc_dequeue
> +		 *                                         ** DO-NOT-DECREASE **
> +		 *                                         rq0->nr_pref_llc_running

						The above block should be under CPU 0

> +		 *
> +		 *                                     attach_task(p, rq1)
> +		 *                                       account_llc_enqueue
> +		 *                                         ** DO-NOT-INCREASE **
> +		 *                                         rq1->nr_pref_llc_running
> +		 *
> +		 *                                     pick_eevdf
> +		 *                                       __dequeue_task  [real dequeue]
> +		 *                                         account_llc_dequeue(DEQUEUE_DELAYED)
> +		 *                                           ** DO-NOT-DECREASE **
> +		 *                                           rq1->nr_pref_llc_running
> +		 *                                           p->pref_llc_queued = 0;
> +		 *
> +		 *                                         clear_delayed
> +		 *                                           p->se.sched_delayed = 0;
> +		 *                                           ** DO-NOT-INCREASE as pref_llc_queued=0 **
> +		 *                                           rq1->nr_pref_llc_running
>  		 */


Thanks for describing the operation scenario.
However the above cases are not comprehensive and a bit long for comment.


>  		pref_llc_running_dec(rq, p);
>  		/*
> @@ -6415,23 +6465,18 @@ static __always_inline void return_cfs_rq_runtime(struct cfs_rq *cfs_rq);
>  
>  static void set_delayed(struct sched_entity *se)
>  {
> -	/*
> -	 * Drop a task leaving the runnable set. Must run before sched_delayed
> -	 * is set, or task_pref_llc_runnable() would already exclude it;
> -	 * clear_delayed() mirrors this after clearing the flag.
> -	 */
> -	if (entity_is_task(se))
> -		pref_llc_running_dec(rq_of(cfs_rq_of(se)), task_of(se));
> -
> -	se->sched_delayed = 1;
> -
>  	/*
>  	 * Delayed se of cfs_rq have no tasks queued on them.
>  	 * Do not adjust h_nr_runnable since __dequeue_task()
>  	 * will account it for blocked tasks.
>  	 */
> -	if (!entity_is_task(se))
> +	if (!entity_is_task(se)) {
> +		se->sched_delayed = 1;
>  		return;
> +	}
> +
> +	pref_llc_running_dec(rq_of(cfs_rq_of(se)), task_of(se));
> +	se->sched_delayed = 1;

This change looks good and make the code cleaner.

Tim

>  
>  	for_each_sched_entity(se) {
>  		struct cfs_rq *cfs_rq = cfs_rq_of(se);

  parent reply	other threads:[~2026-09-14 22:25 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 17:46 [PATCH 0/4] sched/cache: Fixes for cache aware scheduling Tim Chen
2026-09-10 17:46 ` [PATCH 1/4] sched/cache: Keep nr_pref_llc_running in the runnable domain Tim Chen
2026-09-10 18:33   ` Kayra Cizmeci
2026-09-10 20:46     ` Tim Chen
2026-09-10 22:03       ` Kayra Cizmeci
2026-09-14  2:02         ` Chen Yu
2026-09-14  5:27           ` Kayra Cizmeci
2026-09-14 22:25           ` Tim Chen [this message]
2026-09-10 22:48   ` Kayra Cizmeci
2026-09-10 17:46 ` [PATCH 2/4] sched/cache: Honor migrate_llc_task semantics in active load balance Tim Chen
2026-09-10 17:46 ` [PATCH 3/4] sched/cache: Decouple sched_cache_group from mm Tim Chen
2026-09-10 17:46 ` [PATCH 4/4] sched/cache: Introduce task_struct->sched_cache_grp Tim Chen
2026-09-10 19:19   ` Peter Zijlstra
2026-09-10 22:50     ` Tim Chen
2026-09-14 14:34       ` 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=025bdcdef34170b1ffcc673c6b59cb51abc8fef5.camel@linux.intel.com \
    --to=tim.c.chen@linux.intel.com \
    --cc=brauner@kernel.org \
    --cc=bsegall@google.com \
    --cc=chen.yu@linux.dev \
    --cc=dietmar.eggemann@arm.com \
    --cc=imv4bel@gmail.com \
    --cc=jack@suse.cz \
    --cc=juri.lelli@redhat.com \
    --cc=kayracizmeci@gmail.com \
    --cc=kees@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=ricardo.neri-calderon@linux.intel.com \
    --cc=rostedt@goodmis.org \
    --cc=srikar@linux.ibm.com \
    --cc=sshegde@linux.ibm.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vineethr@linux.ibm.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vschneid@redhat.com \
    --cc=wanglu.priv@gmail.com \
    --cc=yi1.lai@intel.com \
    --cc=yu.c.chen@intel.com \
    --cc=zhanxusheng1024@gmail.com \
    --cc=zhanxusheng@xiaomi.com \
    --cc=ziqianlu@bytedance.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®