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 void (*fn)(void *, size_t);
45 static void t_md5(void *buf, size_t size)
48 struct fio_md5_ctx ctx = { .hash = digest };
53 for (i = 0; i < NR_CHUNKS; i++)
54 fio_md5_update(&ctx, buf, size);
57 static void t_crc64(void *buf, size_t size)
61 for (i = 0; i < NR_CHUNKS; i++)
65 static void t_crc32(void *buf, size_t size)
69 for (i = 0; i < NR_CHUNKS; i++)
73 static void t_crc32c(void *buf, size_t size)
77 for (i = 0; i < NR_CHUNKS; i++)
78 fio_crc32c(buf, size);
81 static void t_crc16(void *buf, size_t size)
85 for (i = 0; i < NR_CHUNKS; i++)
89 static void t_crc7(void *buf, size_t size)
93 for (i = 0; i < NR_CHUNKS; i++)
97 static void t_sha1(void *buf, size_t size)
100 struct fio_sha1_ctx ctx = { .H = sha };
105 for (i = 0; i < NR_CHUNKS; i++)
106 fio_sha1_update(&ctx, buf, size);
109 static void t_sha256(void *buf, size_t size)
112 struct fio_sha256_ctx ctx = { .buf = sha };
115 fio_sha256_init(&ctx);
117 for (i = 0; i < NR_CHUNKS; i++)
118 fio_sha256_update(&ctx, buf, size);
121 static void t_sha512(void *buf, size_t size)
124 struct fio_sha512_ctx ctx = { .buf = sha };
127 fio_sha512_init(&ctx);
129 for (i = 0; i < NR_CHUNKS; i++)
130 fio_sha512_update(&ctx, buf, size);
133 static void t_xxhash(void *buf, size_t size)
138 state = XXH32_init(0x8989);
140 for (i = 0; i < NR_CHUNKS; i++)
141 XXH32_update(state, buf, size);
146 static struct test_type t[] = {
202 static unsigned int get_test_mask(const char *type)
204 char *ostr, *str = strdup(type);
211 while ((name = strsep(&str, ",")) != NULL) {
212 for (i = 0; t[i].name; i++) {
213 if (!strcmp(t[i].name, name)) {
224 static int list_types(void)
228 for (i = 0; t[i].name; i++)
229 printf("%s\n", t[i].name);
234 int fio_crctest(const char *type)
236 unsigned int test_mask = 0;
237 uint64_t mb = CHUNK * NR_CHUNKS;
238 struct frand_state state;
242 crc32c_intel_probe();
246 else if (!strcmp(type, "help") || !strcmp(type, "list"))
249 test_mask = get_test_mask(type);
252 fprintf(stderr, "fio: unknown hash `%s`. Available:\n", type);
257 init_rand_seed(&state, 0x8989);
258 fill_random_buf(&state, buf, CHUNK);
260 for (i = 0; t[i].name; i++) {
265 if (!(t[i].mask & test_mask))
269 * For first run, make sure CPUs are spun up and that
270 * we've touched the data.
277 fio_gettime(&tv, NULL);
279 usec = utime_since_now(&tv);
281 mb_sec = (double) mb / (double) usec;
282 mb_sec /= (1.024 * 1.024);
283 printf("%s:\t%8.2f MB/sec\n", t[i].name, mb_sec);