From 5b0ced00b5000054494fe1dfedb495ec4ba76465 Mon Sep 17 00:00:00 2001 From: Stephane Gourichon Date: Mon, 5 Oct 2020 17:58:44 +0200 Subject: [PATCH 1/3] Confirm parameters in log. --- litex/soc/software/libbase/memtest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c index 982153969..70ae84e46 100644 --- a/litex/soc/software/libbase/memtest.c +++ b/litex/soc/software/libbase/memtest.c @@ -185,7 +185,7 @@ void memspeed(unsigned int *addr, unsigned long size, bool read_only) __attribute__((unused)) unsigned long data; const unsigned int sz = sizeof(unsigned long); - printf("Memspeed at 0x%p...\n", addr); + printf("Memspeed at 0x%p size 0x%x (%u read or write operations), read_only? %s...\n", addr, size, (size/sz), read_only?"true":"false"); /* init timer */ timer0_en_write(0); @@ -232,7 +232,7 @@ int memtest(unsigned int *addr, unsigned long maxsize) unsigned long addr_size = MEMTEST_ADDR_SIZE < maxsize ? MEMTEST_ADDR_SIZE : maxsize; unsigned long data_size = MEMTEST_DATA_SIZE < maxsize ? MEMTEST_DATA_SIZE : maxsize; - printf("Memtest at 0x%p...\n", addr); + printf("Memtest at 0x%p size 0x%x...\n", addr, maxsize); bus_errors = memtest_bus(addr, bus_size); addr_errors = memtest_addr(addr, addr_size, MEMTEST_ADDR_RANDOM); From cbbbb3f468da3d7fd89ed909b0bd58d5463ab8a0 Mon Sep 17 00:00:00 2001 From: Stephane Gourichon Date: Mon, 5 Oct 2020 18:40:24 +0200 Subject: [PATCH 2/3] Only display write speed if write test actually performed. --- litex/soc/software/libbase/memtest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litex/soc/software/libbase/memtest.c b/litex/soc/software/libbase/memtest.c index 70ae84e46..625b46429 100644 --- a/litex/soc/software/libbase/memtest.c +++ b/litex/soc/software/libbase/memtest.c @@ -203,8 +203,8 @@ 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); } - printf(" Write: %ldMiB/s\n", write_speed); /* flush CPU and L2 caches */ flush_cpu_dcache(); From f71275a3f18915c6c50b17b926be73bf0ea7dd3a Mon Sep 17 00:00:00 2001 From: Stephane Gourichon Date: Mon, 5 Oct 2020 18:04:40 +0200 Subject: [PATCH 3/3] 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)