Skip to content

Commit 97b6847

Browse files
dmatlackbonzini
authored andcommitted
KVM: Cap vcpu->halt_poll_ns before halting rather than after
Cap vcpu->halt_poll_ns based on the max halt polling time just before halting, rather than after the last halt. This arguably provides better accuracy if an admin disables halt polling in between halts, although the improvement is nominal. A side-effect of this change is that grow_halt_poll_ns() no longer needs to access vcpu->kvm->max_halt_poll_ns, which will be useful in a future commit where the max halt polling time can come from the module parameter halt_poll_ns instead. Signed-off-by: David Matlack <dmatlack@google.com> Message-Id: <20221117001657.1067231-2-dmatlack@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 6d3085e commit 97b6847

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

virt/kvm/kvm_main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3377,9 +3377,6 @@ static void grow_halt_poll_ns(struct kvm_vcpu *vcpu)
33773377
if (val < grow_start)
33783378
val = grow_start;
33793379

3380-
if (val > vcpu->kvm->max_halt_poll_ns)
3381-
val = vcpu->kvm->max_halt_poll_ns;
3382-
33833380
vcpu->halt_poll_ns = val;
33843381
out:
33853382
trace_kvm_halt_poll_ns_grow(vcpu->vcpu_id, val, old);
@@ -3492,11 +3489,16 @@ static inline void update_halt_poll_stats(struct kvm_vcpu *vcpu, ktime_t start,
34923489
void kvm_vcpu_halt(struct kvm_vcpu *vcpu)
34933490
{
34943491
bool halt_poll_allowed = !kvm_arch_no_poll(vcpu);
3495-
bool do_halt_poll = halt_poll_allowed && vcpu->halt_poll_ns;
34963492
ktime_t start, cur, poll_end;
34973493
bool waited = false;
3494+
bool do_halt_poll;
34983495
u64 halt_ns;
34993496

3497+
if (vcpu->halt_poll_ns > vcpu->kvm->max_halt_poll_ns)
3498+
vcpu->halt_poll_ns = vcpu->kvm->max_halt_poll_ns;
3499+
3500+
do_halt_poll = halt_poll_allowed && vcpu->halt_poll_ns;
3501+
35003502
start = cur = poll_end = ktime_get();
35013503
if (do_halt_poll) {
35023504
ktime_t stop = ktime_add_ns(start, vcpu->halt_poll_ns);

0 commit comments

Comments
 (0)