public inbox for linux-tegra@vger.kernel.org
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: Juri Lelli <juri.lelli@redhat.com>,
	Waiman Long <longman@redhat.com>, Tejun Heo <tj@kernel.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Michal Koutny <mkoutny@suse.com>, Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	Phil Auld <pauld@redhat.com>
Cc: Qais Yousef <qyousef@layalina.io>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	"Joel Fernandes (Google)" <joel@joelfernandes.org>,
	Suleiman Souhlal <suleiman@google.com>,
	Aashish Sharma <shraash@google.com>,
	Shin Kawamura <kawasin@google.com>,
	Vineeth Remanan Pillai <vineeth@bitbyteword.org>,
	linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
	"linux-tegra@vger.kernel.org" <linux-tegra@vger.kernel.org>
Subject: Re: [PATCH v2 3/2] sched/deadline: Check bandwidth overflow earlier for hotplug
Date: Fri, 10 Jan 2025 11:52:38 +0000	[thread overview]
Message-ID: <ba51a43f-796d-4b79-808a-b8185905638a@nvidia.com> (raw)
In-Reply-To: <Zzc1DfPhbvqDDIJR@jlelli-thinkpadt14gen4.remote.csb>

Hi Juri,

On 15/11/2024 11:48, Juri Lelli wrote:
> Currently we check for bandwidth overflow potentially due to hotplug
> operations at the end of sched_cpu_deactivate(), after the cpu going
> offline has already been removed from scheduling, active_mask, etc.
> This can create issues for DEADLINE tasks, as there is a substantial
> race window between the start of sched_cpu_deactivate() and the moment
> we possibly decide to roll-back the operation if dl_bw_deactivate()
> returns failure in cpuset_cpu_inactive(). An example is a throttled
> task that sees its replenishment timer firing while the cpu it was
> previously running on is considered offline, but before
> dl_bw_deactivate() had a chance to say no and roll-back happened.
> 
> Fix this by directly calling dl_bw_deactivate() first thing in
> sched_cpu_deactivate() and do the required calculation in the former
> function considering the cpu passed as an argument as offline already.
> 
> By doing so we also simplify sched_cpu_deactivate(), as there is no need
> anymore for any kind of roll-back if we fail early.
> 
> Signed-off-by: Juri Lelli <juri.lelli@redhat.com>
> ---
> Thanks Waiman and Phil for testing and reviewing the scratch version of
> this change. I think the below might be better, as we end up with a
> clean-up as well.
> 
> Please take another look when you/others have time.
> ---
>   kernel/sched/core.c     | 22 +++++++---------------
>   kernel/sched/deadline.c | 12 ++++++++++--
>   2 files changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index d1049e784510..e2c6eacf793e 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -8054,19 +8054,14 @@ static void cpuset_cpu_active(void)
>   	cpuset_update_active_cpus();
>   }
>   
> -static int cpuset_cpu_inactive(unsigned int cpu)
> +static void cpuset_cpu_inactive(unsigned int cpu)
>   {
>   	if (!cpuhp_tasks_frozen) {
> -		int ret = dl_bw_deactivate(cpu);
> -
> -		if (ret)
> -			return ret;
>   		cpuset_update_active_cpus();
>   	} else {
>   		num_cpus_frozen++;
>   		partition_sched_domains(1, NULL, NULL);
>   	}
> -	return 0;
>   }
>   
>   static inline void sched_smt_present_inc(int cpu)
> @@ -8128,6 +8123,11 @@ int sched_cpu_deactivate(unsigned int cpu)
>   	struct rq *rq = cpu_rq(cpu);
>   	int ret;
>   
> +	ret = dl_bw_deactivate(cpu);
> +
> +	if (ret)
> +		return ret;
> +
>   	/*
>   	 * Remove CPU from nohz.idle_cpus_mask to prevent participating in
>   	 * load balancing when not active
> @@ -8173,15 +8173,7 @@ int sched_cpu_deactivate(unsigned int cpu)
>   		return 0;
>   
>   	sched_update_numa(cpu, false);
> -	ret = cpuset_cpu_inactive(cpu);
> -	if (ret) {
> -		sched_smt_present_inc(cpu);
> -		sched_set_rq_online(rq, cpu);
> -		balance_push_set(cpu, false);
> -		set_cpu_active(cpu, true);
> -		sched_update_numa(cpu, true);
> -		return ret;
> -	}
> +	cpuset_cpu_inactive(cpu);
>   	sched_domains_numa_masks_clear(cpu);
>   	return 0;
>   }
> diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
> index 267ea8bacaf6..6e988d4cd787 100644
> --- a/kernel/sched/deadline.c
> +++ b/kernel/sched/deadline.c
> @@ -3505,6 +3505,13 @@ static int dl_bw_manage(enum dl_bw_request req, int cpu, u64 dl_bw)
>   		}
>   		break;
>   	case dl_bw_req_deactivate:
> +		/*
> +		 * cpu is not off yet, but we need to do the math by
> +		 * considering it off already (i.e., what would happen if we
> +		 * turn cpu off?).
> +		 */
> +		cap -= arch_scale_cpu_capacity(cpu);
> +
>   		/*
>   		 * cpu is going offline and NORMAL tasks will be moved away
>   		 * from it. We can thus discount dl_server bandwidth
> @@ -3522,9 +3529,10 @@ static int dl_bw_manage(enum dl_bw_request req, int cpu, u64 dl_bw)
>   		if (dl_b->total_bw - fair_server_bw > 0) {
>   			/*
>   			 * Leaving at least one CPU for DEADLINE tasks seems a
> -			 * wise thing to do.
> +			 * wise thing to do. As said above, cpu is not offline
> +			 * yet, so account for that.
>   			 */
> -			if (dl_bw_cpus(cpu))
> +			if (dl_bw_cpus(cpu) - 1)
>   				overflow = __dl_overflow(dl_b, cap, fair_server_bw, 0);
>   			else
>   				overflow = 1;


