Linux cgroups development
 help / color / mirror / Atom feed
From: Waiman Long <llong@redhat.com>
To: Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Waiman Long <llong@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>
Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
	"Ingo Molnar" <mingo@redhat.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Vincent Guittot" <vincent.guittot@linaro.org>,
	"Steven Rostedt" <rostedt@goodmis.org>,
	"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
	"Valentin Schneider" <vschneid@redhat.com>,
	"Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Qais Yousef" <qyousef@layalina.io>,
	"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
	"Swapnil Sapkal" <swapnil.sapkal@amd.com>,
	"Shrikanth Hegde" <sshegde@linux.ibm.com>,
	"Phil Auld" <pauld@redhat.com>,
	luca.abeni@santannapisa.it, tommaso.cucinotta@santannapisa.it,
	"Jon Hunter" <jonathanh@nvidia.com>
Subject: Re: [PATCH v3 4/8] sched/deadline: Rebuild root domain accounting after every update
Date: Tue, 11 Mar 2025 10:51:51 -0400	[thread overview]
Message-ID: <7fb20de6-46a6-4e87-932e-dfc915fff3dc@redhat.com> (raw)
In-Reply-To: <e6731145-5290-41f8-aafb-1d0f1bcc385a@arm.com>

On 3/11/25 9:29 AM, Dietmar Eggemann wrote:
> On 11/03/2025 13:34, Waiman Long wrote:
>> On 3/11/25 7:59 AM, Juri Lelli wrote:
>>> On 10/03/25 20:16, Waiman Long wrote:
>>>> On 3/10/25 3:18 PM, Waiman Long wrote:
>>>>> On 3/10/25 2:54 PM, Dietmar Eggemann wrote:
>>>>>> On 10/03/2025 10:37, Juri Lelli wrote:
>>>>>>> Rebuilding of root domains accounting information (total_bw) is
>>>>>>> currently broken on some cases, e.g. suspend/resume on aarch64.
>>>>>>> Problem
>>>>>> Nit: Couldn't spot any arch dependency here. I guess it was just
>>>>>> tested
>>>>>> on Arm64 platforms so far.
>>>>>>
>>>>>> [...]
>>>>>>
>>>>>>> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
>>>>>>> index 44093339761c..363ad268a25b 100644
>>>>>>> --- a/kernel/sched/topology.c
>>>>>>> +++ b/kernel/sched/topology.c
>>>>>>> @@ -2791,6 +2791,7 @@ void partition_sched_domains_locked(int
>>>>>>> ndoms_new, cpumask_var_t doms_new[],
>>>>>>>         ndoms_cur = ndoms_new;
>>>>>>>           update_sched_domain_debugfs();
>>>>>>> +    dl_rebuild_rd_accounting();
>>>>>> Won't dl_rebuild_rd_accounting()'s lockdep_assert_held(&cpuset_mutex)
>>>>>> barf when called via cpuhp's:
>>>>>>
>>>>>> sched_cpu_deactivate()
>>>>>>
>>>>>>      cpuset_cpu_inactive()
>>>>>>
>>>>>>        partition_sched_domains()
>>>>>>
>>>>>>          partition_sched_domains_locked()
>>>>>>
>>>>>>            dl_rebuild_rd_accounting()
>>>>>>
>>>>>> ?
>>> Good catch. Guess I didn't notice while testing with LOCKDEP as I was
>>> never able to hit this call path on my systems.
>>>
>>>>> Right. If cpuhp_tasks_frozen is true, partition_sched_domains() will be
>>>>> called without holding cpuset mutex.
>>>>>
>>>>> Well, I think we will need an additional wrapper in cpuset.c that
>>>>> acquires the cpuset_mutex first before calling
>>>>> partition_sched_domains()
>>>>> and use the new wrapper in these cases.
>>>> Actually, partition_sched_domains() is called with the special
>>>> arguments (1,
>>>> NULL, NULL) to reset the domain to a single one. So perhaps something
>>>> like
>>>> the following will be enough to avoid this problem.
>>> I think this would work, as we will still rebuild the accounting after
>>> last CPU comes back from suspend. The thing I am still not sure about is
>>> what we want to do in case we have DEADLINE tasks around, since with
>>> this I belive we would be ignoring them and let suspend proceed.
>> That is the current behavior. You can certainly create a test case to
>> trigger such condition and see what to do about it. Alternatively, you
>> can document that and come up with a follow-up patch later on.
> But don't we rely on that partition_sched_domains_locked() calls
> dl_rebuild_rd_accounting() even in the reset_domain=1 case?
>
> Testcase: suspend/resume
>
> on Arm64 big.LITTLE cpumask=[LITTLE][big]=[0,3-5][1-2]
> plus cmd line option 'isolcpus=3,4'.
>
> with Waiman's snippet:
> https://lkml.kernel.org/r/fd4d6143-9bd2-4a7c-80dc-1e19e4d1b2d1@redhat.com
>
> ...
> [  234.831675] --- > partition_sched_domains_locked() reset_domain=1
> [  234.835966] psci: CPU4 killed (polled 0 ms)
> [  234.838912] Error taking CPU3 down: -16
> [  234.838952] Non-boot CPUs are not disabled
> [  234.838986] Enabling non-boot CPUs ...
> ...
>
> IIRC, that's the old DL accounting issue.

You are right. cpuhp_tasks_frozen will be set in the suspend/resume 
case. In that case, we do need to add a cpuset helper to acquire the 
cpuset_mutex. A test patch as follows (no testing done yet):

diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
index c414daa7d503..ef1ffb9c52b0 100644
--- a/include/linux/cpuset.h
+++ b/include/linux/cpuset.h
@@ -129,6 +129,7 @@ extern void dl_rebuild_rd_accounting(void);
  extern void rebuild_sched_domains(void);

  extern void cpuset_print_current_mems_allowed(void);
+extern void cpuset_reset_sched_domains(void)

  /*
   * read_mems_allowed_begin is required when making decisions involving
@@ -269,6 +270,11 @@ static inline void rebuild_sched_domains(void)
         partition_sched_domains(1, NULL, NULL);
  }

+static inline void cpuset_reset_sched_domains(void)
+{
+       partition_sched_domains(1, NULL, NULL);
+}
+
  static inline void cpuset_print_current_mems_allowed(void)
  {
  }
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 7995cd58a01b..a51099e5d587 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1076,6 +1076,13 @@ void rebuild_sched_domains(void)
         cpus_read_unlock();
  }

+void cpuset_reset_sched_domains(void)
+{
+       mutex_lock(&cpuset_mutex);
+       partition_sched_domains(1, NULL, NULL);
+       mutex_unlock(&cpuset_mutex);
+}
+
  /**
   * cpuset_update_tasks_cpumask - Update the cpumasks of tasks in the 
cpuset.
   * @cs: the cpuset in which each task's cpus_allowed mask needs to be 
changed
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 58593f4d09a1..dbf44ddbb6b4 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8183,7 +8183,7 @@ static void cpuset_cpu_active(void)
                  * operation in the resume sequence, just build a 
single sched
                  * domain, ignoring cpusets.
                  */
-               partition_sched_domains(1, NULL, NULL);
+               cpuset_reset_sched_domains();
                 if (--num_cpus_frozen)
                         return;
                 /*
@@ -8202,7 +8202,7 @@ static void cpuset_cpu_inactive(unsigned int cpu)
                 cpuset_update_active_cpus();
         } else {
                 num_cpus_frozen++;
-               partition_sched_domains(1, NULL, NULL);
+               cpuset_reset_sched_domains();
         }
  }

Cheers,
Longman

>


  reply	other threads:[~2025-03-11 14:51 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-10  9:19 [PATCH v3 0/8] Fix SCHED_DEADLINE bandwidth accounting during suspend Juri Lelli
2025-03-10  9:19 ` [PATCH v3 1/8] sched/deadline: Ignore special tasks when rebuilding domains Juri Lelli
2025-03-12 13:32   ` Valentin Schneider
2025-03-10  9:33 ` [PATCH v3 2/8] sched/topology: Wrappers for sched_domains_mutex Juri Lelli
2025-03-12 13:32   ` Valentin Schneider
2025-03-10  9:35 ` [PATCH v3 3/8] sched/deadline: Generalize unique visiting of root domains Juri Lelli
2025-03-12 13:32   ` Valentin Schneider
2025-03-10  9:37 ` [PATCH v3 4/8] sched/deadline: Rebuild root domain accounting after every update Juri Lelli
2025-03-10 18:54   ` Dietmar Eggemann
2025-03-10 19:18     ` Waiman Long
2025-03-11  0:16       ` Waiman Long
2025-03-11 11:59         ` Juri Lelli
2025-03-11 12:34           ` Waiman Long
2025-03-11 13:29             ` Dietmar Eggemann
2025-03-11 14:51               ` Waiman Long [this message]
2025-03-12  9:53                 ` Dietmar Eggemann
2025-03-12 10:09                   ` Juri Lelli
2025-03-12 13:55                     ` Waiman Long
2025-03-12 14:11                       ` Juri Lelli
2025-03-12 16:29                         ` Dietmar Eggemann
2025-03-12 16:51                           ` Juri Lelli
2025-03-13  9:09                             ` Dietmar Eggemann
2025-03-10  9:38 ` [PATCH v3 5/8] sched/topology: Remove redundant dl_clear_root_domain call Juri Lelli
2025-03-12 13:32   ` Valentin Schneider
2025-03-10  9:39 ` [PATCH v3 6/8] cgroup/cpuset: Remove partition_and_rebuild_sched_domains Juri Lelli
2025-03-12 13:32   ` Valentin Schneider
2025-03-10  9:40 ` [PATCH v3 7/8] sched/topology: Stop exposing partition_sched_domains_locked Juri Lelli
2025-03-12 13:32   ` Valentin Schneider
2025-03-10  9:40 ` [PATCH v3 8/8] include/{topology,cpuset}: Move dl_rebuild_rd_accounting to cpuset.h Juri Lelli
2025-03-12 13:32   ` Valentin Schneider

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=7fb20de6-46a6-4e87-932e-dfc915fff3dc@redhat.com \
    --to=llong@redhat.com \
    --cc=bigeasy@linutronix.de \
    --cc=bsegall@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=jonathanh@nvidia.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luca.abeni@santannapisa.it \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=mkoutny@suse.com \
    --cc=pauld@redhat.com \
    --cc=peterz@infradead.org \
    --cc=qyousef@layalina.io \
    --cc=rostedt@goodmis.org \
    --cc=sshegde@linux.ibm.com \
    --cc=swapnil.sapkal@amd.com \
    --cc=tj@kernel.org \
    --cc=tommaso.cucinotta@santannapisa.it \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.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