From 647631af09ddac1b85bd799de9f42686564186bc Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 7 Jul 2023 11:31:44 +0200 Subject: [PATCH] test/timeout: revert use of memory barriers The memory barriers where introduced with commit "test-timeout: fix build errors with -std=gnu++20" presumably in order to prevent GCC optimization from removing the empty for loops the test is using because using a volatile index variable was no longer an option. However, the memory barriers seem to have a negative effect on the measurements performed with the affected loops. The commit caused the timeout test to fail at least on imx53_qsb. This commit fixes the issue by using a simple empty for loop without volatiles or memory barriers but protected inside a function that is compiled with optimization disabled. Ref #4959 --- repos/os/src/test/timeout/main.cc | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/repos/os/src/test/timeout/main.cc b/repos/os/src/test/timeout/main.cc index 4bedbab118..248481ba48 100644 --- a/repos/os/src/test/timeout/main.cc +++ b/repos/os/src/test/timeout/main.cc @@ -18,7 +18,6 @@ #include #include #include -#include using namespace Genode; @@ -51,17 +50,15 @@ static bool precise_time(Xml_node config) return false; } -struct A1 { -A1() { -log(__func__,__LINE__); -} -}; -struct A2 { -A2() { -log(__func__,__LINE__); +#pragma GCC push_options +#pragma GCC optimize("O0") +void delay_loop(unsigned long num_iterations) +{ + for (unsigned long idx = 0; idx < num_iterations; idx++) { } } -}; +#pragma GCC pop_options + struct Test { @@ -522,7 +519,7 @@ struct Fast_polling : Test /* measure consumed time of a limited busy loop */ uint64_t volatile start_ms = timer_2.elapsed_ms(); - for (unsigned long cnt = 0; cnt < max_cnt; cnt++) memory_barrier(); + delay_loop(max_cnt); uint64_t volatile end_ms = timer_2.elapsed_ms(); /* @@ -569,8 +566,7 @@ struct Fast_polling : Test for (unsigned poll = 0; poll < nr_of_polls; poll++) { /* create delay between two polls */ - for (unsigned long i = 0; i < delay_loops_per_poll_; i++) - memory_barrier(); + delay_loop(delay_loops_per_poll_); /* count delay loops to limit frequency of remote time reading */ delay_loops = delay_loops + delay_loops_per_poll_;