summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2023-02-15 11:03:41 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-02-15 11:03:41 +0100
commit4fc6cb13da6628fef1ce2e3a45a036cc3804b93e (patch)
tree23fee1b7c0dfa12832311a215f3035a23958cacb
parent7526fd0cf744be598be1cc6cd7c6e1b894735283 (diff)
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.
-rw-r--r--kern/timer.c4
1 files changed, 4 insertions, 0 deletions
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