From 57bae864f810899ae052755155702232a03f3655 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 15 Sep 2021 21:53:08 +0200 Subject: [PATCH] Add memcpy perf test --- tests/test.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/test.c b/tests/test.c index 2b9ded3..2dac77d 100644 --- a/tests/test.c +++ b/tests/test.c @@ -11,6 +11,29 @@ #include "synchro.h" #include "time.h" +void testMemcpyPerf() +{ + struct test_struct { + char data[4096]; + }; + // instantiate 2 structs. for our purposes, we don't care what data is in + // there. set them to `volatile` so the compiler won't optimize away what we + // do with them + volatile struct test_struct dest, source; + + printf("Test Memcpy perf\n"); + // run through powers-of-two memcpy's, printing stats for each test + for (size_t len = 1; len <= sizeof(dest); len <<= 1) { + uint32_t start = read_cycle_counter(); // << Start count + memcpy((void *)&dest, (void *)&source, len); + uint32_t stop = read_cycle_counter(); // << Stop count + + // print out the cycles consumed + printf("len = %d, %d %d cyccnt = %d, cycles/byte = %d\n", (uint32_t)len, stop, start, + stop - start, (stop - start) / len); + } +} + void testPhymem(void) { printf("Testing memory PHY\n"); @@ -47,7 +70,8 @@ void testPhymem(void) assert(freePageStatFree == freePageStatBegin); assert(usedPageStatFree == usedPageStatBegin); - assertmsg((page = (struct phyMemDesc *)allocPhyPage(1)) != NULL, "Cannot allocate memory\n"); + assertmsg((page = (struct phyMemDesc *)allocPhyPage(1)) != NULL, + "Cannot allocate memory\n"); unrefPhyPage((ulong)page); } @@ -135,7 +159,8 @@ static void testPaging(void) } printf("%d pages freed\n", freeCount); - assertmsg((page = (struct phyMemDesc *)allocPhyPage(1)) != NULL, "Cannot allocate memory\n"); + assertmsg((page = (struct phyMemDesc *)allocPhyPage(1)) != NULL, + "Cannot allocate memory\n"); unrefPhyPage((ulong)page); } @@ -313,6 +338,7 @@ void testKthread() void run_test(void) { + testMemcpyPerf(); { int test = 1000; long long int test64 = 0x100000000;