From: Masanori Misono <m.misono760@gmail.com>
To: David Woodhouse <dwmw@amazon.co.uk>,
Paolo Bonzini <pbonzini@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Rohit Jain <rohit.k.jain@oracle.com>
Cc: Ingo Molnar <mingo@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Masanori Misono <m.misono760@gmail.com>
Subject: [PATCH RFC 1/1] KVM: x86: Don't set preempted when vCPU does HLT VMEXIT
Date: Wed, 26 May 2021 22:37:27 +0900 [thread overview]
Message-ID: <20210526133727.42339-2-m.misono760@gmail.com> (raw)
In-Reply-To: <20210526133727.42339-1-m.misono760@gmail.com>
Change kvm_arch_cpu_put() so that it does not set st->preempted as 1
when a vCPU does HLT VMEXIT. As a result, is_vcpu_preempted(vCPU) becomes
0, and the vCPU becomes a candidate for CFS load balancing.
Signed-off-by: Masanori Misono <m.misono760@gmail.com>
---
arch/x86/kvm/x86.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index bbc4e04e67ad..b3f50b9f2e96 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4170,19 +4170,26 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
{
int idx;
+ bool hlt;
if (vcpu->preempted && !vcpu->arch.guest_state_protected)
vcpu->arch.preempted_in_kernel = !static_call(kvm_x86_get_cpl)(vcpu);
+ hlt = lapic_in_kernel(vcpu) ?
+ vcpu->arch.mp_state == KVM_MP_STATE_HALTED :
+ vcpu->run->exit_reason == KVM_EXIT_HLT;
+
/*
* Take the srcu lock as memslots will be accessed to check the gfn
* cache generation against the memslots generation.
*/
idx = srcu_read_lock(&vcpu->kvm->srcu);
- if (kvm_xen_msr_enabled(vcpu->kvm))
- kvm_xen_runstate_set_preempted(vcpu);
- else
- kvm_steal_time_set_preempted(vcpu);
+ if (!hlt) {
+ if (kvm_xen_msr_enabled(vcpu->kvm))
+ kvm_xen_runstate_set_preempted(vcpu);
+ else
+ kvm_steal_time_set_preempted(vcpu);
+ }
srcu_read_unlock(&vcpu->kvm->srcu, idx);
static_call(kvm_x86_vcpu_put)(vcpu);
--
2.31.1
next prev parent reply other threads:[~2021-05-26 13:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-26 13:37 [PATCH RFC 0/1] Make vCPUs that are HLT state candidates for load balancing Masanori Misono
2021-05-26 13:37 ` Masanori Misono [this message]
2021-05-26 14:43 ` Peter Zijlstra
2021-05-26 14:49 ` Peter Zijlstra
2021-05-26 16:15 ` Sean Christopherson
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=20210526133727.42339-2-m.misono760@gmail.com \
--to=m.misono760@gmail.com \
--cc=dwmw@amazon.co.uk \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rohit.k.jain@oracle.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox