All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Thomas Gleixner <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: john.stultz@linaro.org, hpa@zytor.com, tglx@linutronix.de,
	linux-kernel@vger.kernel.org, mingo@kernel.org,
	peterz@infradead.org
Subject: [tip:timers/core] posix-timers: Make use of cancel/arm callbacks
Date: Mon, 5 Jun 2017 01:22:54 -0700	[thread overview]
Message-ID: <tip-eae1c4ae275fe3e024454c012a548ee0d700f54c@git.kernel.org> (raw)
In-Reply-To: <20170530211657.355396667@linutronix.de>

Commit-ID:  eae1c4ae275fe3e024454c012a548ee0d700f54c
Gitweb:     http://git.kernel.org/tip/eae1c4ae275fe3e024454c012a548ee0d700f54c
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Tue, 30 May 2017 23:15:53 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sun, 4 Jun 2017 15:40:29 +0200

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: Thomas 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

---
 kernel/time/posix-timers.c | 181 +++++++++++++++++++++++++--------------------
 1 file changed, 100 insertions(+), 81 deletions(-)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 0332f7a..8acc9ee 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -744,25 +744,49 @@ SYSCALL_DEFINE1(timer_getoverrun, timer_t, timer_id)
 	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. */
-/* timr->it_lock is taken. */
 static int
 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;
-	enum hrtimer_mode mode;
+	const struct k_clock *kc = timr->kclock;
+	bool sigev_none;
+	ktime_t expires;
 
 	if (old_setting)
 		common_timer_get(timr, old_setting);
 
-	/* disable the timer */
+	/* Prevent rearming by clearing the interval */
 	timr->it_interval = 0;
 	/*
-	 * careful here.  If smp we could be in the "fire" routine which will
-	 * be spinning as we hold the lock.  But this is ONLY an SMP issue.
+	 * Careful here. On SMP systems the timer expiry function could be
+	 * 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;
 
 	timr->it_active = 0;
@@ -770,30 +794,16 @@ common_timer_set(struct k_itimer *timr, int flags,
 		~REQUEUE_PENDING;
 	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)
 		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);
+	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 */
-	if (((timr->it_sigev_notify & ~SIGEV_THREAD_ID) == 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);
+	kc->timer_arm(timr, expires, flags & TIMER_ABSTIME, sigev_none);
+	timr->it_active = !sigev_none;
 	return 0;
 }
 
@@ -847,9 +857,10 @@ retry:
 
 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;
 	timer->it_active = 0;
 	return 0;
