From patchwork Fri Sep 30 21:30:57 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: 77177 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp513058qgf; Fri, 30 Sep 2016 14:34:01 -0700 (PDT) X-Received: by 10.55.144.71 with SMTP id s68mr9704692qkd.290.1475271241745; Fri, 30 Sep 2016 14:34:01 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e53si13434320qte.88.2016.09.30.14.34.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 30 Sep 2016 14:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5RQ-00086L-Br for patch@linaro.org; Fri, 30 Sep 2016 17:34:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Ou-0006Rh-IA for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bq5Ot-0006WE-7t for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:24 -0400 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]:35824) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bq5Ot-0006W3-1V for qemu-devel@nongnu.org; Fri, 30 Sep 2016 17:31:23 -0400 Received: by mail-wm0-x230.google.com with SMTP id f193so7518617wmg.0 for ; Fri, 30 Sep 2016 14:31:22 -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 :mime-version:content-transfer-encoding; bh=7Eiixo13+oMmDdp+ZjaKejV+TT88tnZ/MlAXw9/vtOE=; b=C6e2d4MaFEz79k4KbZPNxxZkjPyhF3lDPNBPcOOD41XUBo6AtkPIcC78CdVoIaM4ow NWtcydJ/shBRePQUO3YcywR4oc3CS+hn6SXMNCjRX56DWCRhWugWanq+hN/Qm5tCCNqB 1AxTYwNMYT+s36I0OH/RPhXRX+AZSgTJEOQY0= 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-transfer-encoding; bh=7Eiixo13+oMmDdp+ZjaKejV+TT88tnZ/MlAXw9/vtOE=; b=gLPhvU1Hy25b7IlUtFN81czawevYK/a0/FDW/U5KKPGFUeDBM62V3FmiUIFfvSI2wQ MrnLKYlrURmHgXDNXdEvdJfF1lSQYppXcSUR0WXZL9dBEfkRA2LDrfg/oEgfP58vI80m LQdelhStNbASr5xUFXIU6HpOrr488eoJxfZFrs8daZnbLmbokhiKFbKtIjX/Da5a3uZp 6UJowVvqSlJ9h/1NSuoQssRMYMRQBLSlNCddyRkwUv+OVr1s58GPEKisbw/6pyS7OP1l +9LC6h3UXvxQyN2zHR++LN1hqHOEw1GIsyHGlrV+l2kb8O7kmrtgm0CZc+g5AmRs4h8E fsiw== X-Gm-Message-State: AA6/9RnE2tsU/MjDuWRWjFQEMUAyJ6Ax2JJepPcbn31zrvCoq+QOR4q7VXXQDLL56Yl9oBYU X-Received: by 10.194.88.106 with SMTP id bf10mr4766005wjb.222.1475271082331; Fri, 30 Sep 2016 14:31:22 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id k206sm6028499wmf.19.2016.09.30.14.31.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 14:31:19 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id DD1F73E0422; Fri, 30 Sep 2016 22:31:17 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org, pbonzini@redhat.com Date: Fri, 30 Sep 2016 22:30:57 +0100 Message-Id: <20160930213106.20186-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160930213106.20186-1-alex.bennee@linaro.org> References: <20160930213106.20186-1-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 Subject: [Qemu-devel] [PATCH v3 06/15] qom/object: update class cache atomically X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mttcg@listserver.greensocs.com, peter.maydell@linaro.org, claudio.fontana@huawei.com, nikunj@linux.vnet.ibm.com, jan.kiszka@siemens.com, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, cota@braap.org, serge.fdrv@gmail.com, bobby.prani@gmail.com, rth@twiddle.net, =?UTF-8?q?Alex=20Benn=C3=A9e?= , =?UTF-8?q?Andreas=20F=C3=A4rber?= , fred.konrad@greensocs.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The idiom CPU_GET_CLASS(cpu) is fairly extensively used in various threads and trips of ThreadSanitizer due to the fact it updates obj->class->object_cast_cache behind the scenes. As this is just a fast-path cache there is no need to lock updates. However to ensure defined C11 behaviour across threads we need to use the plain atomic_read/set primitives and keep the sanitizer happy. Signed-off-by: Alex Bennée Reviewed-by: Marc-André Lureau --- qom/object.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) -- 2.9.3 diff --git a/qom/object.c b/qom/object.c index 8166b7d..7a05e35 100644 --- a/qom/object.c +++ b/qom/object.c @@ -614,7 +614,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename, Object *inst; for (i = 0; obj && i < OBJECT_CLASS_CAST_CACHE; i++) { - if (obj->class->object_cast_cache[i] == typename) { + if (atomic_read(&obj->class->object_cast_cache[i]) == typename) { goto out; } } @@ -631,10 +631,10 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename, if (obj && obj == inst) { for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) { - obj->class->object_cast_cache[i - 1] = - obj->class->object_cast_cache[i]; + atomic_set(&obj->class->object_cast_cache[i - 1], + atomic_read(&obj->class->object_cast_cache[i])); } - obj->class->object_cast_cache[i - 1] = typename; + atomic_set(&obj->class->object_cast_cache[i - 1], typename); } out: @@ -704,7 +704,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, int i; for (i = 0; class && i < OBJECT_CLASS_CAST_CACHE; i++) { - if (class->class_cast_cache[i] == typename) { + if (atomic_read(&class->class_cast_cache[i]) == typename) { ret = class; goto out; } @@ -725,9 +725,10 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, #ifdef CONFIG_QOM_CAST_DEBUG if (class && ret == class) { for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) { - class->class_cast_cache[i - 1] = class->class_cast_cache[i]; + atomic_set(&class->class_cast_cache[i - 1], + atomic_read(&class->class_cast_cache[i])); } - class->class_cast_cache[i - 1] = typename; + atomic_set(&class->class_cast_cache[i - 1], typename); } out: #endif