[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240820043543.837914-2-suleiman@google.com>
Date: Tue, 20 Aug 2024 13:35:41 +0900
From: Suleiman Souhlal <suleiman@...gle.com>
To: Paolo Bonzini <pbonzini@...hat.com>, Sean Christopherson <seanjc@...gle.com>
Cc: Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>, Chao Gao <chao.gao@...el.com>, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, ssouhlal@...ebsd.org,
Suleiman Souhlal <suleiman@...gle.com>
Subject: [PATCH v2 1/3] KVM: Introduce kvm_total_suspend_ns().
It returns the cumulative nanoseconds that the host has been suspended.
It is intended to be used for reporting host suspend time to the guest.
Signed-off-by: Suleiman Souhlal <suleiman@...gle.com>
---
include/linux/kvm_host.h | 2 ++
virt/kvm/kvm_main.c | 13 +++++++++++++
2 files changed, 15 insertions(+)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index b23c6d48392f7c..8fec37b372d8c0 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -2494,4 +2494,6 @@ long kvm_arch_vcpu_pre_fault_memory(struct kvm_vcpu *vcpu,
struct kvm_pre_fault_memory *range);
#endif
+u64 kvm_total_suspend_ns(void);
+
#endif
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index cb2b78e92910fb..2235933d9247bc 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5720,6 +5720,15 @@ static void kvm_shutdown(void)
on_each_cpu(hardware_disable_nolock, NULL, 1);
}
+static u64 last_suspend;
+static u64 total_suspend_ns;
+
+u64
+kvm_total_suspend_ns(void)
+{
+ return total_suspend_ns;
+}
+
static int kvm_suspend(void)
{
/*
@@ -5735,6 +5744,8 @@ static int kvm_suspend(void)
if (kvm_usage_count)
hardware_disable_nolock(NULL);
+
+ last_suspend = ktime_get_boottime_ns();
return 0;
}
@@ -5745,6 +5756,8 @@ static void kvm_resume(void)
if (kvm_usage_count)
WARN_ON_ONCE(__hardware_enable_nolock());
+
+ total_suspend_ns += ktime_get_boottime_ns() - last_suspend;
}
static struct syscore_ops kvm_syscore_ops = {
--
2.46.0.184.g6999bdac58-goog
Powered by blists - more mailing lists