login
Header Space

 
 

Re: [patch] CFS scheduler, -v19

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Bill Davidsen <davidsen@...>
Cc: <davidsen@...>, Linus Torvalds <torvalds@...>, Ian Kent <raven@...>, Chuck Ebbert <cebbert@...>, <linux-kernel@...>
Date: Thursday, July 19, 2007 - 1:17 pm

* Bill Davidsen <davidsen@tmr.com> wrote:


the patch below is merged against 2.6.22.1-cfs-v19 - does it solve the 
autofs problem (without any other bad side-effects)?

	Ingo

------------------->
Subject: time: introduce xtime_seconds
From: Ingo Molnar <mingo@elte.hu>

introduce the xtime_seconds optimization. This is a read-mostly 
low-resolution time source available to sys_time() and kernel-internal 
use. This variable is kept uptodate atomically, and it's monotically 
increased, every time some time interface constructs an xtime-alike time 
result that overflows the seconds value. (it's updated from the timer 
interrupt as well)

this way high-resolution time results update their seconds component at 
the same time sys_time() does it:

 1184858832999989000
 1184858832000000000
 1184858832999992000
 1184858832000000000
 1184858832999996000
 1184858832000000000
 1184858832999999000
 1184858832000000000
 1184858833000003000
 1184858833000000000
 1184858833000006000
 1184858833000000000
 1184858833000009000
 1184858833000000000

 [ these are nsec time results from alternating calls to sys_time() and 
   sys_gettimeofday(), recorded at the seconds boundary. ]

instead of the previous (non-coherent) behavior:

 1184848950999987000
 1184848950000000000
 1184848950999990000
 1184848950000000000
 1184848950999994000
 1184848950000000000
 1184848950999997000
 1184848950000000000
 1184848951000001000
 1184848950000000000
 1184848951000005000
 1184848950000000000
 1184848951000008000
 1184848950000000000
 1184848951000011000
 1184848950000000000
 1184848951000015000

Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 include/linux/time.h      |   13 +++++++++++--
 kernel/time.c             |   25 ++++++-------------------
 kernel/time/timekeeping.c |   26 +++++++++++++++++++++++---
 3 files changed, 40 insertions(+), 24 deletions(-)

Index: linux-cfs-2.6.22.q/include/linux/time.h
===================================================================
--- linux-cfs-2.6.22.q.orig/include/linux/time.h
+++ linux-cfs-2.6.22.q/include/linux/time.h
@@ -91,19 +91,28 @@ static inline struct timespec timespec_s
 extern struct timespec xtime;
 extern struct timespec wall_to_monotonic;
 extern seqlock_t xtime_lock __attribute__((weak));
+extern unsigned long xtime_seconds;
 
 extern unsigned long read_persistent_clock(void);
 void timekeeping_init(void);
 
+extern void __update_xtime_seconds(unsigned long new_xtime_seconds);
+
+static inline void update_xtime_seconds(unsigned long new_xtime_seconds)
+{
+	if (unlikely((long)(new_xtime_seconds - xtime_seconds) > 0))
+		__update_xtime_seconds(new_xtime_seconds);
+}
+
 static inline unsigned long get_seconds(void)
 {
-	return xtime.tv_sec;
+	return xtime_seconds;
 }
 
 struct timespec current_kernel_time(void);
 
 #define CURRENT_TIME		(current_kernel_time())
-#define CURRENT_TIME_SEC	((struct timespec) { xtime.tv_sec, 0 })
+#define CURRENT_TIME_SEC	((struct timespec) { xtime_seconds, 0 })
 
 extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday(struct timespec *tv);
Index: linux-cfs-2.6.22.q/kernel/time.c
===================================================================
--- linux-cfs-2.6.22.q.orig/kernel/time.c
+++ linux-cfs-2.6.22.q/kernel/time.c
@@ -58,11 +58,10 @@ EXPORT_SYMBOL(sys_tz);
 asmlinkage long sys_time(time_t __user * tloc)
 {
 	/*
-	 * We read xtime.tv_sec atomically - it's updated
-	 * atomically by update_wall_time(), so no need to
-	 * even read-lock the xtime seqlock:
+	 * We read xtime_seconds atomically - it's updated
+	 * atomically by update_xtime_seconds():
 	 */
-	time_t i = xtime.tv_sec;
+	time_t i = xtime_seconds;
 
 	smp_rmb(); /* sys_time() results are coherent */
 
@@ -226,11 +225,11 @@ inline struct timespec current_kernel_ti
 
 	do {
 		seq = read_seqbegin(&xtime_lock);
-		
+
 		now = xtime;
 	} while (read_seqretry(&xtime_lock, seq));
 
-	return now; 
+	return now;
 }
 
 EXPORT_SYMBOL(current_kernel_time);
