From 07736d168986132b0c87fdfef6b4e73aa79ac087 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Thu, 24 Mar 2022 11:34:52 +0100 Subject: [PATCH] test/memcpy: fix optimistic results on Linux When executed on Linux, the test was impaired by the copy-on-write optimisation since the source buffer was never initialised. By default, Linux only maps a zeroed page until the first write access to the page occurs. Since the source buffer was never written, the corresponding page was always present in the physically-indexed data cache. In consequence, the test merely measured write performance (similar to memset). genodelabs/genode#4454 --- repos/libports/run/memcpy.run | 15 +++++++++++---- repos/libports/src/test/memcpy/memcpy.h | 10 +++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/repos/libports/run/memcpy.run b/repos/libports/run/memcpy.run index dd65d2380c..cd183f4f00 100644 --- a/repos/libports/run/memcpy.run +++ b/repos/libports/run/memcpy.run @@ -72,7 +72,14 @@ exit 0 # Linux baseline measurements # -# Raspberry Pi 1 -# bytewise memcpy: copied 8388608 KiB in 93390210 usecs (87 MiB/sec) -# libc memcpy: copied 8388608 KiB in 6238602 usecs (1313 MiB/sec) -# libc memset: copied 8388608 KiB in 6023324 usecs (1360 MiB/sec) +# Zynq-7000 @ 666MHz (L2 prefetching enabled, offset=0) +# Genode memcpy: copied 8388608 KiB in 27362177 usecs (299 MiB/sec) +# bytewise memcpy: copied 8388608 KiB in 43882888 usecs (186 MiB/sec) +# libc memcpy: copied 8388608 KiB in 28702066 usecs (285 MiB/sec) +# libc memset: copied 8388608 KiB in 4033019 usecs (2031 MiB/sec) + +# Zynq-7000 @ 666MHz (L2 prefetching enabled, offset=4) +# Genode memcpy: copied 8388608 KiB in 14985454 usecs (546 MiB/sec) +# bytewise memcpy: copied 8388608 KiB in 39478781 usecs (207 MiB/sec) +# libc memcpy: copied 8388608 KiB in 28792091 usecs (284 MiB/sec) +# libc memset: copied 8388608 KiB in 4041102 usecs (2027 MiB/sec) diff --git a/repos/libports/src/test/memcpy/memcpy.h b/repos/libports/src/test/memcpy/memcpy.h index 5d453a47dd..fae7140ebd 100644 --- a/repos/libports/src/test/memcpy/memcpy.h +++ b/repos/libports/src/test/memcpy/memcpy.h @@ -16,11 +16,19 @@ void memcpy_test(void * dst = nullptr, void * src = nullptr, void * const from_buf = src ? src : malloc(size); void * const to_buf = dst ? dst : malloc(size); + /** + * initialising the buffer (with any value) is necessary to + * a) circumvent copy-on-write optimisation on linux and + * b) all pages are already allocated and mapped + */ + memset(from_buf, 0, size); + memset(to_buf, 0, size); + Test test; test.start(); for (unsigned i = 0; i < ITERATION; i++) - test.copy(to_buf, from_buf, BUF_SIZE); + test.copy(to_buf, from_buf, size); test.finished();