From: Peter Zijlstra <peterz@infradead.org>
To: Suleiman Souhlal <suleiman@google.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
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>,
Paolo Bonzini <pbonzini@redhat.com>,
seanjc@google.com, Srikar Dronamraju <srikar@linux.ibm.com>,
David Woodhouse <dwmw2@infradead.org>,
joelaf@google.com, vineethrp@google.com,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
ssouhlal@freebsd.org
Subject: Re: [PATCH v3] sched: Don't try to catch up excess steal time.
Date: Mon, 18 Nov 2024 10:34:54 +0100 [thread overview]
Message-ID: <20241118093454.GF39245@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20241118043745.1857272-1-suleiman@google.com>
On Mon, Nov 18, 2024 at 01:37:45PM +0900, Suleiman Souhlal wrote:
> When steal time exceeds the measured delta when updating clock_task, we
> currently try to catch up the excess in future updates.
> However, this results in inaccurate run times for the future things using
> clock_task, in some situations, as they end up getting additional steal
> time that did not actually happen.
> This is because there is a window between reading the elapsed time in
> update_rq_clock() and sampling the steal time in update_rq_clock_task().
> If the VCPU gets preempted between those two points, any additional
> steal time is accounted to the outgoing task even though the calculated
> delta did not actually contain any of that "stolen" time.
> When this race happens, we can end up with steal time that exceeds the
> calculated delta, and the previous code would try to catch up that excess
> steal time in future clock updates, which is given to the next,
> incoming task, even though it did not actually have any time stolen.
>
> This behavior is particularly bad when steal time can be very long,
> which we've seen when trying to extend steal time to contain the duration
> that the host was suspended [0]. When this happens, clock_task stays
> frozen, during which the running task stays running for the whole
> duration, since its run time doesn't increase.
> However the race can happen even under normal operation.
>
> Ideally we would read the elapsed cpu time and the steal time atomically,
> to prevent this race from happening in the first place, but doing so
> is non-trivial.
>
> Since the time between those two points isn't otherwise accounted anywhere,
> neither to the outgoing task nor the incoming task (because the "end of
> outgoing task" and "start of incoming task" timestamps are the same),
> I would argue that the right thing to do is to simply drop any excess steal
> time, in order to prevent these issues.
>
> [0] https://lore.kernel.org/kvm/20240820043543.837914-1-suleiman@google.com/
>
> Signed-off-by: Suleiman Souhlal <suleiman@google.com>
Right.. uhm.. I don't particularly care much either way. Are other
people with virt clue okay with this?
> ---
> kernel/sched/core.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index a1c353a62c56..13f70316ef39 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -766,13 +766,15 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
> #endif
> #ifdef CONFIG_PARAVIRT_TIME_ACCOUNTING
> if (static_key_false((¶virt_steal_rq_enabled))) {
> - steal = paravirt_steal_clock(cpu_of(rq));
> + u64 prev_steal;
> +
> + steal = prev_steal = paravirt_steal_clock(cpu_of(rq));
> steal -= rq->prev_steal_time_rq;
>
> if (unlikely(steal > delta))
> steal = delta;
>
> - rq->prev_steal_time_rq += steal;
> + rq->prev_steal_time_rq = prev_steal;
> delta -= steal;
> }
> #endif
> --
> 2.47.0.338.g60cca15819-goog
>
next prev parent reply other threads:[~2024-11-18 9:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-18 4:37 Suleiman Souhlal
2024-11-18 9:34 ` Peter Zijlstra [this message]
2024-11-18 10:14 ` David Woodhouse
2024-11-18 19:33 ` Steven Rostedt
2024-11-19 0:10 ` Joel Fernandes
2024-11-19 0:18 ` Steven Rostedt
2024-11-19 0:22 ` Joel Fernandes
2024-12-02 11:14 ` [tip: sched/core] " tip-bot2 for Suleiman Souhlal
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=20241118093454.GF39245@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=dwmw2@infradead.org \
--cc=joelaf@google.com \
--cc=juri.lelli@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rostedt@goodmis.org \
--cc=seanjc@google.com \
--cc=srikar@linux.ibm.com \
--cc=ssouhlal@freebsd.org \
--cc=suleiman@google.com \
--cc=vincent.guittot@linaro.org \
--cc=vineethrp@google.com \
--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
all inboxes | Powered by JetHome®