@@ -1063,76 +1074,84 @@ long clock_nanosleep_restart(struct restart_block *restart_block)
 }
 
 static const struct k_clock clock_realtime = {
-	.clock_getres	= posix_get_hrtimer_res,
-	.clock_get	= posix_clock_realtime_get,
-	.clock_set	= posix_clock_realtime_set,
-	.clock_adj	= posix_clock_realtime_adj,
-	.nsleep		= common_nsleep,
-	.nsleep_restart	= hrtimer_nanosleep_restart,
-	.timer_create	= common_timer_create,
-	.timer_set	= common_timer_set,
-	.timer_get	= common_timer_get,
-	.timer_del	= common_timer_del,
-	.timer_rearm	= common_hrtimer_rearm,
-	.timer_forward	= common_hrtimer_forward,
-	.timer_remaining= common_hrtimer_remaining,
+	.clock_getres		= posix_get_hrtimer_res,
+	.clock_get		= posix_clock_realtime_get,
+	.clock_set		= posix_clock_realtime_set,
+	.clock_adj		= posix_clock_realtime_adj,
+	.nsleep			= common_nsleep,
+	.nsleep_restart		= hrtimer_nanosleep_restart,
+	.timer_create		= common_timer_create,
+	.timer_set		= common_timer_set,
+	.timer_get		= common_timer_get,
+	.timer_del		= common_timer_del,
+	.timer_rearm		= common_hrtimer_rearm,
+	.timer_forward		= common_hrtimer_forward,
+	.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 = {
-	.clock_getres	= posix_get_hrtimer_res,
-	.clock_get	= posix_ktime_get_ts,
-	.nsleep		= common_nsleep,
-	.nsleep_restart	= hrtimer_nanosleep_restart,
-	.timer_create	= common_timer_create,
-	.timer_set	= common_timer_set,
-	.timer_get	= common_timer_get,
-	.timer_del	= common_timer_del,
-	.timer_rearm	= common_hrtimer_rearm,
-	.timer_forward	= common_hrtimer_forward,
-	.timer_remaining= common_hrtimer_remaining,
+	.clock_getres		= posix_get_hrtimer_res,
+	.clock_get		= posix_ktime_get_ts,
+	.nsleep			= common_nsleep,
+	.nsleep_restart		= hrtimer_nanosleep_restart,
+	.timer_create		= common_timer_create,
+	.timer_set		= common_timer_set,
+	.timer_get		= common_timer_get,
+	.timer_del		= common_timer_del,
+	.timer_rearm		= common_hrtimer_rearm,
+	.timer_forward		= common_hrtimer_forward,
+	.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 = {
-	.clock_getres	= posix_get_hrtimer_res,
-	.clock_get	= posix_get_monotonic_raw,
+	.clock_getres		= posix_get_hrtimer_res,
+	.clock_get		= posix_get_monotonic_raw,
 };
 
 static const struct k_clock clock_realtime_coarse = {
-	.clock_getres	= posix_get_coarse_res,
-	.clock_get	= posix_get_realtime_coarse,
+	.clock_getres		= posix_get_coarse_res,
+	.clock_get		= posix_get_realtime_coarse,
 };
 
 static const struct k_clock clock_monotonic_coarse = {
-	.clock_getres	= posix_get_coarse_res,
-	.clock_get	= posix_get_monotonic_coarse,
+	.clock_getres		= posix_get_coarse_res,
+	.clock_get		= posix_get_monotonic_coarse,
 };
 
 static const struct k_clock clock_tai = {
-	.clock_getres	= posix_get_hrtimer_res,
-	.clock_get	= posix_get_tai,
-	.nsleep		= common_nsleep,
-	.nsleep_restart	= hrtimer_nanosleep_restart,
-	.timer_create	= common_timer_create,
-	.timer_set	= common_timer_set,
-	.timer_get	= common_timer_get,
-	.timer_del	= common_timer_del,
-	.timer_rearm	= common_hrtimer_rearm,
-	.timer_forward	= common_hrtimer_forward,
-	.timer_remaining= common_hrtimer_remaining,
+	.clock_getres		= posix_get_hrtimer_res,
+	.clock_get		= posix_get_tai,
+	.nsleep			= common_nsleep,
+	.nsleep_restart		= hrtimer_nanosleep_restart,
+	.timer_create		= common_timer_create,
+	.timer_set		= common_timer_set,
+	.timer_get		= common_timer_get,
+	.timer_del		= common_timer_del,
+	.timer_rearm		= common_hrtimer_rearm,
+	.timer_forward		= common_hrtimer_forward,
+	.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 = {
-	.clock_getres	= posix_get_hrtimer_res,
-	.clock_get	= posix_get_boottime,
-	.nsleep		= common_nsleep,
-	.nsleep_restart	= hrtimer_nanosleep_restart,
-	.timer_create	= common_timer_create,
-	.timer_set	= common_timer_set,
-	.timer_get	= common_timer_get,
-	.timer_del	= common_timer_del,
-	.timer_rearm	= common_hrtimer_rearm,
-	.timer_forward	= common_hrtimer_forward,
-	.timer_remaining= common_hrtimer_remaining,
+	.clock_getres		= posix_get_hrtimer_res,
+	.clock_get		= posix_get_boottime,
+	.nsleep			= common_nsleep,
+	.nsleep_restart		= hrtimer_nanosleep_restart,
+	.timer_create		= common_timer_create,
+	.timer_set		= common_timer_set,
+	.timer_get		= common_timer_get,
+	.timer_del		= common_timer_del,
+	.timer_rearm		= common_hrtimer_rearm,
+	.timer_forward		= common_hrtimer_forward,
+	.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[] = {

  reply	other threads:[~2017-06-05  8:26 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-30 21:15 [patch 00/26] alarmtimers/posixtimers: Bug fixes and spec conformity changes Thomas Gleixner
2017-05-30 21:15 ` [patch 01/26] alarmtimer: Prevent overflow of relative timers Thomas Gleixner
2017-06-04 13:21   ` [tip:timers/urgent] " tip-bot for Thomas Gleixner
2017-06-04 13:24   ` tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 02/26] alarmtimer: Rate limit periodic intervals Thomas Gleixner
2017-06-04 13:22   ` [tip:timers/urgent] " tip-bot for Thomas Gleixner
2017-06-04 13:25   ` tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 03/26] alarmtimer: Remove pointless config conditional Thomas Gleixner
2017-06-05  8:13   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 04/26] posix-timers: Remove unused export of posix_timer_event() Thomas Gleixner
2017-06-05  8:13   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 05/26] posix-clocks: Remove interval timer facility and mmap/fasync callbacks Thomas Gleixner
2017-05-31  9:00   ` Richard Cochran
2017-06-05  8:14   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 06/26] posix-timers: Avoid gazillions of forward declarations Thomas Gleixner
2017-06-05  8:14   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 07/26] posix-timers: Cleanup struct k_itimer Thomas Gleixner
2017-06-05  8:15   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 08/26] posix-timers: Move posix-timer internals to core Thomas Gleixner
2017-05-31 15:37   ` Christoph Hellwig
2017-06-05  8:15   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 09/26] posix-timers: Unify overrun/requeue_pending handling Thomas Gleixner
2017-06-05  8:16   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 10/26] posix-timers: Move interval out of the union Thomas Gleixner
2017-06-05  8:17   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 11/26] posix-timers: Store k_clock pointer in k_itimer Thomas Gleixner
2017-06-05  8:17   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 12/26] posix-timers: Add timer_rearm() callback Thomas Gleixner
2017-06-05  8:18   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 13/26] posix-timers: Rename do_schedule_next_timer Thomas Gleixner
2017-05-31 15:39   ` Christoph Hellwig
2017-06-01 20:50     ` Thomas Gleixner
2017-06-02  7:00       ` Christoph Hellwig
2017-06-05  8:18   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 14/26] posix-timers: Use timer_rearm() callback in posixtimer_rearm() Thomas Gleixner
2017-06-05  8:19   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 15/26] posix-timers: Add active flag to k_itimer Thomas Gleixner
2017-06-05  8:20   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 16/26] posix-timers: Add forward/remaining callbacks Thomas Gleixner
2017-06-05  8:20   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 17/26] posix-timers: Make use of " Thomas Gleixner
2017-06-05  8:21   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 18/26] posix-timers: Zero settings value in common code Thomas Gleixner
2017-06-05  8:21   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-06-09 20:12     ` Andrei Vagin
2017-06-12 19:13       ` [tip:timers/core] posix-timers: Zero out oldval itimerspec tip-bot for Thomas Gleixner
2017-06-12 21:06         ` Andrei Vagin
2017-06-12 22:01           ` Thomas Gleixner
2017-06-12 22:14             ` Andrei Vagin
2017-06-12 19:13       ` [tip:timers/core] posix-timers: Handle relative posix-timers correctly tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 19/26] posix-timers: Add cancel/arm callbacks Thomas Gleixner
2017-06-05  8:22   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 20/26] posix-timers: Make use of " Thomas Gleixner
2017-06-05  8:22   ` tip-bot for Thomas Gleixner [this message]
2017-05-30 21:15 ` [patch 21/26] alarmtimer: Implement timer_rearm() callback Thomas Gleixner
2017-06-05  8:23   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 22/26] alarmtimer: Implement forward callback Thomas Gleixner
2017-06-05  8:24   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 23/26] alarmtimer: Implement remaining callback Thomas Gleixner
2017-06-05  8:24   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 24/26] alarmtimer: Implement try_to_cancel callback Thomas Gleixner
2017-06-05  8:25   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 25/26] alarmtimer: Implement arm callback Thomas Gleixner
2017-06-05  8:25   ` [tip:timers/core] " tip-bot for Thomas Gleixner
2017-05-30 21:15 ` [patch 26/26] alarmtimer: Switch over to generic set/get/rearm routine Thomas Gleixner
2017-06-05  8:26   ` [tip:timers/core] " tip-bot for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-eae1c4ae275fe3e024454c012a548ee0d700f54c@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.