lkml.org 
[lkml]   [2019]   [Aug]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[tip:timers/core] posix-timers: Prepare for PREEMPT_RT
Commit-ID:  3a839db3eaeeef31520de45f3b078204d068e3d0
Gitweb: https://git.kernel.org/tip/3a839db3eaeeef31520de45f3b078204d068e3d0
Author: Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Wed, 31 Jul 2019 00:33:55 +0200
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Thu, 1 Aug 2019 17:46:43 +0200

posix-timers: Prepare for PREEMPT_RT

Posix timer delete retry loops are affected by the same priority inversion
and live lock issues as the other timers.

Provide a RT specific synchronization function which keeps a reference to
the timer by holding rcu read lock to prevent the timer from being freed,
dropping the timer lock and invoking the timer specific wait function.

This does not yet cover posix CPU timers because they need more special
treatment on PREEMPT_RT.

Originally-by: Anna-Maria Gleixenr <anna-maria@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20190730223829.058247862@linutronix.de

---
kernel/time/posix-timers.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 3e663f982c82..a71c1aab071c 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -805,6 +805,29 @@ static int common_hrtimer_try_to_cancel(struct k_itimer *timr)
return hrtimer_try_to_cancel(&timr->it.real.timer);
}

+#ifdef CONFIG_PREEMPT_RT
+static struct k_itimer *timer_wait_running(struct k_itimer *timer,
+ unsigned long *flags)
+{
+ const struct k_clock *kc = READ_ONCE(timer->kclock);
+ timer_t timer_id = READ_ONCE(timer->it_id);
+
+ /* Prevent kfree(timer) after dropping the lock */
+ rcu_read_lock();
+ unlock_timer(timer, *flags);
+
+ if (kc->timer_arm == common_hrtimer_arm)
+ hrtimer_cancel_wait_running(&timer->it.real.timer);
+ else if (kc == &alarm_clock)
+ hrtimer_cancel_wait_running(&timer->it.alarm.alarmtimer.timer);
+ else
+ WARN_ON_ONCE(1);
+ rcu_read_unlock();
+
+ /* Relock the timer. It might be not longer hashed. */
+ return lock_timer(timer_id, flags);
+}
+#else
static struct k_itimer *timer_wait_running(struct k_itimer *timer,
unsigned long *flags)
{
@@ -815,6 +838,7 @@ static struct k_itimer *timer_wait_running(struct k_itimer *timer,
/* Relock the timer. It might be not longer hashed. */
return lock_timer(timer_id, flags);
}
+#endif

/* Set a POSIX.1b interval timer. */
int common_timer_set(struct k_itimer *timr, int flags,
\
 
 \ /
  Last update: 2019-08-01 18:09    [W:0.112 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site