lib/raid6/algos.c | 56 ++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 32 deletions(-)
Instead of using jiffies and waiting for jiffies to wrap before
measuring use the higher precision local_time for benchmarking.
Measure 2500 loops, which works out to be accurate enough for
benchmarking the raid algo data rates. Also add division by zero
checking in case timing measurements are bogus.
Speeds up raid benchmarkingm, reduces calibration time from
48,000 usecs to 4000 usecs on a i9-19200.
Signed-off-by: Colin Ian King <colin.king@intel.com>
---
lib/raid6/algos.c | 56 ++++++++++++++++++++---------------------------
1 file changed, 24 insertions(+), 32 deletions(-)
diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c
index cd2e88ee1..5d974ae8d 100644
--- a/lib/raid6/algos.c
+++ b/lib/raid6/algos.c
@@ -18,6 +18,8 @@
#else
#include <linux/module.h>
#include <linux/gfp.h>
+#include <linux/sched/clock.h>
+
/* In .bss so it's zeroed */
const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
EXPORT_SYMBOL(raid6_empty_zero_page);
@@ -155,12 +157,15 @@ static inline const struct raid6_recov_calls *raid6_choose_recov(void)
static inline const struct raid6_calls *raid6_choose_gen(
void *(*const dptrs)[RAID6_TEST_DISKS], const int disks)
{
- unsigned long perf, bestgenperf, j0, j1;
+ unsigned long perf;
+ const unsigned long max_perf = 2500;
int start = (disks>>1)-1, stop = disks-3; /* work on the second half of the disks */
const struct raid6_calls *const *algo;
const struct raid6_calls *best;
+ const u64 ns_per_mb = 1000000000 >> 20;
+ u64 n, ns, t, ns_best = ~0ULL;
- for (bestgenperf = 0, best = NULL, algo = raid6_algos; *algo; algo++) {
+ for (best = NULL, algo = raid6_algos; *algo; algo++) {
if (!best || (*algo)->priority >= best->priority) {
if ((*algo)->valid && !(*algo)->valid())
continue;
@@ -170,26 +175,20 @@ static inline const struct raid6_calls *raid6_choose_gen(
break;
}
- perf = 0;
-
preempt_disable();
- j0 = jiffies;
- while ((j1 = jiffies) == j0)
- cpu_relax();
- while (time_before(jiffies,
- j1 + (1<<RAID6_TIME_JIFFIES_LG2))) {
+ t = local_clock();
+ for (perf = 0; perf < max_perf; perf++)
(*algo)->gen_syndrome(disks, PAGE_SIZE, *dptrs);
- perf++;
- }
+ ns = local_clock() - t;
preempt_enable();
- if (perf > bestgenperf) {
- bestgenperf = perf;
+ if (ns < ns_best) {
+ ns_best = ns;
best = *algo;
}
- pr_info("raid6: %-8s gen() %5ld MB/s\n", (*algo)->name,
- (perf * HZ * (disks-2)) >>
- (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2));
+ n = max_perf * PAGE_SIZE * ns_per_mb * (disks - 2);
+ pr_info("raid6: %-8s gen() %5llu MB/s (%llu ns)\n", (*algo)->name,
+ (ns > 0) ? n / ns : 0, ns);
}
}
@@ -206,31 +205,24 @@ static inline const struct raid6_calls *raid6_choose_gen(
goto out;
}
- pr_info("raid6: using algorithm %s gen() %ld MB/s\n",
- best->name,
- (bestgenperf * HZ * (disks - 2)) >>
- (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2));
+ n = max_perf * PAGE_SIZE * ns_per_mb * (disks - 2);
+ pr_info("raid6: using algorithm %s gen() %llu MB/s (%llu ns)\n",
+ best->name, (ns_best > 0) ? n / ns_best : 0, ns_best);
if (best->xor_syndrome) {
- perf = 0;
-
preempt_disable();
- j0 = jiffies;
- while ((j1 = jiffies) == j0)
- cpu_relax();
- while (time_before(jiffies,
- j1 + (1 << RAID6_TIME_JIFFIES_LG2))) {
+ t = local_clock();
+ for (perf = 0; perf < max_perf; perf++) {
best->xor_syndrome(disks, start, stop,
PAGE_SIZE, *dptrs);
- perf++;
}
+ ns = local_clock() - t;
preempt_enable();
- pr_info("raid6: .... xor() %ld MB/s, rmw enabled\n",
- (perf * HZ * (disks - 2)) >>
- (20 - PAGE_SHIFT + RAID6_TIME_JIFFIES_LG2 + 1));
+ n = max_perf * PAGE_SIZE * ns_per_mb * (disks - 2);
+ pr_info("raid6: .... xor() %llu MB/s, rmw enabled (%llu ns)\n",
+ (ns > 0) ? n / ns : 0, ns);
}
-
out:
return best;
}
--
2.45.2
Hi Colin, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-nonmm-unstable] [also build test ERROR on akpm-mm/mm-everything linus/master v6.11-rc2 next-20240805] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Colin-Ian-King/md-raid6-algorithms-scale-test-duration-for-speedier-boots/20240806-012444 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable patch link: https://lore.kernel.org/r/20240805170816.6025-1-colin.king%40intel.com patch subject: [PATCH] md/raid6 algorithms: scale test duration for speedier boots config: i386-buildonly-randconfig-002-20240806 (https://download.01.org/0day-ci/archive/20240806/202408061134.O5o8RpVV-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240806/202408061134.O5o8RpVV-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202408061134.O5o8RpVV-lkp@intel.com/ All errors (new ones prefixed by >>): ld: lib/raid6/algos.o: in function `raid6_choose_gen.constprop.0': >> algos.c:(.text+0xe6): undefined reference to `__udivdi3' >> ld: algos.c:(.text+0x163): undefined reference to `__udivdi3' ld: algos.c:(.text+0x1fd): undefined reference to `__udivdi3' -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Hi, Two issues with the patch, firstly the 64 bit divisions should be using div64_u64() and also on i386 testing in a VM the selection of the raid6 avx2* algorithm is sometimes incorrect because of a difference in benchmark speed rates on avx2x2 and avx2x1 - so I think this patch needs to be reverted/removed for now until I can figure out why it's not fully stable. Colin -----Original Message----- From: lkp <lkp@intel.com> Sent: Tuesday, August 6, 2024 5:01 AM To: King, Colin <colin.king@intel.com>; Andrew Morton <akpm@linux-foundation.org>; Masahiro Yamada <masahiroy@kernel.org>; rppt@kernel.org Cc: oe-kbuild-all@lists.linux.dev; Linux Memory Management List <linux-mm@kvack.org>; linux-kernel@vger.kernel.org Subject: Re: [PATCH] md/raid6 algorithms: scale test duration for speedier boots Hi Colin, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-nonmm-unstable] [also build test ERROR on akpm-mm/mm-everything linus/master v6.11-rc2 next-20240805] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Colin-Ian-King/md-raid6-algorithms-scale-test-duration-for-speedier-boots/20240806-012444 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable patch link: https://lore.kernel.org/r/20240805170816.6025-1-colin.king%40intel.com patch subject: [PATCH] md/raid6 algorithms: scale test duration for speedier boots config: i386-buildonly-randconfig-002-20240806 (https://download.01.org/0day-ci/archive/20240806/202408061134.O5o8RpVV-lkp@intel.com/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240806/202408061134.O5o8RpVV-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: | https://lore.kernel.org/oe-kbuild-all/202408061134.O5o8RpVV-lkp@intel. | com/ All errors (new ones prefixed by >>): ld: lib/raid6/algos.o: in function `raid6_choose_gen.constprop.0': >> algos.c:(.text+0xe6): undefined reference to `__udivdi3' >> ld: algos.c:(.text+0x163): undefined reference to `__udivdi3' ld: algos.c:(.text+0x1fd): undefined reference to `__udivdi3' -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Hi Colin, kernel test robot noticed the following build errors: [auto build test ERROR on akpm-mm/mm-nonmm-unstable] [also build test ERROR on akpm-mm/mm-everything linus/master v6.11-rc2 next-20240805] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Colin-Ian-King/md-raid6-algorithms-scale-test-duration-for-speedier-boots/20240806-012444 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable patch link: https://lore.kernel.org/r/20240805170816.6025-1-colin.king%40intel.com patch subject: [PATCH] md/raid6 algorithms: scale test duration for speedier boots config: parisc-defconfig (https://download.01.org/0day-ci/archive/20240806/202408061040.0kdEdUBV-lkp@intel.com/config) compiler: hppa-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240806/202408061040.0kdEdUBV-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202408061040.0kdEdUBV-lkp@intel.com/ All errors (new ones prefixed by >>, old ones prefixed by <<): WARNING: modpost: missing MODULE_DESCRIPTION() in lib/asn1_decoder.o >> ERROR: modpost: "__udivdi3" [lib/raid6/raid6_pq.ko] undefined! -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
© 2016 - 2025 Red Hat, Inc.