Skip to content

Commit 372d387

Browse files
lyakhlgirdwood
authored andcommitted
zephyr: make sure non-atomic 64-bit timer is consistent
The Zephyr timer implementation reads high and low 32 bits in a non-atomic way. Add a loop to make sure the read is consistent. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent 9ac38d8 commit 372d387

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

zephyr/wrapper.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,12 @@ uint64_t platform_timer_get(struct timer *timer)
277277
uint32_t high;
278278
uint64_t time;
279279

280-
/* read low 32 bits */
281-
low = shim_read(SHIM_EXT_TIMER_STAT);
282-
/* TODO: check and see whether 32bit IRQ is pending for timer */
283-
high = timer->hitime;
280+
do {
281+
/* TODO: check and see whether 32bit IRQ is pending for timer */
282+
high = timer->hitime;
283+
/* read low 32 bits */
284+
low = shim_read(SHIM_EXT_TIMER_STAT);
285+
} while (high != timer->hitime);
284286

285287
time = ((uint64_t)high << 32) | low;
286288

0 commit comments

Comments
 (0)