From: Marcelo Tosatti <mtosatti@redhat.com>
To: Glauber Costa <glommer@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, avi@redhat.com
Subject: Re: [PATCH] v4: allow userspace to adjust kvmclock offset
Date: Wed, 14 Oct 2009 15:53:27 -0300 [thread overview]
Message-ID: <20091014185327.GD4218@amt.cnet> (raw)
In-Reply-To: <1255531666-16090-1-git-send-email-glommer@redhat.com>
On Wed, Oct 14, 2009 at 10:47:46AM -0400, Glauber Costa wrote:
> When we migrate a kvm guest that uses pvclock between two hosts, we may
> suffer a large skew. This is because there can be significant differences
> between the monotonic clock of the hosts involved. When a new host with
> a much larger monotonic time starts running the guest, the view of time
> will be significantly impacted.
>
> Situation is much worse when we do the opposite, and migrate to a host with
> a smaller monotonic clock.
>
> This proposed ioctl will allow userspace to inform us what is the monotonic
> clock value in the source host, so we can keep the time skew short, and
> more importantly, never goes backwards. Userspace may also need to trigger
> the current data, since from the first migration onwards, it won't be
> reflected by a simple call to clock_gettime() anymore.
>
> [ v2: uses a struct with a padding ]
> [ v3: provide an ioctl to get clock data too ]
> [ v4: used fixed-width signed type for delta ]
>
> Signed-off-by: Glauber Costa <glommer@redhat.com>
> ---
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/x86.c | 35 ++++++++++++++++++++++++++++++++++-
> include/linux/kvm.h | 7 +++++++
> 3 files changed, 42 insertions(+), 1 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 179a919..c9b0d9f 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -410,6 +410,7 @@ struct kvm_arch{
>
> unsigned long irq_sources_bitmap;
> u64 vm_init_tsc;
> + s64 kvmclock_offset;
> };
>
> struct kvm_vm_stat {
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 9601bc6..09f31e2 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -699,7 +699,8 @@ static void kvm_write_guest_time(struct kvm_vcpu *v)
> /* With all the info we got, fill in the values */
>
> vcpu->hv_clock.system_time = ts.tv_nsec +
> - (NSEC_PER_SEC * (u64)ts.tv_sec);
> + (NSEC_PER_SEC * (u64)ts.tv_sec) + v->kvm->arch.kvmclock_offset;
> +
> /*
> * The interface expects us to write an even number signaling that the
> * update is finished. Since the guest won't see the intermediate
> @@ -2441,6 +2442,38 @@ long kvm_arch_vm_ioctl(struct file *filp,
> r = 0;
> break;
> }
> + case KVM_SET_CLOCK: {
> + struct timespec now;
> + struct kvm_clock_data user_ns;
> + u64 now_ns;
> + s64 delta;
> +
> + r = -EFAULT;
Extra space :)
> #define KVM_CREATE_PIT2 _IOW(KVMIO, 0x77, struct kvm_pit_config)
> #define KVM_SET_BOOT_CPU_ID _IO(KVMIO, 0x78)
> #define KVM_IOEVENTFD _IOW(KVMIO, 0x79, struct kvm_ioeventfd)
> +#define KVM_SET_CLOCK _IOW(KVMIO, 0x7a, struct kvm_clock_data)
> +#define KVM_GET_CLOCK _IOW(KVMIO, 0x7b, struct kvm_clock_data)
_IOR
Otherwise looks fine, please send the userspace changes together.
next prev parent reply other threads:[~2009-10-14 18:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-14 14:47 [PATCH] v4: allow userspace to adjust kvmclock offset Glauber Costa
2009-10-14 18:53 ` Marcelo Tosatti [this message]
2009-10-14 19:12 ` Glauber Costa
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=20091014185327.GD4218@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=glommer@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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.