I have noticed a suspend regression on one of our Tegra boards and 
bisect is pointing to this commit. If I revert this on top of -next then 
I don't see the issue.

The only messages I see when suspend fails are ...

[   53.905976] Error taking CPU1 down: -16
[   53.909887] Non-boot CPUs are not disabled

So far this is only happening on Tegra186 (ARM64). Let me know if you 
have any thoughts.

Thanks
Jon

-- 
nvpublic


       reply	other threads:[~2025-01-10 11:52 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20241114142810.794657-1-juri.lelli@redhat.com>
     [not found] ` <ZzYhyOQh3OAsrPo9@jlelli-thinkpadt14gen4.remote.csb>
     [not found]   ` <Zzc1DfPhbvqDDIJR@jlelli-thinkpadt14gen4.remote.csb>
2025-01-10 11:52     ` Jon Hunter [this message]
2025-01-10 15:45       ` [PATCH v2 3/2] sched/deadline: Check bandwidth overflow earlier for hotplug Juri Lelli
2025-01-10 18:40         ` Jon Hunter
2025-01-13  9:32           ` Juri Lelli
2025-01-13 13:53             ` Jon Hunter
2025-01-14 13:52             ` Jon Hunter
2025-01-14 14:02               ` Juri Lelli
2025-01-15 16:10                 ` Juri Lelli
2025-01-16 13:14                   ` Jon Hunter
2025-01-16 15:55                     ` Juri Lelli
2025-02-03 11:01                       ` Jon Hunter
2025-02-04 17:26                         ` Juri Lelli
2025-02-05  6:53                         ` Juri Lelli
2025-02-05 10:12                           ` Juri Lelli
2025-02-05 16:56                             ` Jon Hunter
2025-02-06  9:29                               ` Juri Lelli
2025-02-07 10:38                                 ` Jon Hunter
2025-02-07 13:38                                   ` Dietmar Eggemann
2025-02-07 14:04                                     ` Jon Hunter
2025-02-07 15:55                                       ` Christian Loehle
2025-02-10 17:09                                         ` Juri Lelli
2025-02-11  8:36                                           ` Dietmar Eggemann
2025-02-11  9:21                                             ` Juri Lelli
2025-02-11 10:43                                               ` Dietmar Eggemann
2025-02-11 10:15                                           ` Christian Loehle
2025-02-11 10:42                                             ` Juri Lelli
2025-02-12 18:22                                               ` Dietmar Eggemann
2025-02-13  6:20                                                 ` Juri Lelli
2025-02-13 12:27                                                   ` Christian Loehle
2025-02-13 13:33                                                     ` Juri Lelli
2025-02-13 13:38                                                       ` Christian Loehle
2025-02-13 14:51                                                         ` Juri Lelli
2025-02-13 14:57                                                           ` Christian Loehle
2025-02-16 16:33                                                   ` Qais Yousef
2025-02-17 14:52                                                     ` Juri Lelli
2025-02-22 23:59                                                       ` Qais Yousef
2025-02-24  9:27                                                         ` Juri Lelli
2025-02-25  0:02                                                           ` Qais Yousef
2025-02-25  9:46                                                             ` Juri Lelli
2025-02-25 10:09                                                               ` Christian Loehle
2025-02-12 23:01                                               ` Jon Hunter
2025-02-13  6:16                                                 ` Juri Lelli
2025-02-13  9:53                                                   ` Jon Hunter
2025-02-14 10:05                                                     ` Jon Hunter
2025-02-17 16:08                                                       ` Juri Lelli
2025-02-17 16:10                                                         ` Jon Hunter
2025-02-17 16:25                                                           ` Juri Lelli
2025-02-18  9:58                                                         ` Juri Lelli
2025-02-18 10:30                                                           ` Juri Lelli
2025-02-18 14:12                                                           ` Dietmar Eggemann
2025-02-18 14:18                                                             ` Juri Lelli
2025-02-19  9:29                                                               ` Dietmar Eggemann
2025-02-19 10:02                                                                 ` Juri Lelli
2025-02-19 11:23                                                                   ` Jon Hunter
2025-02-19 13:09                                                                   ` Dietmar Eggemann
2025-02-19 18:14                                                                     ` Dietmar Eggemann
2025-02-20 10:40                                                                       ` Juri Lelli
2025-02-20 15:25                                                                         ` Juri Lelli
2025-02-21 11:56                                                                           ` Jon Hunter
2025-02-21 14:45                                                                             ` Dietmar Eggemann
2025-02-24 13:53                                                                               ` Dietmar Eggemann
2025-02-24 14:03                                                                                 ` Juri Lelli
2025-02-24 23:39                                                                                   ` Jon Hunter
2025-02-25  9:48                                                                                     ` Juri Lelli
2025-03-03 14:17                                                                                       ` Jon Hunter
2025-03-03 16:00                                                                                         ` Juri Lelli
2025-02-07 14:04                                     ` Jon Hunter
2025-02-07 15:52                                   ` Juri Lelli

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=ba51a43f-796d-4b79-808a-b8185905638a@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=bigeasy@linutronix.de \
    --cc=bsegall@google.com \
    --cc=cgroups@vger.kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=hannes@cmpxchg.org \
    --cc=joel@joelfernandes.org \
    --cc=juri.lelli@redhat.com \
    --cc=kawasin@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=longman@redhat.com \
    --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=shraash@google.com \
    --cc=suleiman@google.com \
    --cc=tj@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vineeth@bitbyteword.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