From: Bijan Mottahedeh <bijan.mottahedeh@oracle.com>
To: qemu-devel@nongnu.org
Cc: kvmarm@lists.cs.columbia.edu
Subject: [Qemu-devel] [RFC QEMU 2/2] arm/virt: Account for guest pause time
Date: Wed, 7 Nov 2018 10:48:24 -0800 [thread overview]
Message-ID: <1541616504-68526-3-git-send-email-bijan.mottahedeh@oracle.com> (raw)
In-Reply-To: <1541616504-68526-1-git-send-email-bijan.mottahedeh@oracle.com>
Accumulate the total guest pause time and update the virtual counter
offset register accordingly in order to account for that time before
resuming the guest.
Signed-off-by: Bijan Mottahedeh <bijan.mottahedeh@oracle.com>
---
hw/intc/arm_gicv3_kvm.c | 39 +++++++++++++++++++++++++++++++++++++++
target/arm/cpu.h | 3 +++
2 files changed, 42 insertions(+)
diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c
index 1e11200..aabd508 100644
--- a/hw/intc/arm_gicv3_kvm.c
+++ b/hw/intc/arm_gicv3_kvm.c
@@ -30,6 +30,7 @@
#include "gicv3_internal.h"
#include "vgic_common.h"
#include "migration/blocker.h"
+#include "target/arm/internals.h"
#ifdef DEBUG_GICV3_KVM
#define DPRINTF(fmt, ...) \
@@ -745,9 +746,38 @@ static void vm_change_state_handler(void *opaque, int running,
{
GICv3State *s = (GICv3State *)opaque;
Error *err = NULL;
+ CPUState *cpu;
+ CPUARMState *env;
+ struct kvm_one_reg reg;
int ret;
+ uint64_t cnt;
if (running) {
+ CPU_FOREACH(cpu) {
+
+ env = (CPUARMState *)(cpu->env_ptr);
+
+ if (!env->pause_start) {
+ continue;
+ }
+
+ /*
+ * Accumulate the total pause time and set the
+ * counter virtual offset accordingly.
+ */
+ cnt = gt_get_countervalue(env);
+ env->pause_total += (cnt - env->pause_start);
+ env->cp15.cntvoff_el2 = cnt - env->pause_total;
+
+ env->pause_start = 0; /* clear for next pause */
+ reg.id = KVM_REG_ARM_TIMER_CNT;
+ reg.addr = (uintptr_t) &env->cp15.cntvoff_el2;
+ ret = kvm_vcpu_ioctl(cpu, KVM_SET_ONE_REG, ®);
+ if (ret) {
+ error_report("Set virtual counter offset failed: %d", ret);
+ abort();
+ }
+ }
return;
}
@@ -760,6 +790,15 @@ static void vm_change_state_handler(void *opaque, int running,
if (ret < 0 && ret != -EFAULT) {
abort();
}
+
+ CPU_FOREACH(cpu) {
+ /*
+ * Record the current pause start time.
+ */
+ env = (CPUARMState *)(cpu->env_ptr);
+ cnt = gt_get_countervalue(env);
+ env->pause_start = cnt;
+ }
}
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index e310ffc..bd0a56e 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -602,6 +602,9 @@ typedef struct CPUARMState {
struct CPUBreakpoint *cpu_breakpoint[16];
struct CPUWatchpoint *cpu_watchpoint[16];
+ uint64_t pause_start; /* start time of last pause */
+ uint64_t pause_total; /* total pause time */
+
/* Fields up to this point are cleared by a CPU reset */
struct {} end_reset_fields;
--
1.8.3.1
next prev parent reply other threads:[~2018-11-07 18:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-07 18:48 [Qemu-devel] [RFC QEMU 0/2] arm/virt: Account for guest pause time Bijan Mottahedeh
2018-11-07 18:48 ` [Qemu-devel] [RFC QEMU 1/2] arm/virt: Initialize generic timer scale factor dynamically Bijan Mottahedeh
2018-11-08 14:21 ` Richard Henderson
2018-11-10 3:12 ` Bijan Mottahedeh
2018-11-07 18:48 ` Bijan Mottahedeh [this message]
2018-11-08 14:32 ` [Qemu-devel] [RFC QEMU 0/2] arm/virt: Account for guest pause time no-reply
2018-11-08 14:34 ` no-reply
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=1541616504-68526-3-git-send-email-bijan.mottahedeh@oracle.com \
--to=bijan.mottahedeh@oracle.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).