@@ -377,19 +376,7 @@ void do_gettimeofday (struct timeval *tv
 	tv->tv_sec = sec;
 	tv->tv_usec = usec;
 
-	/*
-	 * Make sure xtime.tv_sec [returned by sys_time()] always
-	 * follows the gettimeofday() result precisely. This
-	 * condition is extremely unlikely, it can hit at most
-	 * once per second:
-	 */
-	if (unlikely(xtime.tv_sec != tv->tv_sec)) {
-		unsigned long flags;
-
-		write_seqlock_irqsave(&xtime_lock);
-		update_wall_time();
-		write_seqlock_irqrestore(&xtime_lock);
-	}
+	update_xtime_seconds(sec);
 }
 
 EXPORT_SYMBOL(do_gettimeofday);
Index: linux-cfs-2.6.22.q/kernel/time/timekeeping.c
===================================================================
--- linux-cfs-2.6.22.q.orig/kernel/time/timekeeping.c
+++ linux-cfs-2.6.22.q/kernel/time/timekeeping.c
@@ -38,13 +38,26 @@ EXPORT_SYMBOL(xtime_lock);
  * the usual normalization.
  */
 struct timespec xtime __attribute__ ((aligned (16)));
-struct timespec wall_to_monotonic __attribute__ ((aligned (16)));
-
 EXPORT_SYMBOL(xtime);
 
+struct timespec wall_to_monotonic __attribute__ ((aligned (16))) __read_mostly;
+
+unsigned long xtime_seconds __read_mostly;
+
+/* pointer to current clocksource: */
+static struct clocksource *clock __read_mostly;
 
-static struct clocksource *clock; /* pointer to current clocksource */
+/*
+ * Called when either xtime or any xtime-alike result back to
+ * user-space overflows the xtime_seconds field:
+ */
+void __update_xtime_seconds(unsigned long new_xtime_seconds)
+{
+	unsigned long old_xtime_seconds = xtime_seconds;
 
+	if ((long)(new_xtime_seconds - old_xtime_seconds) > 0)
+		cmpxchg(&xtime_seconds, old_xtime_seconds, new_xtime_seconds);
+}
 
 #ifdef CONFIG_GENERIC_TIME
 /**
@@ -92,6 +105,8 @@ static inline void __get_realtime_clock_
 	} while (read_seqretry(&xtime_lock, seq));
 
 	timespec_add_ns(ts, nsecs);
+
+	update_xtime_seconds(ts->tv_sec);
 }
 
 /**
@@ -248,6 +263,8 @@ void __init timekeeping_init(void)
 	clock->cycle_last = clocksource_read(clock);
 
 	xtime.tv_sec = sec;
+	update_xtime_seconds(sec);
+
 	xtime.tv_nsec = 0;
 	set_normalized_timespec(&wall_to_monotonic,
 		-xtime.tv_sec, -xtime.tv_nsec);
@@ -281,6 +298,8 @@ static int timekeeping_resume(struct sys
 		unsigned long sleep_length = now - timekeeping_suspend_time;
 
 		xtime.tv_sec += sleep_length;
+		update_xtime_seconds(xtime.tv_sec);
+
 		wall_to_monotonic.tv_sec -= sleep_length;
 	}
 	/* re-base the last cycle value */
@@ -454,6 +473,7 @@ void update_wall_time(void)
 			clock->xtime_nsec -= (u64)NSEC_PER_SEC << clock->shift;
 			xtime.tv_sec++;
 			second_overflow();
