diff options
author | Oliver Upton <oliver.upton@linux.dev> | 2024-02-26 18:46:45 +0000 |
---|---|---|
committer | Oliver Upton <oliver.upton@linux.dev> | 2024-02-26 18:46:45 +0000 |
commit | da4e9379ebf9a095d599301262be41f23599a7d5 (patch) | |
tree | 32f953e9729d489c0b936cc17a9b12254f917d3f | |
parent | 660be94c5daadf529a303c520422093780759c70 (diff) | |
download | aarch64-memcpy-da4e9379ebf9a095d599301262be41f23599a7d5.tar.gz |
Throw some threads at the problem
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
-rw-r--r-- | main.c | 34 |
1 files changed, 31 insertions, 3 deletions
@@ -1,4 +1,5 @@ #include <assert.h> +#include <pthread.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -29,6 +30,7 @@ enum mode { static size_t test_size = 2UL * GB; static size_t chunk_size = 2UL * GB; static size_t test_iterations = 100; +static size_t dcache_worker_threads = 1; static enum mode test_mode; static bool use_hugetlb; @@ -53,6 +55,7 @@ static void pr_help(const char *progname) 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); + printf(" -t WORKER_THREADS (default: %lu)\n", dcache_worker_threads); pr_modes(); printf(" -H use hugetlb for test buffers\n"); printf(" -h prints this message\n"); @@ -89,6 +92,27 @@ static void dcache_clean_invalidate(const void *buf, size_t size) asm volatile("dsb ish"); } +static void *dcache_maintenance_thread(void *data) +{ + dcache_clean_invalidate(data, test_size / dcache_worker_threads); + return NULL; +} + +static void do_dcache_maintenance(const void *buf) +{ + pthread_t *threads = calloc(dcache_worker_threads, sizeof(pthread_t)); + size_t i; + + for (i = 0; i < dcache_worker_threads; i++) + pthread_create(&threads[i], NULL, dcache_maintenance_thread, + (void *)(buf + (i * (test_size / dcache_worker_threads)))); + + for (i = 0; i < dcache_worker_threads; i++) + pthread_join(threads[i], NULL); + + free(threads); +} + static void do_memcpy(void *dst, const void *src, size_t chunk_size) { switch (test_mode) { @@ -157,7 +181,7 @@ static void run_test(void) for (i = 0; i < test_iterations; i++) { if (test_mode == LDP_STP_DC_CIVAC) { assert(!clock_gettime(CLOCK_MONOTONIC, &dc_start)); - dcache_clean_invalidate(src, test_size); + do_dcache_maintenance(src); assert(!clock_gettime(CLOCK_MONOTONIC, &dc_end)); } @@ -182,7 +206,7 @@ int main(int argc, char **argv) { int c; - while ((c = getopt(argc, argv, "Hhc:s:i:m:")) != -1) { + while ((c = getopt(argc, argv, "Hhc:s:i:m:t:")) != -1) { switch (c) { case 'c': chunk_size = strtoul(optarg, NULL, 0); @@ -211,13 +235,17 @@ int main(int argc, char **argv) case 'H': use_hugetlb = true; break; + case 't': + dcache_worker_threads = strtoul(optarg, NULL, 0); + break; case 'h': pr_help(argv[0]); return 0; } } - if (chunk_size > test_size || test_size % chunk_size != 0) { + if (chunk_size > test_size || test_size % chunk_size != 0 || + test_size % dcache_worker_threads != 0) { pr_help(argv[0]); return 1; } |