From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH v3 4/6] KVM: Optimize vcpu->requests checking
Date: Mon, 9 Jul 2012 20:05:43 +0300 [thread overview]
Message-ID: <1341853545-3023-5-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1341853545-3023-1-git-send-email-avi@redhat.com>
Instead of checking for each request linearly, use for_each_set_bit() to
iterate on just the requests that are set (should be 0 or 1 most of the
time).
To avoid a useless call to find_first_bit(), add an extra check for no
requests set. To avoid an extra indent and an unreviewable patch, I
added a rather ugly goto. This can be fixed in a later patch.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
arch/x86/kvm/x86.c | 62 ++++++++++++++++++++++++++++++++++--------------------
1 file changed, 39 insertions(+), 23 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 162231f..9296dce 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5217,6 +5217,7 @@ static void process_nmi(struct kvm_vcpu *vcpu)
static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
{
+ unsigned req;
int r;
bool req_int_win = !irqchip_in_kernel(vcpu->kvm) &&
vcpu->run->request_interrupt_window;
@@ -5225,57 +5226,67 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
if (unlikely(req_int_win))
kvm_make_request(KVM_REQ_EVENT, vcpu);
- if (vcpu->requests) {
- if (kvm_check_request(KVM_REQ_MMU_RELOAD, vcpu)) {
+ if (!vcpu->requests)
+ goto no_requests;
+
+ for_each_set_bit(req, &vcpu->requests, BITS_PER_LONG) {
+ clear_bit(req, &vcpu->requests);
+ switch (req) {
+ case KVM_REQ_MMU_RELOAD:
kvm_mmu_unload(vcpu);
r = kvm_mmu_reload(vcpu);
if (unlikely(r)) {
kvm_make_request(KVM_REQ_MMU_RELOAD, vcpu);
goto out;
}
- }
- if (kvm_check_request(KVM_REQ_MIGRATE_TIMER, vcpu))
+ break;
+ case KVM_REQ_MIGRATE_TIMER:
__kvm_migrate_timers(vcpu);
- if (kvm_check_request(KVM_REQ_CLOCK_UPDATE, vcpu)) {
+ break;
+ case KVM_REQ_CLOCK_UPDATE:
r = kvm_guest_time_update(vcpu);
if (unlikely(r))
goto out;
- }
- if (kvm_check_request(KVM_REQ_MMU_SYNC, vcpu))
+ break;
+ case KVM_REQ_MMU_SYNC:
kvm_mmu_sync_roots(vcpu);
- if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
+ break;
+ case KVM_REQ_TLB_FLUSH:
kvm_x86_ops->tlb_flush(vcpu);
- if (kvm_check_request(KVM_REQ_REPORT_TPR_ACCESS, vcpu)) {
+ break;
+ case KVM_REQ_REPORT_TPR_ACCESS:
vcpu->run->exit_reason = KVM_EXIT_TPR_ACCESS;
r = 0;
goto out;
- }
- if (kvm_check_request(KVM_REQ_TRIPLE_FAULT, vcpu)) {
+ case KVM_REQ_TRIPLE_FAULT:
vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN;
r = 0;
goto out;
- }
- if (kvm_check_request(KVM_REQ_DEACTIVATE_FPU, vcpu)) {
+ case KVM_REQ_DEACTIVATE_FPU:
vcpu->fpu_active = 0;
kvm_x86_ops->fpu_deactivate(vcpu);
- }
- if (kvm_check_request(KVM_REQ_APF_HALT, vcpu)) {
+ break;
+ case KVM_REQ_APF_HALT:
/* Page is swapped out. Do synthetic halt */
vcpu->arch.apf.halted = true;
r = 1;
goto out;
- }
- if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))
+ case KVM_REQ_STEAL_UPDATE:
record_steal_time(vcpu);
- if (kvm_check_request(KVM_REQ_NMI, vcpu))
+ break;
+ case KVM_REQ_NMI:
process_nmi(vcpu);
- req_immediate_exit =
- kvm_check_request(KVM_REQ_IMMEDIATE_EXIT, vcpu);
- if (kvm_check_request(KVM_REQ_PMU, vcpu))
+ break;
+ case KVM_REQ_IMMEDIATE_EXIT:
+ req_immediate_exit = true;
+ break;
+ case KVM_REQ_PMU:
kvm_handle_pmu_event(vcpu);
- if (kvm_check_request(KVM_REQ_PMI, vcpu))
+ break;
+ case KVM_REQ_PMI:
kvm_deliver_pmi(vcpu);
- if (kvm_check_request(KVM_REQ_EVENT, vcpu)) {
+ break;
+ case KVM_REQ_EVENT:
inject_pending_event(vcpu);
/* enable NMI/IRQ window open exits if needed */
@@ -5288,9 +5299,14 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
update_cr8_intercept(vcpu);
kvm_lapic_sync_to_vapic(vcpu);
}
+ break;
+ default:
+ BUG();
}
}
+no_requests:
+
preempt_disable();
kvm_x86_ops->prepare_guest_switch(vcpu);
--
1.7.11
next prev parent reply other threads:[~2012-07-09 17:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-09 17:05 [PATCH v3 0/6] Optimize vcpu->requests processing Avi Kivity
2012-07-09 17:05 ` [PATCH v3 1/6] KVM: Don't use KVM_REQ_PENDING_TIMER Avi Kivity
2012-07-10 8:50 ` Gleb Natapov
2012-07-10 9:13 ` Avi Kivity
2012-07-09 17:05 ` [PATCH v3 2/6] KVM: Simplify KVM_REQ_EVENT/req_int_win handling Avi Kivity
2012-07-09 17:05 ` [PATCH v3 3/6] KVM: Move mmu reload out of line Avi Kivity
2012-07-10 3:57 ` Xiao Guangrong
2012-07-10 7:48 ` Avi Kivity
2012-07-09 17:05 ` Avi Kivity [this message]
2012-07-09 17:05 ` [PATCH v3 5/6] KVM: Reorder KVM_REQ_EVENT to optimize processing Avi Kivity
2012-07-09 17:05 ` [PATCH v3 6/6] KVM: Clean up vcpu->requests == 0 processing Avi Kivity
2012-09-24 5:55 ` [PATCH v3 0/6] Optimize vcpu->requests processing Xiao Guangrong
2012-09-24 9:48 ` Avi Kivity
2012-09-24 10:19 ` Xiao Guangrong
2012-09-24 10:52 ` Avi Kivity
2012-09-24 11:16 ` Xiao Guangrong
2012-09-24 12:12 ` Avi Kivity
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=1341853545-3023-5-git-send-email-avi@redhat.com \
--to=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.