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: avagin@virtuozzo.com, tglx@linutronix.de, john.stultz@linaro.org,
	gorcunov@openvz.org, peterz@infradead.org, hpa@zytor.com,
	mingo@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip:timers/core] posix-timers: Handle relative posix-timers correctly
Date: Mon, 12 Jun 2017 12:13:49 -0700	[thread overview]
Message-ID: <tip-67edab48caeb75d412706f4b9d3107afd1e07623@git.kernel.org> (raw)
In-Reply-To: <20170609201156.GB21491@outlook.office365.com>

Commit-ID:  67edab48caeb75d412706f4b9d3107afd1e07623
Gitweb:     http://git.kernel.org/tip/67edab48caeb75d412706f4b9d3107afd1e07623
Author:     Thomas Gleixner <tglx@linutronix.de>
AuthorDate: Mon, 12 Jun 2017 19:39:49 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Mon, 12 Jun 2017 21:07:41 +0200

posix-timers: Handle relative posix-timers correctly

The recent rework of the posix timer internals broke the magic posix
mechanism, which requires that relative timers are not affected by
modifications of the underlying clock. That means relative CLOCK_REALTIME
timers cannot use CLOCK_REALTIME, because that can be set and adjusted. The
underlying hrtimer switches the clock for these timers to CLOCK_MONOTONIC.

That still works, but reading the remaining time of such a timer has been
broken in the rework. The old code used the hrtimer internals directly and
avoided the posix clock callbacks. Now common_timer_get() uses the
underlying kclock->timer_get() callback, which is still CLOCK_REALTIME
based. So the remaining time of such a timer is calculated against the
wrong time base.

Handle it by switching the k_itimer->kclock pointer according to the
resulting hrtimer mode. k_itimer->it_clock still contains CLOCK_REALTIME
because the timer might be set with ABSTIME later and then it needs to
switch back to the realtime posix clock implementation.

Fixes: eae1c4ae275f ("posix-timers: Make use of cancel/arm callbacks")
Reported-by: Andrei Vagin <avagin@virtuozzo.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Link: http://lkml.kernel.org/r/20170609201156.GB21491@outlook.office365.com
---
 kernel/time/posix-timers.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
index 88517dc..58c0f60 100644
--- a/kernel/time/posix-timers.c
+++ b/kernel/time/posix-timers.c
@@ -72,6 +72,7 @@ static DEFINE_SPINLOCK(hash_lock);
 
 static const struct k_clock * const posix_clocks[];
 static const struct k_clock *clockid_to_kclock(const clockid_t id);
+static const struct k_clock clock_realtime, clock_monotonic;
 
 /*
  * we assume that the new SIGEV_THREAD_ID shares no bits with the other
@@ -750,6 +751,18 @@ static void common_hrtimer_arm(struct k_itimer *timr, ktime_t expires,
 	enum hrtimer_mode mode;
 
 	mode = absolute ? HRTIMER_MODE_ABS : HRTIMER_MODE_REL;
+	/*
+	 * Posix magic: Relative CLOCK_REALTIME timers are not affected by
+	 * clock modifications, so they become CLOCK_MONOTONIC based under the
+	 * hood. See hrtimer_init(). Update timr->kclock, so the generic
+	 * functions which use timr->kclock->clock_get() work.
+	 *
+	 * Note: it_clock stays unmodified, because the next timer_set() might
+	 * use ABSTIME, so it needs to switch back.
+	 */
+	if (timr->it_clock == CLOCK_REALTIME)
+		timr->kclock = absolute ? &clock_realtime : &clock_monotonic;
+
 	hrtimer_init(&timr->it.real.timer, timr->it_clock, mode);
 	timr->it.real.timer.function = posix_timer_fn;
 

  parent reply	other threads:[~2017-06-12 19:17 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-bot for Thomas Gleixner [this message]
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 ` [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-67edab48caeb75d412706f4b9d3107afd1e07623@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=avagin@virtuozzo.com \
    --cc=gorcunov@openvz.org \
    --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.