From: Suleiman Souhlal <suleiman@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Chao Gao <chao.gao@intel.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
ssouhlal@freebsd.org, Suleiman Souhlal <suleiman@google.com>
Subject: [PATCH v2 2/3] KVM: x86: Include host suspended time in steal time.
Date: Tue, 20 Aug 2024 13:35:42 +0900 [thread overview]
Message-ID: <20240820043543.837914-3-suleiman@google.com> (raw)
In-Reply-To: <20240820043543.837914-1-suleiman@google.com>
When the host resumes from a suspend, the guest thinks any task
that was running during the suspend ran for a long time, even though
the effective run time was much shorter, which can end up having
negative effects with scheduling. This can be particularly noticeable
if the guest task was RT, as it can end up getting throttled for a
long time.
To mitigate this issue, we include the time that the host was
suspended in steal time, which lets the guest subtract the duration from
the tasks' runtime.
Note that the case of a suspend happening during a VM migration
might not be accounted.
Signed-off-by: Suleiman Souhlal <suleiman@google.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/x86.c | 11 ++++++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 4a68cb3eba78f8..728798decb6d12 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -898,6 +898,7 @@ struct kvm_vcpu_arch {
u8 preempted;
u64 msr_val;
u64 last_steal;
+ u64 last_suspend_ns;
struct gfn_to_hva_cache cache;
} st;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 70219e4069874a..104f3d318026fa 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3654,7 +3654,7 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
struct kvm_steal_time __user *st;
struct kvm_memslots *slots;
gpa_t gpa = vcpu->arch.st.msr_val & KVM_STEAL_VALID_BITS;
- u64 steal;
+ u64 steal, suspend_ns;
u32 version;
if (kvm_xen_msr_enabled(vcpu->kvm)) {
@@ -3735,6 +3735,14 @@ static void record_steal_time(struct kvm_vcpu *vcpu)
steal += current->sched_info.run_delay -
vcpu->arch.st.last_steal;
vcpu->arch.st.last_steal = current->sched_info.run_delay;
+ /*
+ * Include the time that the host was suspended in steal time.
+ * Note that the case of a suspend happening during a VM migration
+ * might not be accounted.
+ */
+ suspend_ns = kvm_total_suspend_ns();
+ steal += suspend_ns - vcpu->arch.st.last_suspend_ns;
+ vcpu->arch.st.last_suspend_ns = suspend_ns;
unsafe_put_user(steal, &st->steal, out);
version += 1;
@@ -12280,6 +12288,7 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu)
vcpu->arch.arch_capabilities = kvm_get_arch_capabilities();
vcpu->arch.msr_platform_info = MSR_PLATFORM_INFO_CPUID_FAULT;
+ vcpu->arch.st.last_suspend_ns = kvm_total_suspend_ns();
kvm_xen_init_vcpu(vcpu);
vcpu_load(vcpu);
kvm_set_tsc_khz(vcpu, vcpu->kvm->arch.default_tsc_khz);
--
2.46.0.184.g6999bdac58-goog
next prev parent reply other threads:[~2024-08-20 4:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 4:35 [PATCH v2 0/3] KVM: x86: Include host suspended time in steal time Suleiman Souhlal
2024-08-20 4:35 ` [PATCH v2 1/3] KVM: Introduce kvm_total_suspend_ns() Suleiman Souhlal
2024-08-21 5:40 ` Chao Gao
2024-08-21 6:01 ` Suleiman Souhlal
2024-08-20 4:35 ` Suleiman Souhlal [this message]
2024-08-21 6:31 ` [PATCH v2 2/3] KVM: x86: Include host suspended time in steal time Chao Gao
2024-08-23 4:17 ` Suleiman Souhlal
2024-08-23 5:25 ` Chao Gao
2024-08-23 5:43 ` Suleiman Souhlal
2024-08-28 9:56 ` Suleiman Souhlal
2024-08-20 4:35 ` [PATCH v2 3/3] KVM: x86: Document host suspend being included " Suleiman Souhlal
2024-09-25 13:54 ` [PATCH v2 0/3] KVM: x86: Include host suspended time " Sean Christopherson
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=20240820043543.837914-3-suleiman@google.com \
--to=suleiman@google.com \
--cc=bp@alien8.de \
--cc=chao.gao@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=ssouhlal@freebsd.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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