kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: kvm@vger.kernel.org, pbonzini@redhat.com
Cc: Jim Mattson <jmattson@google.com>, Will Auld <will.auld.intel@gmail.com>
Subject: [kvm-unit-tests PATCH 1/3] x86: tsc_adjust: Remove flaky timing test
Date: Thu, 27 Jan 2022 13:55:46 -0800	[thread overview]
Message-ID: <20220127215548.2016946-1-jmattson@google.com> (raw)

The subtest labeled, "MSR_IA32_TSC_ADJUST msr adjustment on tsc
write," sometimes fails. The behavior tested is neither architected
nor guaranteed. Running under qemu/kvm, the 'est_delta_time' has been
observed to be as much as an order of magnitude greater than the
expression that is supposed to be its upper bound.

Remove the flaky subtest, and replace it with some invariants that
actually are architecturally guaranteed (as long as IA32_TSC doesn't
wrap around).

Fixes: 5fecf5d8cad1 ("Added tests for ia32_tsc_adjust funtionality.")
Cc: Will Auld <will.auld.intel@gmail.com>
Signed-off-by: Jim Mattson <jmattson@google.com>
---
 x86/tsc_adjust.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/x86/tsc_adjust.c b/x86/tsc_adjust.c
index 3636b5e082d5..b0d79c499edb 100644
--- a/x86/tsc_adjust.c
+++ b/x86/tsc_adjust.c
@@ -4,7 +4,6 @@
 int main(void)
 {
 	u64 t1, t2, t3, t4, t5;
-	u64 est_delta_time;
 
 	if (this_cpu_has(X86_FEATURE_TSC_ADJUST)) { // MSR_IA32_TSC_ADJUST Feature is enabled?
 		report(rdmsr(MSR_IA32_TSC_ADJUST) == 0x0,
@@ -26,12 +25,9 @@ int main(void)
 		wrtsc(t4);
 		t2 = rdtsc();
 		t5 = rdmsr(MSR_IA32_TSC_ADJUST);
-		// est of time between reading tsc and writing tsc,
-		// (based on MSR_IA32_TSC_ADJUST msr value) should be small
-		est_delta_time = t4 - t5 - t1;
-		// arbitray 2x latency (wrtsc->rdtsc) threshold
-		report(est_delta_time <= (2 * (t2 - t4)),
-		       "MSR_IA32_TSC_ADJUST msr adjustment on tsc write");
+		report(t1 <= t4 - t5,
+		       "Internal TSC advances across write to IA32_TSC");
+		report(t2 >= t4, "IA32_TSC advances after write to IA32_TSC");
 	}
 	else {
 		report_pass("MSR_IA32_TSC_ADJUST feature not enabled");
-- 
2.35.0.rc2.247.g8bbb082509-goog


             reply	other threads:[~2022-01-27 21:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27 21:55 Jim Mattson [this message]
2022-01-27 21:55 ` [kvm-unit-tests PATCH 2/3] x86: tsc_adjust: Use report_skip when skipping test Jim Mattson
2022-01-27 21:55 ` [kvm-unit-tests PATCH 3/3] x86: Define wrtsc(tsc) as wrmsr(MSR_IA32_TSC, tsc) Jim Mattson
2022-01-28 15:17   ` Paolo Bonzini

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=20220127215548.2016946-1-jmattson@google.com \
    --to=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=will.auld.intel@gmail.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;
as well as URLs for NNTP newsgroup(s).