diff options
author | Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp> | 2011-05-24 22:09:38 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-07-12 04:45:09 -0400 |
commit | b5c9ff731f3cee5a2f2d7154f48f8006b48eb66d (patch) | |
tree | bbea807577dd211bf52eca8397c6630f0bc7a01d /arch/x86/kvm/x86.c | |
parent | adf52235b4082e67f31bf1fba36f1dce312633d6 (diff) |
KVM: x86 emulator: Avoid clearing the whole decode_cache
During tracing the emulator, we noticed that init_emulate_ctxt()
sometimes took a bit longer time than we expected.
This patch is for mitigating the problem by some degree.
By looking into the function, we soon notice that it clears the whole
decode_cache whose size is about 2.5K bytes now. Furthermore, most of
the bytes are taken for the two read_cache arrays, which are used only
by a few instructions.
Considering the fact that we are not assuming the cache arrays have
been cleared when we store actual data, we do not need to clear the
arrays: 2K bytes elimination. In addition, we can avoid clearing the
fetch_cache and regs arrays.
This patch changes the initialization not to clear the arrays.
On our 64-bit host, init_emulate_ctxt() becomes 0.3 to 0.5us faster with
this patch applied.
Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ae2353c50208..d88de565d0c0 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -4506,6 +4506,20 @@ static void inject_emulated_exception(struct kvm_vcpu *vcpu) | |||
4506 | kvm_queue_exception(vcpu, ctxt->exception.vector); | 4506 | kvm_queue_exception(vcpu, ctxt->exception.vector); |
4507 | } | 4507 | } |
4508 | 4508 | ||
4509 | static void init_decode_cache(struct decode_cache *c, | ||
4510 | const unsigned long *regs) | ||
4511 | { | ||
4512 | memset(c, 0, offsetof(struct decode_cache, regs)); | ||
4513 | memcpy(c->regs, regs, sizeof(c->regs)); | ||
4514 | |||
4515 | c->fetch.start = 0; | ||
4516 | c->fetch.end = 0; | ||
4517 | c->io_read.pos = 0; | ||
4518 | c->io_read.end = 0; | ||
4519 | c->mem_read.pos = 0; | ||
4520 | c->mem_read.end = 0; | ||
4521 | } | ||
4522 | |||
4509 | static void init_emulate_ctxt(struct kvm_vcpu *vcpu) | 4523 | static void init_emulate_ctxt(struct kvm_vcpu *vcpu) |
4510 | { | 4524 | { |
4511 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; | 4525 | struct x86_emulate_ctxt *ctxt = &vcpu->arch.emulate_ctxt; |
@@ -4531,8 +4545,7 @@ static void init_emulate_ctxt(struct kvm_vcpu *vcpu) | |||
4531 | X86EMUL_MODE_PROT16; | 4545 | X86EMUL_MODE_PROT16; |
4532 | ctxt->guest_mode = is_guest_mode(vcpu); | 4546 | ctxt->guest_mode = is_guest_mode(vcpu); |
4533 | 4547 | ||
4534 | memset(c, 0, sizeof(struct decode_cache)); | 4548 | init_decode_cache(c, vcpu->arch.regs); |
4535 | memcpy(c->regs, vcpu->arch.regs, sizeof c->regs); | ||
4536 | vcpu->arch.emulate_regs_need_sync_from_vcpu = false; | 4549 | vcpu->arch.emulate_regs_need_sync_from_vcpu = false; |
4537 | } | 4550 | } |
4538 | 4551 | ||