From nobody Wed Nov 5 20:18:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536622777883710.207169979104; Mon, 10 Sep 2018 16:39:37 -0700 (PDT) Received: from localhost ([::1]:54608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzVmG-0006de-Ea for importer@patchew.org; Mon, 10 Sep 2018 19:39:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzVjo-0003al-CO for qemu-devel@nongnu.org; Mon, 10 Sep 2018 19:37:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzVbU-0005Kq-Ba for qemu-devel@nongnu.org; Mon, 10 Sep 2018 19:28:25 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:46757) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzVbU-0005IS-2A for qemu-devel@nongnu.org; Mon, 10 Sep 2018 19:28:24 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 38CCA20A9B; Mon, 10 Sep 2018 19:28:21 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 10 Sep 2018 19:28:21 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id CC9DEE4682; Mon, 10 Sep 2018 19:28:20 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=braap.org; h=cc :date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=mesmtp; bh=ht1DynTiGJEqXT 3NJNAVt6hC3bhQSX4QQQ38HKT+Q4k=; b=D+WEukNi79R9ggbz9zSmX3+uQ5k7La p6GzR2LCy0MxXUiqeS2Tw04RFCSx7/uw9brzkKb1gwTX0frvUGcCn82dcYv8JnLO 7wn6bhLiMPv0Iu4Ud82/HR+Ef9siQQf+wFSgyYp8+/ub3jNBvxbofEN8vzNEVp07 SH+MH9uFay3kU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=ht1DynTiGJEqXT3NJNAVt6hC3bhQSX4QQQ38HKT+Q4k=; b=ARv1nB6/ 4TzHl1O3L8b9Bgrr7S3w1nqNDl6N7Z730NJmEj2rh4+gqrN8Yj7eUj/VQ1J91zmj G281wce92XJxeR037zrgND/OvFZ2kzl5ZpoGpUXAgzqknE37WMfdSpVPXvArL/Xw srm6GEaZJHfbZUzi7DQjWCj+tEalhmkGrM4XjqW+AwAge+IcHBu7n8Bjts69Gwsc C8A9+L4A8ryqeL3YLFIbwzKqOledRVPZ/y9yyjMpkAACEKWq9dghgDcreFf80Sck ImqEpwA+Rg2ItFn9VGtuuY2aN7p22gL1x6aqYKwU2AcjJaDElzXxjP9W8oV7LrM/ ptXRkF4Ltqnirg== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 10 Sep 2018 19:27:45 -0400 Message-Id: <20180910232752.31565-6-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180910232752.31565-1-cota@braap.org> References: <20180910232752.31565-1-cota@braap.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.25 Subject: [Qemu-devel] [PATCH v2 05/12] test-rcu-list: access n_reclaims and n_nodes_removed with atomic64 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: Eduardo Habkost , Peter Crosthwaite , Murilo Opsfelder Araujo , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To avoid undefined behaviour. Note that these "atomics" are atomic in the "access once" sense. The variables are updated by a single thread at a time, so no "full" atomics are necessary. Signed-off-by: Emilio G. Cota --- tests/test-rcu-list.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/test-rcu-list.c b/tests/test-rcu-list.c index 192bfbf02e..2e6f70bd59 100644 --- a/tests/test-rcu-list.c +++ b/tests/test-rcu-list.c @@ -33,8 +33,8 @@ static QemuMutex counts_mutex; static long long n_reads =3D 0LL; static long long n_updates =3D 0LL; -static long long n_reclaims =3D 0LL; -static long long n_nodes_removed =3D 0LL; +static int64_t n_reclaims; +static int64_t n_nodes_removed; static long long n_nodes =3D 0LL; static int g_test_in_charge =3D 0; =20 @@ -104,7 +104,7 @@ static void reclaim_list_el(struct rcu_head *prcu) struct list_element *el =3D container_of(prcu, struct list_element, rc= u); g_free(el); /* Accessed only from call_rcu thread. */ - n_reclaims++; + atomic_set_i64(&n_reclaims, n_reclaims + 1); } =20 #if TEST_LIST_TYPE =3D=3D 1 @@ -232,7 +232,7 @@ static void *rcu_q_updater(void *arg) qemu_mutex_lock(&counts_mutex); n_nodes +=3D n_nodes_local; n_updates +=3D n_updates_local; - n_nodes_removed +=3D n_removed_local; + atomic_set_i64(&n_nodes_removed, n_nodes_removed + n_removed_local); qemu_mutex_unlock(&counts_mutex); return NULL; } @@ -286,19 +286,21 @@ static void rcu_qtest(const char *test, int duration,= int nreaders) n_removed_local++; } qemu_mutex_lock(&counts_mutex); - n_nodes_removed +=3D n_removed_local; + atomic_set_i64(&n_nodes_removed, n_nodes_removed + n_removed_local); qemu_mutex_unlock(&counts_mutex); synchronize_rcu(); - while (n_nodes_removed > n_reclaims) { + while (atomic_read_i64(&n_nodes_removed) > atomic_read_i64(&n_reclaims= )) { g_usleep(100); synchronize_rcu(); } if (g_test_in_charge) { - g_assert_cmpint(n_nodes_removed, =3D=3D, n_reclaims); + g_assert_cmpint(atomic_read_i64(&n_nodes_removed), =3D=3D, + atomic_read_i64(&n_reclaims)); } else { printf("%s: %d readers; 1 updater; nodes read: " \ - "%lld, nodes removed: %lld; nodes reclaimed: %lld\n", - test, nthreadsrunning - 1, n_reads, n_nodes_removed, n_recl= aims); + "%lld, nodes removed: %"PRIi64"; nodes reclaimed: %"PRIi64"= \n", + test, nthreadsrunning - 1, n_reads, + atomic_read_i64(&n_nodes_removed), atomic_read_i64(&n_recla= ims)); exit(0); } } --=20 2.17.1