All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Igor Druzhinin <igor.druzhinin@citrix.com>,
	andrew.cooper3@citrix.com, wl@xen.org,
	xen-devel@lists.xenproject.org
Subject: Re: [Xen-devel] [PATCH 2/2] x86/time: update vtsc_last with cmpxchg and drop vtsc_lock
Date: Mon, 16 Dec 2019 13:55:43 +0100	[thread overview]
Message-ID: <20191216125543.GO11756@Air-de-Roger> (raw)
In-Reply-To: <a69ee32c-02ed-330f-a457-51b1f221ce06@suse.com>

On Mon, Dec 16, 2019 at 01:45:10PM +0100, Jan Beulich wrote:
> On 16.12.2019 13:30, Roger Pau Monné wrote:
> > On Mon, Dec 16, 2019 at 12:21:09PM +0100, Jan Beulich wrote:
> >> On 16.12.2019 11:00, Roger Pau Monné wrote:
> >>> On Fri, Dec 13, 2019 at 10:48:02PM +0000, Igor Druzhinin wrote:
> >>>>  uint64_t pv_soft_rdtsc(const struct vcpu *v, const struct cpu_user_regs *regs)
> >>>>  {
> >>>> -    s_time_t now = get_s_time();
> >>>> +    s_time_t old, new, now = get_s_time();
> >>>>      struct domain *d = v->domain;
> >>>>  
> >>>> -    spin_lock(&d->arch.vtsc_lock);
> >>>> -
> >>>> -    if ( (int64_t)(now - d->arch.vtsc_last) > 0 )
> >>>> -        d->arch.vtsc_last = now;
> >>>> -    else
> >>>> -        now = ++d->arch.vtsc_last;
> >>>> -
> >>>> -    spin_unlock(&d->arch.vtsc_lock);
> >>>> +    do {
> >>>> +        old = d->arch.vtsc_last;
> >>>> +        new = (int64_t)(now - d->arch.vtsc_last) > 0 ? now : old + 1;
> >>>
> >>> Why do you need to do this subtraction? Isn't it easier to just do:
> >>>
> >>> new = now > d->arch.vtsc_last ? now : old + 1;
> >>
> >> This wouldn't be reliable when the TSC wraps. Remember that firmware
> >> may set the TSC, and it has been seen to be set to very large
> >> (effectively negative, if they were signed quantities) values,
> > 
> > s_time_t is a signed value AFAICT (s64).
> 
> Oh, I should have looked at types, rather than inferring uint64_t
> in particular for something like vtsc_last.
> 
> >> which
> >> will then eventually wrap (whereas we're not typically concerned of
> >> 64-bit counters wrapping when they start from zero).
> > 
> > But get_s_time returns the system time in ns since boot, not the TSC
> > value, hence it will start from 0 and we shouldn't be concerned about
> > wraps?
> 
> Good point, seeing that all parts here are s_time_t. Of course
> with all parts being so, there's indeed no need for the cast,
> but comparing both values is then equivalent to comparing the
> difference against zero.

Right, I just think it's easier to compare both values instead of
comparing the difference against zero (and likely less expensive in
terms of performance).

Anyway, I prefer comparing both values instead of the difference, but
that's also correct and I would be fine with it as long as the cast is
dropped.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-12-16 12:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13 22:48 [Xen-devel] [PATCH 0/2] vTSC performance improvements Igor Druzhinin
2019-12-13 22:48 ` [Xen-devel] [PATCH 1/2] x86/time: drop vtsc_{kern, user}count debug counters Igor Druzhinin
2019-12-16  9:47   ` Roger Pau Monné
2019-12-16 14:24     ` Andrew Cooper
2019-12-13 22:48 ` [Xen-devel] [PATCH 2/2] x86/time: update vtsc_last with cmpxchg and drop vtsc_lock Igor Druzhinin
2019-12-16 10:00   ` Roger Pau Monné
2019-12-16 11:21     ` Jan Beulich
2019-12-16 12:30       ` Roger Pau Monné
2019-12-16 12:45         ` Jan Beulich
2019-12-16 12:55           ` Roger Pau Monné [this message]
2019-12-16 12:53     ` Igor Druzhinin
2019-12-16 12:57       ` Roger Pau Monné

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=20191216125543.GO11756@Air-de-Roger \
    --to=roger.pau@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=igor.druzhinin@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=wl@xen.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 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.