linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GIT PULL][PATCH 0/6] Timekeeping changes for tip/timers/core
@ 2016-06-20 19:56 John Stultz
  2016-06-20 19:56 ` [PATCH 1/6] clocksource: Make clocksource insert entry more efficient John Stultz
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: John Stultz @ 2016-06-20 19:56 UTC (permalink / raw)
  To: lkml
  Cc: John Stultz, Prarit Bhargava, Richard Cochran, Thomas Gleixner,
	Ingo Molnar

Hey Thomas, Ingo,
  Here is my current queue of timekeeping changes for 4.8.
Most of them are small cleanups and core y2038 changes.

Let me know if you have any objections.

thanks
-john

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>

You can also grab it via a pull:

The following changes since commit af8c34ce6ae32addda3788d54a7e340cad22516b:

  Linux 4.7-rc2 (2016-06-05 14:31:26 -0700)

are available in the git repository at:

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

for you to fetch changes up to 7c71feb0a6766c7c3a262e3cc33ae231f3953cb6:

  timer: Avoid using timespec (2016-06-20 12:47:33 -0700)

----------------------------------------------------------------
Arnd Bergmann (2):
  time: Avoid timespec in udelay_test
  timer: Avoid using timespec

Deepa Dinamani (1):
  time: Add time64_to_tm()

Minfei Huang (1):
  clocksource: Make clocksource insert entry more efficient

Pratyush Patel (1):
  alarmtimer: Fix comments describing structure fields

Thomas Graziadei (1):
  timekeeping: Fix 1ns/tick drift with GENERIC_TIME_VSYSCALL_OLD

 include/linux/alarmtimer.h |  6 +++---
 include/linux/time.h       | 15 ++++++++++++++-
 kernel/time/alarmtimer.c   |  1 -
 kernel/time/clocksource.c  |  8 +++++---
 kernel/time/test_udelay.c  | 16 ++++++++--------
 kernel/time/timeconv.c     | 11 ++++++-----
 kernel/time/timekeeping.c  | 10 ++++++----
 kernel/time/timer_stats.c  |  6 +++---
 8 files changed, 45 insertions(+), 28 deletions(-)

-- 
1.9.1

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

* [PATCH 1/6] clocksource: Make clocksource insert entry more efficient
  2016-06-20 19:56 [GIT PULL][PATCH 0/6] Timekeeping changes for tip/timers/core John Stultz
@ 2016-06-20 19:56 ` John Stultz
  2016-06-20 19:56 ` [PATCH 2/6] timekeeping: Fix 1ns/tick drift with GENERIC_TIME_VSYSCALL_OLD John Stultz
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: John Stultz @ 2016-06-20 19:56 UTC (permalink / raw)
  To: lkml
  Cc: Minfei Huang, Prarit Bhargava, Richard Cochran, Thomas Gleixner,
	Ingo Molnar, John Stultz

From: Minfei Huang <mnghuan@gmail.com>

In clocksource_enqueue(), it is unnecessary to continue looping
the list, if we find there is an entry that the value of rating
is smaller than the new one. It is safe to be out the loop,
because all of entry are inserted in descending order.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Minfei Huang <mnghuan@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/clocksource.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 56ece14..6a5a310 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -669,10 +669,12 @@ static void clocksource_enqueue(struct clocksource *cs)
 	struct list_head *entry = &clocksource_list;
 	struct clocksource *tmp;
 
-	list_for_each_entry(tmp, &clocksource_list, list)
+	list_for_each_entry(tmp, &clocksource_list, list) {
 		/* Keep track of the place, where to insert */
-		if (tmp->rating >= cs->rating)
-			entry = &tmp->list;
+		if (tmp->rating < cs->rating)
+			break;
+		entry = &tmp->list;
+	}
 	list_add(&cs->list, entry);
 }
 
-- 
1.9.1

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

* [PATCH 2/6] timekeeping: Fix 1ns/tick drift with GENERIC_TIME_VSYSCALL_OLD
  2016-06-20 19:56 [GIT PULL][PATCH 0/6] Timekeeping changes for tip/timers/core John Stultz
  2016-06-20 19:56 ` [PATCH 1/6] clocksource: Make clocksource insert entry more efficient John Stultz
@ 2016-06-20 19:56 ` John Stultz
  2016-06-20 19:56 ` [PATCH 3/6] alarmtimer: Fix comments describing structure fields John Stultz
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: John Stultz @ 2016-06-20 19:56 UTC (permalink / raw)
  To: lkml
  Cc: Thomas Graziadei, Prarit Bhargava, Richard Cochran,
	Thomas Gleixner, Ingo Molnar, John Stultz

From: Thomas Graziadei <thomas.graziadei@omicronenergy.com>

