All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Fitzhardinge <jeremy-TSDbQ3PG+2Y@public.gmane.org>
To: Glauber de Oliveira Costa
	<glommer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: kvm-devel
	<kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>,
	Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
Subject: Re: [RFC] Paravirt timer for KVM
Date: Fri, 12 Oct 2007 11:39:20 -0700	[thread overview]
Message-ID: <470FBF58.2080701@goop.org> (raw)
In-Reply-To: <5d6222a80710120908s6b1f5845head84e7b7a463cd1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Glauber de Oliveira Costa wrote:
> My next TODOs with it are:
> * Get SMP working
> * Try something for stolen time, as jeremy's last suggestion for anthony's patch
> * Measure the time it takes for a hypercall, and subtract this time
> for calculating the expiry time for the timer event.
>   

I don't think there's much point in trying to do stuff like this.  The
guest can be preempted at any time, so there's an arbitrary amount of
time between deciding to set a timeout, and the time the timeout
actually happens.

In theory you can mitigate this by using an absolute rather than
relative timeout value, but in practice I don't think it makes much
difference.

> +
> +/*
> + * This is our read_clock function. The host puts an tsc timestamp each time
> + * it updates a new time, and then we can use it to derive a slightly more
> + * precise notion of elapsed time, converted to nanoseconds.
> + *
> + * If the platform provides a stable tsc, we just use it, and there is no need
> + * for the host to update anything.


How would you deal with suspend/resume/migrate?  Also, do you assume
that stable_tsc also means synchronized tsc on an SMP host?

> + */
> +static cycle_t kvm_clock_read(void) {
> +
> +	u64 delta, last_tsc;
> +	struct timespec *now;
> +
> +	if (hv_clock.stable_tsc) {
> +		rdtscll(last_tsc);
> +		return last_tsc;
>   

So this returns a tsc here? ---->

> +	}
> +
> +	do {
> +		last_tsc = hv_clock.last_tsc;
> +		rmb();
> +		now = &hv_clock.now;
>   

Shouldn't this be taking a copy of now, rather than a pointer to it? 
Otherwise what's the point of this loop?

> +		rmb();
> +	} while (hv_clock.last_tsc != last_tsc);
>   

This won't be an atomic compare on 32-bit; it could get confused by
seeing a half-updated tsc value.

> +
> +	delta = native_read_tsc() - last_tsc;
> +	delta = (delta * hv_clock.tsc_mult) >> KVM_SCALE;
> +
> +	return (cycle_t)now->tv_sec * NSEC_PER_SEC + now->tv_nsec + delta;
>   

---> But returns ns here?

> +}
> +
> +static void kvm_timer_set_mode(enum clock_event_mode mode,
> +				struct clock_event_device *evt)
> +{
> +	WARN_ON(!irqs_disabled());
> +
> +	switch (mode) {
> +	case CLOCK_EVT_MODE_ONESHOT:
> +		/* this is what we want */
> +		break;
> +	case CLOCK_EVT_MODE_RESUME:
> +		break;
> +	case CLOCK_EVT_MODE_PERIODIC:
> +		WARN_ON(1);
> +		break;
> +	case CLOCK_EVT_MODE_UNUSED:
> +	case CLOCK_EVT_MODE_SHUTDOWN:
> +		kvm_hypercall0(KVM_HCALL_STOP_ONESHOT);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +
> +/*
> + * Programming the next event is just a matter of asking the host
> + * to generate us an interrupt when the time expires. We pass the
> + * delta on, and hypervisor will do all remaining tricks. For a more
> + * precise timing, we can just subtract the time spent by the hypercall
>   

Not worthwhile.  It would be better to make the hypercall take an
absolute time, and pass it now+delta.  At least then if you get
preempted past the timeout period you can return -ETIME, and the clock
subsystem will know what to do.

> + */
> +static int kvm_timer_next_event(unsigned long delta,
> +				struct clock_event_device *evt)
> +{
> +	WARN_ON(evt->mode != CLOCK_EVT_MODE_ONESHOT);
> +	kvm_hypercall1(KVM_HCALL_SET_ALARM, delta);
> +	return 0;
> +}
> +
> diff --git a/arch/i386/kernel/setup.c b/arch/i386/kernel/setup.c
> index d474cd6..fd758f9 100644
> --- a/arch/i386/kernel/setup.c
> +++ b/arch/i386/kernel/setup.c
> @@ -46,6 +46,7 @@
>  #include <linux/crash_dump.h>
>  #include <linux/dmi.h>
>  #include <linux/pfn.h>
> +#include <linux/kvm_para.h>
>  
>  #include <video/edid.h>
>  
> @@ -579,6 +580,9 @@ void __init setup_arch(char **cmdline_p)
>  	vmi_init();
>  #endif
>  
> +#ifdef CONFIG_KVM_CLOCK
> +	kvmclock_init();
> +#endif
>   

Why is this necessary?  Can't you hook one of the existing pvops?


    J

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

  parent reply	other threads:[~2007-10-12 18:39 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-12 16:08 [RFC] Paravirt timer for KVM Glauber de Oliveira Costa
     [not found] ` <5d6222a80710120908s6b1f5845head84e7b7a463cd1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-12 18:10   ` Anthony Liguori
     [not found]     ` <470FB8AB.9030101-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-10-15 16:58       ` Glauber de Oliveira Costa
     [not found]         ` <5d6222a80710150958y31338c2ag3a391390b13788da-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-15 17:07           ` Avi Kivity
     [not found]             ` <47139E6F.7030704-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-15 18:09               ` Glauber de Oliveira Costa
     [not found]                 ` <5d6222a80710151109m5376449foc6be5b687c469a2b-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-16  7:31                   ` Avi Kivity
2007-10-12 18:39   ` Jeremy Fitzhardinge [this message]
     [not found]     ` <470FBF58.2080701-TSDbQ3PG+2Y@public.gmane.org>
2007-10-12 18:58       ` Anthony Liguori
2007-10-15 17:15       ` Glauber de Oliveira Costa
2007-10-12 19:48   ` Hollis Blanchard
2007-10-12 20:02     ` Anthony Liguori
     [not found]       ` <470FD2CA.1000702-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-10-12 21:55         ` Hollis Blanchard
2007-10-12 22:07           ` Anthony Liguori
     [not found]             ` <470FF036.6080803-rdkfGonbjUSkNkDKm+mE6A@public.gmane.org>
2007-10-15  4:04               ` Dong, Eddie
     [not found]                 ` <10EA09EFD8728347A513008B6B0DA77A023A6DCE-wq7ZOvIWXbNpB2pF5aRoyrfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2007-10-15 16:01                   ` Hollis Blanchard
2007-10-15 16:47                     ` Avi Kivity
     [not found]                       ` <47139994.4030606-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-15 23:05                         ` Hollis Blanchard
2007-10-16  8:15                           ` Gerd Hoffmann
     [not found]                             ` <4714731D.4040408-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-16 10:27                               ` Avi Kivity
2007-10-16  9:45                           ` Avi Kivity
     [not found]                             ` <4714882C.2050504-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-16 10:03                               ` Dong, Eddie
2007-10-15 17:52                   ` Glauber de Oliveira Costa
     [not found]                     ` <5d6222a80710151052j37f0561dn6dbb5b07f6f697d1-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-16  7:17                       ` Avi Kivity
2007-10-15 17:38           ` Glauber de Oliveira Costa
2007-10-15  8:41         ` Gerd Hoffmann
     [not found]           ` <471327C7.8060304-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-15  9:07             ` Avi Kivity
     [not found]               ` <47132DCF.3060906-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2007-10-15  9:56                 ` Gerd Hoffmann
     [not found]                   ` <47133957.20508-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2007-10-15 10:14                     ` Gildas
2007-10-15 11:02                     ` Carsten Otte
     [not found]                       ` <471348B1.30300-tA70FqPdS9bQT0dZR+AlfA@public.gmane.org>
2007-10-15 16:31                         ` Jeremy Fitzhardinge
2007-10-15 18:03                         ` Glauber de Oliveira Costa
2007-10-15 18:00                     ` Glauber de Oliveira Costa
     [not found]                       ` <5d6222a80710151100p63e8e9aata79b006b43f6c37e-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-16  7:20                         ` Avi Kivity
2007-10-16  7:40                         ` Gerd Hoffmann
2007-10-15 17:53                 ` Glauber de Oliveira Costa
     [not found]     ` <5d6222a80710151029y288fc65bs3d325d5c8d1f039c@mail.gmail.com>
     [not found]       ` <1192489814.22523.36.camel@basalt>
2007-10-16  1:26         ` Glauber de Oliveira Costa
2007-10-12 22:09   ` Hollis Blanchard
2007-10-15 17:48     ` Glauber de Oliveira Costa
     [not found]       ` <5d6222a80710151048t22e747l42106a6507c811c6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-15 22:54         ` Hollis Blanchard
2007-10-16  1:15           ` Glauber de Oliveira Costa
     [not found]             ` <5d6222a80710151815m2330c8b7ocf4fc352954a551c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2007-10-16  9:47               ` Avi Kivity
2007-10-16  7:14         ` Avi Kivity
2007-10-16  8:41   ` Dong, Eddie

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=470FBF58.2080701@goop.org \
    --to=jeremy-tsdbq3pg+2y@public.gmane.org \
    --cc=avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org \
    --cc=glommer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.