Commit eae1c4ae authored by Thomas Gleixner's avatar Thomas Gleixner

posix-timers: Make use of cancel/arm callbacks

Replace the hrtimer calls by calls to the new try_to_cancel()/arm() kclock
callbacks and move the hrtimer specific implementation into the
corresponding callback functions.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: John Stultz <john.stultz@linaro.org>
Link: http://lkml.kernel.org/r/20170530211657.355396667@linutronix.de
parent 525b8ed9
...@@ -744,25 +744,49 @@ SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id) ...@@ -744,25 +744,49 @@ SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id)
return overrun; return overrun;
} }
static void common_hrtimer_arm(struct k_itimer *timr, ktime_t expires,
bool absolute, bool sigev_none)
{
struct hrtimer *timer = &timr->it.real.timer;
enum hrtimer_mode mode;
mode = absolute ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL;
hrtimer_init(&timr->it.real.timer, timr->it_clock, mode);
timr->it.real.timer.function = posix_timer_fn;
if (!absolute)
expires = ktime_add_safe(expires, timer->base->get_time());
hrtimer_set_expires(timer, expires);
if (!sigev_none)
hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
}
static int common_hrtimer_try_to_cancel(struct k_itimer *timr)
{
return hrtimer_try_to_cancel(&timr->it.real.timer);
}
/* Set a POSIX.1b interval timer. */ /* Set a POSIX.1b interval timer. */
/* timr->it_lock is taken. */
static int static int
common_timer_set(struct k_itimer *timr, int flags, common_timer_set(struct k_itimer *timr, int flags,
struct itimerspec64 *new_setting, struct itimerspec64 *old_setting) struct itimerspec64 *new_setting,
struct itimerspec64 *old_setting)
{ {
struct hrtimer *timer = &timr->it.real.timer; const struct k_clock *kc = timr->kclock;
enum hrtimer_mode mode; bool sigev_none;
ktime_t expires;
if (old_setting) if (old_setting)
common_timer_get(timr, old_setting); common_timer_get(timr, old_setting);
/* disable the timer */ /* Prevent rearming by clearing the interval */
timr->it_interval = 0; timr->it_interval = 0;
/* /*
* careful here. If smp we could be in the "fire" routine which will * Careful here. On SMP systems the timer expiry function could be
* be spinning as we hold the lock. But this is ONLY an SMP issue. * active and spinning on timr->it_lock.
*/ */
if (hrtimer_try_to_cancel(timer) < 0) if (kc->timer_try_to_cancel(timr) < 0)
return TIMER_RETRY; return TIMER_RETRY;
timr->it_active = 0; timr->it_active = 0;
...@@ -770,30 +794,16 @@ common_timer_set(struct k_itimer *timr, int flags, ...@@ -770,30 +794,16 @@ common_timer_set(struct k_itimer *timr, int flags,
~REQUEUE_PENDING; ~REQUEUE_PENDING;
timr->it_overrun_last = 0; timr->it_overrun_last = 0;
/* switch off the timer when it_value is zero */ /* Switch off the timer when it_value is zero */
if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec) if (!new_setting->it_value.tv_sec && !new_setting->it_value.tv_nsec)
return 0; return 0;
mode = flags & TIMER_ABSTIME ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL;
hrtimer_init(&timr->it.real.timer, timr->it_clock, mode);
timr->it.real.timer.function = posix_timer_fn;
hrtimer_set_expires(timer, timespec64_to_ktime(new_setting->it_value));
/* Convert interval */
timr->it_interval = timespec64_to_ktime(new_setting->it_interval); timr->it_interval = timespec64_to_ktime(new_setting->it_interval);
expires = timespec64_to_ktime(new_setting->it_value);
sigev_none = (timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE;
/* SIGEV_NONE timers are not queued ! See common_timer_get */ kc->timer_arm(timr, expires, flags & TIMER_ABSTIME, sigev_none);
if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE)) { timr->it_active = !sigev_none;
/* Setup correct expiry time for relative timers */
if (mode == HRTIMER_MODE_REL) {
hrtimer_add_expires(timer, timer->base->get_time());
}
return 0;
}
timr->it_active = 1;
hrtimer_start_expires(timer, mode);
return 0; return 0;
} }
...@@ -847,9 +857,10 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags, ...@@ -847,9 +857,10 @@ SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
static int common_timer_del(struct k_itimer *timer) static int common_timer_del(struct k_itimer *timer)
{ {
timer->it_interval = 0; const struct k_clock *kc = timer->kclock;
if (hrtimer_try_to_cancel(&timer->it.real.timer) < 0) timer->it_interval = 0;
if (kc->timer_try_to_cancel(timer) < 0)
return TIMER_RETRY; return TIMER_RETRY;
timer->it_active = 0; timer->it_active = 0;
return 0; return 0;
...@@ -1075,7 +1086,9 @@ static const struct k_clock clock_realtime = { ...@@ -1075,7 +1086,9 @@ static const struct k_clock clock_realtime = {
.timer_del = common_timer_del, .timer_del = common_timer_del,
.timer_rearm = common_hrtimer_rearm, .timer_rearm = common_hrtimer_rearm,
.timer_forward = common_hrtimer_forward, .timer_forward = common_hrtimer_forward,
.timer_remaining= common_hrtimer_remaining, .timer_remaining = common_hrtimer_remaining,
.timer_try_to_cancel = common_hrtimer_try_to_cancel,
.timer_arm = common_hrtimer_arm,
}; };
static const struct k_clock clock_monotonic = { static const struct k_clock clock_monotonic = {
...@@ -1089,7 +1102,9 @@ static const struct k_clock clock_monotonic = { ...@@ -1089,7 +1102,9 @@ static const struct k_clock clock_monotonic = {
.timer_del = common_timer_del, .timer_del = common_timer_del,
.timer_rearm = common_hrtimer_rearm, .timer_rearm = common_hrtimer_rearm,
.timer_forward = common_hrtimer_forward, .timer_forward = common_hrtimer_forward,
.timer_remaining= common_hrtimer_remaining, .timer_remaining = common_hrtimer_remaining,
.timer_try_to_cancel = common_hrtimer_try_to_cancel,
.timer_arm = common_hrtimer_arm,
}; };
static const struct k_clock clock_monotonic_raw = { static const struct k_clock clock_monotonic_raw = {
...@@ -1118,7 +1133,9 @@ static const struct k_clock clock_tai = { ...@@ -1118,7 +1133,9 @@ static const struct k_clock clock_tai = {
.timer_del = common_timer_del, .timer_del = common_timer_del,
.timer_rearm = common_hrtimer_rearm, .timer_rearm = common_hrtimer_rearm,
.timer_forward = common_hrtimer_forward, .timer_forward = common_hrtimer_forward,
.timer_remaining= common_hrtimer_remaining, .timer_remaining = common_hrtimer_remaining,
.timer_try_to_cancel = common_hrtimer_try_to_cancel,
.timer_arm = common_hrtimer_arm,
}; };
static const struct k_clock clock_boottime = { static const struct k_clock clock_boottime = {
...@@ -1132,7 +1149,9 @@ static const struct k_clock clock_boottime = { ...@@ -1132,7 +1149,9 @@ static const struct k_clock clock_boottime = {
.timer_del = common_timer_del, .timer_del = common_timer_del,
.timer_rearm = common_hrtimer_rearm, .timer_rearm = common_hrtimer_rearm,
.timer_forward = common_hrtimer_forward, .timer_forward = common_hrtimer_forward,
.timer_remaining= common_hrtimer_remaining, .timer_remaining = common_hrtimer_remaining,
.timer_try_to_cancel = common_hrtimer_try_to_cancel,
.timer_arm = common_hrtimer_arm,
}; };
static const struct k_clock * const posix_clocks[] = { static const struct k_clock * const posix_clocks[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment