From nobody Thu Nov 6 01:08:59 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538295734816668.749125255823; Sun, 30 Sep 2018 01:22:14 -0700 (PDT) Received: from localhost ([::1]:54249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6WzP-0000h1-79 for importer@patchew.org; Sun, 30 Sep 2018 04:22:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6WrA-000282-Bl for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g6Wr7-0008Vv-3V for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:36 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:40527) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g6Wr5-0008Qz-7j for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:32 -0400 Received: by mail-wr1-x442.google.com with SMTP id y8-v6so10477789wrh.7 for ; Sun, 30 Sep 2018 01:13:30 -0700 (PDT) Received: from 640k.lan (94-36-187-248.adsl-ull.clienti.tiscali.it. [94.36.187.248]) by smtp.gmail.com with ESMTPSA id u76-v6sm11369194wmd.10.2018.09.30.01.13.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 01:13:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=98JiXw1HWq7pMchx74dg39BF9me3EEF7C19SSsJcjWA=; b=GYUzyyWqM9EMAUzmjv09g2vv3E++xyJlvig4B30KzU8TULI3rqAW7mU60lAcnM4zzM sO27f+a4xYtutY1/TunXvvwvBv/Ifw8VldTQlInfqndSdTvOhIoxNNLkyfCRH2Sl9QMi upU6jWa2PY9GVMyGNsX7DtHRUa5owk5Qk98McMicIuq6YJQ9KJOsv1I80ZMEgL9f9Wue IVaETIZNoBV0veZc6HZxhf7dx2uYIr5NSGT36Urhfq7KT1BzbN/Q149t+6dsAh4ybf5H XYSHX88eJ/J+MTQm8T0ko93RhlRYwFmmUD0qeEK0AkinvHEY4Ff4WBLSzlGJWTPalDrJ 8Q4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=98JiXw1HWq7pMchx74dg39BF9me3EEF7C19SSsJcjWA=; b=q+grztDLMBDsOLB9sg9lo9By8MLfUG5yOxggKi+7QDp4O7K6NlDszKBCtvtTY5Hugk LEpT5AfeXhrvNBVX7HxaOmSsyHCu6dLqdkIB9RIv5XmUd47HT0kSlvOb56s6YntwT3Pb /UG2algC/w38OIlGDyWVAS2jDGqM5FPaT7+hc4i8S5k6EnEtu7UyBJ4UbBGTrJTUS7Ih 5SDGo2mvD2kuV15yc6wYH7eFBJhOGHcyLp9V0bytz34PokLH6a5hGV74CcPxPO9lIHIT RfLnV9A9HiD/qOaG6OIrxczMQrXRuusPsolecCYxyx+ccwULI1+RjEkawVZUqebf9jeJ KljA== X-Gm-Message-State: ABuFfogfd+TR2OvjazVmO6jiL4s1J0QzcrnqIpnDDBQ1hR+hX6y0+hkM QQe8gI3lKoQpaCfu8doyH6nYOxQh X-Google-Smtp-Source: ACcGV61lBxkocxMhcAUE3Kev0nuK6CtlazfqrxkaJ9FPtDRe2JHCP+p6OQko5KlAsRt2iO8pnh9HCQ== X-Received: by 2002:adf:fd4a:: with SMTP id h10-v6mr3837712wrs.280.1538295209727; Sun, 30 Sep 2018 01:13:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 30 Sep 2018 10:12:09 +0200 Message-Id: <1538295197-23704-12-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> References: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PULL 11/79] 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: "Emilio G. Cota" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Emilio G. Cota" 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 Message-Id: <20180910232752.31565-6-cota@braap.org> Signed-off-by: Paolo Bonzini --- 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 192bfbf..2e6f70b 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 1.8.3.1