Skip to content

Commit

Permalink
KVM: Cap vcpu->halt_poll_ns before halting rather than after
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
dmatlack authored and bonzini committed Nov 17, 2022
1 parent 6d3085e commit 97b6847
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3377,9 +3377,6 @@ static void grow_halt_poll_ns(struct kvm_vcpu *vcpu)
if (val < grow_start)
val = grow_start;

if (val > vcpu->kvm->max_halt_poll_ns)
val = vcpu->kvm->max_halt_poll_ns;

vcpu->halt_poll_ns = val;
out:
trace_kvm_halt_poll_ns_grow(vcpu->vcpu_id, val, old);
Expand Down Expand Up @@ -3492,11 +3489,16 @@ static inline void update_halt_poll_stats(struct kvm_vcpu *vcpu, ktime_t start,
void kvm_vcpu_halt(struct kvm_vcpu *vcpu)
{
bool halt_poll_allowed = !kvm_arch_no_poll(vcpu);
bool do_halt_poll = halt_poll_allowed && vcpu->halt_poll_ns;
ktime_t start, cur, poll_end;
bool waited = false;
bool do_halt_poll;
u64 halt_ns;

if (vcpu->halt_poll_ns > vcpu->kvm->max_halt_poll_ns)
vcpu->halt_poll_ns = vcpu->kvm->max_halt_poll_ns;

do_halt_poll = halt_poll_allowed && vcpu->halt_poll_ns;

start = cur = poll_end = ktime_get();
if (do_halt_poll) {
ktime_t stop = ktime_add_ns(start, vcpu->halt_poll_ns);
Expand Down

0 comments on commit 97b6847

Please sign in to comment.