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 if (posix_memalign(&src, page_size, BUF_SIZE))
192 if (posix_memalign(&dst, page_size, BUF_SIZE))
195 init_rand_seed(&state, 0x8989, 0);
196 fill_random_buf(&state, src, BUF_SIZE);
198 for (i = 0; tests[i].name; i++) {
207 int fio_memcpy_test(const char *type)
209 unsigned int test_mask = 0;
214 else if (!strcmp(type, "help") || !strcmp(type, "list"))
217 test_mask = get_test_mask(type);
220 fprintf(stderr, "fio: unknown hash `%s`. Available:\n", type);
225 fprintf(stderr, "setting up mem regions failed\n");
229 for (i = 0; t[i].name; i++) {
234 if (!(t[i].mask & test_mask))
238 * For first run, make sure CPUs are spun up and that
239 * we've touched the data.
242 t[i].fn(&t[i], &tests[0]);
244 printf("%s\n", t[i].name);
246 for (j = 0; tests[j].name; j++) {
247 fio_gettime(&ts, NULL);
248 t[i].fn(&t[i], &tests[j]);
249 usec = utime_since_now(&ts);
252 unsigned long long mb = NR_ITERS * BUF_SIZE;
254 mb_sec = (double) mb / (double) usec;
255 mb_sec /= (1.024 * 1.024);
256 printf("\t%s:\t%8.2f MiB/sec\n", tests[j].name, mb_sec);
258 printf("\t%s:inf MiB/sec\n", tests[j].name);