From patchwork Wed Sep 26 18:37:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 147632 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp1066829lji; Wed, 26 Sep 2018 11:38:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV61yJ+dBB5paCz/nKJRkjPQDYPj5lE/e9FABUJtdm1jsRP3+7rxLw2f8VuAoEqDQarFdi/6z X-Received: by 2002:a0c:d2b4:: with SMTP id q49-v6mr5453299qvh.46.1537987083487; Wed, 26 Sep 2018 11:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537987083; cv=none; d=google.com; s=arc-20160816; b=GVuEEEkNxqpnVcCqNpbhZJ5yyEaFSsCsmv7Mm87Ayy/whWBdvbKVDRnv/9QAWNAq+y Z6ejxGN8Izt6g21d0uNOdv6LdAv5BT+YnuqYnhP4fAifhrsDndwt9RaLPsHQ88s8d7QO FtpOY/5S2Cov4m8Y7Ud5S+5xnvo9bxGv39wcXDwcQjosqbfWZ4VktzXjnrDSW2EVAFFP irenn/B0PCi4kvkNMWZBpFDKGPTp8VNNzY0Rlx4fyaWL9b+Q1bAMdGcTeSteHowCF7Av NhgPX7tFBdlAB8fJ4R+RctC6i8m+x4l9W8x2YysaG6d7SWCEn3txJj7HuFdYxmkFy/ja vQBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=gUr4Rg30kEa57DsN+a3e5NMAEgxvwTzfEYRCfyICEQw=; b=Hf9j1qoJh+vltoM8pSDStr4HomCdFL/f1cWw/VcTV8Fe/tOqocAXsoY6CWVthsIQ9v E6eFzqwW8N1yV5zE244Ffej0Ql/YulqFNQVMzg9cBE2xJvCl13DZcQNBk18HG+T0hiKx 1seHIf47y+T84CeC9EmMHWU8wLVjg2Fd4U9nKwweqm6v5wnYYFVb+Ssswz+0qtOtn05f KnDj33rZJTDpFVoeBgMT107r/lUXslClbPyquVBZQHcBAcYnufvPTmvpamyA8R5UB8aN j1NZ0o/mBpCB4jR0Q+cMFiZ0mTCOb8YxMP/hyjqqEFmEzUnVzNf07g+hf+uBOKRZIRL4 M2Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=G464ZV8e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k7-v6si595255qke.215.2018.09.26.11.38.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 26 Sep 2018 11:38:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=G464ZV8e; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5EhG-0001tt-TU for patch@linaro.org; Wed, 26 Sep 2018 14:38:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5Ego-0001ip-4e for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5Egm-0007R3-LO for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:34 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]:46617) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g5Egm-0007QT-Az for qemu-devel@nongnu.org; Wed, 26 Sep 2018 14:37:32 -0400 Received: by mail-pf1-x431.google.com with SMTP id d8-v6so6931572pfo.13 for ; Wed, 26 Sep 2018 11:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gUr4Rg30kEa57DsN+a3e5NMAEgxvwTzfEYRCfyICEQw=; b=G464ZV8e20L2YVHWR7RatP/R8NfmkPYLSHM+PbuHSVbqb6OUVWqx2QZIDWjonPxaeF ztNhvEwJEexjIwGvtDdgvCxOdWmXMbIoaURgLhMUBev6EFo2zG9P/PHd3V3SS2xZU13x ZUsxoaELB86KaIQtezhKMJXtAMlSLXujPBkto= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gUr4Rg30kEa57DsN+a3e5NMAEgxvwTzfEYRCfyICEQw=; b=lYmjQKY+zDdrcnfNNCzQWJshkAPFM3gFYQ1IDqAWzj1/3mBRPuR+Kzym4KwiWWTwDM DxeSy7BvaBz/aA6QKakilwB16fGDZLYhAygjPrNgEMilS00HVwtGvVAK2QpaBinz71EM PA0ufDrp2YB043qGaHmp5rSZOXUlv7hGvC0KEVckAoPrE37+ED/WUUctY+LBfPiFATKJ 6qCfB3d8y3ZSwvUxRYWjeElvS7qShqJM8YNNSUkgiexI4aGMKL7bRlcRp6MYNEIWRmVo JuNOUnujK4N0FvLBfVftnUX+OKY4j+KmQr4jmKrt0a0PwbN6sSHmHoc3ktHf28JK310p ZdDw== X-Gm-Message-State: ABuFfogwUsYx9dLmVgEFJ9kmMp0mDHDQlLgd2NRXWrj4+Cd6OHskNtZL hwqU+VKH1KS++60u0jNHNtMLl4O2cEQ= X-Received: by 2002:a17:902:40d:: with SMTP id 13-v6mr7288339ple.257.1537987050911; Wed, 26 Sep 2018 11:37:30 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-8-179.tukw.qwest.net. [97.113.8.179]) by smtp.gmail.com with ESMTPSA id b14-v6sm9735952pfc.178.2018.09.26.11.37.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Sep 2018 11:37:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 26 Sep 2018 11:37:08 -0700 Message-Id: <20180926183709.21293-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180926183709.21293-1-richard.henderson@linaro.org> References: <20180926183709.21293-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::431 Subject: [Qemu-devel] [PULL 12/13] 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: peter.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" 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 Signed-off-by: Richard Henderson --- tests/qht-bench.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) -- 2.17.1 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 = 1000; static double resize_rate; /* 0.0 to 1.0 */ static unsigned int n_rz_threads = 1; static QemuThread *rz_threads; +static bool precompute_hash; 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 == *b; } -static inline uint32_t h(unsigned long v) +static uint32_t h(unsigned long v) { return tb_hash_func7(v, 0, 0, 0, 0); } +static uint32_t hval(unsigned long v) +{ + return v; +} + +static uint32_t (*hfunc)(unsigned long v) = h; + /* * From: https://en.wikipedia.org/wiki/Xorshift * This is faster than rand_r(), and gives us a wider range (RAND_MAX is only @@ -149,7 +157,7 @@ static void do_rw(struct thread_info *info) bool read; p = &keys[info->r & (lookup_range - 1)]; - hash = h(*p); + hash = hfunc(*p); read = qht_lookup(&ht, p, hash); if (read) { stats->rd++; @@ -158,7 +166,7 @@ static void do_rw(struct thread_info *info) } } else { p = &keys[info->r & (update_range - 1)]; - hash = h(*p); + hash = hfunc(*p); if (info->write_op) { bool written = false; @@ -289,7 +297,9 @@ static void htable_init(void) /* avoid allocating memory later by allocating all the keys now */ keys = g_malloc(sizeof(*keys) * n); for (i = 0; i < n; i++) { - keys[i] = populate_offset + i; + long val = populate_offset + i; + + keys[i] = precompute_hash ? h(val) : hval(val); } /* some sanity checks */ @@ -321,7 +331,7 @@ static void htable_init(void) r = xorshift64star(r); p = &keys[r & (init_range - 1)]; - hash = h(*p); + hash = hfunc(*p); if (qht_insert(&ht, p, hash, NULL)) { break; } @@ -412,7 +422,7 @@ static void parse_args(int argc, char *argv[]) int c; for (;;) { - c = getopt(argc, argv, "d:D:g:k:K:l:hn:N:o:r:Rs:S:u:"); + c = 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 = atol(optarg); break; + case 'p': + precompute_hash = true; + hfunc = hval; + break; case 'r': update_range = pow2ceil(atol(optarg)); break;