linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Radim Krcmar <rkrcmar@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Cochran <richardcochran@gmail.com>,
	Miroslav Lichvar <mlichvar@redhat.com>
Subject: Re: [patch 2/3] KVM: x86: add KVM_HC_CLOCK_OFFSET hypercall
Date: Fri, 13 Jan 2017 18:07:40 +0100	[thread overview]
Message-ID: <20170113170739.GF22440@potion> (raw)
In-Reply-To: <20170113154321.GB4796@amt.cnet>

2017-01-13 13:43-0200, Marcelo Tosatti:
> On Fri, Jan 13, 2017 at 04:31:58PM +0100, Radim Krcmar wrote:
>> 2017-01-13 10:01-0200, Marcelo Tosatti:
>> > Add a hypercall to retrieve the host realtime clock
>> > and the TSC value used to calculate that clock read.
>> > 
>> > Used to implement clock synchronization between
>> > host and guest.
>> > 
>> > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
>> > 
>> > ---
>> > Index: kvm-ptpdriver/Documentation/virtual/kvm/hypercalls.txt
>> > @@ -81,3 +81,33 @@
>> > +6. KVM_HC_CLOCK_OFFSET
>> > +------------------------
>> > +Architecture: x86
>> > +Status: active
>> > +Purpose: Hypercall used to synchronize host and guest clocks.
>> > +Usage:
>> > +
>> > +a0: guest physical address where host copies
>> > +"struct kvm_clock_offset" structure.
>> > +
>> > +a1: clock_type, ATM only KVM_CLOCK_OFFSET_WALLCLOCK (0)
>> > +is supported (hosts CLOCK_REALTIME clock).
>> > +
>> > +		struct kvm_clock_offset {
>> > +			__s64 sec;
>> > +			__s64 nsec;
>> 
>> Why is nsec:
>>  1) signed -- it is a remainder after division by NSEC_PER_SEC
> 
> Because "struct timespec" is signed because it can be used for
> time deltas (you won't actually get signed values for
> kvm_get_walltime_and_clockread).
> 
> Just wanted to match "struct timespec".
> 
>>  2) bigger than 32 bit -- NSEC_PER_SEC < 2^32
>> ?
> 
> Again matching struct timespec.

It is "long" in struct timespec, which could also be "s32" ...
I'd rather waste those 8 bytes inside padding -- its purpose is clear
there. :)

>> > +			__u64 tsc;
>> > +			__u32 flags;
>> > +			__u32 pad;
>> > +		};
>> > +
>> > +       Where:
>> > +               * sec: seconds from clock_type clock.
>> > +               * nsec: nanoseconds from clock_type clock.
>> 
>> The important part of an offset is the starting point -- I assume it is
>> the the usual one, but documentation better be explicit.
> 
> Don't get what you mean? (the values have same meaning as hosts
> clock_gettime(CLOCK_REALTIME), supposedly that is clear).

Ah, I didn't understand that clock_type was refering to CLOCK_REALTIME.

I'd drop offset from the hypercall name.  IIUC, all various clock types
would be compared to TSC, so we could name the hypercall somewhat like
KVM_HC_CLOCK_AT_TSC -- we want to know what was the time on the selected
clock when TSC was at value __u64 tsc.
The only offset is between sec+nsec and the beginning of time (and tsc
and 0), but we don't care about that offset by itself -- we care about
relation of sec+nsec to tsc, which isn't a simple offset as they flow
differently.

If we wanted to be more generic, then KVM_HC_CLOCK_PAIRING/SNAPSHOT/...
and argument 1 would contain clock_types, here REALTIME and TSC.

  reply	other threads:[~2017-01-13 17:07 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-13 12:01 [patch 0/3] KVM virtual PTP driver Marcelo Tosatti
2017-01-13 12:01 ` [patch 1/3] KVM: x86: provide realtime host clock via vsyscall notifiers Marcelo Tosatti
2017-01-13 15:18   ` Radim Krcmar
2017-01-13 15:34     ` Marcelo Tosatti
2017-01-13 16:28       ` Radim Krcmar
2017-01-13 17:51         ` Marcelo Tosatti
2017-01-16 15:40           ` Radim Krcmar
2017-01-13 15:41     ` Konrad Rzeszutek Wilk
2017-01-13 15:46       ` Marcelo Tosatti
2017-01-13 12:01 ` [patch 2/3] KVM: x86: add KVM_HC_CLOCK_OFFSET hypercall Marcelo Tosatti
2017-01-13 15:31   ` Radim Krcmar
2017-01-13 15:43     ` Marcelo Tosatti
2017-01-13 17:07       ` Radim Krcmar [this message]
2017-01-13 17:57         ` Marcelo Tosatti
2017-01-13 12:01 ` [patch 3/3] PTP: add kvm PTP driver Marcelo Tosatti
2017-01-13 15:56   ` Radim Krcmar
2017-01-13 17:40     ` Marcelo Tosatti
2017-01-16 16:26       ` Radim Krcmar
2017-01-16 16:54         ` Radim Krcmar
2017-01-16 17:08           ` Marcelo Tosatti
2017-01-16 17:27             ` Radim Krcmar
2017-01-16 17:39               ` Marcelo Tosatti
2017-01-16 18:01                 ` Radim Krcmar
2017-01-16 19:36                   ` Marcelo Tosatti
2017-01-16 19:47                     ` Marcelo Tosatti
2017-01-16 20:01                       ` Marcelo Tosatti
2017-01-17  8:03                         ` Miroslav Lichvar
2017-01-17 11:30                           ` Marcelo Tosatti
2017-01-17 15:36                             ` Radim Krcmar
2017-01-18 12:17                               ` Marcelo Tosatti
2017-01-18 12:24                                 ` Marcelo Tosatti
2017-01-18 12:46                                   ` Paolo Bonzini
2017-01-18 13:36                                     ` Miroslav Lichvar
2017-01-18 14:02                                       ` Paolo Bonzini
2017-01-18 14:50                                         ` Marcelo Tosatti
2017-01-18 15:35                                           ` Radim Krcmar
2017-01-18 15:45                                           ` Paolo Bonzini
2017-01-18 15:57                                             ` Marcelo Tosatti
2017-01-18 14:24                                     ` Marcelo Tosatti
2017-01-18 15:54                                       ` Miroslav Lichvar
2017-01-18 16:07                                         ` Paolo Bonzini
2017-01-18 16:14                                         ` Radim Krcmar
2017-01-18 14:37                                     ` Marcelo Tosatti
2017-01-18 14:53                                       ` Marcelo Tosatti
2017-01-18 15:20                                         ` Radim Krcmar
2017-01-18 15:28                                           ` Marcelo Tosatti
2017-01-20 14:18                                             ` Radim Krcmar
2017-01-18 15:59                                     ` Radim Krcmar
2017-01-16 17:04         ` Marcelo Tosatti
2017-01-16 17:46           ` Radim Krcmar
2017-01-16 19:33             ` Marcelo Tosatti
2017-01-14 15:26     ` Richard Cochran
2017-01-16 15:48       ` Radim Krcmar
2017-01-13 18:45 [patch 0/3] KVM virtual PTP driver (v2) Marcelo Tosatti
2017-01-13 18:46 ` [patch 2/3] KVM: x86: add KVM_HC_CLOCK_OFFSET hypercall Marcelo Tosatti

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=20170113170739.GF22440@potion \
    --to=rkrcmar@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlichvar@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=richardcochran@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).