From patchwork Fri May 29 13:23:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187312 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp585066ilb; Fri, 29 May 2020 06:28:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy92WLLaeFnGp0dVsLyoi4Bd5yYShlBKJ2gHxon8DODRw109SQ3h7XSQnZAegx7ZuIPhi9q X-Received: by 2002:a25:b94d:: with SMTP id s13mr12865656ybm.289.1590758894568; Fri, 29 May 2020 06:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590758894; cv=none; d=google.com; s=arc-20160816; b=MKi7srnu0hf0czewQ+eELusBtzOfc0egQ019oezx9M8S8Svj6Y5jV7pzUnWIsJ5uDh WXawPT8t5ygpZyD0Bag/t46Ognu7gPBqigRdWNbIyzHAenjstA7OCB6rdJ1/MR/kLHSl eKnxe7Wln9wRIBeAqiOmd54WKfHCdef8nwNLCkY99IoS3r7L5m2mWMVJYTV5in3rh2Ta 3d1Y2J4e9gHjdpp2oq/eia9EZva1yvP6KUO1oNOrTh43C7dNbaMjJ1T+d5xj6GOBabUW UzNkkElvfBnCJaRfxM/LzJNeYfH9zBhzxETLj71S9M3vI9EClkFXZKdTD7ph9q/4EH44 SyRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=mGW6wnv9FlzkC02Bo8Bk1So4QHTwo22NecRxOgB5aoI=; b=NoSYtNlmCAs4hFyp5eMel2IrHkltqPWj9T5Slud2V54tqGLM3gL+UqqjkSDDPt9upt lK6CL/Tgf7z3VLqx2b04gh3teatUtQaYNK56EzWE4VlCwtTwrHIsEm19wRlYTvMHvzvi KHzRMi9bmSk9LKAQHuJu2JVjyDm9jdOZtOzAllFA91AVzmopAOlj/XlXj97jCBmNb5PL 9MH0v7Q65xlDOdttC98mwlpgjPkIDsECB12GQJcUm+t7fweK9RMw0YKjDD+FA7m5yhvo kx7cJBHHXhbe53DUOvCN05uWmvsq6U7los6EZ1NVSDAn74emlBxa4vVqY6cukw6xFk9S PAeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KFzDwUz0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p198si2199886yba.481.2020.05.29.06.28.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:28:14 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=KFzDwUz0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef3W-0003KG-19 for patch@linaro.org; Fri, 29 May 2020 09:28:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezJ-0004gu-9L for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:53 -0400 Received: from mail-pj1-x1044.google.com ([2607:f8b0:4864:20::1044]:53970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezI-0003ew-8w for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:52 -0400 Received: by mail-pj1-x1044.google.com with SMTP id ci21so1341149pjb.3 for ; Fri, 29 May 2020 06:23:51 -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=KFzDwUz0qmHA3ULFQs62is1dlym1KjMxCz7QHytByajg9YXKw3fNmWRKR6EH5Ky7kW 4JKfsNQ+ZVDM+BPyKe7zVh+MCSCgo/kzRcpzZgYmCeNixvvg+z+QpcmNeexDJAjxYULY y9DM8HqjwGPBlFGuJ0P7XqnSMvOREJUY5ddJxT/RpvRPcJNk/OhE30txVCMqbKbbAV3s d8GEUR4Su+uTZShn1O+6YoVdCIR/gwKTFUiLIR8gtCEGLgpVV+gWu45yuJs0Bg+Zj9IR HWASs/NVP5KVvdIzORPltuHjD9niHxbA+P/pGcPXKDaf3pORipzIuG3DsntNHII0lWuN pJsg== 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=sPbtEEIPGoHCjY5Yh/hGCfgi+594oQEaLvg6j+ocsSrG4FMajuXqRTUB8KUtEeW0PT 2VT8/31beiFJkVIiwPSPpriGYpseg06Ru+RPpUskw+aEKv4QQjkt7bzYXk5XC2cIAM7M KBcA3l7pHMvwc4hglLThaDKAZlzsScBU1BPHxuGRQGqMq8noUQkMHaCbX1tEeceAZ5FZ iA4Rwp8yFKPkabs/9r5XtBNZ8t/7rRSrubsr+bVlyee4KYQR4M9762CfI+hNQTo11ENm C1dtqY46rE3GkBVRjv7ZydGBe3eJ3ECNYGUNSSPph4ypx41lJGMhDuDyOnqfoc9ExP4t Gpsg== X-Gm-Message-State: AOAM533GthxIwUMPEx3TldNYp7csWFn/rYUbiQ+eP/hLACHEZigPi9Z/ 1umiaUV3H0+saWizdOdbA+F/HtmRK4cPbw== X-Received: by 2002:a17:90a:f292:: with SMTP id fs18mr9260316pjb.37.1590758630496; Fri, 29 May 2020 06:23:50 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:49 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 08/12] thread: add tsan annotations to QemuSpin Date: Fri, 29 May 2020 09:23:38 -0400 Message-Id: <20200529132341.755-8-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::1044; envelope-from=robert.foley@linaro.org; helo=mail-pj1-x1044.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+patch=linaro.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(-) -- 2.17.1 Reviewed-by: Alex Bennée 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 {