diff options
author | Sandrine Bailleux <sandrine.bailleux@arm.com> | 2018-12-20 14:44:13 +0100 |
---|---|---|
committer | Sandrine Bailleux <sandrine.bailleux@arm.com> | 2018-12-20 16:29:19 +0100 |
commit | d01a4c64411249d6011f1690f1cea15f106198e4 (patch) | |
tree | a28e0cc86597fe7c0cf1f056c389f276fa68d957 | |
parent | 0d8a473144b608fc3812dae5602d73e5724da741 (diff) | |
download | tf-a-tests-d01a4c64411249d6011f1690f1cea15f106198e4.tar.gz |
Introduce syscounter_read() helper function
syscounter_read() reads the system counter value. It encapsulates the
instruction barrier required to get an accurate timestamp for any
time-sensitive related operation.
Change-Id: Ib2cfe7789ee1471e614140d425d29ab5c8d306ea
Signed-off-by: Sandrine Bailleux <sandrine.bailleux@arm.com>
-rw-r--r-- | include/lib/aarch32/arch_helpers.h | 12 | ||||
-rw-r--r-- | include/lib/aarch64/arch_helpers.h | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/include/lib/aarch32/arch_helpers.h b/include/lib/aarch32/arch_helpers.h index ee7ed3145..3e6e6f9cc 100644 --- a/include/lib/aarch32/arch_helpers.h +++ b/include/lib/aarch32/arch_helpers.h @@ -442,4 +442,16 @@ static inline void disable_fiq(void) void disable_mmu_icache(void); +/* Read the count value of the system counter. */ +static inline uint64_t syscounter_read(void) +{ + /* + * The instruction barrier is needed to guarantee that we read an + * accurate value. Otherwise, the CPU might speculatively read it and + * return a stale value. + */ + isb(); + return read64_cntpct(); +} + #endif /* ARCH_HELPERS_H */ diff --git a/include/lib/aarch64/arch_helpers.h b/include/lib/aarch64/arch_helpers.h index 1d9202d04..053f8ba67 100644 --- a/include/lib/aarch64/arch_helpers.h +++ b/include/lib/aarch64/arch_helpers.h @@ -468,4 +468,16 @@ static inline uint64_t el_implemented(unsigned int el) } } +/* Read the count value of the system counter. */ +static inline uint64_t syscounter_read(void) +{ + /* + * The instruction barrier is needed to guarantee that we read an + * accurate value. Otherwise, the CPU might speculatively read it and + * return a stale value. + */ + isb(); + return read_cntpct_el0(); +} + #endif /* ARCH_HELPERS_H */ |