Skip to content

Commit

Permalink
KVM: Reconcile discrepancies in halt-polling stats
Browse files Browse the repository at this point in the history
Move the halt-polling "success" and histogram stats update into the
dedicated helper to fix a discrepancy where the success/fail "time" stats
consider polling successful so long as the wait is avoided, but the main
"success" and histogram stats consider polling successful if and only if
a wake event was detected by the halt-polling loop.

Move halt_attempted_poll to the helper as well so that all the stats are
updated in a single location.  While it's a bit odd to update the stat
well after the fact, practically speaking there's no meaningful advantage
to updating before polling.

Note, there is a functional change in addition to the success vs. fail
change.  The histogram updates previously called ktime_get() instead of
using "cur".  But that change is desirable as it means all the stats are
now updated with the same polling time, and avoids the extra ktime_get(),
which isn't expensive but isn't free either.

Reviewed-by: David Matlack <[email protected]>
Signed-off-by: Sean Christopherson <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
sean-jc authored and bonzini committed Dec 8, 2021
1 parent 29e7289 commit 30c9434
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3275,12 +3275,23 @@ static int kvm_vcpu_check_block(struct kvm_vcpu *vcpu)
static inline void update_halt_poll_stats(struct kvm_vcpu *vcpu, ktime_t start,
ktime_t end, bool success)
{
struct kvm_vcpu_stat_generic *stats = &vcpu->stat.generic;
u64 poll_ns = ktime_to_ns(ktime_sub(end, start));

if (success)
vcpu->stat.generic.halt_poll_success_ns += poll_ns;
else
vcpu->stat.generic.halt_poll_fail_ns += poll_ns;
++vcpu->stat.generic.halt_attempted_poll;

if (success) {
++vcpu->stat.generic.halt_successful_poll;

if (!vcpu_valid_wakeup(vcpu))
++vcpu->stat.generic.halt_poll_invalid;

stats->halt_poll_success_ns += poll_ns;
KVM_STATS_LOG_HIST_UPDATE(stats->halt_poll_success_hist, poll_ns);
} else {
stats->halt_poll_fail_ns += poll_ns;
KVM_STATS_LOG_HIST_UPDATE(stats->halt_poll_fail_hist, poll_ns);
}
}

/*
Expand All @@ -3301,30 +3312,16 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
if (do_halt_poll) {
ktime_t stop = ktime_add_ns(ktime_get(), vcpu->halt_poll_ns);

++vcpu->stat.generic.halt_attempted_poll;
do {
/*
* This sets KVM_REQ_UNHALT if an interrupt
* arrives.
*/
if (kvm_vcpu_check_block(vcpu) < 0) {
++vcpu->stat.generic.halt_successful_poll;
if (!vcpu_valid_wakeup(vcpu))
++vcpu->stat.generic.halt_poll_invalid;

KVM_STATS_LOG_HIST_UPDATE(
vcpu->stat.generic.halt_poll_success_hist,
ktime_to_ns(ktime_get()) -
ktime_to_ns(start));
if (kvm_vcpu_check_block(vcpu) < 0)
goto out;
}
cpu_relax();
poll_end = cur = ktime_get();
} while (kvm_vcpu_can_poll(cur, stop));

KVM_STATS_LOG_HIST_UPDATE(
vcpu->stat.generic.halt_poll_fail_hist,
ktime_to_ns(ktime_get()) - ktime_to_ns(start));
}


Expand Down

0 comments on commit 30c9434

Please sign in to comment.