From nobody Wed Nov 5 13:14:13 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 1536606671665434.52484597657974; Mon, 10 Sep 2018 12:11:11 -0700 (PDT) Received: from localhost ([::1]:53587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzRaY-0001P7-Km for importer@patchew.org; Mon, 10 Sep 2018 15:11:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fzRPc-0001Tk-Qa for qemu-devel@nongnu.org; Mon, 10 Sep 2018 14:59:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fzRPb-0001Kw-3l for qemu-devel@nongnu.org; Mon, 10 Sep 2018 14:59:52 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:35791) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fzRPa-0001DR-Tn for qemu-devel@nongnu.org; Mon, 10 Sep 2018 14:59:50 -0400 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id EF2A821F3C; Mon, 10 Sep 2018 14:59:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 10 Sep 2018 14:59:08 -0400 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id 9C34510298; Mon, 10 Sep 2018 14:59:08 -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=iN5Wimj//o+Y/q ruL0UaJpUL1+d3vp9l2ed7Y8857OY=; b=E10xLwGAzzqeywRqo2FhdL33ASqnOe nyJJhEudbfTvHGMk5FacaC08/3GvjakyCsrFEQOGkmC0R9GyqhfXH+FEueTU08/h Z2e5CcS/SUDSmSG8y5oWzLiIfaHng1MA1C7x7YjfVPCleLneEN184e//+rK7Xtz+ R7dblR/TY/MSg= 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=iN5Wimj//o+Y/qruL0UaJpUL1+d3vp9l2ed7Y8857OY=; b=oF/2hgbm l6e4xhRF0rU1x8bqzXv1hedHaAdryEEiI0/G4J2EiAFxiE2BLVBp/1h0j3iIn4+R 8Dn3JpShya43bx3Iyl3whKBwnFifvcwk5eg3tVW+Yl8O78KV0l6T0LE5yNyl0+TB TH4gRJLVfbpwcWEBu7+ttbnbVqkJ9sFl6tpa4ihDUEZUZlKA6ERp+evTwcK8uEuQ sFaNaDT9U65ZIo6QpFh2PBgqLf5sOOrZhB4G7Qd/bHcH3sB7CE3WXVXs96SKcS0j y4z/VVxkS39YIzmx8krqeBfmAq53DY6CihCas5x4Hnfn9WQZiMZQzVmWu0uSbR+W bstdujaG8HTZiw== X-ME-Proxy: X-ME-Sender: From: "Emilio G. Cota" To: qemu-devel@nongnu.org Date: Mon, 10 Sep 2018 14:58:59 -0400 Message-Id: <20180910185859.27917-13-cota@braap.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180910185859.27917-1-cota@braap.org> References: <20180910185859.27917-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 12/12] qht-bench: add -p flag to precompute hash values 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: =?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" Precomputing the hash values allows us to perform more frequent accesses to the hash table, thereby reaching higher throughputs. We keep the old behaviour by default, since (1) we might confuse users if they measured a speedup without changing anything in the QHT implementation, and (2) benchmarking the hash function "on line" is also valuable. Before: $ taskset -c 0 tests/qht-bench -n 1 Throughput: 38.18 MT/s After: $ taskset -c 0 tests/qht-bench -n 1 Throughput: 38.16 MT/s After (with precomputing): $ taskset -c 0 tests/qht-bench -n 1 -p Throughput: 50.87 MT/s Signed-off-by: Emilio G. Cota --- tests/qht-bench.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/tests/qht-bench.c b/tests/qht-bench.c index f492b3a20a..2089e2bed1 100644 --- a/tests/qht-bench.c +++ b/tests/qht-bench.c @@ -53,6 +53,7 @@ static unsigned long resize_delay =3D 1000; static double resize_rate; /* 0.0 to 1.0 */ static unsigned int n_rz_threads =3D 1; static QemuThread *rz_threads; +static bool precompute_hash; =20 static double update_rate; /* 0.0 to 1.0 */ static uint64_t update_threshold; @@ -101,11 +102,18 @@ static bool is_equal(const void *ap, const void *bp) return *a =3D=3D *b; } =20 -static inline uint32_t h(unsigned long v) +static uint32_t h(unsigned long v) { return tb_hash_func7(v, 0, 0, 0, 0); } =20 +static uint32_t hval(unsigned long v) +{ + return v; +} + +static uint32_t (*hfunc)(unsigned long v) =3D h; + /* * From: https://en.wikipedia.org/wiki/Xorshift * This is faster than rand_r(), and gives us a wider range (RAND_MAX is o= nly @@ -149,7 +157,7 @@ static void do_rw(struct thread_info *info) bool read; =20 p =3D &keys[info->r & (lookup_range - 1)]; - hash =3D h(*p); + hash =3D hfunc(*p); read =3D qht_lookup(&ht, p, hash); if (read) { stats->rd++; @@ -158,7 +166,7 @@ static void do_rw(struct thread_info *info) } } else { p =3D &keys[info->r & (update_range - 1)]; - hash =3D h(*p); + hash =3D hfunc(*p); if (info->write_op) { bool written =3D false; =20 @@ -289,7 +297,9 @@ static void htable_init(void) /* avoid allocating memory later by allocating all the keys now */ keys =3D g_malloc(sizeof(*keys) * n); for (i =3D 0; i < n; i++) { - keys[i] =3D populate_offset + i; + long val =3D populate_offset + i; + + keys[i] =3D precompute_hash ? h(val) : hval(val); } =20 /* some sanity checks */ @@ -321,7 +331,7 @@ static void htable_init(void) =20 r =3D xorshift64star(r); p =3D &keys[r & (init_range - 1)]; - hash =3D h(*p); + hash =3D hfunc(*p); if (qht_insert(&ht, p, hash, NULL)) { break; } @@ -412,7 +422,7 @@ static void parse_args(int argc, char *argv[]) int c; =20 for (;;) { - c =3D getopt(argc, argv, "d:D:g:k:K:l:hn:N:o:r:Rs:S:u:"); + c =3D getopt(argc, argv, "d:D:g:k:K:l:hn:N:o:pr:Rs:S:u:"); if (c < 0) { break; } @@ -451,6 +461,10 @@ static void parse_args(int argc, char *argv[]) case 'o': populate_offset =3D atol(optarg); break; + case 'p': + precompute_hash =3D true; + hfunc =3D hval; + break; case 'r': update_range =3D pow2ceil(atol(optarg)); break; --=20 2.17.1