From patchwork Wed Feb 6 15:30:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 218676 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 DAF3C2C02C7 for ; Thu, 7 Feb 2013 02:31:44 +1100 (EST) Received: from localhost ([::1]:51518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U36yN-0003aC-30 for incoming@patchwork.ozlabs.org; Wed, 06 Feb 2013 10:31:43 -0500 Received: from eggs.gnu.org ([208.118.235.92]:50060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U36yA-0003F5-O1 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 1U36y4-0007vh-KU for qemu-devel@nongnu.org; Wed, 06 Feb 2013 10:31:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U36y4-0007vU-BQ for qemu-devel@nongnu.org; Wed, 06 Feb 2013 10:31:24 -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 r16FVNWM002914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 6 Feb 2013 10:31:23 -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 r16FUraT013286; Wed, 6 Feb 2013 10:31:22 -0500 From: Stefan Hajnoczi To: Date: Wed, 6 Feb 2013 16:30:15 +0100 Message-Id: <1360164617-12103-3-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 2/4] trace: Direct access of atomics is verboten, use the API 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 The GLib Reference Manual says: It is very important that all accesses to a particular integer or pointer be performed using only this API and that different sizes of operation are not mixed or used on overlapping memory regions. Never read or assign directly from or to a value -- always use this API. Signed-off-by: Markus Armbruster Reviewed-by: Laszlo Ersek Reviewed-by: Harsh Prateek Bora Signed-off-by: Stefan Hajnoczi --- trace/simple.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/trace/simple.c b/trace/simple.c index ccbdb6a..592ff48 100644 --- a/trace/simple.c +++ b/trace/simple.c @@ -166,13 +166,13 @@ static gpointer writeout_thread(gpointer opaque) for (;;) { wait_for_trace_records_available(); - if (dropped_events) { + if (g_atomic_int_get(&dropped_events)) { dropped.rec.event = DROPPED_EVENT_ID, dropped.rec.timestamp_ns = get_clock(); dropped.rec.length = sizeof(TraceRecord) + sizeof(uint64_t), dropped.rec.reserved = 0; while (1) { - dropped_count = dropped_events; + dropped_count = g_atomic_int_get(&dropped_events); if (g_atomic_int_compare_and_exchange(&dropped_events, dropped_count, 0)) { break; @@ -214,7 +214,7 @@ int trace_record_start(TraceBufferRecord *rec, TraceEventID event, size_t datasi uint64_t timestamp_ns = get_clock(); while (1) { - old_idx = trace_idx; + old_idx = g_atomic_int_get(&trace_idx); smp_rmb(); new_idx = old_idx + rec_len; @@ -275,7 +275,8 @@ void trace_record_finish(TraceBufferRecord *rec) record.event |= TRACE_RECORD_VALID; write_to_buffer(rec->tbuf_idx, &record, sizeof(TraceRecord)); - if ((trace_idx - writeout_idx) > TRACE_BUF_FLUSH_THRESHOLD) { + if ((g_atomic_int_get(&trace_idx) - writeout_idx) + > TRACE_BUF_FLUSH_THRESHOLD) { flush_trace_file(false); } }