From patchwork Mon Sep 6 10:17:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 1524886 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=uCfIKvcH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H34911qLZz9sRf; Mon, 6 Sep 2021 20:17:56 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1mNBhF-0004MW-3P; Mon, 06 Sep 2021 10:17:49 +0000 Received: from smtp-relay-canonical-1.internal ([10.131.114.174] helo=smtp-relay-canonical-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1mNBhD-0004MQ-5l for kernel-team@lists.ubuntu.com; Mon, 06 Sep 2021 10:17:47 +0000 Received: from localhost (1.general.cking.uk.vpn [10.172.193.212]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id CAA1C3F101; Mon, 6 Sep 2021 10:17:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1630923466; bh=k3mt0waMENh6y68J+JpXCf3sDS7Ly3J1EHRKsMbqoIw=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=uCfIKvcHza3krIDTzvofOUZPGovCN/+mSVH3ZpxWWdy+bk4WHedyVLzzB3PQHHG4J TPp0AnKCn2/yVab76AOQgG1DehRg/LJdK17BPTorv1Fv0bhCn0iPERIe6XrCWPhvWu 2K6uviDSh7gx6SvMmjuC193CQL/8jUEXKUVe/UkXkCVD9akB7bOAMHw0sehcE+p4Oy 3tjo08io0Pm/tK+9osluDJOIndg+2tYs6X3AUXKTYKXQPOy5wWIlfG6zmVYuHyky4n eRMEg8PH8SsrfPgj+bcAvx57hoJ6OI8j0zjr+EattxUKH0VJDYfNUe2ZVgWdtU7/Y9 rzQ/Au+HI2G3A== From: Colin King To: kernel-team@lists.ubuntu.com Subject: [PATCH][IMPISH] UBUNTU: SAUCE: md/raid6 algorithms: scale test duration for speedier boots Date: Mon, 6 Sep 2021 11:17:46 +0100 Message-Id: <20210906101746.568343-1-colin.king@canonical.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Colin Ian King The original code runs for a set run time based on the duration of 2^RAID6_TIME_JIFFIES_LG2. The default kernel value for RAID6_TIME_JIFFIES_LG2 is 4, however, emperical testing shows that a value of 3.5 is the sweet spot for getting consistent benchmarking results and speeding up the run time of the benchmarking. To achieve 2^3.5 we use the following: 2^3.5 = 2^4 / 2^0.5 = 2^4 / sqrt(2) = 2^4 * 0.707106781 Too keep this as integer math that is as accurate as required and avoiding overflow, this becomes: = 2^4 * 181 / 256 = (2^4 * 181) >> 8 We also need to scale down perf by the same factor, however, to get a good approximate integer result without an overflow we scale by 2^4.0 * sqrt(2) = = 2 ^ 4 * 1.41421356237 = 2 ^ 4 * 1448 / 1024 = (2 ^ 4 * 1448) >> 10 This has been tested on 2 AWS instances, a small t2 and a medium m3 with 30 boot tests each and compared to the same instances booted 30 times on an umodified kernel. In all results, we get the same algorithms being selected and a 100% consistent result over the 30 boots, showing that this optimised jiffy timing scaling does not break the original functionality. On the t2.small we see a saving of ~0.126 seconds and t3.medium a saving of ~0.18 seconds. Tested on a 4 CPU VM on an 8 thread Xeon server; seeing a saving of ~0.35 seconds (average over 50 boots). The testing included double checking the algorithm chosen by the optimized selection and seeing the same as pre-optimised version. Signed-off-by: Colin Ian King --- lib/raid6/algos.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c index 6d5e5000fdd7..5d5b04632168 100644 --- a/lib/raid6/algos.c +++ b/lib/raid6/algos.c @@ -152,6 +152,10 @@ static inline const struct raid6_calls *raid6_choose_gen( for (bestgenperf = 0, bestxorperf = 0, best = NULL, algo = raid6_algos; *algo; algo++) { if (!best || (*algo)->prefer >= best->prefer) { + /* 2 ^ (RAID6_TIME_JIFFIES_LG2 - 0.5) */ + const unsigned long raid6_time_jiffies = + ((1 << RAID6_TIME_JIFFIES_LG2) * 181) >> 8; + if ((*algo)->valid && !(*algo)->valid()) continue; @@ -167,7 +171,7 @@ static inline const struct raid6_calls *raid6_choose_gen( while ((j1 = jiffies) == j0) cpu_relax(); while (time_before(jiffies, - j1 + (1<gen_syndrome(disks, PAGE_SIZE, *dptrs); perf++; } @@ -178,8 +182,8 @@ static inline const struct raid6_calls *raid6_choose_gen( best = *algo; } pr_info("raid6: %-8s gen() %5ld MB/s\n", (*algo)->name, - (perf * HZ * (disks-2)) >> - (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2)); + (((perf * HZ * (disks-2)) >> + (20 - 16 + RAID6_TIME_JIFFIES_LG2)) * 1448) >> 10); if (!(*algo)->xor_syndrome) continue; @@ -191,7 +195,7 @@ static inline const struct raid6_calls *raid6_choose_gen( while ((j1 = jiffies) == j0) cpu_relax(); while (time_before(jiffies, - j1 + (1<xor_syndrome(disks, start, stop, PAGE_SIZE, *dptrs); perf++; @@ -202,8 +206,8 @@ static inline const struct raid6_calls *raid6_choose_gen( bestxorperf = perf; pr_info("raid6: %-8s xor() %5ld MB/s\n", (*algo)->name, - (perf * HZ * (disks-2)) >> - (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1)); + (((perf * HZ * (disks-2)) >> + (20 - 16 + RAID6_TIME_JIFFIES_LG2 + 1)) * 1448) >> 10); } } @@ -215,8 +219,8 @@ static inline const struct raid6_calls *raid6_choose_gen( (20 - PAGE_SHIFT+RAID6_TIME_JIFFIES_LG2)); if (best->xor_syndrome) pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n", - (bestxorperf * HZ * (disks-2)) >> - (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1)); + (((bestxorperf * HZ * (disks-2)) >> + (20 - 16 + RAID6_TIME_JIFFIES_LG2 + 1)) * 1448) >> 10); } else pr_info("raid6: skip pq benchmark and using algorithm %s\n", best->name);