From f71275a3f18915c6c50b17b926be73bf0ea7dd3a Mon Sep 17 00:00:00 2001 From: Stephane Gourichon Date: Mon, 5 Oct 2020 18:04:40 +0200 Subject: [PATCH] Show speeds in bytes per second. Forcing megabytes per second for everyone does not make sense. Showing bytes per second allows to distinguish between low performance and a performance measurement bug. Anyway previous code claims speeds were in MiB/s, they were not, actually MB/s. --- litex/soc/software/libbase/memtest.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c index 625b46429..2c51580b2 100644 --- a/litex/soc/software/libbase/memtest.c +++ b/litex/soc/software/libbase/memtest.c @@ -179,7 +179,7 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only) { volatile unsigned long *array = (unsigned long *)addr; int i; - unsigned int start, end; + uint32_t start, end; unsigned long write_speed = 0; unsigned long read_speed; __attribute__((unused)) unsigned long data; @@ -202,8 +202,10 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only) } timer0_update_value_write(1); end = timer0_value_read(); - write_speed = (size*(CONFIG_CLOCK_FREQUENCY/1000000))/(start - end); - printf(" Write: %ldMiB/s\n", write_speed); + uint64_t numerator = ((uint64_t)size)*((uint64_t)CONFIG_CLOCK_FREQUENCY); + uint64_t denominator = ((uint64_t)start - (uint64_t)end); + write_speed = numerator/denominator; + printf(" Write speed: %lub/s\n", write_speed); } /* flush CPU and L2 caches */ @@ -221,8 +223,10 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only) } timer0_update_value_write(1); end = timer0_value_read(); - read_speed = (size*(CONFIG_CLOCK_FREQUENCY/1000000))/(start - end); - printf(" Read: %ldMiB/s\n", read_speed); + uint64_t numerator = ((uint64_t)size)*((uint64_t)CONFIG_CLOCK_FREQUENCY); + uint64_t denominator = ((uint64_t)start - (uint64_t)end); + read_speed = numerator/denominator; + printf(" Read speed: %lub/s\n", read_speed); } int memtest(unsigned int *addr, unsigned long maxsize)