xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Stefano Stabellini <sstabellini@kernel.org>
Cc: andrew.cooper3@citrix.com, xen-devel@lists.xenproject.org
Subject: Re: [PATCH] xen/time: fix system_time for vtsc=1 PV guests
Date: Fri, 22 Apr 2016 05:12:39 -0600	[thread overview]
Message-ID: <571A234702000078000E4B3C@prv-mh.provo.novell.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1604221043200.6744@sstabellini-ThinkPad-X260>

>>> On 22.04.16 at 12:08, <sstabellini@kernel.org> wrote:
> On Fri, 22 Apr 2016, Jan Beulich wrote:
>> >>> On 21.04.16 at 15:29, <sstabellini@kernel.org> wrote:
>> > --- a/xen/arch/x86/time.c
>> > +++ b/xen/arch/x86/time.c
>> > @@ -784,7 +784,7 @@ static void __update_vcpu_system_time(struct vcpu *v, 
> int force)
>> >      struct cpu_time       *t;
>> >      struct vcpu_time_info *u, _u = {};
>> >      struct domain *d = v->domain;
>> > -    s_time_t tsc_stamp;
>> > +    s_time_t stime_stamp, tsc_stamp = 0;
>> 
>> I don't see why the initializer needs adding here.
> 
> Ops, sorry, I developed the patch against 4.6, the useless
> initialization derives from it.
> 
> 
>> > @@ -807,7 +808,11 @@ static void __update_vcpu_system_time(struct vcpu *v, 
> int force)
>> >                  tsc_stamp = -gtime_to_gtsc(d, -stime);
>> >          }
>> >          else
>> > +        {
>> >              tsc_stamp = gtime_to_gtsc(d, stime);
>> > +            if (!tsc_stamp)
>> 
>> Coding style.
>> 
>> > +                stime_stamp = d->arch.vtsc_offset;
>> > +        }
>> 
>> While I can see this being the right thing for getting the two stamps
>> in sync, is that really helping the guest? Time ought to be not moving
>> forward until getting past vtsc_offset afaict, and that can't be good.
> 
> It helps a lot in my test case: without this Linux hangs due to lost
> timer interrupts (because they are set in the past).
> 
> 
>> I.e. it would seem to me that it's gtime_to_gtsc() that needs
>> adjustment to properly deal with time < d->arch.vtsc_offset.
> 
> I agree that it would be nice to fix gtime_to_gtsc, but how do you
> suggest to do it?

See below.

>> Plus I can't see why, in the worst case, the gTSC value can't be
>> wrapped through zero into negative (or really huge positive) range:
>> Such TSC values are certainly not invalid, and guests shouldn't really
>> make assumptions on TSC values being in the small positive range
>> when they boot.
> 
> Am I understanding correctly that you are suggesting to let the
> subtraction in gtime_to_gtsc return a negative -- actually a wrapped
> around positive?  Something like:
> 
> diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
> index 7a01c90..896fd9f 100644
> --- a/xen/arch/x86/time.c
> +++ b/xen/arch/x86/time.c
> @@ -1757,8 +1757,8 @@ custom_param("tsc", tsc_parse);
>  u64 gtime_to_gtsc(struct domain *d, u64 time)
>  {
>      if ( !is_hvm_domain(d) )
> -        time = max_t(s64, time - d->arch.vtsc_offset, 0);
> -    return scale_delta(time, &d->arch.ns_to_vtsc);
> +        time = time - d->arch.vtsc_offset;
> +    return scale_delta(time2, &d->arch.ns_to_vtsc);
>  }
>  
> Unfortunately that wouldn't solve the problem because of the scaling.

Of course. I thought more along the lines of

u64 gtime_to_gtsc(struct domain *d, u64 time)
{
    if ( !is_hvm_domain(d) )
    {
        if ( time < d->arch.vtsc_offset )
             return -scale_delta(d->arch.vtsc_offset - time, &d->arch.ns_to_vtsc);
        time -= d->arch.vtsc_offset;
    }
    return scale_delta(time, &d->arch.ns_to_vtsc);
}

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2016-04-22 11:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-21 13:29 [PATCH] xen/time: fix system_time for vtsc=1 PV guests Stefano Stabellini
2016-04-22  9:21 ` Jan Beulich
2016-04-22 10:08   ` Stefano Stabellini
2016-04-22 11:12     ` Jan Beulich [this message]
2016-04-22 17:56       ` Stefano Stabellini

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=571A234702000078000E4B3C@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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).