mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Pavel Tatashin <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: tglx@linutronix.de, torvalds@linux-foundation.org,
	peterz@infradead.org, mingo@kernel.org,
	linux-kernel@vger.kernel.org, hpa@zytor.com,
	pasha.tatashin@oracle.com
Subject: [tip:sched/urgent] sched/clock: Fix broken stable to unstable transfer
Date: Mon, 27 Mar 2017 03:27:22 -0700	[thread overview]
Message-ID: <tip-7b09cc5a9debc86c903c2eff8f8a1fdef773c649@git.kernel.org> (raw)
In-Reply-To: <1490214265-899964-2-git-send-email-pasha.tatashin@oracle.com>

Commit-ID:  7b09cc5a9debc86c903c2eff8f8a1fdef773c649
Gitweb:     http://git.kernel.org/tip/7b09cc5a9debc86c903c2eff8f8a1fdef773c649
Author:     Pavel Tatashin <pasha.tatashin@oracle.com>
AuthorDate: Wed, 22 Mar 2017 16:24:17 -0400
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 27 Mar 2017 10:23:48 +0200

sched/clock: Fix broken stable to unstable transfer

When it is determined that the clock is actually unstable, and
we switch from stable to unstable, the __clear_sched_clock_stable()
function is eventually called.

In this function we set gtod_offset so the following holds true:

  sched_clock() + raw_offset == ktime_get_ns() + gtod_offset

But instead of getting the latest timestamps, we use the last values
from scd, so instead of sched_clock() we use scd->tick_raw, and
instead of ktime_get_ns() we use scd->tick_gtod.

However, later, when we use gtod_offset sched_clock_local() we do not
add it to scd->tick_gtod to calculate the correct clock value when we
determine the boundaries for min/max clocks.

This can result in tick granularity sched_clock() values, so fix it.

Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: hpa@zytor.com
Fixes: 5680d8094ffa ("sched/clock: Provide better clock continuity")
Link: http://lkml.kernel.org/r/1490214265-899964-2-git-send-email-pasha.tatashin@oracle.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/clock.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/clock.c b/kernel/sched/clock.c
index 24a3e01..00a45c4 100644
--- a/kernel/sched/clock.c
+++ b/kernel/sched/clock.c
@@ -221,7 +221,7 @@ static inline u64 wrap_max(u64 x, u64 y)
  */
 static u64 sched_clock_local(struct sched_clock_data *scd)
 {
-	u64 now, clock, old_clock, min_clock, max_clock;
+	u64 now, clock, old_clock, min_clock, max_clock, gtod;
 	s64 delta;
 
 again:
@@ -238,9 +238,10 @@ again:
 	 *		      scd->tick_gtod + TICK_NSEC);
 	 */
 
-	clock = scd->tick_gtod + __gtod_offset + delta;
-	min_clock = wrap_max(scd->tick_gtod, old_clock);
-	max_clock = wrap_max(old_clock, scd->tick_gtod + TICK_NSEC);
+	gtod = scd->tick_gtod + __gtod_offset;
+	clock = gtod + delta;
+	min_clock = wrap_max(gtod, old_clock);
+	max_clock = wrap_max(old_clock, gtod + TICK_NSEC);
 
 	clock = wrap_max(clock, min_clock);
 	clock = wrap_min(clock, max_clock);

  reply	other threads:[~2017-03-27 10:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-22 20:24 [v1 0/9] Early boot time stamps for x86 Pavel Tatashin
2017-03-22 20:24 ` [v1 1/9] sched/clock: broken stable to unstable transfer Pavel Tatashin
2017-03-27 10:27   ` tip-bot for Pavel Tatashin [this message]
2017-03-22 20:24 ` [v1 2/9] sched/clock: interface to allow timestamps early in boot Pavel Tatashin
2017-03-22 20:24 ` [v1 3/9] x86/cpu: determining x86 vendor early Pavel Tatashin
2017-03-22 20:24 ` [v1 4/9] x86/tsc: early MSR-based CPU/TSC frequency discovery Pavel Tatashin
2017-03-22 20:24 ` [v1 5/9] x86/tsc: disable early messages from quick_pit_calibrate Pavel Tatashin
2017-03-22 20:24 ` [v1 6/9] x86/tsc: use cpuid to determine TSC frequency Pavel Tatashin
2017-03-22 20:24 ` [v1 7/9] x86/tsc: use cpuid to determine CPU frequency Pavel Tatashin
2017-03-22 20:24 ` [v1 8/9] x86/tsc: tsc early Pavel Tatashin
2017-03-24  5:38   ` kbuild test robot
2017-03-22 20:24 ` [v1 9/9] x86/tsc: use " Pavel Tatashin
2017-03-22 20:27 ` [v1 0/9] Early boot time stamps for x86 Peter Zijlstra
2017-03-23  0:02   ` Pasha Tatashin
2017-03-22 20:28 ` Peter Zijlstra
2017-03-22 23:59   ` Pasha Tatashin
2017-03-23 10:56     ` Thomas Gleixner
2017-03-23 14:39       ` Pasha Tatashin
2017-03-23 18:40         ` 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-7b09cc5a9debc86c903c2eff8f8a1fdef773c649@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=pasha.tatashin@oracle.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®