From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTSxr-0004vg-8Q for qemu-devel@nongnu.org; Tue, 08 Oct 2013 04:48:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTSxi-0003d4-SU for qemu-devel@nongnu.org; Tue, 08 Oct 2013 04:48:23 -0400 Received: from mail-ea0-x22c.google.com ([2a00:1450:4013:c01::22c]:32782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTSxi-0003cp-Jv for qemu-devel@nongnu.org; Tue, 08 Oct 2013 04:48:14 -0400 Received: by mail-ea0-f172.google.com with SMTP id r16so3833836ead.3 for ; Tue, 08 Oct 2013 01:48:13 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 8 Oct 2013 10:47:36 +0200 Message-Id: <1381222058-16701-7-git-send-email-pbonzini@redhat.com> In-Reply-To: <1381222058-16701-1-git-send-email-pbonzini@redhat.com> References: <1381222058-16701-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 6/8] timers: introduce cpu_get_clock_locked List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: alex@alex.org.uk This fixes a deadlock in cpu_disable_ticks. Signed-off-by: Paolo Bonzini --- Should be squashed in Ping Fan's patches. cpus.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/cpus.c b/cpus.c index 08eaf23..01acce2 100644 --- a/cpus.c +++ b/cpus.c @@ -166,6 +166,20 @@ int64_t cpu_get_ticks(void) } } +static int64_t cpu_get_clock_locked(void) +{ + int64_t ti; + + if (!timers_state.cpu_ticks_enabled) { + ti = timers_state.cpu_clock_offset; + } else { + ti = get_clock(); + ti += timers_state.cpu_clock_offset; + } + + return ti; +} + /* return the host CPU monotonic timer and handle stop/restart */ int64_t cpu_get_clock(void) { @@ -174,12 +188,7 @@ int64_t cpu_get_clock(void) do { start = seqlock_read_begin(&timers_state.clock_seqlock); - if (!timers_state.cpu_ticks_enabled) { - ti = timers_state.cpu_clock_offset; - } else { - ti = get_clock(); - ti += timers_state.cpu_clock_offset; - } + ti = cpu_get_clock_locked(); } while (seqlock_read_retry(&timers_state.clock_seqlock, start)); return ti; @@ -220,7 +233,7 @@ void cpu_disable_ticks(void) seqlock_write_lock(&timers_state.clock_seqlock); if (timers_state.cpu_ticks_enabled) { timers_state.cpu_ticks_offset = cpu_get_ticks(); - timers_state.cpu_clock_offset = cpu_get_clock(); + timers_state.cpu_clock_offset = cpu_get_clock_locked(); timers_state.cpu_ticks_enabled = 0; } seqlock_write_unlock(&timers_state.clock_seqlock); -- 1.8.3.1