The user notices the problem in a raw and real time drift, calling
clock_gettime with CLOCK_REALTIME / CLOCK_MONOTONIC_RAW on a system
with no ntp correction taking place (no ntpd or ptp stuff running).

The problem is, that old_vsyscall_fixup adds an extra 1ns even though
xtime_nsec is already held in full nsecs and the remainder in this
case is 0. Do the rounding up buisness only if needed.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Thomas Graziadei <thomas.graziadei@omicronenergy.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/timekeeping.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 479d25c..a196e08 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -480,10 +480,12 @@ static inline void old_vsyscall_fixup(struct timekeeper *tk)
 	* users are removed, this can be killed.
 	*/
 	remainder = tk->tkr_mono.xtime_nsec & ((1ULL << tk->tkr_mono.shift) - 1);
-	tk->tkr_mono.xtime_nsec -= remainder;
-	tk->tkr_mono.xtime_nsec += 1ULL << tk->tkr_mono.shift;
-	tk->ntp_error += remainder << tk->ntp_error_shift;
-	tk->ntp_error -= (1ULL << tk->tkr_mono.shift) << tk->ntp_error_shift;
+	if (remainder != 0) {
+		tk->tkr_mono.xtime_nsec -= remainder;
+		tk->tkr_mono.xtime_nsec += 1ULL << tk->tkr_mono.shift;
+		tk->ntp_error += remainder << tk->ntp_error_shift;
+		tk->ntp_error -= (1ULL << tk->tkr_mono.shift) << tk->ntp_error_shift;
+	}
 }
 #else
 #define old_vsyscall_fixup(tk)
-- 
1.9.1

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

* [PATCH 3/6] alarmtimer: Fix comments describing structure fields
  2016-06-20 19:56 [GIT PULL][PATCH 0/6] Timekeeping changes for tip/timers/core John Stultz
  2016-06-20 19:56 ` [PATCH 1/6] clocksource: Make clocksource insert entry more efficient John Stultz
  2016-06-20 19:56 ` [PATCH 2/6] timekeeping: Fix 1ns/tick drift with GENERIC_TIME_VSYSCALL_OLD John Stultz
@ 2016-06-20 19:56 ` John Stultz
  2016-06-20 19:56 ` [PATCH 4/6] time: Add time64_to_tm() John Stultz
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: John Stultz @ 2016-06-20 19:56 UTC (permalink / raw)
  To: lkml
  Cc: Pratyush Patel, Prarit Bhargava, Richard Cochran,
	Thomas Gleixner, Ingo Molnar, John Stultz

From: Pratyush Patel <pratyushpatel.1995@gmail.com>

