From 86c5c25b6ca99025ac8ebcbe5c53ea0f398d1f44 Mon Sep 17 00:00:00 2001 From: Rasmus Villemoes Date: Fri, 22 Aug 2025 20:18:46 +0200 Subject: [PATCH] memtest: don't volatile-qualify local variables It is obviously important that the addr pointer used to access the memory region being tested is volatile-qualified, to prevent the compiler from optimizing out the "write this value, read it back, check that it is what we expect". However, none of these auxiliary variables have any such need for, effectively, being forced to live on the stack and cause each and every reference to them to do a memory access. This makes the memtest about 15% faster on a beagleboneblack. Before: => dcache off => time mtest 0x81000000 0x81100000 0 1 Testing 81000000 ... 81100000: Iteration: 1 Tested 1 iteration(s) with 0 errors. time: 10.868 seconds After: => dcache off => time mtest 0x81000000 0x81100000 0 1 Testing 81000000 ... 81100000: Iteration: 1 Tested 1 iteration(s) with 0 errors. time: 9.209 seconds [Without the 'dcache off', there's no difference in the time, about 0.6s, but the memtest cannot usefully be done with dcache enabled.] Signed-off-by: Rasmus Villemoes Tested-by: Anshul Dalal --- cmd/mem.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/mem.c b/cmd/mem.c index b8afe62e474..3bba46ad7da 100644 --- a/cmd/mem.c +++ b/cmd/mem.c @@ -719,12 +719,9 @@ static ulong mem_test_alt(vu_long *buf, ulong start_addr, ulong end_addr, ulong errs = 0; ulong val, readback; int j; - vu_long offset; - vu_long test_offset; - vu_long pattern; - vu_long temp; - vu_long anti_pattern; - vu_long num_words; + ulong offset, test_offset; + ulong pattern, anti_pattern; + ulong temp, num_words; static const ulong bitpattern[] = { 0x00000001, /* single bit */ 0x00000003, /* two adjacent bits */ -- 2.47.3