diff options
author | Oliver Upton <oliver.upton@linux.dev> | 2023-11-29 08:54:38 +0000 |
---|---|---|
committer | Oliver Upton <oliver.upton@linux.dev> | 2023-11-29 08:54:38 +0000 |
commit | e1b00f7a4adca5928ab3032e17743180a83bb4d0 (patch) | |
tree | 55be912cbae148f0957239cd9bb758b69ec7a571 | |
parent | 1b8e795f85aaf9fc7c92000195f54b0990e38f10 (diff) | |
download | aarch64-memcpy-e1b00f7a4adca5928ab3032e17743180a83bb4d0.tar.gz |
make this look a bit more like read() && use data
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
-rw-r--r-- | main.c | 38 |
1 files changed, 28 insertions, 10 deletions
@@ -25,6 +25,7 @@ enum mode { }; static size_t test_size = 2UL * GB; +static size_t chunk_size = 2UL * GB; static size_t test_iterations = 100; static enum mode test_mode; static bool use_hugetlb; @@ -45,6 +46,7 @@ static void pr_help(const char *progname) { printf("%s [OPTIONS]\n", progname); printf(" -s SIZE (default: %lu)\n", test_size); + printf(" -c CHUNK_SIZE (default: %lu)\n", chunk_size); printf(" -i ITERATIONS (default: %lu)\n", test_iterations); printf(" -m MODE (default: %d)\n", test_mode); pr_modes(); @@ -72,23 +74,23 @@ static void destroy_test_buffer(void *buf) munmap(buf, test_size); } -static void do_memcpy(void *dst, const void *src) +static void do_memcpy(void *dst, const void *src, size_t chunk_size) { switch (test_mode) { case LDP_STR: - memcpy_ldp_str(dst, src, test_size); + memcpy_ldp_str(dst, src, chunk_size); break; case LDP_STTR: - memcpy_ldp_sttr(dst, src, test_size); + memcpy_ldp_sttr(dst, src, chunk_size); break; case LDR_STP: - memcpy_ldr_stp(dst, src, test_size); + memcpy_ldr_stp(dst, src, chunk_size); break; case LDTR_STP: - memcpy_ldtr_stp(dst, src, test_size); + memcpy_ldtr_stp(dst, src, chunk_size); break; case LDP_STP: - memcpy_ldp_stp(dst, src, test_size); + memcpy_ldp_stp(dst, src, chunk_size); break; default: assert(0); @@ -112,7 +114,7 @@ static void run_test(void) void *dst = setup_test_buffer(); void *src = setup_test_buffer(); struct timespec start, end; - size_t i; + size_t offset, i; printf("Iters: %lu\n", test_iterations); printf("Mode: %d\n", test_mode); @@ -121,8 +123,12 @@ static void run_test(void) assert(!clock_gettime(CLOCK_MONOTONIC, &start)); - for (i = 0; i < test_iterations; i++) - do_memcpy(dst, src); + for (i = 0; i < test_iterations; i++) { + for (offset = 0; offset < test_size; offset += chunk_size) { + do_memcpy(dst + offset, src + offset, chunk_size); + assert(!memchr(dst + offset, 0, chunk_size)); + } + } assert(!clock_gettime(CLOCK_MONOTONIC, &end)); @@ -136,8 +142,15 @@ int main(int argc, char **argv) { int c; - while ((c = getopt(argc, argv, "Hhs:i:m:")) != -1) { + while ((c = getopt(argc, argv, "Hhc:s:i:m:")) != -1) { switch (c) { + case 'c': + chunk_size = strtoul(optarg, NULL, 0); + if ((chunk_size % 64 != 0) || (chunk_size < 128)) { + pr_help(argv[0]); + return 1; + } + break; case 's': test_size = strtoul(optarg, NULL, 0); if ((test_size % 64 != 0) || (test_size < 128)) { @@ -164,6 +177,11 @@ int main(int argc, char **argv) } } + if (chunk_size > test_size || test_size % chunk_size != 0) { + pr_help(argv[0]); + return 1; + } + run_test(); return 0; } |