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"
24 #define NR_CHUNKS 2048U
29 uint64_t (*fn)(void *, size_t);
45 static void randomize_buf(void *buf, unsigned int size, int seed)
47 struct frand_state state;
49 init_rand_seed(&state, seed);
50 fill_random_buf(&state, buf, size);
53 static uint64_t t_md5(void *buf, size_t size)
56 struct fio_md5_ctx ctx = { .hash = digest };
62 fio_gettime(&s, NULL);
63 for (i = 0; i < NR_CHUNKS; i++)
64 fio_md5_update(&ctx, buf, size);
66 return utime_since_now(&s);
69 static uint64_t t_crc64(void *buf, size_t size)
74 fio_gettime(&s, NULL);
75 for (i = 0; i < NR_CHUNKS; i++)
78 return utime_since_now(&s);
81 static uint64_t t_crc32(void *buf, size_t size)
86 fio_gettime(&s, NULL);
87 for (i = 0; i < NR_CHUNKS; i++)
90 return utime_since_now(&s);
93 static uint64_t t_crc32c(void *buf, size_t size)
98 fio_gettime(&s, NULL);
99 for (i = 0; i < NR_CHUNKS; i++)
100 fio_crc32c(buf, size);
102 return utime_since_now(&s);
105 static uint64_t t_crc16(void *buf, size_t size)
110 fio_gettime(&s, NULL);
111 for (i = 0; i < NR_CHUNKS; i++)
112 fio_crc16(buf, size);
114 return utime_since_now(&s);
117 static uint64_t t_crc7(void *buf, size_t size)
123 fio_gettime(&s, NULL);
124 for (i = 0; i < NR_CHUNKS; i++)
127 ret = utime_since_now(&s);
131 static uint64_t t_sha1(void *buf, size_t size)
134 struct fio_sha1_ctx ctx = { .H = sha };
141 fio_gettime(&s, NULL);
142 for (i = 0; i < NR_CHUNKS; i++)
143 fio_sha1_update(&ctx, buf, size);
145 ret = utime_since_now(&s);
149 static uint64_t t_sha256(void *buf, size_t size)
152 struct fio_sha256_ctx ctx = { .buf = sha };
157 fio_sha256_init(&ctx);
159 fio_gettime(&s, NULL);
160 for (i = 0; i < NR_CHUNKS; i++)
161 fio_sha256_update(&ctx, buf, size);
163 ret = utime_since_now(&s);
167 static uint64_t t_sha512(void *buf, size_t size)
170 struct fio_sha512_ctx ctx = { .buf = sha };
175 fio_sha512_init(&ctx);
177 fio_gettime(&s, NULL);
178 for (i = 0; i < NR_CHUNKS; i++)
179 fio_sha512_update(&ctx, buf, size);
181 ret = utime_since_now(&s);
185 static uint64_t t_xxhash(void *buf, size_t size)
192 state = XXH32_init(0x8989);
194 fio_gettime(&s, NULL);
195 for (i = 0; i < NR_CHUNKS; i++)
196 XXH32_update(state, buf, size);
199 ret = utime_since_now(&s);
203 static struct test_type t[] = {
259 static unsigned int get_test_mask(const char *type)
261 char *ostr, *str = strdup(type);
268 while ((name = strsep(&str, ",")) != NULL) {
269 for (i = 0; t[i].name; i++) {
270 if (!strcmp(t[i].name, name)) {
281 static int list_types(void)
285 for (i = 0; t[i].name; i++)
286 printf("%s\n", t[i].name);
291 int fio_crctest(const char *type)
293 unsigned int test_mask = 0;
294 uint64_t mb = CHUNK * NR_CHUNKS;
298 crc32c_intel_probe();
302 else if (!strcmp(type, "help") || !strcmp(type, "list"))
305 test_mask = get_test_mask(type);
308 fprintf(stderr, "fio: unknown hash `%s`. Available:\n", type);
313 randomize_buf(buf, CHUNK, 0x8989);
315 for (i = 0; t[i].name; i++) {
319 if (!(t[i].mask & test_mask))
322 usec = t[i].fn(buf, CHUNK);
324 usec = t[i].fn(buf, CHUNK);
326 mb_sec = (double) mb / (double) usec;
327 mb_sec /= (1.024 * 1.024);
328 printf("%s:\t%8.2f MB/sec\n", t[i].name, mb_sec);