All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH v3 3/6] x86/time: streamline platform time init on plt_update()
Date: Fri, 9 Sep 2016 17:32:46 +0100	[thread overview]
Message-ID: <57D2E42E.1050409@oracle.com> (raw)
In-Reply-To: <57C598DF020000780010A275@prv-mh.provo.novell.com>

On 08/30/2016 01:31 PM, Jan Beulich wrote:
>>>> On 30.08.16 at 14:10, <joao.m.martins@oracle.com> wrote:
>> What would be a preferred period - probably capping it to a day/hour/minutes? Or
>> keeping the current calculated value? Maximum right now in current platform timers
>> are few minutes depending on the HPET frequency.
> 
> Ideally I would see you just use the calculated value, unless that
> causes problems elsewhere. Depending on such possible problems
> would be what cap to alternatively use.

While sending v4 out, I spotted some issues with platform timer overflow
handling when we get close to u64 boundary. Specific to clocksource=tsc, and
setting up the plt_overflow, one would see at boot:

"Platform timer appears to have unexpectedly wrapped 10 or more times"

The counter doesn't wrap or stop at all.
But current overflowing checking goes like:

	count = plt_src.read_counter();
        plt_stamp64 += (count - plt_stamp) & plt_mask;

	now = NOW();
	plt_wrap = __read_platform_stime(plt_stamp64);
	plt_stamp = count;

	for (i=0;...)
	{

	plt_now = plt_wrap;
	plt_wrap = __read_platform_stime(plt_stamp64 + plt_mask + 1);

@@	if ( ABS(plt_wrap - now) > ABS(plt_now - now) )
            break; // didn't wrap around
	// did wrap
	plt_stamp64 += plt_mask + 1;

	}

	if (i!=0)
		"Platform timer appears to have unexpectedly wrapped "

Effectively the calculation in @@ doesn't handle the fact that for
clocksource=tsc, "ABS(plt_wrap - now)" would be == to "ABS(plt_now -
now)". Not that is right to be so, but TSC is a 64-bit counter and "plt_mask +
1" overflows the u64, turning the above condition into a comparison of same
value. For <= 32-bit platform timers the current math works fine, but reaching
the 64-bit boundary not so much. And then handling the wraparound further below
with "plt_stamp64 += plt_mask + 1" is effectively adding zeroes, which is
assuming that plt_stamp64/plt_stamp is alone enough to not represent any
discontinuity.

I am not sure we shouldn't handle this way at least for clocksource=tsc: we only
see issues when the delta of the two stamps overflows a u64 (computed with:
plt_stamp64 + (read_counter() - plt_stamp)). Keeping those two stamps updated
more often and we won't see issues. When the wraparound happens (in lots lots of
years away) we could not only update plt_stamp64 and plt_stamp, but also
increment stime_platform_stamp and platform_timer_stamp. This lets us compensate
when the stamps wraparound since for stime_platform_stamp (in ns) that would
only happen after STIME_MAX. Or as a simpler alternative, keeping this patch and
update plt_stamp64 (zeroing this one out) plus plt_stamp on
platform_time_calibration() as additional change.

Would that sound reasonable - am I overlooking something? To some extent this
might also applicable to the general case, although platform timer is now only
used for initial seeding so probably a non-visible issue.

Joao

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

  reply	other threads:[~2016-09-09 16:31 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-24 12:43 [PATCH v3 0/6] x86/time: PVCLOCK_TSC_STABLE_BIT support Joao Martins
2016-08-24 12:43 ` [PATCH v3 1/6] x86/time: refactor init_platform_time() Joao Martins
2016-08-25 10:03   ` Jan Beulich
2016-08-26 14:54     ` Joao Martins
2016-08-24 12:43 ` [PATCH v3 2/6] x86/time: implement tsc as clocksource Joao Martins
2016-08-25 10:06   ` Jan Beulich
2016-08-26 15:11     ` Joao Martins
2016-08-29  9:36       ` Jan Beulich
2016-08-30 12:08         ` Joao Martins
2016-08-30 12:30           ` Jan Beulich
2016-08-30 13:59             ` Joao Martins
2016-08-24 12:43 ` [PATCH v3 3/6] x86/time: streamline platform time init on plt_update() Joao Martins
2016-08-25 10:13   ` Jan Beulich
2016-08-26 15:12     ` Joao Martins
2016-08-29  9:41       ` Jan Beulich
2016-08-30 12:10         ` Joao Martins
2016-08-30 12:31           ` Jan Beulich
2016-09-09 16:32             ` Joao Martins [this message]
2016-09-12  7:26               ` Jan Beulich
2016-09-12 10:35                 ` Joao Martins
2016-08-24 12:43 ` [PATCH v3 4/6] x86/time: refactor read_platform_stime() Joao Martins
2016-08-25 10:17   ` Jan Beulich
2016-08-26 15:13     ` Joao Martins
2016-08-29  9:42       ` Jan Beulich
2016-08-24 12:43 ` [PATCH v3 5/6] x86/time: implement PVCLOCK_TSC_STABLE_BIT Joao Martins
2016-08-25 10:37   ` Jan Beulich
2016-08-26 15:44     ` Joao Martins
2016-08-29 10:06       ` Jan Beulich
2016-08-30 12:26         ` Joao Martins
2016-08-30 12:45           ` Jan Beulich
2016-08-30 14:14             ` Joao Martins
2016-08-24 12:43 ` [PATCH v3 6/6] docs: update clocksource option Joao Martins
2016-08-25 10:38   ` Jan Beulich
2016-08-26 15:13     ` Joao Martins
2016-08-24 12:50 ` [PATCH v3 0/6] x86/time: PVCLOCK_TSC_STABLE_BIT support Joao Martins

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=57D2E42E.1050409@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --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.