xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: xen-devel@lists.xen.org
Subject: Re: [PATCH 01/13] x86/time.c: Use system time to calculate elapsed_nsec in tsc_get_info()
Date: Fri, 9 Oct 2015 14:59:54 -0400	[thread overview]
Message-ID: <56180EAA.6050405@oracle.com> (raw)
In-Reply-To: <20151009165112.GB23023@hzzhang-OptiPlex-9020.sh.intel.com>

On 10/09/2015 12:51 PM, Haozhong Zhang wrote:
> On Fri, Oct 09, 2015 at 12:31:53PM -0400, Boris Ostrovsky wrote:
>> On 10/09/2015 12:19 PM, Jan Beulich wrote:
>>>>>> On 09.10.15 at 18:09, <boris.ostrovsky@oracle.com> wrote:
>>>> On 10/09/2015 11:11 AM, Jan Beulich wrote:
>>>>>>>> On 09.10.15 at 16:00, <haozhong.zhang@intel.com> wrote:
>>>>>> On Fri, Oct 09, 2015 at 09:41:36AM -0400, Boris Ostrovsky wrote:
>>>>>>> On 10/09/2015 02:51 AM, Jan Beulich wrote:
>>>>>>>>>>> On 28.09.15 at 09:13, <haozhong.zhang@intel.com> wrote:
>>>>>>>>> When the TSC mode of a domain is TSC_MODE_DEFAULT and no TSC emulation
>>>>>>>>> is used, the existing tsc_get_info() calculates elapsed_nsec by scaling
>>>>>>>>> the host TSC with a ratio between guest TSC rate and
>>>>>>>>> nanoseconds. However, the result will be incorrect if the guest TSC rate
>>>>>>>>> differs from the host TSC rate. This patch fixes this problem by using
>>>>>>>>> the system time as elapsed_nsec.
>>>>>>>> For both this and patch 2, while at a first glance (and taking into
>>>>>>>> account just the visible patch context) what you say seems to
>>>>>>>> make sense, the explanation is far from sufficient namely when
>>>>>>>> looking at the function as a whole. For one, effects on existing
>>>>>>>> cases need to be explicitly described, in particular why SVM's TSC
>>>>>>>> ratio code works without that change (or whether it has been
>>>>>>>> broken all along, in which case these would become backporting
>>>>>>>> candidates; input from SVM maintainers would be appreciated
>>>>>>>> too). That may in particular mean being more specific about
>>>>>>>> what is actually wrong with scaling the host TSC here (i.e. in
>>>>>>>> which way both results differ), when supposedly that matches
>>>>>>>> what the hardware does when TSC ratio is supported.
>>>>>>> If elapsed_nsec is the time that guest has been running then how can
>>>>>>> get_s_time(), which is system time, be the right answer here? But what
>>>>>>> confuses me even more is that existing code is not doing that neither.
>>>>>>>
>>>>>>> Shouldn't elapsed_nsec be offset by d->arch.vtsc_offset on the get side?
>>>>>>> I.e.
>>>>>>>
>>>>>>> *elapsed_nsec = get_s_time() - d->arch.vtsc_offset?
>>>>>>>
>>>>>> Yes, I should minus d->arch.vtsc_offset here.
>>>>> In which case - afaict - the code becomes identical to that of the
>>>>> TSC_MODE_ALWAYS_EMULATE case as well as the
>>>>> TSC_MODE_DEFAULT w/ d->arch.vtsc true. Which seems quite
>>>>> unlikely to be correct.
>>>> *elapsed_nsec = *gtsc_khz = 0; ? Because we are effectively in
>>>> TSC_MODE_NEVER.
>>> How that? Talk here has been about TSC_MODE_DEFAULT...
>> AFAIUI, TSC_MODE_DEFAULT is a shorthand for saying "I will let the
>> hypervisor pick whether the guest will be in TSC_MODE_ALWAYS_EMULATE or
>> TSC_MODE_NEVER". d->arch.vtsc is what ends up being internal implementation
>> of user-provided mode (for the most parts; I think hvm_cpuid() being the
>> only true exception --- and perhaps it needs to be looked at).
>>
>> So if we have d->arch.vtsc=0 (which is the case we are talking about here)
>> then we are really in NEVER mode
>>
> Not quite understand this. Is tsc_set_info() the only place to set
> d->arch.tsc_mode ?

Yes.

