Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932098AbbKLL3H (ORCPT ); Thu, 12 Nov 2015 06:29:07 -0500 Received: from smtp.citrix.com ([66.165.176.89]:19476 "EHLO SMTP.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753962AbbKLL3F (ORCPT ); Thu, 12 Nov 2015 06:29:05 -0500 X-IronPort-AV: E=Sophos;i="5.20,281,1444694400"; d="scan'208";a="311781896" Date: Thu, 12 Nov 2015 11:28:47 +0000 From: Stefano Stabellini X-X-Sender: sstabellini@kaball.uk.xensource.com To: Arnd Bergmann CC: , Stefano Stabellini , , , Subject: Re: [PATCH v3 5/6] xen/arm: introduce xen_read_wallclock In-Reply-To: <6299736.g7Jp9b7byl@wuerfel> Message-ID: References: <1447260696-450-5-git-send-email-stefano.stabellini@eu.citrix.com> <6299736.g7Jp9b7byl@wuerfel> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1853 Lines: 43 On Wed, 11 Nov 2015, Arnd Bergmann wrote: > 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. Much better, I'll do that. Thanks for the suggestion! -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/