+			update_xtime_seconds(xtime.tv_sec);
 		}
 
 		/* interpolator bits */
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch] CFS scheduler, -v19, Ingo Molnar, (Fri Jul 6, 1:33 pm)
Re: [patch] CFS scheduler, -v19, Ed Tomlinson, (Sat Jul 14, 1:19 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Mon Jul 16, 5:17 am)
Re: [patch] CFS scheduler, -v19, Ed Tomlinson, (Mon Jul 16, 7:10 am)
Re: [patch] CFS scheduler, -v19, Mike Galbraith, (Sun Jul 15, 1:25 am)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Mon Jul 16, 4:00 am)
Re: [patch] CFS scheduler, -v19, Markus, (Sun Jul 15, 8:53 am)
Re: [patch] CFS scheduler, -v19, Mike Galbraith, (Sun Jul 15, 3:46 pm)
Re: [patch] CFS scheduler, -v19, Markus, (Sun Jul 15, 5:11 pm)
Re: [patch] CFS scheduler, -v19, Mike Galbraith, (Mon Jul 16, 2:42 am)
Re: [patch] CFS scheduler, -v19, Markus, (Sat Jul 14, 7:34 am)
Re: [patch] CFS scheduler, -v19, Markus, (Sat Jul 14, 11:11 am)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Mon Jul 16, 5:41 am)
Re: [patch] CFS scheduler, -v19, Markus, (Mon Jul 16, 1:59 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Tue Jul 17, 3:37 am)
Re: [patch] CFS scheduler, -v19, Markus, (Tue Jul 17, 9:06 am)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Tue Jul 17, 1:06 pm)
Re: [patch] CFS scheduler, -v19, Markus, (Tue Jul 17, 3:42 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Tue Jul 17, 4:09 pm)
Re: [patch] CFS scheduler, -v19, Linus Torvalds, (Tue Jul 17, 4:37 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Tue Jul 17, 4:43 pm)
Re: [patch] CFS scheduler, -v19, Markus, (Tue Oct 16, 8:02 pm)
Re: [patch] CFS scheduler, -v19, Markus, (Thu Aug 9, 1:34 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Fri Aug 10, 3:46 am)
Re: [patch] CFS scheduler, -v19, Markus, (Tue Aug 14, 1:15 pm)
Re: [patch] CFS scheduler, -v19, Markus, (Fri Jul 20, 6:26 pm)
Re: [patch] CFS scheduler, -v19, Markus, (Tue Jul 17, 6:03 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Tue Jul 17, 1:13 pm)
Re: [patch] CFS scheduler, -v19, Mike Galbraith, (Tue Jul 10, 4:08 am)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Wed Jul 11, 1:26 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Wed Jul 11, 4:55 pm)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Fri Jul 13, 5:19 pm)
Re: [patch] CFS scheduler, -v19, Chuck Ebbert, (Mon Jul 16, 5:34 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Mon Jul 16, 5:55 pm)
Re: [patch] CFS scheduler, -v19, Ian Kent, (Tue Jul 17, 1:01 am)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Tue Jul 17, 3:45 am)
Re: [patch] CFS scheduler, -v19, Linus Torvalds, (Wed Jul 18, 12:03 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Thu Jul 19, 4:16 am)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Wed Jul 18, 5:37 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Thu Jul 19, 10:32 am)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Thu Jul 19, 10:32 pm)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Thu Jul 19, 1:06 pm)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Thu Jul 19, 1:26 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Thu Jul 19, 1:42 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Thu Jul 19, 1:17 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Thu Jul 19, 1:10 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Thu Jul 19, 4:53 am)
Re: [patch] CFS scheduler, -v19, Ian Kent, (Wed Jul 18, 1:31 pm)
RE: [patch] CFS scheduler, -v19, David Schwartz, (Tue Jul 17, 5:16 pm)
RE: [patch] CFS scheduler, -v19, Ian Kent, (Wed Jul 18, 1:59 am)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Wed Jul 18, 3:54 am)
Re: [patch] CFS scheduler, -v19, Linus Torvalds, (Wed Jul 18, 1:23 pm)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Wed Jul 18, 9:50 am)
Re: [patch] CFS scheduler, -v19, Chuck Ebbert, (Tue Jul 17, 12:30 pm)
Re: [patch] CFS scheduler, -v19, Ian Kent, (Tue Jul 17, 7:17 am)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Tue Jul 17, 1:16 pm)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Tue Jul 17, 9:24 pm)
Re: [patch] CFS scheduler, -v19, Ian Kent, (Wed Jul 18, 2:19 am)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Tue Jul 17, 12:22 am)
Re: [patch] CFS scheduler, -v19, Bill Davidsen, (Thu Jul 12, 8:41 am)
Re: [patch] CFS scheduler, -v19, Willy Tarreau, (Sun Jul 8, 1:46 pm)
Re: [patch] CFS scheduler, -v19, Ingo Molnar, (Mon Jul 9, 6:39 pm)
Re: [patch] CFS scheduler, -v19, Willy Tarreau, (Tue Jul 17, 5:44 pm)
speck-geostationary