linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19
@ 2018-07-12 20:17 John Stultz
  2018-07-12 20:17 ` [PATCH 1/2] selftest: timers: Tweak raw_skew to SKIP when ADJ_OFFSET/other clock adjustments are in progress John Stultz
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: John Stultz @ 2018-07-12 20:17 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Miroslav Lichvar,
	Richard Cochran, Prarit Bhargava, Stephen Boyd, Shuah Khan,
	linux-kselftest

Hey Thomas,
  I had a few other items in my stack here, but you've already
queued them in -tip, so here's what I have left.

Let me know if you have any objections or feedback for change.

thanks
-john

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org

The following changes since commit 021c91791a5e7e85c567452f1be3e4c2c6cb6063:

  Linux 4.18-rc3 (2018-07-01 16:04:53 -0700)

are available in the git repository at:

  https://git.linaro.org/people/john.stultz/linux.git fortglx/4.19/time

for you to fetch changes up to b061c7a513afe14a68af41cec7c3476befc40e95:

  timekeeping: Update multiplier when NTP frequency is set directly (2018-07-10 12:44:25 -0700)

----------------------------------------------------------------
John Stultz (1):
      selftest: timers: Tweak raw_skew to SKIP when ADJ_OFFSET/other clock adjustments are in progress

Miroslav Lichvar (1):
      timekeeping: Update multiplier when NTP frequency is set directly

 kernel/time/timekeeping.c                 | 36 ++++++++++++++++++++++++++++++------
 tools/testing/selftests/timers/raw_skew.c |  5 +++++
 2 files changed, 35 insertions(+), 6 deletions(-)

-- 
2.7.4


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] selftest: timers: Tweak raw_skew to SKIP when ADJ_OFFSET/other clock adjustments are in progress
  2018-07-12 20:17 [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19 John Stultz
@ 2018-07-12 20:17 ` John Stultz
  2018-07-12 20:17 ` [PATCH 2/2] timekeeping: Update multiplier when NTP frequency is set directly John Stultz
  2018-07-12 20:26 ` [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19 Thomas Gleixner
  2 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2018-07-12 20:17 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Thomas Gleixner, Ingo Molnar, Miroslav Lichvar,
	Richard Cochran, Prarit Bhargava, Stephen Boyd, Shuah Khan,
	linux-kselftest

In the past we've warned when ADJ_OFFSET was in progress, usually
caused by ntpd or some other time adjusting daemon running in non
steady sate, which can cause the skew calculations to be
incorrect.

Thus, this patch checks to see if the clock was being adjusted
when we fail so that we don't cause false negatives.

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Suggested-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
v2: Widened the checks to look for other clock adjustments that
    could happen, as suggested by Miroslav
v3: Fixed up commit message
---
 tools/testing/selftests/timers/raw_skew.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/selftests/timers/raw_skew.c b/tools/testing/selftests/timers/raw_skew.c
index ca6cd14..dcf73c5 100644
--- a/tools/testing/selftests/timers/raw_skew.c
+++ b/tools/testing/selftests/timers/raw_skew.c
@@ -134,6 +134,11 @@ int main(int argv, char **argc)
 	printf(" %lld.%i(act)", ppm/1000, abs((int)(ppm%1000)));
 
 	if (llabs(eppm - ppm) > 1000) {
+		if (tx1.offset || tx2.offset ||
+		    tx1.freq != tx2.freq || tx1.tick != tx2.tick) {
+			printf("	[SKIP]\n");
+			return ksft_exit_skip("The clock was adjusted externally. Shutdown NTPd or other time sync daemons\n");
+		}
 		printf("	[FAILED]\n");
 		return ksft_exit_fail();
 	}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] timekeeping: Update multiplier when NTP frequency is set directly
  2018-07-12 20:17 [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19 John Stultz
  2018-07-12 20:17 ` [PATCH 1/2] selftest: timers: Tweak raw_skew to SKIP when ADJ_OFFSET/other clock adjustments are in progress John Stultz
@ 2018-07-12 20:17 ` John Stultz
  2018-07-12 20:26 ` [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19 Thomas Gleixner
  2 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2018-07-12 20:17 UTC (permalink / raw)
  To: lkml
  Cc: Miroslav Lichvar, Thomas Gleixner, Ingo Molnar, Richard Cochran,
	Prarit Bhargava, Stephen Boyd, John Stultz

From: Miroslav Lichvar <mlichvar@redhat.com>

When the NTP frequency is set directly from userspace using the
ADJ_FREQUENCY or ADJ_TICK timex mode, immediately update the
timekeeper's multiplier instead of waiting for the next tick.

This removes a hidden non-deterministic delay in setting of the
frequency and allows an extremely tight control of the system clock
with update rates close to or even exceeding the kernel HZ.

The update is limited to archs using modern timekeeping
(!ARCH_USES_GETTIMEOFFSET).

Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Miroslav Lichvar <mlichvar@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Stephen Boyd <sboyd@kernel.org>
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/timekeeping.c | 36 ++++++++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 4786df9..6772011 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -34,6 +34,14 @@
 #define TK_MIRROR		(1 << 1)
 #define TK_CLOCK_WAS_SET	(1 << 2)
 
+enum timekeeping_adv_mode {
+	/* Update timekeeper when a tick has passed */
+	TK_ADV_TICK,
+
+	/* Update timekeeper on a direct frequency change */
+	TK_ADV_FREQ
+};
+
 /*
  * The most important data for readout fits into a single 64 byte
  * cache line.
@@ -2021,11 +2029,11 @@ static u64 logarithmic_accumulation(struct timekeeper *tk, u64 offset,
 	return offset;
 }
 
-/**
- * update_wall_time - Uses the current clocksource to increment the wall time
- *
+/*
+ * timekeeping_advance - Updates the timekeeper to the current time and
+ * current NTP tick length
  */
-void update_wall_time(void)
+static void timekeeping_advance(enum timekeeping_adv_mode mode)
 {
 	struct timekeeper *real_tk = &tk_core.timekeeper;
 	struct timekeeper *tk = &shadow_timekeeper;
@@ -2042,14 +2050,17 @@ void update_wall_time(void)
 
 #ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 	offset = real_tk->cycle_interval;
+
+	if (mode != TK_ADV_TICK)
+		goto out;
 #else
 	offset = clocksource_delta(tk_clock_read(&tk->tkr_mono),
 				   tk->tkr_mono.cycle_last, tk->tkr_mono.mask);
-#endif
 
 	/* Check if there's really nothing to do */
-	if (offset < real_tk->cycle_interval)
+	if (offset < real_tk->cycle_interval && mode == TK_ADV_TICK)
 		goto out;
+#endif
 
 	/* Do some additional sanity checking */
 	timekeeping_check_update(tk, offset);
@@ -2106,6 +2117,15 @@ void update_wall_time(void)
 }
 
 /**
+ * update_wall_time - Uses the current clocksource to increment the wall time
+ *
+ */
+void update_wall_time(void)
+{
+	timekeeping_advance(TK_ADV_TICK);
+}
+
+/**
  * getboottime64 - Return the real time of system boot.
  * @ts:		pointer to the timespec64 to be set
  *
@@ -2327,6 +2347,10 @@ int do_adjtimex(struct timex *txc)
 	write_seqcount_end(&tk_core.seq);
 	raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
 
+	/* Update the multiplier immediately if frequency was set directly */
+	if (txc->modes & (ADJ_FREQUENCY | ADJ_TICK))
+		timekeeping_advance(TK_ADV_FREQ);
+
 	if (tai != orig_tai)
 		clock_was_set();
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19
  2018-07-12 20:17 [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19 John Stultz
  2018-07-12 20:17 ` [PATCH 1/2] selftest: timers: Tweak raw_skew to SKIP when ADJ_OFFSET/other clock adjustments are in progress John Stultz
  2018-07-12 20:17 ` [PATCH 2/2] timekeeping: Update multiplier when NTP frequency is set directly John Stultz
@ 2018-07-12 20:26 ` Thomas Gleixner
  2018-07-12 20:34   ` John Stultz
  2 siblings, 1 reply; 5+ messages in thread
From: Thomas Gleixner @ 2018-07-12 20:26 UTC (permalink / raw)
  To: John Stultz
  Cc: lkml, Ingo Molnar, Miroslav Lichvar, Richard Cochran,
	Prarit Bhargava, Stephen Boyd, Shuah Khan, linux-kselftest

John,

On Thu, 12 Jul 2018, John Stultz wrote:

>   I had a few other items in my stack here, but you've already
> queued them in -tip, so here's what I have left.

Did I miss you replying on them that you picked them up? Normally when I
see that you or Daniel picked something up I happily move the mails to the
done folder unless I see something horrible.

> Let me know if you have any objections or feedback for change.

One small request for the next pull request. Please write a short summary,
optionally in a tag, then pulling the tag adds it to the merge commit message.
But plain in the pull request mail is fine as well.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19
  2018-07-12 20:26 ` [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19 Thomas Gleixner
@ 2018-07-12 20:34   ` John Stultz
  0 siblings, 0 replies; 5+ messages in thread
From: John Stultz @ 2018-07-12 20:34 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: lkml, Ingo Molnar, Miroslav Lichvar, Richard Cochran,
	Prarit Bhargava, Stephen Boyd, Shuah Khan, linux-kselftest

On Thu, Jul 12, 2018 at 1:26 PM, Thomas Gleixner <tglx@linutronix.de> wrote:
> On Thu, 12 Jul 2018, John Stultz wrote:
>
>>   I had a few other items in my stack here, but you've already
>> queued them in -tip, so here's what I have left.
>
> Did I miss you replying on them that you picked them up? Normally when I
> see that you or Daniel picked something up I happily move the mails to the
> done folder unless I see something horrible.

No, that's my fault. I'll try to be better about making that clear so
you don't duplicate work. You're just much faster then I am :)

>> Let me know if you have any objections or feedback for change.
>
> One small request for the next pull request. Please write a short summary,
> optionally in a tag, then pulling the tag adds it to the merge commit message.
> But plain in the pull request mail is fine as well.

Sure, I'll try to take a swing at this next time, I've not done much
with git tags (other then trying to do a signature tag long ago when I
still had a valid gpg key :)

thanks
-john

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-07-12 20:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-12 20:17 [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19 John Stultz
2018-07-12 20:17 ` [PATCH 1/2] selftest: timers: Tweak raw_skew to SKIP when ADJ_OFFSET/other clock adjustments are in progress John Stultz
2018-07-12 20:17 ` [PATCH 2/2] timekeeping: Update multiplier when NTP frequency is set directly John Stultz
2018-07-12 20:26 ` [GIT PULL][PATCH 0/2] Few timekeeping items for 4.19 Thomas Gleixner
2018-07-12 20:34   ` John Stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).