public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] sched: Don't try to catch up excess steal time.
@ 2024-09-11 11:15 Suleiman Souhlal
  2024-09-12 14:47 ` Srikar Dronamraju
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Suleiman Souhlal @ 2024-09-11 11:15 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Juri Lelli, Vincent Guittot
  Cc: Dietmar Eggemann, Steven Rostedt, Ben Segall, Mel Gorman,
	Valentin Schneider, Paolo Bonzini, joelaf, vineethrp,
	linux-kernel, kvm, ssouhlal, Srikar Dronamraju, David Woodhouse,
	Sean Christopherson, Suleiman Souhlal

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, as they end up getting additional steal time that did not
actually happen.

For example, suppose a task in a VM runs for 10ms and had 15ms of steal
time reported while it ran. clock_task rightly doesn't advance. Then, a
different taks runs on the same rq for 10ms without any time stolen in
the host.
Because of the current catch up mechanism, clock_sched inaccurately ends
up advancing by only 5ms instead of 10ms even though there wasn't any
actual time stolen. The second task is getting charged for less time
than it ran, even though it didn't deserve it.
This can result in tasks getting more run time than they should actually
get.

So, we instead don't make future updates pay back past excess stolen time.

Signed-off-by: Suleiman Souhlal <suleiman@google.com>
---
v2:
- Slightly changed to simply moving one line up instead of adding
  new variable.

v1: https://lore.kernel.org/lkml/20240806111157.1336532-1-suleiman@google.com
---
 kernel/sched/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index f3951e4a55e5..6c34de8b3fbb 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -730,11 +730,11 @@ static void update_rq_clock_task(struct rq *rq, s64 delta)
 	if (static_key_false((&paravirt_steal_rq_enabled))) {
 		steal = paravirt_steal_clock(cpu_of(rq));
 		steal -= rq->prev_steal_time_rq;
+		rq->prev_steal_time_rq += steal;
 
 		if (unlikely(steal > delta))
 			steal = delta;
 
-		rq->prev_steal_time_rq += steal;
 		delta -= steal;
 	}
 #endif
-- 
2.46.0.598.g6f2099f65c-goog


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-09-25 16:29 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-11 11:15 [PATCH v2] sched: Don't try to catch up excess steal time Suleiman Souhlal
2024-09-12 14:47 ` Srikar Dronamraju
2024-09-25 11:04 ` Suleiman Souhlal
2024-09-25 11:45 ` David Woodhouse
2024-09-25 13:25   ` Suleiman Souhlal
2024-09-25 14:26     ` David Woodhouse
2024-09-25 15:15       ` Suleiman Souhlal
2024-09-25 15:34         ` David Woodhouse
2024-09-25 16:29           ` Suleiman Souhlal
     [not found]   ` <CAJWu+oqkMNr6kxndEw3HP_Ap14W38xpUGjS=3EeSqTXZEmDBQQ@mail.gmail.com>
2024-09-25 14:02     ` David Woodhouse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox