File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -456,12 +456,18 @@ extern u64 hrtimer_next_event_without(const struct hrtimer *exclude);
456
456
457
457
extern bool hrtimer_active (const struct hrtimer * timer );
458
458
459
- /*
460
- * Helper function to check, whether the timer is on one of the queues
459
+ /**
460
+ * hrtimer_is_queued = check, whether the timer is on one of the queues
461
+ * @timer: Timer to check
462
+ *
463
+ * Returns: True if the timer is queued, false otherwise
464
+ *
465
+ * The function can be used lockless, but it gives only a current snapshot.
461
466
*/
462
- static inline int hrtimer_is_queued (struct hrtimer * timer )
467
+ static inline bool hrtimer_is_queued (struct hrtimer * timer )
463
468
{
464
- return timer -> state & HRTIMER_STATE_ENQUEUED ;
469
+ /* The READ_ONCE pairs with the update functions of timer->state */
470
+ return !!(READ_ONCE (timer -> state ) & HRTIMER_STATE_ENQUEUED );
465
471
}
466
472
467
473
/*
Original file line number Diff line number Diff line change @@ -966,7 +966,8 @@ static int enqueue_hrtimer(struct hrtimer *timer,
966
966
967
967
base -> cpu_base -> active_bases |= 1 << base -> index ;
968
968
969
- timer -> state = HRTIMER_STATE_ENQUEUED ;
969
+ /* Pairs with the lockless read in hrtimer_is_queued() */
970
+ WRITE_ONCE (timer -> state , HRTIMER_STATE_ENQUEUED );
970
971
971
972
return timerqueue_add (& base -> active , & timer -> node );
972
973
}
@@ -988,7 +989,8 @@ static void __remove_hrtimer(struct hrtimer *timer,
988
989
struct hrtimer_cpu_base * cpu_base = base -> cpu_base ;
989
990
u8 state = timer -> state ;
990
991
991
- timer -> state = newstate ;
992
+ /* Pairs with the lockless read in hrtimer_is_queued() */
993
+ WRITE_ONCE (timer -> state , newstate );
992
994
if (!(state & HRTIMER_STATE_ENQUEUED ))
993
995
return ;
994
996
@@ -1013,8 +1015,9 @@ static void __remove_hrtimer(struct hrtimer *timer,
1013
1015
static inline int
1014
1016
remove_hrtimer (struct hrtimer * timer , struct hrtimer_clock_base * base , bool restart )
1015
1017
{
1016
- if (hrtimer_is_queued (timer )) {
1017
- u8 state = timer -> state ;
1018
+ u8 state = timer -> state ;
1019
+
1020
+ if (state & HRTIMER_STATE_ENQUEUED ) {
1018
1021
int reprogram ;
1019
1022
1020
1023
/*
You can’t perform that action at this time.
0 commit comments