From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2Hhz-0004aP-Ft for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:19:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2Hht-0007MM-M9 for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:19:39 -0400 Received: from mail-ea0-x22a.google.com ([2a00:1450:4013:c01::22a]:64403) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2Hht-0007M0-DS for qemu-devel@nongnu.org; Thu, 25 Jul 2013 05:19:33 -0400 Received: by mail-ea0-f170.google.com with SMTP id h10so789564eaj.29 for ; Thu, 25 Jul 2013 02:19:32 -0700 (PDT) Date: Thu, 25 Jul 2013 11:19:29 +0200 From: Stefan Hajnoczi Message-ID: <20130725091929.GD21033@stefanha-thinkpad.redhat.com> References: <1E8E204.8000201@redhat.com> <1374343603-29183-1-git-send-email-alex@alex.org.uk> <1374343603-29183-3-git-send-email-alex@alex.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1374343603-29183-3-git-send-email-alex@alex.org.uk> Subject: Re: [Qemu-devel] [PATCHv2] [RFC 2/7] aio / timers: qemu-timer.c utility functions and add list of clocks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Bligh Cc: Kevin Wolf , Anthony Liguori , qemu-devel@nongnu.org, Stefan Hajnoczi , Paolo Bonzini , rth@twiddle.net On Sat, Jul 20, 2013 at 07:06:38PM +0100, Alex Bligh wrote: > Add utility functions to qemu-timer.c for nanosecond timing. > > Ensure we keep track of all QEMUClocks on a list. > > Add qemu_clock_deadline_ns and qemu_clock_deadline_all_ns to > calculate deadlines to nanosecond accuracy. > > Add utility function qemu_soonest_timeout to calculate soonest deadline. > > Add qemu_timeout_ns_to_ms to convert a timeout in nanoseconds back to > milliseconds for when ppoll is not used. Please split this into smaller patches. There are several logical changes happening here. > @@ -61,6 +71,15 @@ int64_t cpu_get_ticks(void); > void cpu_enable_ticks(void); > void cpu_disable_ticks(void); > > +static inline int64_t qemu_soonest_timeout(int64_t timeout1, int64_t timeout2) > +{ > + /* we can abuse the fact that -1 (which means infinite) is a maximal > + * value when cast to unsigned. As this is disgusting, it's kept in > + * one inline function. > + */ > + return ((uint64_t) timeout1 < (uint64_t) timeout2) ? timeout1 : timeout2; The straightforward version isn't much longer than the commented casting trick: if (timeout1 == -1) { return timeout2; } else if (timeout2 == -1) { return timeout1; } else { return timeout1 < timeout2 ? timeout1 : timeout2; } > @@ -48,6 +44,8 @@ struct QEMUClock { > > int type; > bool enabled; > + > + QLIST_ENTRY(QEMUClock) list; I don't think global state is necessary. The run_timers()/clock_deadline() users have QEMUClock references, they can just call per-QEMUClock functions instead of requiring qemu-timers.c to keep a list. This way AioContext clocks are safe to use from threads. > +void qemu_free_clock(QEMUClock *clock) > +{ > + QLIST_REMOVE(clock, list); > + g_free(clock); assert that there are no timers left?