Reg-sync: Allow selective register Synchronization
PATCH v4 1/2 Allow selective runtime register synchronization
In reply to Jason J. HerneFrom: "Jason J. Herne" <[email protected]>
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.
--- target-s390x/cpu.h | 17 +++++++++++++ target-s390x/kvm.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+)
target-s390x/cpu.h +17 -0
@@ -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,
target-s390x/kvm.c +67 -0
96 lines not on this page · raw message
Signature · 1 line
1.7.10.4
v4 cover Reg-sync: Allow selective register Synchronization
Selective KVM Register synchronization work for S390. This is re-work of the patch set submitted here:
https://lists.nongnu.org/archive/html/qemu-devel/2013-01/msg01631.html
The selective runtime register sync code has been made S390 specific. This is the latest version of the code, fit to the latest commit on master.
PATCH v4 2/2 Utilize selective runtime reg sync for hot code paths
From: "Jason J. Herne" <[email protected]>
Make use of new kvm_s390_get_registers_partial() for kvm_handle_css_inst() and handle_hypercall() since they only need registers from the partial set and they are called quite frequently.
--- target-s390x/kvm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
target-s390x/kvm.c +12 -3
@@ -467,12 +467,16 @@ static int kvm_handle_css_inst(S390CPU *cpu, struct kvm_run *run,int r =0 ;int no_cc =0 ;CPUS390XState *env = &cpu->env; +CPUState *cs =ENV_GET_CPU (env);if (ipa0 !=0xb2 ) {/* Not handled for now. */ return -1 ; } -cpu_synchronize_state (env); + +kvm_s390_get_registers_partial (cs); + cs->kvm_vcpu_dirty = true; +switch (ipa1) {case PRIV_XSCH : r =ioinst_handle_xsch (env, env->regs[1 ]);
@@ -603,7 +607,10 @@ static int handle_priv(S390CPU *cpu, struct kvm_run *run,static int handle_hypercall (CPUS390XState *env,struct kvm_run *run) { -cpu_synchronize_state (env); +CPUState *cs =ENV_GET_CPU (env); + +kvm_s390_get_registers_partial (cs); + cs->kvm_vcpu_dirty = true; env->regs[2 ] =s390_virtio_hypercall (env);return 0 ;
@@ -808,7 +815,9 @@ static int handle_tsch(S390CPU *cpu)struct kvm_run *run = cs->kvm_run;int ret; -cpu_synchronize_state (env); +kvm_s390_get_registers_partial (cs); + cs->kvm_vcpu_dirty = true; + ret =ioinst_handle_tsch (env, env->regs[1 ], run->s390_tsch.ipb);if (ret >=0 ) {/* Success; set condition code. */
Signature · 1 line
1.7.10.4
Alexander Graf
AppliedQuoted 6 lines · Jason J. Herne
Selective KVM Register synchronization work for S390. This is re-work of the patch set submitted here:
https://lists.nongnu.org/archive/html/qemu-devel/2013-01/msg01631.htmlThe selective runtime register sync code has been made S390 specific. This is the latest version of the code, fit to the latest commit on master.
Thanks, applied both to s390-next.
Alex