-
Notifications
You must be signed in to change notification settings - Fork 60
/
0134-md-raid6-algorithms-scale-test-duration-for-speedier.patch
127 lines (115 loc) · 4.01 KB
/
0134-md-raid6-algorithms-scale-test-duration-for-speedier.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
From 1848e77c8d0356181344a7481f31eea42bf97f9e Mon Sep 17 00:00:00 2001
From: Colin Ian King <[email protected]>
Date: Fri, 28 Apr 2023 17:01:35 +0100
Subject: [PATCH] md/raid6 algorithms: scale test duration for speedier boots
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 benchmarking from 48,000 usecs to 4000 usecs, saving
0.044 seconds on boot.
Signed-off-by: Colin Ian King <[email protected]>
---
lib/raid6/algos.c | 53 ++++++++++++++++++++---------------------------
1 file changed, 22 insertions(+), 31 deletions(-)
diff --git a/lib/raid6/algos.c b/lib/raid6/algos.c
index a22a05c9af8a..e2ba261394f6 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);
@@ -143,12 +145,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;
@@ -158,26 +163,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);
}
}
@@ -194,31 +193,23 @@ 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.42.0