From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6dao-0004uq-DF for qemu-devel@nongnu.org; Tue, 06 Aug 2013 05:30:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V6dag-0003c1-19 for qemu-devel@nongnu.org; Tue, 06 Aug 2013 05:30:14 -0400 Received: from mail-wi0-x22e.google.com ([2a00:1450:400c:c05::22e]:43498) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V6daf-0003au-SA for qemu-devel@nongnu.org; Tue, 06 Aug 2013 05:30:05 -0400 Received: by mail-wi0-f174.google.com with SMTP id j17so2431002wiw.13 for ; Tue, 06 Aug 2013 02:30:05 -0700 (PDT) Date: Tue, 6 Aug 2013 11:30:02 +0200 From: Stefan Hajnoczi Message-ID: <20130806093002.GA3501@stefanha-thinkpad.redhat.com> References: <1375688006-16780-1-git-send-email-pingfank@linux.vnet.ibm.com> <1375688006-16780-3-git-send-email-pingfank@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1375688006-16780-3-git-send-email-pingfank@linux.vnet.ibm.com> Subject: Re: [Qemu-devel] [PATCH 2/4] timer: protect timers_state's clock with seqlock List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Liu Ping Fan Cc: Kevin Wolf , Stefan Hajnoczi , Jan Kiszka , qemu-devel@nongnu.org, Alex Bligh , Paolo Bonzini , MORITA Kazutaka On Mon, Aug 05, 2013 at 03:33:24PM +0800, Liu Ping Fan wrote: > diff --git a/cpus.c b/cpus.c > index 85e743d..ab92db9 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -107,12 +107,17 @@ static int64_t qemu_icount; > typedef struct TimersState { > int64_t cpu_ticks_prev; > int64_t cpu_ticks_offset; > + /* QemuClock will be read out of BQL, so protect is with private lock. > + * As for cpu_ticks, no requirement to read it outside BQL. > + * Lock rule: innermost > + */ Please document exactly which fields the lock protects. > /* enable cpu_get_ticks() */ > void cpu_enable_ticks(void) > { > + /* Here, the really thing protected by seqlock is cpu_clock. */ What is cpu_clock? > @@ -364,6 +383,9 @@ static const VMStateDescription vmstate_timers = { > > void configure_icount(const char *option) > { > + QemuMutex *mutex = g_malloc0(sizeof(QemuMutex)); > + qemu_mutex_init(mutex); > + seqlock_init(&timers_state.clock_seqlock, mutex); We always set up this mutex, so it could be a field in timers_state. That avoids the g_malloc() without g_free().