From 4fc6cb13da6628fef1ce2e3a45a036cc3804b93e Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Wed, 15 Feb 2023 11:03:41 +0100 Subject: timer: Fix atomicity of timer reads Similarly to update_mapped_time/read_mapped_time, one need to synchronize the writes and read to make sure they are performed in the expected order. --- kern/timer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kern/timer.c b/kern/timer.c index af6d4b28..3b81ab79 100644 --- a/kern/timer.c +++ b/kern/timer.c @@ -334,7 +334,9 @@ void timer_normalize(timer_t timer) high_increment = timer->low_bits/TIMER_HIGH_UNIT; timer->high_bits_check += high_increment; + __sync_synchronize(); timer->low_bits %= TIMER_HIGH_UNIT; + __sync_synchronize(); timer->high_bits += high_increment; } @@ -356,7 +358,9 @@ static void timer_grab( #endif do { (save)->high = (timer)->high_bits; + __sync_synchronize (); (save)->low = (timer)->low_bits; + __sync_synchronize (); /* * If the timer was normalized while we were doing this, * the high_bits value read above and the high_bits check -- cgit v1.2.3