public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Roman Kagan <rkagan@virtuozzo.com>
Cc: kvm@vger.kernel.org, "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>
Subject: Re: [PATCH kvm-unit-tests] x86:kvmclock-test: add testcases for x-cpu clock warp
Date: Thu, 16 Jun 2016 08:51:01 -0300	[thread overview]
Message-ID: <20160616115101.GA5035@amt.cnet> (raw)
In-Reply-To: <1466016110-29334-1-git-send-email-rkagan@virtuozzo.com>

On Wed, Jun 15, 2016 at 09:41:50PM +0300, Roman Kagan wrote:
> Add testcases for clock monotonicity across vCPUs.  In a sense this is a
> reduced adaptation of Ingo Molnar's time-wrap-test.
> 
> These testcases are extremely unlikely to pass on SMP VMs, so they are
> reported as XFAILs.  Their purpose is to demonstrate that it's
> impossible to achieve clock monotonicity across vCPUs (unless you can
> completely exclude preemption of vCPUs by the hypervisor, of course).

Don't think this is true: to confirm, run time-warp-test.c on a
multi-guest vcpu with SMP, and check that TSC monotonicity does not fail
across vCPUs.

This means that TSCs are monotonic, which means that any paravirt clock
based on TSC should be able to be monotonic as well.

Please submit Hyper-V patchset with the rdmsr(REF_CLOCK) reading Hyper-V
tsc page, i'll submit code to fix kvmclock update monotonicity
on top of it.

> 
> Note that even in the (faked) case of PVCLOCK_TSC_STABLE_BIT unset, when
> pvclock_clocksource_read() tries to monotonize the clock using basically
> the same technique as the testcase uses, it still fails the global
> monotonicity test.
> 
> Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
> ---
> the patch applies on top of my earlier patch "x86/kvmclock_test: rework
> to avoid spinlocks"
> 
>  x86/kvmclock_test.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 62 insertions(+)
> 
> diff --git a/x86/kvmclock_test.c b/x86/kvmclock_test.c
> index fc3cb2e..0af30c8 100644
> --- a/x86/kvmclock_test.c
> +++ b/x86/kvmclock_test.c
> @@ -15,6 +15,8 @@ struct warp_test_info {
>  	long long worst;
>  };
>  struct warp_test_info wti[MAX_CPU];
> +struct warp_test_info xwti[MAX_CPU];
> +atomic64_t last_value = ATOMIC64_INIT(0);
>  
>  struct perf_test_info {
>  	unsigned long long cycles;
> @@ -80,6 +82,38 @@ static void warp_test_cpu(void *data)
>  	atomic_dec(&cpus_left);
>  }
>  
> +static void xwarp_test_cpu(void *data)
> +{
> +	struct warp_test_info *ti = data;
> +	unsigned long long t = kvm_clock_read();
> +	unsigned long long end = t + DURATION * NSEC_PER_SEC;
> +	ti->warps = 0;
> +	ti->stalls = 0;
> +	ti->worst = 0;
> +
> +	do {
> +		long long delta;
> +		u64 last;
> +
> +		t = kvm_clock_read();
> +		last = atomic64_read(&last_value);
> +		delta = t - last;
> +
> +		while (t > last)
> +			last = atomic64_cmpxchg(&last_value, last, t);
> +
> +		if (delta < 0) {
> +			ti->warps++;
> +			if (delta < ti->worst)
> +				ti->worst = delta;
> +		}
> +		if (delta == 0)
> +			ti->stalls++;
> +	} while (t < end);
> +
> +	atomic_dec(&cpus_left);
> +}
> +
>  static void perf_test_cpu(void *data)
>  {
>  	struct perf_test_info *ti = data;
> @@ -121,6 +155,32 @@ static void warp_test(int ncpus, bool stable)
>  	       warps == 0, stable ? "" : "out", warps, worst, stalls);
>  }
>  
> +static void xwarp_test(int ncpus, bool stable)
> +{
> +	int i;
> +	unsigned long long warps = 0, stalls = 0;
> +	long long worst = 0;
> +
> +	pvclock_set_flags(stable ? PVCLOCK_RAW_CYCLE_BIT : 0);
> +
> +	atomic_set(&cpus_left, ncpus);
> +	for (i = ncpus - 1; i >= 0; i--)
> +		on_cpu_async(i, xwarp_test_cpu, &xwti[i]);
> +	while (atomic_read(&cpus_left));
> +
> +	for (i = 0; i < ncpus; i++) {
> +		warps += xwti[i].warps;
> +		stalls += xwti[i].stalls;
> +		if (xwti[i].worst < worst)
> +			worst = xwti[i].worst;
> +	}
> +
> +	report_xfail("with%s TSC_STABLE: x-cpu warps:"
> +		     " %llu (worst %lld), stalls: %llu",
> +		     ncpus > 1, warps == 0, stable ? "" : "out",
> +		     warps, worst, stalls);
> +}
> +
>  static void perf_test(int ncpus, bool stable)
>  {
>  	int i;
> @@ -169,6 +229,8 @@ int main(int ac, char **av)
>  
>  	warp_test(ncpus, true);
>  	warp_test(ncpus, false);
> +	xwarp_test(ncpus, true);
> +	xwarp_test(ncpus, false);
>  	perf_test(ncpus, true);
>  	perf_test(ncpus, false);
>  
> -- 
> 2.5.5

  reply	other threads:[~2016-06-16 19:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15 18:41 [PATCH kvm-unit-tests] x86:kvmclock-test: add testcases for x-cpu clock warp Roman Kagan
2016-06-16 11:51 ` Marcelo Tosatti [this message]
2016-06-20 16:55 ` Roman Kagan
2016-06-27 11:26   ` Paolo Bonzini
2016-06-27 14:37     ` Roman Kagan

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=20160616115101.GA5035@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkagan@virtuozzo.com \
    --cc=rkrcmar@redhat.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