Updated struct alarm and struct alarm_timer descriptions.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Pratyush Patel <pratyushpatel.1995@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/alarmtimer.h | 6 +++---
 kernel/time/alarmtimer.c   | 1 -
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/linux/alarmtimer.h b/include/linux/alarmtimer.h
index 52f3b7d..9d80312 100644
--- a/include/linux/alarmtimer.h
+++ b/include/linux/alarmtimer.h
@@ -26,10 +26,10 @@ enum alarmtimer_restart {
  * struct alarm - Alarm timer structure
  * @node:	timerqueue node for adding to the event list this value
  *		also includes the expiration time.
- * @period:	Period for recuring alarms
+ * @timer:	hrtimer used to schedule events while running
  * @function:	Function pointer to be executed when the timer fires.
- * @type:	Alarm type (BOOTTIME/REALTIME)
- * @enabled:	Flag that represents if the alarm is set to fire or not
+ * @type:	Alarm type (BOOTTIME/REALTIME).
+ * @state:	Flag that represents if the alarm is set to fire or not.
  * @data:	Internal data value.
  */
 struct alarm {
diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index e840ed86..c3aad68 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -30,7 +30,6 @@
  * struct alarm_base - Alarm timer bases
  * @lock:		Lock for syncrhonized access to the base
  * @timerqueue:		Timerqueue head managing the list of events
- * @timer: 		hrtimer used to schedule events while running
  * @gettime:		Function to read the time correlating to the base
  * @base_clockid:	clockid for the base
  */
-- 
1.9.1

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

* [PATCH 4/6] time: Add time64_to_tm()
  2016-06-20 19:56 [GIT PULL][PATCH 0/6] Timekeeping changes for tip/timers/core John Stultz
                   ` (2 preceding siblings ...)
  2016-06-20 19:56 ` [PATCH 3/6] alarmtimer: Fix comments describing structure fields John Stultz
@ 2016-06-20 19:56 ` John Stultz
  2016-06-20 19:56 ` [PATCH 5/6] time: Avoid timespec in udelay_test John Stultz
  2016-06-20 19:56 ` [PATCH 6/6] timer: Avoid using timespec John Stultz
  5 siblings, 0 replies; 7+ messages in thread
From: John Stultz @ 2016-06-20 19:56 UTC (permalink / raw)
  To: lkml
  Cc: Deepa Dinamani, Prarit Bhargava, Richard Cochran,
	Thomas Gleixner, Ingo Molnar, John Stultz

From: Deepa Dinamani <deepa.kernel@gmail.com>

time_to_tm() takes time_t as an argument.
time_t is not y2038 safe.
Add time64_to_tm() that takes time64_t as an argument
which is y2038 safe.
The plan is to eventually replace all calls to time_to_tm()
by time64_to_tm().

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 include/linux/time.h   | 15 ++++++++++++++-
 kernel/time/timeconv.c | 11 ++++++-----
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/linux/time.h b/include/linux/time.h
index 297f09f..4cea09d 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -205,7 +205,20 @@ struct tm {
 	int tm_yday;
 };
 
-void time_to_tm(time_t totalsecs, int offset, struct tm *result);
+void time64_to_tm(time64_t totalsecs, int offset, struct tm *result);
+
+/**
+ * time_to_tm - converts the calendar time to local broken-down time
+ *
+ * @totalsecs	the number of seconds elapsed since 00:00:00 on January 1, 1970,
+ *		Coordinated Universal Time (UTC).
+ * @offset	offset seconds adding to totalsecs.
+ * @result	pointer to struct tm variable to receive broken-down time
+ */
+static inline void time_to_tm(time_t totalsecs, int offset, struct tm *result)
+{
+	time64_to_tm(totalsecs, offset, result);
+}
 
 /**
  * timespec_to_ns - Convert timespec to nanoseconds
diff --git a/kernel/time/timeconv.c b/kernel/time/timeconv.c
index 86628e7..7142580 100644
--- a/kernel/time/timeconv.c
+++ b/kernel/time/timeconv.c
@@ -67,20 +67,21 @@ static const unsigned short __mon_yday[2][13] = {
 #define SECS_PER_DAY	(SECS_PER_HOUR * 24)
 
 /**
- * time_to_tm - converts the calendar time to local broken-down time
+ * time64_to_tm - converts the calendar time to local broken-down time
  *
  * @totalsecs	the number of seconds elapsed since 00:00:00 on January 1, 1970,
  *		Coordinated Universal Time (UTC).
  * @offset	offset seconds adding to totalsecs.
  * @result	pointer to struct tm variable to receive broken-down time
  */
-void time_to_tm(time_t totalsecs, int offset, struct tm *result)
+void time64_to_tm(time64_t totalsecs, int offset, struct tm *result)
 {
 	long days, rem, y;
+	int remainder;
 	const unsigned short *ip;
 
-	days = totalsecs / SECS_PER_DAY;
-	rem = totalsecs % SECS_PER_DAY;
+	days = div_s64_rem(totalsecs, SECS_PER_DAY, &remainder);
+	rem = remainder;
 	rem += offset;
 	while (rem < 0) {
 		rem += SECS_PER_DAY;
@@ -124,4 +125,4 @@ void time_to_tm(time_t totalsecs, int offset, struct tm *result)
 	result->tm_mon = y;
 	result->tm_mday = days + 1;
 }
-EXPORT_SYMBOL(time_to_tm);
+EXPORT_SYMBOL(time64_to_tm);
-- 
1.9.1

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

* [PATCH 5/6] time: Avoid timespec in udelay_test
  2016-06-20 19:56 [GIT PULL][PATCH 0/6] Timekeeping changes for tip/timers/core John Stultz
                   ` (3 preceding siblings ...)
  2016-06-20 19:56 ` [PATCH 4/6] time: Add time64_to_tm() John Stultz
@ 2016-06-20 19:56 ` John Stultz
  2016-06-20 19:56 ` [PATCH 6/6] timer: Avoid using timespec John Stultz
  5 siblings, 0 replies; 7+ messages in thread
From: John Stultz @ 2016-06-20 19:56 UTC (permalink / raw)
  To: lkml
  Cc: Arnd Bergmann, Prarit Bhargava, Richard Cochran, Thomas Gleixner,
	Ingo Molnar, John Stultz

From: Arnd Bergmann <arnd@arndb.de>

udelay_test_single() uses ktime_get_ts() to get two timespec values
and calculate the difference between them, while udelay_test_show()
uses the same to printk() the current monotonic time.

Both of these are y2038 safe on all machines, but we want to
get rid of struct timespec anyway, so this converts the code to
use ktime_get_ns() and ktime_get_ts64() respectively.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/test_udelay.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/kernel/time/test_udelay.c b/kernel/time/test_udelay.c
index e622ba3..b0928ab 100644
--- a/kernel/time/test_udelay.c
+++ b/kernel/time/test_udelay.c
@@ -43,13 +43,13 @@ static int udelay_test_single(struct seq_file *s, int usecs, uint32_t iters)
 	int allowed_error_ns = usecs * 5;
 
 	for (i = 0; i < iters; ++i) {
-		struct timespec ts1, ts2;
+		s64 kt1, kt2;
 		int time_passed;
 
-		ktime_get_ts(&ts1);
+		kt1 = ktime_get_ns();
 		udelay(usecs);
-		ktime_get_ts(&ts2);
-		time_passed = timespec_to_ns(&ts2) - timespec_to_ns(&ts1);
+		kt2 = ktime_get_ns();
+		time_passed = kt2 - kt1;
 
 		if (i == 0 || time_passed < min)
 			min = time_passed;
@@ -87,11 +87,11 @@ static int udelay_test_show(struct seq_file *s, void *v)
 	if (usecs > 0 && iters > 0) {
 		return udelay_test_single(s, usecs, iters);
 	} else if (usecs == 0) {
-		struct timespec ts;
+		struct timespec64 ts;
 
-		ktime_get_ts(&ts);
-		seq_printf(s, "udelay() test (lpj=%ld kt=%ld.%09ld)\n",
-				loops_per_jiffy, ts.tv_sec, ts.tv_nsec);
+		ktime_get_ts64(&ts);
+		seq_printf(s, "udelay() test (lpj=%ld kt=%lld.%09ld)\n",
+				loops_per_jiffy, (s64)ts.tv_sec, ts.tv_nsec);
 		seq_puts(s, "usage:\n");
 		seq_puts(s, "echo USECS [ITERS] > " DEBUGFS_FILENAME "\n");
 		seq_puts(s, "cat " DEBUGFS_FILENAME "\n");
-- 
1.9.1

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

* [PATCH 6/6] timer: Avoid using timespec
  2016-06-20 19:56 [GIT PULL][PATCH 0/6] Timekeeping changes for tip/timers/core John Stultz
                   ` (4 preceding siblings ...)
  2016-06-20 19:56 ` [PATCH 5/6] time: Avoid timespec in udelay_test John Stultz
@ 2016-06-20 19:56 ` John Stultz
  5 siblings, 0 replies; 7+ messages in thread
From: John Stultz @ 2016-06-20 19:56 UTC (permalink / raw)
  To: lkml
  Cc: Arnd Bergmann, Prarit Bhargava, Richard Cochran, Thomas Gleixner,
	Ingo Molnar, John Stultz

From: Arnd Bergmann <arnd@arndb.de>

The tstats_show() function prints a ktime_t variable by converting
it to struct timespec first. The algorithm is ok, but we want to
stop using timespec in general because of the 32-bit time_t
overflow problem.

This changes the code to use struct timespec64, without any
functional change.

Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
 kernel/time/timer_stats.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
index 1adecb4..087204c 100644
--- a/kernel/time/timer_stats.c
+++ b/kernel/time/timer_stats.c
@@ -279,7 +279,7 @@ static void print_name_offset(struct seq_file *m, unsigned long addr)
 
 static int tstats_show(struct seq_file *m, void *v)
 {
-	struct timespec period;
+	struct timespec64 period;
 	struct entry *entry;
 	unsigned long ms;
 	long events = 0;
@@ -295,11 +295,11 @@ static int tstats_show(struct seq_file *m, void *v)
 
 	time = ktime_sub(time_stop, time_start);
 
-	period = ktime_to_timespec(time);
+	period = ktime_to_timespec64(time);
 	ms = period.tv_nsec / 1000000;
 
 	seq_puts(m, "Timer Stats Version: v0.3\n");
-	seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
+	seq_printf(m, "Sample period: %ld.%03ld s\n", (long)period.tv_sec, ms);
 	if (atomic_read(&overflow_count))
 		seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
 	seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
-- 
1.9.1

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

end of thread, other threads:[~2016-06-20 19:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-20 19:56 [GIT PULL][PATCH 0/6] Timekeeping changes for tip/timers/core John Stultz
2016-06-20 19:56 ` [PATCH 1/6] clocksource: Make clocksource insert entry more efficient John Stultz
2016-06-20 19:56 ` [PATCH 2/6] timekeeping: Fix 1ns/tick drift with GENERIC_TIME_VSYSCALL_OLD John Stultz
2016-06-20 19:56 ` [PATCH 3/6] alarmtimer: Fix comments describing structure fields John Stultz
2016-06-20 19:56 ` [PATCH 4/6] time: Add time64_to_tm() John Stultz
2016-06-20 19:56 ` [PATCH 5/6] time: Avoid timespec in udelay_test John Stultz
2016-06-20 19:56 ` [PATCH 6/6] timer: Avoid using timespec 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).