6 #include "../gettime.h"
7 #include "../fio_time.h"
10 #include "../crc/md5.h"
11 #include "../crc/crc64.h"
12 #include "../crc/crc32.h"
13 #include "../crc/crc32c.h"
14 #include "../crc/crc16.h"
15 #include "../crc/crc7.h"
16 #include "../crc/sha1.h"
17 #include "../crc/sha256.h"
18 #include "../crc/sha512.h"
19 #include "../crc/xxhash.h"
20 #include "../crc/murmur3.h"
26 #define NR_CHUNKS 2048U
31 void (*fn)(struct test_type *, void *, size_t);
50 static void t_md5(struct test_type *t, void *buf, size_t size)
53 struct fio_md5_ctx ctx = { .hash = digest };
58 for (i = 0; i < NR_CHUNKS; i++)
59 fio_md5_update(&ctx, buf, size);
64 static void t_crc64(struct test_type *t, void *buf, size_t size)
68 for (i = 0; i < NR_CHUNKS; i++)
72 static void t_crc32(struct test_type *t, void *buf, size_t size)
76 for (i = 0; i < NR_CHUNKS; i++)
80 static void t_crc32c(struct test_type *t, void *buf, size_t size)
84 for (i = 0; i < NR_CHUNKS; i++)
85 fio_crc32c(buf, size);
88 static void t_crc16(struct test_type *t, void *buf, size_t size)
92 for (i = 0; i < NR_CHUNKS; i++)
96 static void t_crc7(struct test_type *t, void *buf, size_t size)
100 for (i = 0; i < NR_CHUNKS; i++)
104 static void t_sha1(struct test_type *t, void *buf, size_t size)
107 struct fio_sha1_ctx ctx = { .H = sha };
112 for (i = 0; i < NR_CHUNKS; i++)
113 fio_sha1_update(&ctx, buf, size);
116 static void t_sha256(struct test_type *t, void *buf, size_t size)
119 struct fio_sha256_ctx ctx = { .buf = sha };
122 fio_sha256_init(&ctx);
124 for (i = 0; i < NR_CHUNKS; i++)
125 fio_sha256_update(&ctx, buf, size);
127 fio_sha256_final(&ctx);
130 static void t_sha512(struct test_type *t, void *buf, size_t size)
133 struct fio_sha512_ctx ctx = { .buf = sha };
136 fio_sha512_init(&ctx);
138 for (i = 0; i < NR_CHUNKS; i++)
139 fio_sha512_update(&ctx, buf, size);
142 static void t_murmur3(struct test_type *t, void *buf, size_t size)
146 for (i = 0; i < NR_CHUNKS; i++)
147 murmurhash3(buf, size, 0x8989);
150 static void t_jhash(struct test_type *t, void *buf, size_t size)
154 for (i = 0; i < NR_CHUNKS; i++)
155 t->output += jhash(buf, size, 0x8989);
158 static void t_xxhash(struct test_type *t, void *buf, size_t size)
163 state = XXH32_init(0x8989);
165 for (i = 0; i < NR_CHUNKS; i++)
166 XXH32_update(state, buf, size);
168 t->output = XXH32_digest(state);
171 static struct test_type t[] = {
237 static unsigned int get_test_mask(const char *type)
239 char *ostr, *str = strdup(type);
246 while ((name = strsep(&str, ",")) != NULL) {
247 for (i = 0; t[i].name; i++) {
248 if (!strcmp(t[i].name, name)) {
259 static int list_types(void)
263 for (i = 0; t[i].name; i++)
264 printf("%s\n", t[i].name);
269 int fio_crctest(const char *type)
271 unsigned int test_mask = 0;
272 uint64_t mb = CHUNK * NR_CHUNKS;
273 struct frand_state state;
277 crc32c_intel_probe();
281 else if (!strcmp(type, "help") || !strcmp(type, "list"))
284 test_mask = get_test_mask(type);
287 fprintf(stderr, "fio: unknown hash `%s`. Available:\n", type);
292 init_rand_seed(&state, 0x8989);
293 fill_random_buf(&state, buf, CHUNK);
295 for (i = 0; t[i].name; i++) {
301 if (!(t[i].mask & test_mask))
305 * For first run, make sure CPUs are spun up and that
306 * we've touched the data.
310 t[i].fn(&t[i], buf, CHUNK);
313 fio_gettime(&tv, NULL);
314 t[i].fn(&t[i], buf, CHUNK);
315 usec = utime_since_now(&tv);
317 mb_sec = (double) mb / (double) usec;
318 mb_sec /= (1.024 * 1.024);
319 if (strlen(t[i].name) >= 7)
322 sprintf(pre, "\t\t");
323 printf("%s:%s%8.2f MB/sec\n", t[i].name, pre, mb_sec);