From nobody Wed Nov 5 20:17:20 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 1536623250738898.2523739377216; Mon, 10 Sep 2018 16:47:30 -0700 (PDT) Received: from localhost ([::1]:54659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzVtx-0005r3-Nh for importer@patchew.org; Mon, 10 Sep 2018 19:47:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40356) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzVjm-0003X0-UC 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 1fzVbS-0005Ix-0b for qemu-devel@nongnu.org; Mon, 10 Sep 2018 19:28:25 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:38513) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzVbR-0005Hp-PC for qemu-devel@nongnu.org; Mon, 10 Sep 2018 19:28:21 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 096A021DBB; 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 96535E49D9; 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=9Aw/BbIrwBwhyZ gpARUx7wuD1Okwr64mCWGenmkTTII=; b=v19Wu54s7bSkhg5DFK3Ul0+0Cigw3e q4iaHp5kpQmTT/jaI3oyGZvlv4dD3lsqzB0Zjj6AhLGuCJNxAJU3HsNuay5wqtKt 76szpeXOuKGLMReUzVc116nLNCv+eQVqzJUP1+k/0OJsvsZmBcqI5X4PIFPUCtQM 4GARrjyUEWdp0= 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=9Aw/BbIrwBwhyZgpARUx7wuD1Okwr64mCWGenmkTTII=; b=JkdmWh/B 2D1d7+wQokPWG5KuOEBQkFm+zdle0SYwVEmv+UYXS6ynhVcl1RlNelY6E7UN83fK Yn2dcgSip2dMXRA+muQwQN0IdfB3Mu4ZBubii7PCaWOJzN11schdNipi07ccLPE9 /C6lZxwI8uIB9pET9gVarQSZ2XJt+8gGbDKVEYqwwvbOvsj+0O7WK+diIazAMlep lG1bMRtxRloulAzJdPTX0rRHgMRe11GYqNMzjjHscl/rvHZ47aHX5CXb941kMr8c 6tasNFAYGAb8us32esfdBJkHQ1e/NYeAu8SXOsG2gPjMaMUTaTNDqWrjDTaVxEz7 dM98go8lXOX/mA== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 10 Sep 2018 19:27:44 -0400 Message-Id: <20180910232752.31565-5-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 04/12] qsp: use atomic64 accessors 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" With the seqlock, we either have to use atomics to remain within defined behaviour (and note that 64-bit atomics aren't always guaranteed to compile, irrespective of __nocheck), or drop the atomics and be in undefined behaviour territory. Fix it by dropping the seqlock and using atomic64 accessors. This will limit scalability when !CONFIG_ATOMIC64, but those machines (1) don't have many users and (2) are unlikely to have many cores. - With CONFIG_ATOMIC64: $ tests/atomic_add-bench -n 1 -m -p Throughput: 13.00 Mops/s - Forcing !CONFIG_ATOMIC64: $ tests/atomic_add-bench -n 1 -m -p Throughput: 10.89 Mops/s Signed-off-by: Emilio G. Cota --- util/qsp.c | 49 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/util/qsp.c b/util/qsp.c index b0c2575d10..c16af03f6a 100644 --- a/util/qsp.c +++ b/util/qsp.c @@ -84,13 +84,6 @@ struct QSPEntry { uint64_t n_acqs; uint64_t ns; unsigned int n_objs; /* count of coalesced objs; only used for reporti= ng */ -#ifndef CONFIG_ATOMIC64 - /* - * If we cannot update the counts atomically, then use a seqlock. - * We don't need an associated lock because the updates are thread-loc= al. - */ - QemuSeqLock sequence; -#endif }; typedef struct QSPEntry QSPEntry; =20 @@ -344,47 +337,16 @@ static QSPEntry *qsp_entry_get(const void *obj, const= char *file, int line, return qsp_entry_find(&qsp_ht, &orig, hash); } =20 -/* - * @from is in the global hash table; read it atomically if the host - * supports it, otherwise use the seqlock. - */ -static void qsp_entry_aggregate(QSPEntry *to, const QSPEntry *from) -{ -#ifdef CONFIG_ATOMIC64 - to->ns +=3D atomic_read__nocheck(&from->ns); - to->n_acqs +=3D atomic_read__nocheck(&from->n_acqs); -#else - unsigned int version; - uint64_t ns, n_acqs; - - do { - version =3D seqlock_read_begin(&from->sequence); - ns =3D atomic_read__nocheck(&from->ns); - n_acqs =3D atomic_read__nocheck(&from->n_acqs); - } while (seqlock_read_retry(&from->sequence, version)); - - to->ns +=3D ns; - to->n_acqs +=3D n_acqs; -#endif -} - /* * @e is in the global hash table; it is only written to by the current th= read, * so we write to it atomically (as in "write once") to prevent torn reads. - * If the host doesn't support u64 atomics, use the seqlock. */ static inline void do_qsp_entry_record(QSPEntry *e, int64_t delta, bool ac= q) { -#ifndef CONFIG_ATOMIC64 - seqlock_write_begin(&e->sequence); -#endif - atomic_set__nocheck(&e->ns, e->ns + delta); + atomic_set_u64(&e->ns, e->ns + delta); if (acq) { - atomic_set__nocheck(&e->n_acqs, e->n_acqs + 1); + atomic_set_u64(&e->n_acqs, e->n_acqs + 1); } -#ifndef CONFIG_ATOMIC64 - seqlock_write_end(&e->sequence); -#endif } =20 static inline void qsp_entry_record(QSPEntry *e, int64_t delta) @@ -550,7 +512,12 @@ static void qsp_aggregate(struct qht *global_ht, void = *p, uint32_t h, void *up) =20 hash =3D qsp_entry_no_thread_hash(e); agg =3D qsp_entry_find(ht, e, hash); - qsp_entry_aggregate(agg, e); + /* + * The entry is in the global hash table; read from it atomically (as = in + * "read once"). + */ + agg->ns +=3D atomic_read_u64(&e->ns); + agg->n_acqs +=3D atomic_read_u64(&e->n_acqs); } =20 static void qsp_iter_diff(struct qht *orig, void *p, uint32_t hash, void *= htp) --=20 2.17.1