7 #include "../fio_time.h"
8 #include "../gettime.h"
11 #define BUF_SIZE 32 * 1024 * 1024ULL
22 static struct memcpy_test tests[] = {
56 .name = "131072 bytes",
60 .name = "262144 bytes",
64 .name = "524288 bytes",
75 void (*fn)(struct memcpy_type *, struct memcpy_test *);
84 #define do_test(t, test, fn) do { \
89 for (i = 0; i < NR_ITERS; i++) { \
97 (fn)(dst, src, this); \
105 static void t_memcpy(struct memcpy_type *t, struct memcpy_test *test)
107 do_test(t, test, memcpy);
110 static void t_memmove(struct memcpy_type *t, struct memcpy_test *test)
112 do_test(t, test, memmove);
115 static void simple_memcpy(void *dst, void const *src, size_t len)
124 static void t_simple(struct memcpy_type *t, struct memcpy_test *test)
126 do_test(t, test, simple_memcpy);
129 static struct memcpy_type t[] = {
151 static unsigned int get_test_mask(const char *type)
153 char *ostr, *str = strdup(type);
160 while ((name = strsep(&str, ",")) != NULL) {
161 for (i = 0; t[i].name; i++) {
162 if (!strcmp(t[i].name, name)) {
173 static int list_types(void)
177 for (i = 0; t[i].name; i++)
178 printf("%s\n", t[i].name);
183 static int setup_tests(void)
185 struct memcpy_test *test;
186 struct frand_state state;
190 src = malloc(BUF_SIZE);
191 dst = malloc(BUF_SIZE);
198 init_rand_seed(&state, 0x8989, 0);
199 fill_random_buf(&state, src, BUF_SIZE);
201 for (i = 0; tests[i].name; i++) {
210 static void free_tests(void)
216 int fio_memcpy_test(const char *type)
218 unsigned int test_mask = 0;
223 else if (!strcmp(type, "help") || !strcmp(type, "list"))
226 test_mask = get_test_mask(type);
229 fprintf(stderr, "fio: unknown hash `%s`. Available:\n", type);
234 fprintf(stderr, "setting up mem regions failed\n");
238 for (i = 0; t[i].name; i++) {
243 if (!(t[i].mask & test_mask))
247 * For first run, make sure CPUs are spun up and that
248 * we've touched the data.
251 t[i].fn(&t[i], &tests[0]);
253 printf("%s\n", t[i].name);
255 for (j = 0; tests[j].name; j++) {
256 fio_gettime(&ts, NULL);
257 t[i].fn(&t[i], &tests[j]);
258 usec = utime_since_now(&ts);
261 unsigned long long mb = NR_ITERS * BUF_SIZE;
263 mb_sec = (double) mb / (double) usec;
264 mb_sec /= (1.024 * 1.024);
265 printf("\t%s:\t%8.2f MiB/sec\n", tests[j].name, mb_sec);
267 printf("\t%s:inf MiB/sec\n", tests[j].name);