public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: arnd@arndb.de (Arnd Bergmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 5/6] xen/arm: introduce xen_read_wallclock
Date: Wed, 11 Nov 2015 21:33:57 +0100	[thread overview]
Message-ID: <6299736.g7Jp9b7byl@wuerfel> (raw)
In-Reply-To: <1447260696-450-5-git-send-email-stefano.stabellini@eu.citrix.com>

On Wednesday 11 November 2015 16:51:35 Stefano Stabellini wrote:
> +static void xen_read_wallclock(struct timespec64 *ts)
> +{
> +       u32 version;
> +       u64 delta;
> +       struct timespec64 now;
> +       struct shared_info *s = HYPERVISOR_shared_info;
> +       struct pvclock_wall_clock *wall_clock = &(s->wc);
> +
> +       /* get wallclock at system boot */
> +       do {
> +               version = wall_clock->version;
> +               rmb();          /* fetch version before time */
> +               now.tv_sec  = ((uint64_t)wall_clock->sec_hi << 32) | wall_clock->sec;
> +               now.tv_nsec = wall_clock->nsec;
> +               rmb();          /* fetch time before checking version */
> +       } while ((wall_clock->version & 1) || (version != wall_clock->version));
> +
> +       /* time since system boot */
> +       delta = ktime_get_ns();
> +       delta += now.tv_sec * (u64)NSEC_PER_SEC + now.tv_nsec;
> +
> +       *ts = ns_to_timespec64(delta);
> +}

Looks correct to me and better than the previous versions, but you are still
converting from timespec64 to nanoseconds and back. While I previously
recommended going all the way to nanoseconds here, I guess this you
can even avoid the ns_to_timespec64() if you stay within timespec64
domain and replace the last lines with

	ktime_get_ts64(&ts_monotonic);
	*ts = timespec64_add(now, ts_monotonic);

which avoids both the multiplication and division.

	Arnd

  reply	other threads:[~2015-11-11 20:33 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-11 16:49 [PATCH v3 0/6] Xen wallclock on arm and arm64 Stefano Stabellini
2015-11-11 16:51 ` [PATCH v3 1/6] xen: rename dom0_op to platform_op Stefano Stabellini
2015-11-12 15:01   ` Stefano Stabellini
2015-11-12 15:23   ` Boris Ostrovsky
2015-11-11 16:51 ` [PATCH v3 2/6] xen/arm: introduce HYPERVISOR_platform_op on arm and arm64 Stefano Stabellini
2015-11-11 16:51 ` [PATCH v3 3/6] xen: introduce XENPF_settime64 Stefano Stabellini
2015-11-12 15:30   ` Boris Ostrovsky
2015-11-12 16:10     ` Arnd Bergmann
2015-11-12 16:34     ` Stefano Stabellini
2015-11-12 17:16       ` Boris Ostrovsky
2015-11-12 19:27         ` Arnd Bergmann
2015-11-11 16:51 ` [PATCH v3 4/6] arm: extend pvclock_wall_clock with sec_hi Stefano Stabellini
2015-11-11 16:51 ` [PATCH v3 5/6] xen/arm: introduce xen_read_wallclock Stefano Stabellini
2015-11-11 20:33   ` Arnd Bergmann [this message]
2015-11-12 11:28     ` Stefano Stabellini
2015-11-11 16:51 ` [PATCH v3 6/6] xen/arm: set the system time in Xen via the XENPF_settime64 hypercall Stefano Stabellini
2015-11-11 20:35   ` Arnd Bergmann

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=6299736.g7Jp9b7byl@wuerfel \
    --to=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.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