From patchwork Fri May 22 16:07:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 1296336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=dF1P08+W; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49TBVL5XWYz9sSF for ; Sat, 23 May 2020 02:18:02 +1000 (AEST) Received: from localhost ([::1]:51688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcAMy-0006Pj-GD for incoming@patchwork.ozlabs.org; Fri, 22 May 2020 12:18:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcAKL-00031t-WD for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:19 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:40692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jcAKK-00069X-1W for qemu-devel@nongnu.org; Fri, 22 May 2020 12:15:17 -0400 Received: by mail-pf1-x442.google.com with SMTP id v2so317078pfv.7 for ; Fri, 22 May 2020 09:15:15 -0700 (PDT) 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; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=dF1P08+W1ySZKkdJtEBOMsR7tfuqSb7PFhn5sie4eh3zucjXn7ftbpYsWjrUwNiQdW SQHW0NXOvu7erCgRnAVl2kTymTE/vic71Q+fIdCIkA1+rwGRuvP83xMuxy0LF62m3wwg PFLQMkUGOdN9KZQWBIXZ8AEUjvlYKeyXED+l2M1lnflct+fn50dUOyCvxrnVBMZ/GsGU ases1B3fuvzf0oefio9BzK1KzeU+wtACKkgkP3zBCO94703CQPvtvisDAjFnyi8RFjXy cf/qjX4n8SsCxRQhAfC1UQJEg2L3Y/V3eie+HohwJYLmxQsBknTomF+vlO9eMPIQ9a+s iLxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=IPueW35ASYAOydobpu/r7pkZfYUG1v0oNDJ5fZDuBnQChlPjMreqESpac0Vwcn3VlU KN1RUR8JfSrQ0RJt1+mUR7ceojGAHasc0mFfiCn8yzrBsYCQahMAvlsBxv04YJakCd86 AKSuVM1/9acBrd3FXY6P9EDpRAHC+bsRB4IVj8AnMQLoZvc6i4gMOcXnJnpucsZgbY69 wEL4fjFTQEBTGgRm3tdfjftiXC7gS0DImFhuu9M34jaiLgh3bwiwJ3snn61QvM+r/HkX QZ+zLdaW4ctuUkz2AmAxJAT3ePHqzCCxy31lQFgxpqoI7HaJfDZ8CL9QTd3OGz/5RT70 1aQA== X-Gm-Message-State: AOAM5327XnCNpzFXSi+9gXUKaNkrmKkHWyE9lMEzqbGOHgT+esujTVtR uoYztVtpunh6qDOiwILlPqzrjFTLMl143w== X-Google-Smtp-Source: ABdhPJyuDaqzES88dCe0KcGqW6YrYPhqTjIrG/1drcJkt+KZ9APKc0/DeN7o4bHyMG0FJCK3V+5aSg== X-Received: by 2002:a63:4d4e:: with SMTP id n14mr12683505pgl.93.1590164114424; Fri, 22 May 2020 09:15:14 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:f1d9:5fce:c451:d2e2]) by smtp.gmail.com with ESMTPSA id y75sm7255428pfb.212.2020.05.22.09.15.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2020 09:15:13 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH 08/19] thread: add tsan annotations to QemuSpin Date: Fri, 22 May 2020 12:07:44 -0400 Message-Id: <20200522160755.886-9-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200522160755.886-1-robert.foley@linaro.org> References: <20200522160755.886-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Signed-off-by: Emilio G. Cota Signed-off-by: Robert Foley --- include/qemu/thread.h | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index e50a073889..43fc094b96 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -206,6 +206,10 @@ void qemu_thread_atexit_add(struct Notifier *notifier); */ void qemu_thread_atexit_remove(struct Notifier *notifier); +#ifdef CONFIG_TSAN +#include +#endif + struct QemuSpin { int value; }; @@ -213,23 +217,46 @@ struct QemuSpin { static inline void qemu_spin_init(QemuSpin *spin) { __sync_lock_release(&spin->value); +#ifdef CONFIG_TSAN + __tsan_mutex_create(spin, __tsan_mutex_not_static); +#endif } -static inline void qemu_spin_destroy(QemuSpin *spin) -{ } +/* const parameter because the only purpose here is the TSAN annotation */ +static inline void qemu_spin_destroy(const QemuSpin *spin) +{ +#ifdef CONFIG_TSAN + __tsan_mutex_destroy((void *)spin, __tsan_mutex_not_static); +#endif +} static inline void qemu_spin_lock(QemuSpin *spin) { +#ifdef CONFIG_TSAN + __tsan_mutex_pre_lock(spin, 0); +#endif while (unlikely(__sync_lock_test_and_set(&spin->value, true))) { while (atomic_read(&spin->value)) { cpu_relax(); } } +#ifdef CONFIG_TSAN + __tsan_mutex_post_lock(spin, 0, 0); +#endif } static inline bool qemu_spin_trylock(QemuSpin *spin) { - return __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + __tsan_mutex_pre_lock(spin, __tsan_mutex_try_lock); +#endif + bool busy = __sync_lock_test_and_set(&spin->value, true); +#ifdef CONFIG_TSAN + unsigned flags = __tsan_mutex_try_lock; + flags |= busy ? __tsan_mutex_try_lock_failed : 0; + __tsan_mutex_post_lock(spin, flags, 0); +#endif + return busy; } static inline bool qemu_spin_locked(QemuSpin *spin) @@ -239,7 +266,13 @@ static inline bool qemu_spin_locked(QemuSpin *spin) static inline void qemu_spin_unlock(QemuSpin *spin) { +#ifdef CONFIG_TSAN + __tsan_mutex_pre_unlock(spin, 0); +#endif __sync_lock_release(&spin->value); +#ifdef CONFIG_TSAN + __tsan_mutex_post_unlock(spin, 0); +#endif } struct QemuLockCnt {