From patchwork Wed Feb 6 15:30:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 218678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 34C382C02CC for ; Thu, 7 Feb 2013 02:32:12 +1100 (EST) Received: from localhost ([::1]:53645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U36yo-0004iT-A7 for incoming@patchwork.ozlabs.org; Wed, 06 Feb 2013 10:32:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U36y9-0003C0-Eb for qemu-devel@nongnu.org; Wed, 06 Feb 2013 10:31:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U36y6-0007wG-Su for qemu-devel@nongnu.org; Wed, 06 Feb 2013 10:31:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:15574) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U36y6-0007w8-K1 for qemu-devel@nongnu.org; Wed, 06 Feb 2013 10:31:26 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r16FVPju010240 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 6 Feb 2013 10:31:26 -0500 Received: from localhost (ovpn-112-20.ams2.redhat.com [10.36.112.20]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r16FVOi6013860; Wed, 6 Feb 2013 10:31:25 -0500 From: Stefan Hajnoczi To: Date: Wed, 6 Feb 2013 16:30:16 +0100 Message-Id: <1360164617-12103-4-git-send-email-stefanha@redhat.com> In-Reply-To: <1360164617-12103-1-git-send-email-stefanha@redhat.com> References: <1360164617-12103-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Markus Armbruster , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 3/4] trace: Clean up the "try to update atomic until it worked" loops X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Markus Armbruster Signed-off-by: Markus Armbruster Reviewed-by: Laszlo Ersek Reviewed-by: Harsh Prateek Bora Signed-off-by: Stefan Hajnoczi --- trace/simple.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/trace/simple.c b/trace/simple.c index 592ff48..74701e3 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -171,13 +171,10 @@ static gpointer writeout_thread(gpointer opaque) dropped.rec.timestamp_ns = get_clock(); dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t), dropped.rec.reserved = 0; - while (1) { + do { dropped_count = g_atomic_int_get(&dropped_events); - if (g_atomic_int_compare_and_exchange(&dropped_events, - dropped_count, 0)) { - break; - } - } + } while (!g_atomic_int_compare_and_exchange(&dropped_events, + dropped_count, 0)); dropped.rec.arguments[0] = dropped_count; unused = fwrite(&dropped.rec, dropped.rec.length, 1, trace_fp); } @@ -213,7 +210,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi uint32_t rec_len = sizeof(TraceRecord) + datasize; uint64_t timestamp_ns = get_clock(); - while (1) { + do { old_idx = g_atomic_int_get(&trace_idx); smp_rmb(); new_idx = old_idx + rec_len; @@ -223,12 +220,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi g_atomic_int_inc(&dropped_events); return -ENOSPC; } - - if (g_atomic_int_compare_and_exchange(&trace_idx, - old_idx, new_idx)) { - break; - } - } + } while (!g_atomic_int_compare_and_exchange(&trace_idx, old_idx, new_idx)); idx = old_idx % TRACE_BUF_LEN;