Skip to content

Commit 1b63232

Browse files
committed
btrfs-progs: crypto: add filter by name to hash-speedtest
Use glob/fnmatch expression to filter hashes, case insensitive: $ ./hash-speedtest -f 'crc*' $ ./hash-speedtest -f '*ref' The NULL-MEMCPY run is always done to warm up caches. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent ba231cb commit 1b63232

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

crypto/hash-speedtest.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <time.h>
1919
#include <getopt.h>
2020
#include <unistd.h>
21+
#include <fnmatch.h>
2122
#if HAVE_LINUX_PERF_EVENT_H == 1 && HAVE_LINUX_HW_BREAKPOINT_H == 1
2223
#include <linux/perf_event.h>
2324
#include <linux/hw_breakpoint.h>
@@ -176,6 +177,7 @@ int main(int argc, char **argv) {
176177
u8 hash[32];
177178
int idx;
178179
int iter;
180+
char *filter = NULL;
179181
struct contestant {
180182
char name[16];
181183
int (*digest)(const u8 *buf, size_t length, u8 *out);
@@ -237,11 +239,12 @@ int main(int argc, char **argv) {
237239
{ "cycles", no_argument, NULL, 'c' },
238240
{ "time", no_argument, NULL, 't' },
239241
{ "perf", no_argument, NULL, 'p' },
242+
{ "filter", required_argument, NULL, 'f' },
240243
{ NULL, 0, NULL, 0}
241244
};
242245
int c;
243246

244-
c = getopt_long(argc, argv, "ctp", long_options, NULL);
247+
c = getopt_long(argc, argv, "cf:tp", long_options, NULL);
245248
if (c < 0)
246249
break;
247250
switch (c) {
@@ -252,6 +255,11 @@ int main(int argc, char **argv) {
252255
}
253256
units = UNITS_CYCLES;
254257
break;
258+
case 'f':
259+
free(filter);
260+
filter = strdup(optarg);
261+
printf("Use filter: %s\n", filter);
262+
break;
255263
case 't':
256264
units = UNITS_TIME;
257265
break;
@@ -296,6 +304,12 @@ int main(int argc, char **argv) {
296304
/* Backend not compiled in */
297305
if (c->backend == 1)
298306
continue;
307+
308+
if (c->digest == hash_null_memcpy)
309+
/* Always run NULL-MEMCPY to warm up memory. */;
310+
else if (filter && fnmatch(filter, c->name, FNM_CASEFOLD) != 0)
311+
continue;
312+
299313
printf("%14s: ", c->name);
300314
fflush(stdout);
301315

@@ -335,6 +349,7 @@ int main(int argc, char **argv) {
335349
putchar('\n');
336350
}
337351
perf_finish();
352+
free(filter);
338353

339354
return 0;
340355
}

0 commit comments

Comments
 (0)