From nobody Thu Nov 6 01:09:03 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538296096614777.846244440345; Sun, 30 Sep 2018 01:28:16 -0700 (PDT) Received: from localhost ([::1]:54281 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6X5H-0006hz-If for importer@patchew.org; Sun, 30 Sep 2018 04:28:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41219) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6WrA-00027w-9K 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-0008Vr-3P for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:36 -0400 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]:46950) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g6Wr5-0008PN-4u for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:32 -0400 Received: by mail-wr1-x433.google.com with SMTP id z3-v6so10451690wrr.13 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.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 01:13:28 -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=FPqWsP12EJmFztfvyn7oimHsO7mtkbITzbDcmF+fUag=; b=pa3lWu7TItLWo69S+OnD4+5yhyAwNMIAAcsPiJQ2NKUtd1bNVT6P+U6+m+98Oj1UqF Lbbmk2ZrwmKZqNACYVusXmT+OIcRUiWTu0lJjFsv6JLTAV7jbqgkRpNi3uFN1Q9KOnuz Bu4zB8bHAxMi99m3B6o6i06cgBRR0EWnT1myYpiA1xgQVXHMJx1cCWoaBta6K2zn+4gg KyybsdH+CNqUkHt5b+voFVpW5ZP6a3xj27sxM34ZpAadHhAY6ITjsEZjkdBB9rCwrxqJ NaXfCapzYgzGQA2sIsN4T75ufDm1YwhPW5GRg+cv/m56wd7OQ1eT+2UOIts5v8xN4f7p Pujg== 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=FPqWsP12EJmFztfvyn7oimHsO7mtkbITzbDcmF+fUag=; b=YqyQ438bVDPq0OebteIgCbVfVsBYDMPQ2ABr3I6Uck6TQPMNcPOOH+cuuB3RcPo4GW olca/Ch2O0mT0AzmLyUm+oJI2cehGh3ZH/K3DxzDyXOLvSyYnPMaZKTq36xgWsyJ/JTg tObYR21E3nL8y1XgWr8kyzFtL2g3Pnizat0aCVwm3fljBNy3/KbHHNr83CZ5cMjoRmdC bs79DOSvn4D3H2JLDaRrHYtom2HxwDYk3Pa+k9AEpPCQ3px/d17ooOx2e+WXtnrduzsZ MH0pHy4nhqXtFEyuBAYGDK6MvPXBAlXEcz/OPRJR9Oplo/ytcDPwz+grmbI/HukBGKYN N2Jg== X-Gm-Message-State: ABuFfoi552KQOwn4qSTsZ3Xu6XrC1IoP1fjlXjD74oCEEj3pK6B/MLs6 IlfrphltEug6C3qHxykUK2TmY6Z1 X-Google-Smtp-Source: ACcGV63Bp4/X9EknUT9Yatrk/IYSalVemg31+bHQ2U6dCeA3b3J+9BYKFbXfei4orbTV3sp7Tau80A== X-Received: by 2002:adf:e403:: with SMTP id g3-v6mr3527312wrm.96.1538295208884; Sun, 30 Sep 2018 01:13:28 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 30 Sep 2018 10:12:08 +0200 Message-Id: <1538295197-23704-11-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::433 Subject: [Qemu-devel] [PULL 10/79] 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: "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" 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 Message-Id: <20180910232752.31565-5-cota@braap.org> Signed-off-by: Paolo Bonzini --- util/qsp.c | 49 ++++++++----------------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/util/qsp.c b/util/qsp.c index b0c2575..c16af03 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 @@ -345,46 +338,15 @@ static QSPEntry *qsp_entry_get(const void *obj, const= char *file, int line, } =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 1.8.3.1