From: Imran Khan <imran.f.khan@oracle.com>
To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [RFC PATCH] sched/rt: skip RT bandwidth accounting for unobserved CPU stalls
Date: Thu, 7 May 2026 21:00:27 +0800 [thread overview]
Message-ID: <20260507130027.3281306-1-imran.f.khan@oracle.com> (raw)
After a CPU stall which the guest scheduler did not observe ( for example
KVM live-migration where stop_and_copy takes long), the next update_curr_rt()
charges a delta_exec equal to the entire stall to the current RT task and
also to rt_rq::rt_time. With the default sched_rt_runtime_us=950000 and
sched_rt_period_us=1000000, even a few seconds of stall can set rt_throttled
, dequeue the current RT task and keep it off the runq for multiple seconds.
For example following snippet shows one such instance where pid 30274
was the current task on CPU 45, during live migration. After live migration
it got preempted and has been on the runq for the last ~10 secs. CPU is idle
but RT task can't get on it because rt_runtime overrun has not been
compensated yet:
crash> runq -c 45
CPU 45 RUNQUEUE: ff1c8cb63d972840
CURRENT: PID: 0 TASK: ff1c8c77c6c7a080 COMMAND: "swapper/45"
RT PRIO_ARRAY: ff1c8cb63d972ac0
[ 0] PID: 30274 TASK: ff1c8c7d9aad4100 COMMAND: "NMSending"
[ 0] PID: 30791 TASK: ff1c8c7c2098a080 COMMAND: "cssdagent"
>>> per_cpu(prog["runqueues"], 45).clock_task.value_()
10537385941842
>>> per_cpu(prog["runqueues"], 45).rt.rt_time.value_()
6571872703
>>> per_cpu(prog["runqueues"], 45).clock_task.value_() - \
find_task(30274).se.exec_start.value_()
10537394410
This snippet is from a system using v5.15.y kernel and as of now I don't
have a vmcore with current upstream tip but I could reproduce similar time jump
on current tip as well.
This change resets delta_exec to zero upon detecting a guest pause and hence
prevents exorbitant jumps in rt_rq::rt_time.
Signed-off-by: Imran Khan <imran.f.khan@oracle.com>
---
kernel/sched/rt.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
I have kept the patch RFC because I am not sure if it should be fixed on the
KVM side.
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index f69e1f16d9238..e8d83080c3842 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -7,6 +7,8 @@
#include "sched.h"
#include "pelt.h"
+#include <linux/kvm_para.h>
+
int sched_rr_timeslice = RR_TIMESLICE;
/* More than 4 hours if BW_SHIFT equals 20. */
static const u64 max_rt_runtime = MAX_BW;
@@ -989,6 +991,18 @@ static void update_curr_rt(struct rq *rq)
if (!rt_bandwidth_enabled())
return;
+ /*
+ * Forgive RT bandwidth charged across an unobserved CPU stall
+ * like KVM live-migration stop_and_copy.
+ *
+ * The magnitude check is to avoid race where the local softlockup
+ * hrtimer consumed PVCLOCK_GUEST_STOPPED bit before this
+ * update_curr_rt() call.
+ */
+ if (kvm_check_and_clear_guest_paused() ||
+ unlikely(delta_exec > (u64)sysctl_sched_rt_period * NSEC_PER_USEC))
+ delta_exec = 0;
+
for_each_sched_rt_entity(rt_se) {
struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
int exceeded;
base-commit: 591cd656a1bf5ea94a222af5ef2ee76df029c1d2
--
2.34.1
reply other threads:[~2026-05-07 13:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260507130027.3281306-1-imran.f.khan@oracle.com \
--to=imran.f.khan@oracle.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--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
all inboxes | Powered by JetHome®