Skip to content

Commit

Permalink
btrfs-progs: crypto: add filter by name to hash-speedtest
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kdave committed Jan 8, 2025
1 parent ba231cb commit 1b63232
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crypto/hash-speedtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <time.h>
#include <getopt.h>
#include <unistd.h>
#include <fnmatch.h>
#if HAVE_LINUX_PERF_EVENT_H == 1 && HAVE_LINUX_HW_BREAKPOINT_H == 1
#include <linux/perf_event.h>
#include <linux/hw_breakpoint.h>
Expand Down Expand Up @@ -176,6 +177,7 @@ int main(int argc, char **argv) {
u8 hash[32];
int idx;
int iter;
char *filter = NULL;
struct contestant {
char name[16];
int (*digest)(const u8 *buf, size_t length, u8 *out);
Expand Down Expand Up @@ -237,11 +239,12 @@ int main(int argc, char **argv) {
{ "cycles", no_argument, NULL, 'c' },
{ "time", no_argument, NULL, 't' },
{ "perf", no_argument, NULL, 'p' },
{ "filter", required_argument, NULL, 'f' },
{ NULL, 0, NULL, 0}
};
int c;

c = getopt_long(argc, argv, "ctp", long_options, NULL);
c = getopt_long(argc, argv, "cf:tp", long_options, NULL);
if (c < 0)
break;
switch (c) {
Expand All @@ -252,6 +255,11 @@ int main(int argc, char **argv) {
}
units = UNITS_CYCLES;
break;
case 'f':
free(filter);
filter = strdup(optarg);
printf("Use filter: %s\n", filter);
break;
case 't':
units = UNITS_TIME;
break;
Expand Down Expand Up @@ -296,6 +304,12 @@ int main(int argc, char **argv) {
/* Backend not compiled in */
if (c->backend == 1)
continue;

if (c->digest == hash_null_memcpy)
/* Always run NULL-MEMCPY to warm up memory. */;
else if (filter && fnmatch(filter, c->name, FNM_CASEFOLD) != 0)
continue;

printf("%14s: ", c->name);
fflush(stdout);

Expand Down Expand Up @@ -335,6 +349,7 @@ int main(int argc, char **argv) {
putchar('\n');
}
perf_finish();
free(filter);

return 0;
}

0 comments on commit 1b63232

Please sign in to comment.