Message ID | 20090527001543.GA8493@linux-sh.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
On Wed, 2009-05-27 at 09:15 +0900, Paul Mundt wrote: > unsigned long long __attribute__((weak)) sched_clock(void) > { > + /* > + * Use the current clocksource when it becomes available later in > + * the boot process, and ensure that it is usable for sched_clock(). > + */ > + if (clock && (clock->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK)) > + return cyc2ns(clock, clocksource_read(clock)); > + > + /* Otherwise just fall back on jiffies */ > return (unsigned long long)(jiffies - INITIAL_JIFFIES) Do we really need all this complexity in a fast path? the jiffies clocksource is static and always ready. Could we instead remove the usage of "clock" and create a new pointer called "sched_clocksource" and initialize it to the jiffies clock, and allow the clocksource management code to update that new pointer based on the CLOCK_SOURCE_USE_FOR_SCHED_CLOCK flag when new clocksources are registered/removed/marked unstable etc.. that would eliminate all the code in sched_clock except one line, unsigned long long __attribute__((weak)) sched_clock(void) { return cyc2ns(sched_clocksource, clocksource_read(sched_clocksource)); } Daniel -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, May 27, 2009 at 09:25:25AM -0700, Daniel Walker wrote: > On Wed, 2009-05-27 at 09:15 +0900, Paul Mundt wrote: > > > unsigned long long __attribute__((weak)) sched_clock(void) > > { > > + /* > > + * Use the current clocksource when it becomes available later in > > + * the boot process, and ensure that it is usable for sched_clock(). > > + */ > > + if (clock && (clock->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK)) > > + return cyc2ns(clock, clocksource_read(clock)); > > + > > + /* Otherwise just fall back on jiffies */ > > return (unsigned long long)(jiffies - INITIAL_JIFFIES) > > Do we really need all this complexity in a fast path? the jiffies > clocksource is static and always ready. Could we instead remove the > usage of "clock" and create a new pointer called "sched_clocksource" and > initialize it to the jiffies clock, and allow the clocksource management > code to update that new pointer based on the > CLOCK_SOURCE_USE_FOR_SCHED_CLOCK flag when new clocksources are > registered/removed/marked unstable etc.. > > that would eliminate all the code in sched_clock except one line, > > unsigned long long __attribute__((weak)) sched_clock(void) > { > return cyc2ns(sched_clocksource, clocksource_read(sched_clocksource)); > } > It would, but then what would that do to the sched_clock() value? It will reset once a CLOCK_SOURCE_USE_FOR_SCHED_CLOCK clocksource comes along, which basically means that sched_clock() then rolls back, which is worse than simply being delayed a bit. So even if we were to use a special sched_clocksource, it still could not be used until it was set up at registration time. Now we could of course add a sched_clocksource assignment in select_clocksource(), but that's really no different than just testing 'clock' as we do today. All it does is move the flag test in to a different path. So, I think the current v3 is still the best solution. -- To unsubscribe from this list: send the line "unsubscribe linux-sh" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h index c56457c..70d156f 100644 --- a/include/linux/clocksource.h +++ b/include/linux/clocksource.h @@ -212,6 +212,7 @@ extern struct clocksource *clock; /* current clocksource */ #define CLOCK_SOURCE_WATCHDOG 0x10 #define CLOCK_SOURCE_VALID_FOR_HRES 0x20 +#define CLOCK_SOURCE_USE_FOR_SCHED_CLOCK 0x40 /* simplify initialization of mask field */ #define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1) diff --git a/kernel/sched_clock.c b/kernel/sched_clock.c index e1d16c9..a0c18da 100644 --- a/kernel/sched_clock.c +++ b/kernel/sched_clock.c @@ -30,6 +30,7 @@ #include <linux/percpu.h> #include <linux/ktime.h> #include <linux/sched.h> +#include <linux/clocksource.h> /* * Scheduler clock - returns current time in nanosec units. @@ -38,6 +39,14 @@ */ unsigned long long __attribute__((weak)) sched_clock(void) { + /* + * Use the current clocksource when it becomes available later in + * the boot process, and ensure that it is usable for sched_clock(). + */ + if (clock && (clock->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK)) + return cyc2ns(clock, clocksource_read(clock)); + + /* Otherwise just fall back on jiffies */ return (unsigned long long)(jiffies - INITIAL_JIFFIES) * (NSEC_PER_SEC / HZ); }