aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSandrine Bailleux <sandrine.bailleux@arm.com>2018-12-20 14:57:16 +0100
committerSandrine Bailleux <sandrine.bailleux@arm.com>2018-12-20 16:29:31 +0100
commitba7695b39bb82d5ceba093b0c18dd38cc9af61c3 (patch)
treebd7dd5eb9dc1a690a2c8fb8531197bc354e60d30 /lib
parentd01a4c64411249d6011f1690f1cea15f106198e4 (diff)
downloadtf-a-tests-ba7695b39bb82d5ceba093b0c18dd38cc9af61c3.tar.gz
Fix waitus()
waitus() was missing an instruction barrier before reading the system counter value. As a result, the CPU could speculatively read it and we would potentially base our delay loop on stale values. waitus() now uses the syscounter_read() helper function introduced in the previous patch, which has the required ISB. Change-Id: Ic37254485a9cdc4d4d2c86d245aa3273454e82ff Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/delay/delay.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/lib/delay/delay.c b/lib/delay/delay.c
index d88e500c..f6b29d1e 100644
--- a/lib/delay/delay.c
+++ b/lib/delay/delay.c
@@ -5,22 +5,14 @@
*/
#include <arch_helpers.h>
-#include <tftf.h>
void waitus(uint64_t us)
{
- uint64_t cntp_ct_val_base;
- uint32_t cnt_frq;
- uint64_t wait_cycles;
+ uint64_t start_count_val = syscounter_read();
+ uint64_t wait_cycles = (us * read_cntfrq_el0()) / 1000000;
- cnt_frq = read_cntfrq_el0();
- cntp_ct_val_base = read_cntpct_el0();
-
- /* Waitms in terms of counter freq */
- wait_cycles = (us * cnt_frq) / 1000000;
-
- while (read_cntpct_el0() - cntp_ct_val_base < wait_cycles)
- ;
+ while ((syscounter_read() - start_count_val) < wait_cycles)
+ /* Busy wait... */;
}
void waitms(uint64_t ms)