> Though it may decide d->arch.vtsc should be 1, it
> still sets d->arch.tsc_mode to the user provided TSC mode for a
> non-pvh domain. And then in tsc_get_info(), it should never fall into
> TSC_MODE_NEVER_EMULATE branch if d->arch.tsc_mode is not.

I was trying to say that TSC behavior in current incarnation is 
equivalent to _NEVER if d->arch.vtsc is 0. But when we call 
tsc_get_info() we can not handle it out of _NEVER case (because, as you 
pointed out, d->arch.vtsc may change after migration). And we don't.

-boris


>
> - Haozhong
>
>> -boris
>>
>>>> That can't be right...
>>> Why not? tsc_set_info() doesn't care about any of its other input
>>> values when that mode is in effect.
>>>
>>> Jan
>>>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

  reply	other threads:[~2015-10-09 18:59 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-28  7:13 [PATCH 00/13] Add VMX TSC scaling support Haozhong Zhang
2015-09-28  7:13 ` [PATCH 01/13] x86/time.c: Use system time to calculate elapsed_nsec in tsc_get_info() Haozhong Zhang
2015-10-09  6:51   ` Jan Beulich
2015-10-09 13:41     ` Boris Ostrovsky
2015-10-09 14:00       ` Haozhong Zhang
2015-10-09 15:11         ` Jan Beulich
2015-10-09 16:09           ` Boris Ostrovsky
2015-10-09 16:19             ` Jan Beulich
2015-10-09 16:31               ` Boris Ostrovsky
2015-10-09 16:51                 ` Haozhong Zhang
2015-10-09 18:59                   ` Boris Ostrovsky [this message]
2015-10-09 14:39       ` Jan Beulich
2015-10-09 15:37         ` Boris Ostrovsky
2015-10-09 16:39           ` Haozhong Zhang
2015-10-09 16:44             ` Boris Ostrovsky
2015-10-09 14:35     ` Haozhong Zhang
2015-10-09 14:43       ` Jan Beulich
2015-10-09 15:56         ` Boris Ostrovsky
2015-10-14  2:45     ` Haozhong Zhang
2015-10-14  9:40       ` Jan Beulich
2015-10-14 10:00         ` Haozhong Zhang
2015-10-14 10:20           ` Jan Beulich
2015-10-14 10:24             ` Haozhong Zhang
2015-09-28  7:13 ` [PATCH 02/13] x86/time.c: Get the correct guest TSC rate " Haozhong Zhang
2015-09-28  7:13 ` [PATCH 03/13] x86/hvm: Collect information of TSC scaling ratio Haozhong Zhang
2015-10-22 12:53   ` Jan Beulich
2015-10-22 14:40     ` Haozhong Zhang
2015-10-22 14:51       ` Jan Beulich
2015-10-22 15:57         ` Haozhong Zhang
2015-09-28  7:13 ` [PATCH 04/13] x86/hvm: Setup " Haozhong Zhang
2015-10-22 13:13   ` Jan Beulich
2015-10-22 15:55     ` Haozhong Zhang
2015-10-22 16:05       ` Jan Beulich
2015-10-22 16:39         ` Haozhong Zhang
2015-10-23  7:44     ` Haozhong Zhang
2015-10-23  7:59       ` Jan Beulich
2015-10-23  8:18         ` Haozhong Zhang
2015-10-23  8:31           ` Jan Beulich
2015-10-23  8:40             ` Haozhong Zhang
2015-10-23  9:18               ` Jan Beulich
2015-09-28  7:13 ` [PATCH 05/13] x86/hvm: Replace architecture TSC scaling by a common function Haozhong Zhang
2015-10-22 13:52   ` Jan Beulich
2015-10-23  0:49     ` Haozhong Zhang
2015-09-28  7:13 ` [PATCH 06/13] x86/hvm: Scale host TSC when setting/getting guest TSC Haozhong Zhang
2015-10-22 14:17   ` Jan Beulich
2015-10-22 15:44     ` Boris Ostrovsky
2015-10-22 16:23       ` Haozhong Zhang
2015-10-27 20:16       ` Aravind Gopalakrishnan
2015-10-28  1:51         ` Haozhong Zhang
2015-11-09  7:43         ` Haozhong Zhang
2015-11-12 13:50           ` George Dunlap
2015-10-22 16:03     ` Haozhong Zhang
2015-10-27  1:54     ` Haozhong Zhang
2015-10-27  8:15       ` Jan Beulich
2015-10-27  8:25         ` Haozhong Zhang
2015-10-27  8:44     ` Haozhong Zhang
2015-10-27 13:10       ` Boris Ostrovsky
2015-10-27 13:55         ` Boris Ostrovsky
2015-10-27 16:13           ` haozhong.zhang
2015-10-27 16:13         ` haozhong.zhang
2015-09-28  7:13 ` [PATCH 07/13] x86/hvm: Move saving/loading vcpu's TSC to common code Haozhong Zhang
2015-10-22 14:54   ` Jan Beulich
2015-09-28  7:13 ` [PATCH 08/13] x86/hvm: Detect TSC scaling through hvm_funcs in tsc_set_info() Haozhong Zhang
2015-10-22 15:01   ` Jan Beulich
2015-09-28  7:13 ` [PATCH 09/13] x86/time.c: Scale host TSC in pvclock properly Haozhong Zhang
2015-09-28 16:36   ` Boris Ostrovsky
2015-09-29  0:19     ` Haozhong Zhang
2015-10-22 15:50   ` Boris Ostrovsky
2015-10-22 16:44     ` Haozhong Zhang
2015-10-22 19:15       ` Boris Ostrovsky
2015-09-28  7:13 ` [PATCH 10/13] vmx: Detect and initialize VMX RDTSC(P) scaling Haozhong Zhang
2015-10-27 13:19   ` Jan Beulich
2015-10-27 16:17     ` Haozhong Zhang
2015-09-28  7:13 ` [PATCH 11/13] vmx: Use scaled host TSC to calculate TSC offset Haozhong Zhang
2015-10-22 15:55   ` Boris Ostrovsky
2015-10-22 17:12     ` Haozhong Zhang
2015-10-22 19:19       ` Boris Ostrovsky
2015-10-23  0:52         ` Haozhong Zhang
2015-10-27 13:29   ` Jan Beulich
2015-10-27 16:21     ` Haozhong Zhang
2015-09-28  7:13 ` [PATCH 12/13] vmx: Add a call-back to apply TSC scaling ratio to hardware Haozhong Zhang
2015-09-28 16:02   ` Boris Ostrovsky
2015-09-29  1:07     ` Haozhong Zhang
2015-09-29  9:33       ` Andrew Cooper
2015-09-29 10:02         ` Haozhong Zhang
2015-09-29 10:25           ` Andrew Cooper
2015-09-29 13:59             ` Haozhong Zhang
2015-10-27 13:33   ` Jan Beulich
2015-10-28  2:41     ` Haozhong Zhang
2015-09-28  7:13 ` [PATCH 13/13] tools/libxl: Add 'vtsc_khz' option to set guest TSC rate Haozhong Zhang
2015-09-28 11:47   ` Julien Grall
2015-09-28 12:11     ` Haozhong Zhang
2015-09-28 14:19   ` Wei Liu
2015-09-29  0:40     ` Haozhong Zhang
2015-09-29  9:20       ` Wei Liu
2015-09-29  9:50         ` Haozhong Zhang
2015-09-29 10:24           ` Julien Grall
2015-09-29 10:07       ` Ian Campbell
2015-09-29 10:33         ` Wei Liu
2015-09-29 12:57         ` Haozhong Zhang
2015-09-29 10:04   ` Ian Campbell
2015-09-29 10:13     ` Haozhong Zhang
2015-09-29 10:24       ` Andrew Cooper
2015-09-29 10:28         ` Ian Campbell
2015-09-29 10:31           ` Andrew Cooper
2015-09-29 13:53           ` Haozhong Zhang
2015-09-29 13:56             ` Andrew Cooper
2015-09-29 14:01               ` Haozhong Zhang
2015-09-29 14:37                 ` Ian Campbell
2015-09-29 15:16                   ` Haozhong Zhang
2015-09-28 10:51 ` [PATCH 00/13] Add VMX TSC scaling support Andrew Cooper
2015-09-28 13:48   ` Boris Ostrovsky
2015-11-22 17:54 ` Haozhong Zhang
2015-11-23 15:37   ` Boris Ostrovsky
2015-11-24 13:05     ` Haozhong Zhang
2015-11-24 14:19       ` Boris Ostrovsky
2015-11-24 14:25       ` Haozhong Zhang

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=56180EAA.6050405@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=xen-devel@lists.xen.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 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).