6 #include "../gettime.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"
21 #define NR_CHUNKS 2048
41 static void randomize_buf(void *buf, unsigned int size, int seed)
43 struct frand_state state;
45 init_rand_seed(&state, seed);
46 fill_random_buf(&state, buf, size);
49 static uint64_t t_md5(void)
52 struct fio_md5_ctx ctx = { .hash = digest };
61 randomize_buf(buf, CHUNK, 0x8989);
63 fio_gettime(&s, NULL);
64 for (i = 0; i < NR_CHUNKS; i++)
65 fio_md5_update(&ctx, buf, CHUNK);
67 ret = utime_since_now(&s);
72 static uint64_t t_crc64(void)
80 randomize_buf(buf, CHUNK, 0x8989);
82 fio_gettime(&s, NULL);
83 for (i = 0; i < NR_CHUNKS; i++)
84 fio_crc64(buf, CHUNK);
86 ret = utime_since_now(&s);
91 static uint64_t t_crc32(void)
99 randomize_buf(buf, CHUNK, 0x8989);
101 fio_gettime(&s, NULL);
102 for (i = 0; i < NR_CHUNKS; i++)
103 fio_crc32(buf, CHUNK);
105 ret = utime_since_now(&s);
110 static uint64_t t_crc32c(void)
118 randomize_buf(buf, CHUNK, 0x8989);
120 fio_gettime(&s, NULL);
121 for (i = 0; i < NR_CHUNKS; i++)
122 fio_crc32c(buf, CHUNK);
124 ret = utime_since_now(&s);
129 static uint64_t t_crc16(void)
137 randomize_buf(buf, CHUNK, 0x8989);
139 fio_gettime(&s, NULL);
140 for (i = 0; i < NR_CHUNKS; i++)
141 fio_crc16(buf, CHUNK);
143 ret = utime_since_now(&s);
148 static uint64_t t_crc7(void)
156 randomize_buf(buf, CHUNK, 0x8989);
158 fio_gettime(&s, NULL);
159 for (i = 0; i < NR_CHUNKS; i++)
160 fio_crc7(buf, CHUNK);
162 ret = utime_since_now(&s);
167 static uint64_t t_sha1(void)
170 struct fio_sha1_ctx ctx = { .H = sha };
179 randomize_buf(buf, CHUNK, 0x8989);
181 fio_gettime(&s, NULL);
182 for (i = 0; i < NR_CHUNKS; i++)
183 fio_sha1_update(&ctx, buf, CHUNK);
185 ret = utime_since_now(&s);
190 static uint64_t t_sha256(void)
193 struct fio_sha256_ctx ctx = { .buf = sha };
199 fio_sha256_init(&ctx);
202 randomize_buf(buf, CHUNK, 0x8989);
204 fio_gettime(&s, NULL);
205 for (i = 0; i < NR_CHUNKS; i++)
206 fio_sha256_update(&ctx, buf, CHUNK);
208 ret = utime_since_now(&s);
213 static uint64_t t_sha512(void)
216 struct fio_sha512_ctx ctx = { .buf = sha };
222 fio_sha512_init(&ctx);
225 randomize_buf(buf, CHUNK, 0x8989);
227 fio_gettime(&s, NULL);
228 for (i = 0; i < NR_CHUNKS; i++)
229 fio_sha512_update(&ctx, buf, CHUNK);
231 ret = utime_since_now(&s);
236 static struct test_type t[] = {
287 static unsigned int get_test_mask(const char *type)
289 char *ostr, *str = strdup(type);
296 while ((name = strsep(&str, ",")) != NULL) {
297 for (i = 0; t[i].name; i++) {
298 if (!strncmp(t[i].name, name, strlen(t[i].name))) {
309 int fio_crctest(const char *type)
311 unsigned int test_mask = 0;
312 uint64_t mb = CHUNK * NR_CHUNKS;
315 crc32c_intel_probe();
320 test_mask = get_test_mask(type);
322 for (i = 0; t[i].name; i++) {
326 if (!(t[i].mask & test_mask))
330 mb_sec = (double) mb / (double) usec;
331 mb_sec /= (1.024 * 1.024);
332 printf("%s:\t%.2f MB/sec\n", t[i].name, mb_sec);