Received: from eggs.gnu.org ([2001:4830:134:3::10]:54779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEajU-00079u-Fb for qemu-devel@nongnu.org; Wed, 28 Aug 2013 04:04:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VEajN-0001xA-4p for qemu-devel@nongnu.org; Wed, 28 Aug 2013 04:04:04 -0400 Received: from mail-ee0-f45.google.com ([74.125.83.45]:49640) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VEajM-0001x0-Ue for qemu-devel@nongnu.org; Wed, 28 Aug 2013 04:03:57 -0400 Received: by mail-ee0-f45.google.com with SMTP id c50so2756861eek.32 for ; Wed, 28 Aug 2013 01:03:41 -0700 (PDT) Date: Wed, 28 Aug 2013 10:03:37 +0200 From: Stefan Hajnoczi Message-ID: <20130828080337.GC4696@stefanha-thinkpad.muc.redhat.com> References: <1377591839-2743-1-git-send-email-stefanha@redhat.com> <1377591839-2743-3-git-send-email-stefanha@redhat.com> <57013E01-633A-4F71-9AC9-921D0917832B@alex.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <57013E01-633A-4F71-9AC9-921D0917832B@alex.org.uk> Subject: Re: [Qemu-devel] [PATCH v2 2/2] qemu-timer: make qemu_timer_mod_ns() and qemu_timer_del() thread-safe List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex Bligh Cc: Paolo Bonzini , Ping Fan Liu , qemu-devel@nongnu.org, Stefan Hajnoczi On Tue, Aug 27, 2013 at 09:55:22AM +0100, Alex Bligh wrote: > On 27 Aug 2013, at 09:23, Stefan Hajnoczi wrote: > > diff --git a/include/qemu/timer.h b/include/qemu/timer.h > > index e4934dd..b58903b 100644 > > --- a/include/qemu/timer.h > > +++ b/include/qemu/timer.h > > @@ -115,6 +115,10 @@ static inline int64_t qemu_clock_get_us(QEMUClockType type) > > * Determines whether a clock's default timer list > > * has timers attached > > * > > + * Note that this function should not be used when other threads also access > > + * the timer list. The return value may be outdated by the time it is acted > > + * upon. > > + * > > I'm in two minds as to whether there is a problem with the comment or the > code here. Despite git's best endeavours, this is a comment on qemu_clock_has_timers, > which is called in qemu_clock_warp in cpus.c. I'm still a little confused as > to what thread(s) that can be called from. Remember icount is a TCG feature and will only be accessed from a single thread. > > @@ -531,6 +545,9 @@ void timer_mod_ns(QEMUTimer *ts, int64_t expire_time); > > * > > * Modify a timer to expiry at @expire_time, taking into > > * account the scale associated with the timer. > > + * > > + * This function is thread-safe but the timer and its timer list must not be > > + * freed while this function is running. > > */ > > void timer_mod(QEMUTimer *ts, int64_t expire_timer); > > timer_mod and timer_mod_ns are inevitably called having just read the > clock with qemu_clock_get. I am presuming these are thread safe (I haven't > checked) and if so the documentation for them should be similar adjusted. > Otherwise making these thread safe is all but useless. Ping Fan's series deals with thread-safe clock sources, this series only tackles the timer_list. We need to apply both series to be able to use timers from threads. Stefan