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);
59 static void t_crc64(void *buf, size_t size)
63 for (i = 0; i < NR_CHUNKS; i++)
67 static void t_crc32(void *buf, size_t size)
71 for (i = 0; i < NR_CHUNKS; i++)
75 static void t_crc32c(void *buf, size_t size)
79 for (i = 0; i < NR_CHUNKS; i++)
80 fio_crc32c(buf, size);
83 static void t_crc16(void *buf, size_t size)
87 for (i = 0; i < NR_CHUNKS; i++)
91 static void t_crc7(void *buf, size_t size)
95 for (i = 0; i < NR_CHUNKS; i++)
99 static void t_sha1(void *buf, size_t size)
102 struct fio_sha1_ctx ctx = { .H = sha };
107 for (i = 0; i < NR_CHUNKS; i++)
108 fio_sha1_update(&ctx, buf, size);
111 static void t_sha256(void *buf, size_t size)
114 struct fio_sha256_ctx ctx = { .buf = sha };
117 fio_sha256_init(&ctx);
119 for (i = 0; i < NR_CHUNKS; i++)
120 fio_sha256_update(&ctx, buf, size);
122 fio_sha256_final(&ctx);
125 static void t_sha512(void *buf, size_t size)
128 struct fio_sha512_ctx ctx = { .buf = sha };
131 fio_sha512_init(&ctx);
133 for (i = 0; i < NR_CHUNKS; i++)
134 fio_sha512_update(&ctx, buf, size);
137 static void t_xxhash(void *buf, size_t size)
142 state = XXH32_init(0x8989);
144 for (i = 0; i < NR_CHUNKS; i++)
145 XXH32_update(state, buf, size);
150 static struct test_type t[] = {
206 static unsigned int get_test_mask(const char *type)
208 char *ostr, *str = strdup(type);
215 while ((name = strsep(&str, ",")) != NULL) {
216 for (i = 0; t[i].name; i++) {
217 if (!strcmp(t[i].name, name)) {
228 static int list_types(void)
232 for (i = 0; t[i].name; i++)
233 printf("%s\n", t[i].name);
238 int fio_crctest(const char *type)
240 unsigned int test_mask = 0;
241 uint64_t mb = CHUNK * NR_CHUNKS;
242 struct frand_state state;
246 crc32c_intel_probe();
250 else if (!strcmp(type, "help") || !strcmp(type, "list"))
253 test_mask = get_test_mask(type);
256 fprintf(stderr, "fio: unknown hash `%s`. Available:\n", type);
261 init_rand_seed(&state, 0x8989);
262 fill_random_buf(&state, buf, CHUNK);
264 for (i = 0; t[i].name; i++) {
269 if (!(t[i].mask & test_mask))
273 * For first run, make sure CPUs are spun up and that
274 * we've touched the data.
281 fio_gettime(&tv, NULL);
283 usec = utime_since_now(&tv);
285 mb_sec = (double) mb / (double) usec;
286 mb_sec /= (1.024 * 1.024);
287 printf("%s:\t%8.2f MB/sec\n", t[i].name, mb_sec);