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 "../lib/murmur3.h"
25 #define NR_CHUNKS 2048U
30 void (*fn)(void *, size_t);
47 static void t_md5(void *buf, size_t size)
50 struct fio_md5_ctx ctx = { .hash = digest };
55 for (i = 0; i < NR_CHUNKS; i++)
56 fio_md5_update(&ctx, buf, size);
61 static void t_crc64(void *buf, size_t size)
65 for (i = 0; i < NR_CHUNKS; i++)
69 static void t_crc32(void *buf, size_t size)
73 for (i = 0; i < NR_CHUNKS; i++)
77 static void t_crc32c(void *buf, size_t size)
81 for (i = 0; i < NR_CHUNKS; i++)
82 fio_crc32c(buf, size);
85 static void t_crc16(void *buf, size_t size)
89 for (i = 0; i < NR_CHUNKS; i++)
93 static void t_crc7(void *buf, size_t size)
97 for (i = 0; i < NR_CHUNKS; i++)
101 static void t_sha1(void *buf, size_t size)
104 struct fio_sha1_ctx ctx = { .H = sha };
109 for (i = 0; i < NR_CHUNKS; i++)
110 fio_sha1_update(&ctx, buf, size);
113 static void t_sha256(void *buf, size_t size)
116 struct fio_sha256_ctx ctx = { .buf = sha };
119 fio_sha256_init(&ctx);
121 for (i = 0; i < NR_CHUNKS; i++)
122 fio_sha256_update(&ctx, buf, size);
124 fio_sha256_final(&ctx);
127 static void t_sha512(void *buf, size_t size)
130 struct fio_sha512_ctx ctx = { .buf = sha };
133 fio_sha512_init(&ctx);
135 for (i = 0; i < NR_CHUNKS; i++)
136 fio_sha512_update(&ctx, buf, size);
139 static void t_murmur3(void *buf, size_t size)
143 for (i = 0; i < NR_CHUNKS; i++)
144 murmurhash3(buf, size, 0x8989);
147 static void t_xxhash(void *buf, size_t size)
152 state = XXH32_init(0x8989);
154 for (i = 0; i < NR_CHUNKS; i++)
155 XXH32_update(state, buf, size);
160 static struct test_type t[] = {
221 static unsigned int get_test_mask(const char *type)
223 char *ostr, *str = strdup(type);
230 while ((name = strsep(&str, ",")) != NULL) {
231 for (i = 0; t[i].name; i++) {
232 if (!strcmp(t[i].name, name)) {
243 static int list_types(void)
247 for (i = 0; t[i].name; i++)
248 printf("%s\n", t[i].name);
253 int fio_crctest(const char *type)
255 unsigned int test_mask = 0;
256 uint64_t mb = CHUNK * NR_CHUNKS;
257 struct frand_state state;
261 crc32c_intel_probe();
265 else if (!strcmp(type, "help") || !strcmp(type, "list"))
268 test_mask = get_test_mask(type);
271 fprintf(stderr, "fio: unknown hash `%s`. Available:\n", type);
276 init_rand_seed(&state, 0x8989);
277 fill_random_buf(&state, buf, CHUNK);
279 for (i = 0; t[i].name; i++) {
285 if (!(t[i].mask & test_mask))
289 * For first run, make sure CPUs are spun up and that
290 * we've touched the data.
297 fio_gettime(&tv, NULL);
299 usec = utime_since_now(&tv);
301 mb_sec = (double) mb / (double) usec;
302 mb_sec /= (1.024 * 1.024);
303 if (strlen(t[i].name) >= 7)
306 sprintf(pre, "\t\t");
307 printf("%s:%s%8.2f MB/sec\n", t[i].name, pre, mb_sec);