public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: John Stultz <john.stultz@linaro.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>
Subject: [patch 26/26] alarmtimer: Switch over to generic set/get/rearm routine
Date: Tue, 30 May 2017 23:15:59 +0200	[thread overview]
Message-ID: <20170530211657.825471962@linutronix.de> (raw)
In-Reply-To: 20170530211533.216608851@linutronix.de

[-- Attachment #1: alarmtimer--Switch-over-to-generic-set-get-rearm-routine.patch --]
[-- Type: text/plain, Size: 6293 bytes --]

All required callbacks are in place. Switch the alarm timer based posix
interval timer callbacks to the common implementation and remove the
incorrect private implementation.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/time/alarmtimer.c   |  121 ++++++---------------------------------------
 kernel/time/posix-timers.c |   12 +---
 kernel/time/posix-timers.h |    6 ++
 3 files changed, 29 insertions(+), 110 deletions(-)

--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -515,20 +515,26 @@ static enum alarmtimer_type clock2alarm(
 static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm,
 							ktime_t now)
 {
-	unsigned long flags;
 	struct k_itimer *ptr = container_of(alarm, struct k_itimer,
-						it.alarm.alarmtimer);
+					    it.alarm.alarmtimer);
 	enum alarmtimer_restart result = ALARMTIMER_NORESTART;
+	unsigned long flags;
+	int si_private = 0;
 
 	spin_lock_irqsave(&ptr->it_lock, flags);
-	if ((ptr->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) {
-		if (posix_timer_event(ptr, 0))
-			ptr->it_overrun++;
-	}
 
-	/* Re-add periodic timers */
-	if (ptr->it_interval) {
-		ptr->it_overrun += alarm_forward(alarm, now, ptr->it_interval);
+	ptr->it_active = 0;
+	if (ptr->it_interval)
+		si_private = ++ptr->it_requeue_pending;
+
+	if (posix_timer_event(ptr, si_private) && ptr->it_interval) {
+		/*
+		 * Handle ignored signals and rearm the timer. This will go
+		 * away once we handle ignored signals proper.
+		 */
+		ptr->it_overrun += alarm_forward_now(alarm, ptr->it_interval);
+		++ptr->it_requeue_pending;
+		ptr->it_active = 1;
 		result = ALARMTIMER_RESTART;
 	}
 	spin_unlock_irqrestore(&ptr->it_lock, flags);
@@ -659,97 +665,6 @@ static int alarm_timer_create(struct k_i
 }
 
 /**
- * alarm_timer_get - posix timer_get interface
- * @timr: k_itimer pointer
- * @cur_setting: itimerspec data to fill
- *
- * Copies out the current itimerspec data
- */
-static void alarm_timer_get(struct k_itimer *timr,
-			    struct itimerspec64 *cur_setting)
-{
-	ktime_t relative_expiry_time =
-		alarm_expires_remaining(&(timr->it.alarm.alarmtimer));
-
-	if (ktime_to_ns(relative_expiry_time) > 0) {
-		cur_setting->it_value = ktime_to_timespec64(relative_expiry_time);
-	} else {
-		cur_setting->it_value.tv_sec = 0;
-		cur_setting->it_value.tv_nsec = 0;
-	}
-
-	cur_setting->it_interval = ktime_to_timespec64(timr->it_interval);
-}
-
-/**
- * alarm_timer_del - posix timer_del interface
- * @timr: k_itimer pointer to be deleted
- *
- * Cancels any programmed alarms for the given timer.
- */
-static int alarm_timer_del(struct k_itimer *timr)
-{
-	if (!rtcdev)
-		return -ENOTSUPP;
-
-	if (alarm_try_to_cancel(&timr->it.alarm.alarmtimer) < 0)
-		return TIMER_RETRY;
-
-	return 0;
-}
-
-/**
- * alarm_timer_set - posix timer_set interface
- * @timr: k_itimer pointer to be deleted
- * @flags: timer flags
- * @new_setting: itimerspec to be used
- * @old_setting: itimerspec being replaced
- *
- * Sets the timer to new_setting, and starts the timer.
- */
-static int alarm_timer_set(struct k_itimer *timr, int flags,
-			   struct itimerspec64 *new_setting,
-			   struct itimerspec64 *old_setting)
-{
-	ktime_t exp;
-
-	if (!rtcdev)
-		return -ENOTSUPP;
-
-	if (flags & ~TIMER_ABSTIME)
-		return -EINVAL;
-
-	if (old_setting)
-		alarm_timer_get(timr, old_setting);
-
-	/* If the timer was already set, cancel it */
-	if (alarm_try_to_cancel(&timr->it.alarm.alarmtimer) < 0)
-		return TIMER_RETRY;
-
-	/* start the timer */
-	timr->it_interval = timespec64_to_ktime(new_setting->it_interval);
-
-	/*
-	 * Rate limit to the tick as a hot fix to prevent DOS. Will be
-	 * mopped up later.
-	 */
-	if (timr->it_interval < TICK_NSEC)
-		timr->it_interval = TICK_NSEC;
-
-	exp = timespec64_to_ktime(new_setting->it_value);
-	/* Convert (if necessary) to absolute time */
-	if (flags != TIMER_ABSTIME) {
-		ktime_t now;
-
-		now = alarm_bases[timr->it.alarm.alarmtimer.type].gettime();
-		exp = ktime_add_safe(now, exp);
-	}
-
-	alarm_start(&timr->it.alarm.alarmtimer, exp);
-	return 0;
-}
-
-/**
  * alarmtimer_nsleep_wakeup - Wakeup function for alarm_timer_nsleep
  * @alarm: ptr to alarm that fired
  *
@@ -926,9 +841,9 @@ const struct k_clock alarm_clock = {
 	.clock_getres		= alarm_clock_getres,
 	.clock_get		= alarm_clock_get,
 	.timer_create		= alarm_timer_create,
-	.timer_set		= alarm_timer_set,
-	.timer_del		= alarm_timer_del,
-	.timer_get		= alarm_timer_get,
+	.timer_set		= common_timer_set,
+	.timer_del		= common_timer_del,
+	.timer_get		= common_timer_get,
 	.timer_arm		= alarm_timer_arm,
 	.timer_rearm		= alarm_timer_rearm,
 	.timer_forward		= alarm_timer_forward,
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -637,8 +637,7 @@ static int common_hrtimer_forward(struct
  * it is the same as a requeue pending timer WRT to what we should
  * report.
  */
-static void
-common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
+void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting)
 {
 	const struct k_clock *kc = timr->kclock;
 	ktime_t now, remaining, iv;
@@ -768,10 +767,9 @@ static int common_hrtimer_try_to_cancel(
 }
 
 /* Set a POSIX.1b interval timer. */
-static int
-common_timer_set(struct k_itimer *timr, int flags,
-		 struct itimerspec64 *new_setting,
-		 struct itimerspec64 *old_setting)
+int common_timer_set(struct k_itimer *timr, int flags,
+		     struct itimerspec64 *new_setting,
+		     struct itimerspec64 *old_setting)
 {
 	const struct k_clock *kc = timr->kclock;
 	bool sigev_none;
@@ -855,7 +853,7 @@ SYSCALL_DEFINE4(timer_settime, timer_t,
 	return error;
 }
 
-static int common_timer_del(struct k_itimer *timer)
+int common_timer_del(struct k_itimer *timer)
 {
 	const struct k_clock *kc = timer->kclock;
 
--- a/kernel/time/posix-timers.h
+++ b/kernel/time/posix-timers.h
@@ -5,3 +5,9 @@ extern const struct k_clock clock_thread
 extern const struct k_clock alarm_clock;
 
 int posix_timer_event(struct k_itimer *timr, int si_private);
+
+void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting);
+int common_timer_set(struct k_itimer *timr, int flags,
+		     struct itimerspec64 *new_setting,
+		     struct itimerspec64 *old_setting);
+int common_timer_del(struct k_itimer *timer);

  parent reply	other threads:[~2017-05-30 21:42 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:timers/core] " tip-bot for Thomas Gleixner
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 ` Thomas Gleixner [this message]
2017-06-05  8:26   ` [tip:timers/core] alarmtimer: Switch over to generic set/get/rearm routine 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=20170530211657.825471962@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox