From patchwork Mon Jan 25 16:49:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 8112401 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 02E9FBEEE5 for ; Mon, 25 Jan 2016 16:51:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4481B2025A for ; Mon, 25 Jan 2016 16:51:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 512DB202F8 for ; Mon, 25 Jan 2016 16:51:41 +0000 (UTC) Received: from localhost ([::1]:39657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNkMe-0002Uu-Oa for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Jan 2016 11:51:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNkKk-0007WO-2B for qemu-devel@nongnu.org; Mon, 25 Jan 2016 11:49:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aNkKi-0005fs-VB for qemu-devel@nongnu.org; Mon, 25 Jan 2016 11:49:41 -0500 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]:33208) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aNkKi-0005fc-Jm for qemu-devel@nongnu.org; Mon, 25 Jan 2016 11:49:40 -0500 Received: by mail-wm0-x230.google.com with SMTP id 123so73472547wmz.0 for ; Mon, 25 Jan 2016 08:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=ob1gzN2+r0N5yLrWmjCzqGc42xfgVpnAvzK0zpNJuNk=; b=L7CWHL6aChHe8tOXbuMloHOtPkv++d9tFec+6zvowylPq++qjIrXX/TfP7k7vtt/A7 1vBjsT71X2WavtJUfjE7Iqwiuia4rkgqmVaX5vjOs9Sv2Ls2kTMKBV3GaNA6YGbsFb3J 2H/1KQgkbuIJRaKjZyb40Zys0E+kUj/7zIIuU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=ob1gzN2+r0N5yLrWmjCzqGc42xfgVpnAvzK0zpNJuNk=; b=f47W7VmPTUfcWXLUkdUBu52l8s8D9XxAc8RdysMdX4Pi7g/XVQS+0Ti88vEg5e0ZAk kw7CgjcUk3KxETQFU8hroXAM9EJvPkcYa4UOoJosbvF7tHG1gGz6F/kH5Tdwva6KCen6 Xgd+7HCb9M1lUk5mlrPZi1TUm6cuWkWrA2cKr58AiU50Wb8EfnYyEQyN91+BC/vJlHsi cykbBwjAFXRcROKxgkttLFkKh2qH7KKCtinbS44IzD6j5cIhsyqj5zS08VbZTMYqQHrp Z5+RmS14eedoIbhCuXdcCVOH5st7adZkLbY7/kGjBePx2XFpKZqGEyLXwk6ZjEkbYVwg tLvg== X-Gm-Message-State: AG10YOTgG9ProOgPKG258xqw0ey8hXEFpcTN5co7pba5/SIh1EeodbVogHATbtY2GzHVWUO9 X-Received: by 10.194.19.101 with SMTP id d5mr5075083wje.72.1453740579945; Mon, 25 Jan 2016 08:49:39 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z137sm17013255wmc.8.2016.01.25.08.49.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jan 2016 08:49:38 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id DF6603E110D; Mon, 25 Jan 2016 16:49:33 +0000 (GMT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Mon, 25 Jan 2016 16:49:18 +0000 Message-Id: <1453740558-16303-5-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1453740558-16303-1-git-send-email-alex.bennee@linaro.org> References: <1453740558-16303-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::230 Cc: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, "open list:Block I/O path" , mark.burton@greensocs.com, a.rigo@virtualopensystems.com, Stefan Hajnoczi , pbonzini@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , fred.konrad@greensocs.com Subject: [Qemu-devel] [RFC PATCH 4/4] tsan: various fixes for make check 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP After building with the ThreadSanitizer I ran make check and started going through the failures reported. Most are failures to use atomic primitives to access variables previously atomically set. While this likely will work on x86 it could cause problems on other architectures. - async: use atomic reads for scheduled/notify_me - thread-pool: use atomic_mb_read/set to for thread ->state - test-thread-pool: use atomic read for data.n Signed-off-by: Alex Bennée --- async.c | 4 ++-- tests/test-thread-pool.c | 2 +- thread-pool.c | 9 ++++----- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/async.c b/async.c index e106072..8d5f810 100644 --- a/async.c +++ b/async.c @@ -165,7 +165,7 @@ aio_compute_timeout(AioContext *ctx) QEMUBH *bh; for (bh = ctx->first_bh; bh; bh = bh->next) { - if (!bh->deleted && bh->scheduled) { + if (!bh->deleted && atomic_read(&bh->scheduled)) { if (bh->idle) { /* idle bottom halves will be polled at least * every 10ms */ @@ -286,7 +286,7 @@ void aio_notify(AioContext *ctx) * with atomic_or in aio_ctx_prepare or atomic_add in aio_poll. */ smp_mb(); - if (ctx->notify_me) { + if (atomic_read(&ctx->notify_me)) { event_notifier_set(&ctx->notifier); atomic_mb_set(&ctx->notified, true); } diff --git a/tests/test-thread-pool.c b/tests/test-thread-pool.c index ccdee39..5694ad9 100644 --- a/tests/test-thread-pool.c +++ b/tests/test-thread-pool.c @@ -46,7 +46,7 @@ static void test_submit(void) { WorkerTestData data = { .n = 0 }; thread_pool_submit(pool, worker_cb, &data); - while (data.n == 0) { + while (atomic_read(&data.n) == 0) { aio_poll(ctx, true); } g_assert_cmpint(data.n, ==, 1); diff --git a/thread-pool.c b/thread-pool.c index 402c778..97b2c0c 100644 --- a/thread-pool.c +++ b/thread-pool.c @@ -99,15 +99,14 @@ static void *worker_thread(void *opaque) req = QTAILQ_FIRST(&pool->request_list); QTAILQ_REMOVE(&pool->request_list, req, reqs); - req->state = THREAD_ACTIVE; + atomic_mb_set(&req->state, THREAD_ACTIVE); qemu_mutex_unlock(&pool->lock); ret = req->func(req->arg); req->ret = ret; /* Write ret before state. */ - smp_wmb(); - req->state = THREAD_DONE; + atomic_mb_set(&req->state, THREAD_DONE); qemu_mutex_lock(&pool->lock); @@ -167,7 +166,7 @@ static void thread_pool_completion_bh(void *opaque) restart: QLIST_FOREACH_SAFE(elem, &pool->head, all, next) { - if (elem->state != THREAD_DONE) { + if (atomic_read(&elem->state) != THREAD_DONE) { continue; } @@ -201,7 +200,7 @@ static void thread_pool_cancel(BlockAIOCB *acb) trace_thread_pool_cancel(elem, elem->common.opaque); qemu_mutex_lock(&pool->lock); - if (elem->state == THREAD_QUEUED && + if (atomic_mb_read(&elem->state) == THREAD_QUEUED && /* No thread has yet started working on elem. we can try to "steal" * the item from the worker if we can get a signal from the * semaphore. Because this is non-blocking, we can do it with