From: Alexander Graf <agraf@suse.de>
To: qemu-ppc@nongnu.org
Cc: Blue Swirl <blauwirbel@gmail.com>,
qemu-devel@nongnu.org, Aurelien Jarno <aurelien@aurel32.net>,
"Jason J. Herne" <jjherne@us.ibm.com>
Subject: [Qemu-devel] [PATCH 22/24] Allow selective runtime register synchronization
Date: Fri, 26 Apr 2013 20:19:31 +0200 [thread overview]
Message-ID: <1367000373-7972-23-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1367000373-7972-1-git-send-email-agraf@suse.de>
From: Jason J. Herne <jjherne@us.ibm.com>
We want to avoid expensive register synchronization IOCTL's on the hot path so
a new kvm_s390_get_registers_partial() is introduced as a compliment to
kvm_arch_get_registers(). The new function is called on the hot path, and
kvm_arch_get_registers() is called when we need the complete runtime register
state.
kvm_arch_put_registers() is updated to only sync the partial runtime set when
we've only dirtied the partial runtime set. This is to avoid sending bad data
back to KVM if we've only partially synced the runtime register set.
Signed-off-by: Jason J. Herne <jjherne@us.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Alexander Graf <agraf@suse.de>
---
target-s390x/cpu.h | 17 +++++++++++++
target-s390x/kvm.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/target-s390x/cpu.h b/target-s390x/cpu.h
index e351005..0ce82cf 100644
--- a/target-s390x/cpu.h
+++ b/target-s390x/cpu.h
@@ -78,6 +78,11 @@ typedef struct MchkQueue {
uint16_t type;
} MchkQueue;
+/* Defined values for CPUS390XState.runtime_reg_dirty_mask */
+#define KVM_S390_RUNTIME_DIRTY_NONE 0
+#define KVM_S390_RUNTIME_DIRTY_PARTIAL 1
+#define KVM_S390_RUNTIME_DIRTY_FULL 2
+
typedef struct CPUS390XState {
uint64_t regs[16]; /* GP registers */
CPU_DoubleU fregs[16]; /* FP registers */
@@ -121,6 +126,13 @@ typedef struct CPUS390XState {
uint64_t cputm;
uint32_t todpr;
+ /* on S390 the runtime register set has two dirty states:
+ * a partial dirty state in which only the registers that
+ * are needed all the time are fetched. And a fully dirty
+ * state in which all runtime registers are fetched.
+ */
+ uint32_t runtime_reg_dirty_mask;
+
CPU_COMMON
/* reset does memset(0) up to here */
@@ -1068,6 +1080,7 @@ void kvm_s390_io_interrupt(S390CPU *cpu, uint16_t subchannel_id,
uint32_t io_int_word);
void kvm_s390_crw_mchk(S390CPU *cpu);
void kvm_s390_enable_css_support(S390CPU *cpu);
+int kvm_s390_get_registers_partial(CPUState *cpu);
#else
static inline void kvm_s390_io_interrupt(S390CPU *cpu,
uint16_t subchannel_id,
@@ -1082,6 +1095,10 @@ static inline void kvm_s390_crw_mchk(S390CPU *cpu)
static inline void kvm_s390_enable_css_support(S390CPU *cpu)
{
}
+static inline int kvm_s390_get_registers_partial(CPUState *cpu)
+{
+ return -ENOSYS;
+}
#endif
static inline void s390_io_interrupt(S390CPU *cpu,
diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c
index 644f484..02b2e39 100644
--- a/target-s390x/kvm.c
+++ b/target-s390x/kvm.c
@@ -123,6 +123,7 @@ int kvm_arch_put_registers(CPUState *cs, int level)
{
S390CPU *cpu = S390_CPU(cs);
CPUS390XState *env = &cpu->env;
+ struct kvm_one_reg reg;
struct kvm_sregs sregs;
struct kvm_regs regs;
int ret;
@@ -147,6 +148,30 @@ int kvm_arch_put_registers(CPUState *cs, int level)
}
}
+ if (env->runtime_reg_dirty_mask == KVM_S390_RUNTIME_DIRTY_FULL) {
+ reg.id = KVM_REG_S390_CPU_TIMER;
+ reg.addr = (__u64)&(env->cputm);
+ ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
+ if (ret < 0) {
+ return ret;
+ }
+
+ reg.id = KVM_REG_S390_CLOCK_COMP;
+ reg.addr = (__u64)&(env->ckc);
+ ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
+ if (ret < 0) {
+ return ret;
+ }
+
+ reg.id = KVM_REG_S390_TODPR;
+ reg.addr = (__u64)&(env->todpr);
+ ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
+ if (ret < 0) {
+ return ret;
+ }
+ }
+ env->runtime_reg_dirty_mask = KVM_S390_RUNTIME_DIRTY_NONE;
+
/* Do we need to save more than that? */
if (level == KVM_PUT_RUNTIME_STATE) {
return 0;
@@ -186,11 +211,52 @@ int kvm_arch_get_registers(CPUState *cs)
{
S390CPU *cpu = S390_CPU(cs);
CPUS390XState *env = &cpu->env;
+ struct kvm_one_reg reg;
+ int r;
+
+ r = kvm_s390_get_registers_partial(cs);
+ if (r < 0) {
+ return r;
+ }
+
+ reg.id = KVM_REG_S390_CPU_TIMER;
+ reg.addr = (__u64)&(env->cputm);
+ r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
+ if (r < 0) {
+ return r;
+ }
+
+ reg.id = KVM_REG_S390_CLOCK_COMP;
+ reg.addr = (__u64)&(env->ckc);
+ r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
+ if (r < 0) {
+ return r;
+ }
+
+ reg.id = KVM_REG_S390_TODPR;
+ reg.addr = (__u64)&(env->todpr);
+ r = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
+ if (r < 0) {
+ return r;
+ }
+
+ env->runtime_reg_dirty_mask = KVM_S390_RUNTIME_DIRTY_FULL;
+ return 0;
+}
+
+int kvm_s390_get_registers_partial(CPUState *cs)
+{
+ S390CPU *cpu = S390_CPU(cs);
+ CPUS390XState *env = &cpu->env;
struct kvm_sregs sregs;
struct kvm_regs regs;
int ret;
int i;
+ if (env->runtime_reg_dirty_mask) {
+ return 0;
+ }
+
/* get the PSW */
env->psw.addr = cs->kvm_run->psw_addr;
env->psw.mask = cs->kvm_run->psw_mask;
@@ -236,6 +302,7 @@ int kvm_arch_get_registers(CPUState *cs)
/* no prefix without sync regs */
}
+ env->runtime_reg_dirty_mask = KVM_S390_RUNTIME_DIRTY_PARTIAL;
return 0;
}
--
1.6.0.2
next prev parent reply other threads:[~2013-04-26 18:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-26 18:19 [Qemu-devel] [PULL 00/24] s390 patch queue 2013-04-26 Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 01/24] S390: Make IPL reset address dynamic Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 02/24] S390: IPL: Support ELF firmware Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 03/24] S390: IPL: Use different firmware for different machines Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 04/24] S390: ccw firmware: Add start assembly Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 05/24] S390: ccw firmware: Add main program Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 06/24] S390: ccw firmware: Add sclp output Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 07/24] S390: ccw firmware: Add virtio device drivers Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 08/24] S390: ccw firmware: Add glue header Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 09/24] S390: ccw firmware: Add bootmap interpreter Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 10/24] S390: ccw firmware: Add Makefile Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 11/24] s390-ccw.img: replace while loop with a disabled wait on s390 bios Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 12/24] s390-ccw.img: build s390-ccw rom on s3900 system by default Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 13/24] s390-ccw.img: Take care of the elf->img transition Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 14/24] s390-ccw.img: Fix compile warning in s390 ccw virtio code Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 15/24] s390-ccw.img: Detect devices with stsch Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 16/24] s390-ccw.img: Enhance drain_irqs() Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 17/24] s390-ccw.img: Rudimentary error checking Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 18/24] s390-ccw.img: Get queue config from host Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 19/24] S390: ccw firmware: Add compiled blob Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 20/24] S390: CCW: Use new, working firmware by default Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 21/24] Common: Add quick access to first boot device Alexander Graf
2013-04-26 18:19 ` Alexander Graf [this message]
2013-04-26 18:19 ` [Qemu-devel] [PATCH 23/24] Utilize selective runtime reg sync for hot code paths Alexander Graf
2013-04-26 18:19 ` [Qemu-devel] [PATCH 24/24] virtio-rng-s390: add properties Alexander Graf
2013-04-26 20:14 ` [Qemu-devel] [PULL 00/24] s390 patch queue 2013-04-26 Blue Swirl
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=1367000373-7972-23-git-send-email-agraf@suse.de \
--to=agraf@suse.de \
--cc=aurelien@aurel32.net \
--cc=blauwirbel@gmail.com \
--cc=jjherne@us.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).