[PATCH v3 12/21] KVM: selftests: Allow +/- 1 tolerance if expected TSC frequency is <100
From: Sean Christopherson
Date: Wed Sep 30 2026 - 14:13:07 EST
Massage the nested TSC scaling test's checker to allow for validating an
expected TSC frequency of 1Hz, which is achievable for L2 since L1 can use
a completely arbitrary fractional ratio. To do so, set the minimum
tolerance to 1, and make the thresholds inclusive, i.e. for an expected
frequency of 1, allow the actual frequency to be in the range of [0,2].
Because scaling L2's frequency down to a single Hz makes the virtual TSC
run soooo comically slow, and because all of the math is done with basic
integer arithmetic, it's very easy for the test to observe what appears to
be a frequency of 0.
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c b/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c
index 8c96b8e501f9..d790ab36a198 100644
--- a/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c
+++ b/tools/testing/selftests/kvm/x86/nested_tsc_scaling_test.c
@@ -36,11 +36,11 @@ static void host_check_tsc_freq(int level, u64 actual, u64 expected)
{
u64 tolerance, thresh_low, thresh_high;
- tolerance = expected / 100;
+ tolerance = max(expected / 100, (u64)1);
thresh_low = expected - tolerance;
thresh_high = expected + tolerance;
- TEST_ASSERT(thresh_low < actual && thresh_high > actual,
+ TEST_ASSERT(thresh_low <= actual && thresh_high >= actual,
"L%u TSC freq is '%lu', expected to be between %lu and %lu",
level, actual, thresh_low, thresh_high);
}
--
2.56.0.rc1.315.gc6ed9934b7-goog