From nobody Mon Apr 29 13:35:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1593202260; cv=none; d=zohomail.com; s=zohoarc; b=oL0Lxn+vlxUFNtBZBXISVVNEhg79UlZFFgk/tJUT2m6Zsnkyqdyy2TEzE8LzLu6mQkdtyI9SHZb0JglbLi1Jkx5CJqkPjPoCLWZHr4bF+OD7kxlebZbGgJagOg3GSWGsr8coIype5Mcj7s0lubmQaZI70zGOzr7UI8mFX2MVMto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593202260; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hxw6BjVwQMIa1uoPxedqx8XGWOQD0NGxS2kvL4q3yy8=; b=iJbK97fCY7H0rclzpi8FCoT32t7eYjSU2MJv11V6syhmLTPOozu4/m6vJZtXYJkGVKoz1VxoSxRlXrCJKqg1tqTLWc23BW0BPe8FsncG3fAJ/E7q98jv3jZ5NQ/wV7Qv3/T+dSzdfsWyzuMS4hQDFb9rvT4vTGVut5Jjq2l7bK8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593202260883298.2618132953911; Fri, 26 Jun 2020 13:11:00 -0700 (PDT) Received: from localhost ([::1]:45534 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jougd-0005cA-Hb for importer@patchew.org; Fri, 26 Jun 2020 16:10:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54578) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joufe-0004M4-Rk for qemu-devel@nongnu.org; Fri, 26 Jun 2020 16:09:58 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1joufd-00042T-4n for qemu-devel@nongnu.org; Fri, 26 Jun 2020 16:09:58 -0400 Received: by mail-pf1-x443.google.com with SMTP id j1so5086375pfe.4 for ; Fri, 26 Jun 2020 13:09:56 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id n8sm23879405pgi.18.2020.06.26.13.09.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 13:09:54 -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 :mime-version:content-transfer-encoding; bh=hxw6BjVwQMIa1uoPxedqx8XGWOQD0NGxS2kvL4q3yy8=; b=p+RuJNwrhJwZzEjMil2KSK43gxw9c+9Cn27jYyvT7FTHmrnzki4Un4F4HvfliyZTfh zXg3MOoJ+ONJRbRqBL+3x/DlskkOFR5Pv03YSLmatXGGMw3clTstv9gJr4m/vWUkDZEF CBH7TvujTskzBLKxmyLPmM7vz5Oo9h3Poeiv71ZablgVXZIPmYqo777WsK6qOPK50nde SmUXWbP9JsnlKn74DgQeHsaZ5mjwr+9R1fj4cXkmHMS+cuZzUWSTM2wt4vIHVpHZN8o8 ul4nASLcZ7/qGz/SGDT5xixR7NfFPCAHQfBDw6F46jXdXo7vBfac0kn3xXk3fqVLna0w Cvqw== 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:mime-version:content-transfer-encoding; bh=hxw6BjVwQMIa1uoPxedqx8XGWOQD0NGxS2kvL4q3yy8=; b=U4AINskNL5PbOouh5ucX2DuQVaz2cEFcoCqfXrjmlt7nYwPyuYtAfzDMSJ7Ls3fdKr NkMjMpJ2Vx6hsjTJI5TX2+hIo7FQ3E1NJemGbDYC78ncZfxZhG54YiL/gBd0A1FWdOPC Y+fLHKbvgUR46sUN5S8VnCv8wI5oo75mKcmBSdlmRtBCbAgVSlaXJfwrDeyPcChcTvn7 htOGF44Ri0Ui1cwQcFfWO+xqmHTbUD1J6oMdhJpqD49riuna0f/65IeUMs24D6Qax9JZ jM2CDi9qWa6hQHftN5dcjvichU+zK7Zf2vWjEOUebczGkChcWXlAoTbivZMW3GXgkcMJ tXQg== X-Gm-Message-State: AOAM531P8h4NmKeIhb/PyiCJwL2EPtv0rDn4wSzMLtBzeTuNIoVN0GoC msVvXXTvu40HANHN+uau1vPkIzy2YW0= X-Google-Smtp-Source: ABdhPJySL9DB2KuzQm4AqOozxNZFtkP0eB09mp1/CHx78taMbXTCz5oaVyoh9Itih5DIfoAWn+ufFg== X-Received: by 2002:a62:ea14:: with SMTP id t20mr813019pfh.264.1593202195174; Fri, 26 Jun 2020 13:09:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] tests/qht-bench: Adjust testing rate by -1 Date: Fri, 26 Jun 2020 13:09:49 -0700 Message-Id: <20200626200950.1015121-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200626200950.1015121-1-richard.henderson@linaro.org> References: <20200626200950.1015121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x443.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Since the seed must be non-zero, subtracting 1 means puts the rate in 0..UINT64_MAX-1, which allows the 0 and UINT64_MAX thresholds to corrspond to 0% (never) and 100% (always). Suggested-by: Emilio G. Cota Signed-off-by: Richard Henderson Reviewed-by: Emilio G. Cota Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/qht-bench.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/qht-bench.c b/tests/qht-bench.c index eb88a90137..ad885d89d0 100644 --- a/tests/qht-bench.c +++ b/tests/qht-bench.c @@ -25,7 +25,13 @@ struct thread_stats { struct thread_info { void (*func)(struct thread_info *); struct thread_stats stats; - uint64_t r; + /* + * Seed is in the range [1..UINT64_MAX], because the RNG requires + * a non-zero seed. To use, subtract 1 and compare against the + * threshold with =3D. This lets threshold =3D 0 never match (0% h= it), + * and threshold =3D UINT64_MAX always match (100% hit). + */ + uint64_t seed; bool write_op; /* writes alternate between insertions and removals */ bool resize_down; } QEMU_ALIGNED(64); /* avoid false sharing among threads */ @@ -131,8 +137,9 @@ static uint64_t xorshift64star(uint64_t x) static void do_rz(struct thread_info *info) { struct thread_stats *stats =3D &info->stats; + uint64_t r =3D info->seed - 1; =20 - if (info->r < resize_threshold) { + if (r < resize_threshold) { size_t size =3D info->resize_down ? resize_min : resize_max; bool resized; =20 @@ -151,13 +158,14 @@ static void do_rz(struct thread_info *info) static void do_rw(struct thread_info *info) { struct thread_stats *stats =3D &info->stats; + uint64_t r =3D info->seed - 1; uint32_t hash; long *p; =20 - if (info->r >=3D update_threshold) { + if (r >=3D update_threshold) { bool read; =20 - p =3D &keys[info->r & (lookup_range - 1)]; + p =3D &keys[r & (lookup_range - 1)]; hash =3D hfunc(*p); read =3D qht_lookup(&ht, p, hash); if (read) { @@ -166,7 +174,7 @@ static void do_rw(struct thread_info *info) stats->not_rd++; } } else { - p =3D &keys[info->r & (update_range - 1)]; + p =3D &keys[r & (update_range - 1)]; hash =3D hfunc(*p); if (info->write_op) { bool written =3D false; @@ -208,7 +216,7 @@ static void *thread_func(void *p) =20 rcu_read_lock(); while (!atomic_read(&test_stop)) { - info->r =3D xorshift64star(info->r); + info->seed =3D xorshift64star(info->seed); info->func(info); } rcu_read_unlock(); @@ -221,7 +229,7 @@ static void *thread_func(void *p) static void prepare_thread_info(struct thread_info *info, int i) { /* seed for the RNG; each thread should have a different one */ - info->r =3D (i + 1) ^ time(NULL); + info->seed =3D (i + 1) ^ time(NULL); /* the first update will be a write */ info->write_op =3D true; /* the first resize will be down */ --=20 2.25.1 From nobody Mon Apr 29 13:35:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1593202273; cv=none; d=zohomail.com; s=zohoarc; b=EHUq017319CepH6aw/iXISib0+8CaSM4jRuBtE0/BIriBZdz66u2wMoXp4Y3Ihr2S4RUJc7KxfZGRgAbOjYq4J1vYkA4Cs8jL17mgDTXxkWg1wv4DZVhN9HqH93buYltUjsW7SvivgWKRKefTDLAveukko6d7M8ub6wBgKEXf3o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593202273; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SW802rsBjyjH3nSM8zwvWR8Kt24bL/tDHyeHn/2Y6L4=; b=baFlOZo//mtaXP2V9E99S74l6FXgqp4Bv4EiJMxhu3JcOtgXgJHunjsEssOGCZP8UA5203l09HYGmkT8btu/BWbHh0E14E+pLsGTiow8LLR7Gl7WwTmg1IW0we0r1EGHB9OkvjvZ5LYllo0pct4VOUFBUN6A4/neMH4it0dMMvc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593202273098795.398677184658; Fri, 26 Jun 2020 13:11:13 -0700 (PDT) Received: from localhost ([::1]:45724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jougp-0005gb-T8 for importer@patchew.org; Fri, 26 Jun 2020 16:11:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jouff-0004MH-P0 for qemu-devel@nongnu.org; Fri, 26 Jun 2020 16:09:59 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:46722) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1joufe-000443-5Q for qemu-devel@nongnu.org; Fri, 26 Jun 2020 16:09:59 -0400 Received: by mail-pf1-x442.google.com with SMTP id b16so5060093pfi.13 for ; Fri, 26 Jun 2020 13:09:57 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id n8sm23879405pgi.18.2020.06.26.13.09.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 13:09:55 -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 :mime-version:content-transfer-encoding; bh=SW802rsBjyjH3nSM8zwvWR8Kt24bL/tDHyeHn/2Y6L4=; b=N7qHoavy76cIFRRnP7H8p2TP83RVrVKT4yO7yN3Hg85MvuXYyNU91RAGg4g6RJMjUq 9UiS/9BG5IO2nfY4OA6Gq+5Gc9667D1p+DCxWjtCBD6Bc59Q5r+G1JU1SRjJiyZ95TW0 HWgIRYzhpCchKvuT/69134fepgDiQSsf8I7XkePCga8MJAMtSf/TWY5fknSG7hM1m71Q Q+4PaBB6ZiWSDCBZZCeBz2/L4Axzv2pixXMqkLxyVoXbiH6WE56ZM7Ihfru49fCrIhOa 1XWhH5enJkSd9NoW/AZuhQLg5TDJnNN2SvDK5k7tfsIip4+Dhd1z/wK0dGCFZQDJUzWE 7TfQ== 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:mime-version:content-transfer-encoding; bh=SW802rsBjyjH3nSM8zwvWR8Kt24bL/tDHyeHn/2Y6L4=; b=Mk/2Q2Nm6oS5bQBwQAvxxJyg2LGXMBMkUHjaRbP29h9DiQs/wcaUTp9fFweI2r+k45 vMmyHHrulbif0LBpzLoznQmOJiCU/jJmhTGB+NzL6b6THTRxtxQIEEPNM1ee9uuXLYY3 Yrl9GQI5CKdh+tOlnQyQzA7ZswIfc3JZrcSjX3WuhzzAwKAWRNfrKDMhWFKE6arkivkR ZOHeozVJrmxm3jzevHwTHcEZyJ8MjubVOWhNp/rTSNvjza0U5VEtValXty69YjBOsoGn WxbLmW3Q3d/w0PHX8cmf07InbUbasbp7ZMeYr4IecMUEVyQ9N4D+yu7mMP5Fxa44Dz6f xGOA== X-Gm-Message-State: AOAM531cxfLkjzSxJvrlzK5lxOwICR3NO00J9m+7rLtKYwXn49eGG/Go +BOCDJSQqsFWjuQycDADzU4jlUTES0k= X-Google-Smtp-Source: ABdhPJxwx1bqsjUFmUaJMqD7eI0VJ6arOGJwYBAk3Vx3zJmmhqFdqSw4cvnrC+nc8BOiiBF94tMczw== X-Received: by 2002:aa7:9289:: with SMTP id j9mr4573050pfa.124.1593202196355; Fri, 26 Jun 2020 13:09:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] tests/qht-bench: Adjust threshold computation Date: Fri, 26 Jun 2020 13:09:50 -0700 Message-Id: <20200626200950.1015121-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200626200950.1015121-1-richard.henderson@linaro.org> References: <20200626200950.1015121-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::442; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x442.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In 06c4cc3660b3, we split the multiplication in two parts to avoid a clang warning. But because double still rounds to 53 bits, this does not provide additional precision beyond multiplication by nextafter(0x1p64, 0), the largest representable value smaller than 2**64. However, since we have eliminated 1.0, mutiplying by 2**64 produces a better distribution of input values to the output values. Signed-off-by: Richard Henderson Reviewed-by: Emilio G. Cota Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/qht-bench.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/qht-bench.c b/tests/qht-bench.c index ad885d89d0..362f03cb03 100644 --- a/tests/qht-bench.c +++ b/tests/qht-bench.c @@ -289,11 +289,25 @@ static void pr_params(void) =20 static void do_threshold(double rate, uint64_t *threshold) { + /* + * For 0 <=3D rate <=3D 1, scale to fit in a uint64_t. + * + * Scale by 2**64, with a special case for 1.0. + * The remainder of the possible values are scattered between 0 + * and 0xfffffffffffff800 (nextafter(0x1p64, 0)). + * + * Note that we cannot simply scale by UINT64_MAX, because that + * value is not representable as an IEEE double value. + * + * If we scale by the next largest value, nextafter(0x1p64, 0), + * then the remainder of the possible values are scattered between + * 0 and 0xfffffffffffff000. Which leaves us with a gap between + * the final two inputs that is twice as large as any other. + */ if (rate =3D=3D 1.0) { *threshold =3D UINT64_MAX; } else { - *threshold =3D (rate * 0xffff000000000000ull) - + (rate * 0x0000ffffffffffffull); + *threshold =3D rate * 0x1p64; } } =20 --=20 2.25.1