* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-26 23:08 ` Paul Mundt
@ 2009-05-26 23:13 ` Paul Mundt
2009-05-26 23:25 ` john stultz
2009-05-26 23:49 ` Thomas Gleixner
2 siblings, 0 replies; 57+ messages in thread
From: Paul Mundt @ 2009-05-26 23:13 UTC (permalink / raw)
To: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Wed, May 27, 2009 at 08:08:55AM +0900, Paul Mundt wrote:
> On Tue, May 26, 2009 at 10:17:02PM +0200, Thomas Gleixner wrote:
> > On Tue, 26 May 2009, Peter Zijlstra wrote:
> > > On Tue, 2009-05-26 at 16:31 +0200, Linus Walleij wrote:
> > > > The definition of "rating" from the kerneldoc does not
> > > > seem to imply that, it's a subjective measure AFAICT.
> >
> > Right, there is no rating threshold defined, which allows to deduce
> > that. The TSC on x86 which might be unreliable, but usable as
> > sched_clock has an initial rating of 300 which can be changed later
> > on to 0 when the TSC is unusable as a time of day source. In that
> > case clock is replaced by HPET which has a rating > 100 but is
> > definitely not a good choice for sched_clock
> >
> > > > Else you might want an additional criteria, like
> > > > cyc2ns(1) (much less than) jiffies_to_usecs(1)*1000
> > > > (however you do that the best way)
> > > > so you don't pick something
> > > > that isn't substantially faster than the jiffy counter atleast?
> >
> > What we can do is add another flag to the clocksource e.g.
> > CLOCK_SOURCE_USE_FOR_SCHED_CLOCK and check this instead of the
> > rating.
> >
> Ok, so based on this and John's locking concerns, how about something
> like this? It doesn't handle the wrapping cases, but I wonder if we
> really want to add that amount of logic to sched_clock() in the first
> place. Clocksources that wrap frequently could either leave the flag
> unset, or do something similar to the TSC code where the cyc2ns shift is
> used. If this is something we want to handle generically, then I'll have
> a go at generalizing the TSC cyc2ns scaling bits for the next spin.
>
Lets try that again..
---
include/linux/clocksource.h | 2 ++
kernel/sched_clock.c | 22 ++++++++++++++++++++++
kernel/time/clocksource.c | 2 +-
3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index c56457c..cfd873e 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -203,6 +203,7 @@ struct clocksource {
};
extern struct clocksource *clock; /* current clocksource */
+extern spinlock_t clocksource_lock;
/*
* Clock source flags bits::
@@ -212,6 +213,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..c7027cd 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,27 @@
*/
unsigned long long __attribute__((weak)) sched_clock(void)
{
+ /*
+ * Use the current clocksource when it becomes available later in
+ * the boot process. As this needs to be fast, we only make a
+ * single pass at grabbing the spinlock. If the clock is changing
+ * out from underneath us, fall back on jiffies and try it again
+ * the next time around.
+ */
+ if (clock && _raw_spin_trylock(&clocksource_lock)) {
+ /*
+ * Only use clocksources suitable for sched_clock()
+ */
+ if (clock->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK) {
+ cycle_t now = cyc2ns(clock, clocksource_read(clock));
+ _raw_spin_unlock(&clocksource_lock);
+ return now;
+ }
+
+ _raw_spin_unlock(&clocksource_lock);
+ }
+
+ /* If all else fails, fall back on jiffies */
return (unsigned long long)(jiffies - INITIAL_JIFFIES)
* (NSEC_PER_SEC / HZ);
}
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 80189f6..437a6cf 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -127,7 +127,7 @@ static struct clocksource *curr_clocksource = &clocksource_jiffies;
static struct clocksource *next_clocksource;
static struct clocksource *clocksource_override;
static LIST_HEAD(clocksource_list);
-static DEFINE_SPINLOCK(clocksource_lock);
+DEFINE_SPINLOCK(clocksource_lock);
static char override_name[32];
static int finished_booting;
^ permalink raw reply related [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-26 23:08 ` Paul Mundt
2009-05-26 23:13 ` Paul Mundt
@ 2009-05-26 23:25 ` john stultz
2009-05-26 23:44 ` Paul Mundt
2009-05-26 23:49 ` Thomas Gleixner
2 siblings, 1 reply; 57+ messages in thread
From: john stultz @ 2009-05-26 23:25 UTC (permalink / raw)
To: Paul Mundt
Cc: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Wed, 2009-05-27 at 08:08 +0900, Paul Mundt wrote:
> On Tue, May 26, 2009 at 10:17:02PM +0200, Thomas Gleixner wrote:
> > On Tue, 26 May 2009, Peter Zijlstra wrote:
> > > On Tue, 2009-05-26 at 16:31 +0200, Linus Walleij wrote:
> > > > The definition of "rating" from the kerneldoc does not
> > > > seem to imply that, it's a subjective measure AFAICT.
> >
> > Right, there is no rating threshold defined, which allows to deduce
> > that. The TSC on x86 which might be unreliable, but usable as
> > sched_clock has an initial rating of 300 which can be changed later
> > on to 0 when the TSC is unusable as a time of day source. In that
> > case clock is replaced by HPET which has a rating > 100 but is
> > definitely not a good choice for sched_clock
> >
> > > > Else you might want an additional criteria, like
> > > > cyc2ns(1) (much less than) jiffies_to_usecs(1)*1000
> > > > (however you do that the best way)
> > > > so you don't pick something
> > > > that isn't substantially faster than the jiffy counter atleast?
> >
> > What we can do is add another flag to the clocksource e.g.
> > CLOCK_SOURCE_USE_FOR_SCHED_CLOCK and check this instead of the
> > rating.
> >
> Ok, so based on this and John's locking concerns, how about something
> like this? It doesn't handle the wrapping cases, but I wonder if we
> really want to add that amount of logic to sched_clock() in the first
> place. Clocksources that wrap frequently could either leave the flag
> unset, or do something similar to the TSC code where the cyc2ns shift is
> used. If this is something we want to handle generically, then I'll have
> a go at generalizing the TSC cyc2ns scaling bits for the next spin.
Yea. So this is a little better. There's still a few other issues to
consider:
1) What if a clocksource is registered that has the _SCHED_CLOCK bit
set, but is not selected for timekeeping due it being unstable like the
TSC?
2) Conditionally returning jiffies if the lock is held seems troubling.
Might get some crazy values that way.
thanks
-john
> ---
>
> include/linux/clocksource.h | 2 ++
> kernel/sched_clock.c | 22 ++++++++++++++++++++++
> 2 files changed, 24 insertions(+)
>
> diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
> index c56457c..cfd873e 100644
> --- a/include/linux/clocksource.h
> +++ b/include/linux/clocksource.h
> @@ -203,6 +203,7 @@ struct clocksource {
> };
>
> extern struct clocksource *clock; /* current clocksource */
> +extern spinlock_t clocksource_lock;
>
> /*
> * Clock source flags bits::
> @@ -212,6 +213,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..c7027cd 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,27 @@
> */
> unsigned long long __attribute__((weak)) sched_clock(void)
> {
> + /*
> + * Use the current clocksource when it becomes available later in
> + * the boot process. As this needs to be fast, we only make a
> + * single pass at grabbing the spinlock. If the clock is changing
> + * out from underneath us, fall back on jiffies and try it again
> + * the next time around.
> + */
> + if (clock && _raw_spin_trylock(&clocksource_lock)) {
> + /*
> + * Only use clocksources suitable for sched_clock()
> + */
> + if (clock->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK) {
> + cycle_t now = cyc2ns(clock, clocksource_read(clock));
> + _raw_spin_unlock(&clocksource_lock);
> + return now;
> + }
> +
> + _raw_spin_unlock(&clocksource_lock);
> + }
> +
> + /* If all else fails, fall back on jiffies */
> return (unsigned long long)(jiffies - INITIAL_JIFFIES)
> * (NSEC_PER_SEC / HZ);
> }
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-26 23:25 ` john stultz
@ 2009-05-26 23:44 ` Paul Mundt
2009-05-27 0:18 ` Thomas Gleixner
2009-05-27 0:22 ` john stultz
0 siblings, 2 replies; 57+ messages in thread
From: Paul Mundt @ 2009-05-26 23:44 UTC (permalink / raw)
To: john stultz
Cc: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Tue, May 26, 2009 at 04:25:03PM -0700, john stultz wrote:
> On Wed, 2009-05-27 at 08:08 +0900, Paul Mundt wrote:
> > On Tue, May 26, 2009 at 10:17:02PM +0200, Thomas Gleixner wrote:
> > > On Tue, 26 May 2009, Peter Zijlstra wrote:
> > > > On Tue, 2009-05-26 at 16:31 +0200, Linus Walleij wrote:
> > > > > The definition of "rating" from the kerneldoc does not
> > > > > seem to imply that, it's a subjective measure AFAICT.
> > >
> > > Right, there is no rating threshold defined, which allows to deduce
> > > that. The TSC on x86 which might be unreliable, but usable as
> > > sched_clock has an initial rating of 300 which can be changed later
> > > on to 0 when the TSC is unusable as a time of day source. In that
> > > case clock is replaced by HPET which has a rating > 100 but is
> > > definitely not a good choice for sched_clock
> > >
> > > > > Else you might want an additional criteria, like
> > > > > cyc2ns(1) (much less than) jiffies_to_usecs(1)*1000
> > > > > (however you do that the best way)
> > > > > so you don't pick something
> > > > > that isn't substantially faster than the jiffy counter atleast?
> > >
> > > What we can do is add another flag to the clocksource e.g.
> > > CLOCK_SOURCE_USE_FOR_SCHED_CLOCK and check this instead of the
> > > rating.
> > >
> > Ok, so based on this and John's locking concerns, how about something
> > like this? It doesn't handle the wrapping cases, but I wonder if we
> > really want to add that amount of logic to sched_clock() in the first
> > place. Clocksources that wrap frequently could either leave the flag
> > unset, or do something similar to the TSC code where the cyc2ns shift is
> > used. If this is something we want to handle generically, then I'll have
> > a go at generalizing the TSC cyc2ns scaling bits for the next spin.
>
>
> Yea. So this is a little better. There's still a few other issues to
> consider:
>
> 1) What if a clocksource is registered that has the _SCHED_CLOCK bit
> set, but is not selected for timekeeping due it being unstable like the
> TSC?
>
See, this is what I thought the rating information was useful for, as the
rating is subsequently dropped if it is not usable. But perhaps it makes
more sense to just clear the bit at the same time that the rating is
lowered once it turns out to be unstable.
> 2) Conditionally returning jiffies if the lock is held seems troubling.
> Might get some crazy values that way.
>
What would you recommend instead? We do not want to spin here, and if we
are in the middle of changing clocksources and returning jiffies anyways,
then this same issue pops up in the current sched_clock() implementation
regardless of whether we are testing for lock contention or not.
Likewise, even if we were to spin, the same situation exists if the new
clocksource does not have the _SCHED_CLOCK bit set and we have to fall
back on jiffies anyways, doesn't it?
Put another way, and unless I'm missing something obvious, if we ignore
my changes to sched_clock(), how is your concern not applicable to case
where we are changing clocksources and using generic sched_clock() as it
is today?
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-26 23:44 ` Paul Mundt
@ 2009-05-27 0:18 ` Thomas Gleixner
2009-05-27 0:22 ` john stultz
1 sibling, 0 replies; 57+ messages in thread
From: Thomas Gleixner @ 2009-05-27 0:18 UTC (permalink / raw)
To: Paul Mundt
Cc: john stultz, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Wed, 27 May 2009, Paul Mundt wrote:
> > Yea. So this is a little better. There's still a few other issues to
> > consider:
> >
> > 1) What if a clocksource is registered that has the _SCHED_CLOCK bit
> > set, but is not selected for timekeeping due it being unstable like the
> > TSC?
> >
> See, this is what I thought the rating information was useful for, as the
> rating is subsequently dropped if it is not usable. But perhaps it makes
> more sense to just clear the bit at the same time that the rating is
> lowered once it turns out to be unstable.
Stop worrying about TSC please. The x86 f*cked up timers need special
handling which is definitely not required for most of arch/*. x86
overrides that anyway and handles the TSC f*ckup in the
CONFIG_HAVE_UNSTABLE_SCHED_CLOCK section of sched_clock.c which is
completely irrelevant to any architecture which has a sane set of
timers.
The only extra magic which is required to avoid that (sub)arch
maintainers need to specify a sched_clock() implementation to override
the weak generic one is really the simple
if (clock && (clock->flags & CLOCKSOURCE_USE_FOR_SCHED_CLOCK))
return ....
We need no locking there at all.
We have a workaround in place, which overrides the weak sched_clock()
implementation, to make x86 efficient, so why do we want to impose all
that x86 crap on folks which deal with architectures which got the
timers right ?
Thanks,
tglx
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-26 23:44 ` Paul Mundt
2009-05-27 0:18 ` Thomas Gleixner
@ 2009-05-27 0:22 ` john stultz
2009-05-27 0:26 ` Paul Mundt
2009-05-27 0:27 ` Thomas Gleixner
1 sibling, 2 replies; 57+ messages in thread
From: john stultz @ 2009-05-27 0:22 UTC (permalink / raw)
To: Paul Mundt
Cc: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel
On Wed, 2009-05-27 at 08:44 +0900, Paul Mundt wrote:
> On Tue, May 26, 2009 at 04:25:03PM -0700, john stultz wrote:
> > On Wed, 2009-05-27 at 08:08 +0900, Paul Mundt wrote:
> > > On Tue, May 26, 2009 at 10:17:02PM +0200, Thomas Gleixner wrote:
> > > > On Tue, 26 May 2009, Peter Zijlstra wrote:
> > > > > On Tue, 2009-05-26 at 16:31 +0200, Linus Walleij wrote:
> > > > > > The definition of "rating" from the kerneldoc does not
> > > > > > seem to imply that, it's a subjective measure AFAICT.
> > > >
> > > > Right, there is no rating threshold defined, which allows to deduce
> > > > that. The TSC on x86 which might be unreliable, but usable as
> > > > sched_clock has an initial rating of 300 which can be changed later
> > > > on to 0 when the TSC is unusable as a time of day source. In that
> > > > case clock is replaced by HPET which has a rating > 100 but is
> > > > definitely not a good choice for sched_clock
> > > >
> > > > > > Else you might want an additional criteria, like
> > > > > > cyc2ns(1) (much less than) jiffies_to_usecs(1)*1000
> > > > > > (however you do that the best way)
> > > > > > so you don't pick something
> > > > > > that isn't substantially faster than the jiffy counter atleast?
> > > >
> > > > What we can do is add another flag to the clocksource e.g.
> > > > CLOCK_SOURCE_USE_FOR_SCHED_CLOCK and check this instead of the
> > > > rating.
> > > >
> > > Ok, so based on this and John's locking concerns, how about something
> > > like this? It doesn't handle the wrapping cases, but I wonder if we
> > > really want to add that amount of logic to sched_clock() in the first
> > > place. Clocksources that wrap frequently could either leave the flag
> > > unset, or do something similar to the TSC code where the cyc2ns shift is
> > > used. If this is something we want to handle generically, then I'll have
> > > a go at generalizing the TSC cyc2ns scaling bits for the next spin.
> >
> >
> > Yea. So this is a little better. There's still a few other issues to
> > consider:
> >
> > 1) What if a clocksource is registered that has the _SCHED_CLOCK bit
> > set, but is not selected for timekeeping due it being unstable like the
> > TSC?
> >
> See, this is what I thought the rating information was useful for, as the
> rating is subsequently dropped if it is not usable. But perhaps it makes
> more sense to just clear the bit at the same time that the rating is
> lowered once it turns out to be unstable.
Yes, if we're dropping a clocksource we should also drop the bit. That
shouldn't be a problem.
The point I was making, is that multiple clocksources may be registered
at one time (TSC, ACPI_PM, etc). But only one is being managed by the
timekeeping code (clock). So there may be the case where the
sched_clock() is different then the timekeeping clock (which is common
on x86).
So I suspect we need a special hook that grabs the best _SCHED_CLOCK
clocksource (as computed at clocksource registration time) and provides
it to the generic sched_clock() interface.
> > 2) Conditionally returning jiffies if the lock is held seems troubling.
> > Might get some crazy values that way.
> >
> What would you recommend instead? We do not want to spin here, and if we
> are in the middle of changing clocksources and returning jiffies anyways,
> then this same issue pops up in the current sched_clock() implementation
> regardless of whether we are testing for lock contention or not.
> Likewise, even if we were to spin, the same situation exists if the new
> clocksource does not have the _SCHED_CLOCK bit set and we have to fall
> back on jiffies anyways, doesn't it?
>
> Put another way, and unless I'm missing something obvious, if we ignore
> my changes to sched_clock(), how is your concern not applicable to case
> where we are changing clocksources and using generic sched_clock() as it
> is today?
Well, Thomas' point that locking isn't necessary, as sched_clock()
doesn't have to be correct, is probably right.
So, I think a get_sched_clocksource() interface would be ideal (if we
want to get academic at a later date, the pointer could be atomically
updated, and we'd keep it valid for some time via an rcu like method).
Additionally, you can set the jiffies clocksource as a _SCHED_CLOCK
clocksource and drop the jiffies fallback code completely.
thanks
-john
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-27 0:22 ` john stultz
@ 2009-05-27 0:26 ` Paul Mundt
2009-05-27 1:09 ` john stultz
2009-05-27 0:27 ` Thomas Gleixner
1 sibling, 1 reply; 57+ messages in thread
From: Paul Mundt @ 2009-05-27 0:26 UTC (permalink / raw)
To: john stultz
Cc: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel
On Tue, May 26, 2009 at 05:22:10PM -0700, john stultz wrote:
> On Wed, 2009-05-27 at 08:44 +0900, Paul Mundt wrote:
> > What would you recommend instead? We do not want to spin here, and if we
> > are in the middle of changing clocksources and returning jiffies anyways,
> > then this same issue pops up in the current sched_clock() implementation
> > regardless of whether we are testing for lock contention or not.
> > Likewise, even if we were to spin, the same situation exists if the new
> > clocksource does not have the _SCHED_CLOCK bit set and we have to fall
> > back on jiffies anyways, doesn't it?
> >
> > Put another way, and unless I'm missing something obvious, if we ignore
> > my changes to sched_clock(), how is your concern not applicable to case
> > where we are changing clocksources and using generic sched_clock() as it
> > is today?
>
> Well, Thomas' point that locking isn't necessary, as sched_clock()
> doesn't have to be correct, is probably right.
>
> So, I think a get_sched_clocksource() interface would be ideal (if we
> want to get academic at a later date, the pointer could be atomically
> updated, and we'd keep it valid for some time via an rcu like method).
>
> Additionally, you can set the jiffies clocksource as a _SCHED_CLOCK
> clocksource and drop the jiffies fallback code completely.
>
I thought about that initially as well, but in the case of the jiffies
clocksource, that won't handle INITIAL_JIFFIES, which we want to subtract
to make printk times sane.
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-27 0:26 ` Paul Mundt
@ 2009-05-27 1:09 ` john stultz
0 siblings, 0 replies; 57+ messages in thread
From: john stultz @ 2009-05-27 1:09 UTC (permalink / raw)
To: Paul Mundt
Cc: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel
On Wed, 2009-05-27 at 09:26 +0900, Paul Mundt wrote:
> On Tue, May 26, 2009 at 05:22:10PM -0700, john stultz wrote:
> > On Wed, 2009-05-27 at 08:44 +0900, Paul Mundt wrote:
> > > What would you recommend instead? We do not want to spin here, and if we
> > > are in the middle of changing clocksources and returning jiffies anyways,
> > > then this same issue pops up in the current sched_clock() implementation
> > > regardless of whether we are testing for lock contention or not.
> > > Likewise, even if we were to spin, the same situation exists if the new
> > > clocksource does not have the _SCHED_CLOCK bit set and we have to fall
> > > back on jiffies anyways, doesn't it?
> > >
> > > Put another way, and unless I'm missing something obvious, if we ignore
> > > my changes to sched_clock(), how is your concern not applicable to case
> > > where we are changing clocksources and using generic sched_clock() as it
> > > is today?
> >
> > Well, Thomas' point that locking isn't necessary, as sched_clock()
> > doesn't have to be correct, is probably right.
> >
> > So, I think a get_sched_clocksource() interface would be ideal (if we
> > want to get academic at a later date, the pointer could be atomically
> > updated, and we'd keep it valid for some time via an rcu like method).
> >
> > Additionally, you can set the jiffies clocksource as a _SCHED_CLOCK
> > clocksource and drop the jiffies fallback code completely.
> >
> I thought about that initially as well, but in the case of the jiffies
> clocksource, that won't handle INITIAL_JIFFIES, which we want to subtract
> to make printk times sane.
Fair point, but that shouldn't be a big issue, we can fix that in the
jiffies clocksource read() implementation.
thanks
-john
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-27 0:22 ` john stultz
2009-05-27 0:26 ` Paul Mundt
@ 2009-05-27 0:27 ` Thomas Gleixner
1 sibling, 0 replies; 57+ messages in thread
From: Thomas Gleixner @ 2009-05-27 0:27 UTC (permalink / raw)
To: john stultz
Cc: Paul Mundt, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel
John,
On Tue, 26 May 2009, john stultz wrote:
> > See, this is what I thought the rating information was useful for, as the
> > rating is subsequently dropped if it is not usable. But perhaps it makes
> > more sense to just clear the bit at the same time that the rating is
> > lowered once it turns out to be unstable.
>
> Yes, if we're dropping a clocksource we should also drop the bit. That
> shouldn't be a problem.
>
> The point I was making, is that multiple clocksources may be registered
> at one time (TSC, ACPI_PM, etc). But only one is being managed by the
> timekeeping code (clock). So there may be the case where the
> sched_clock() is different then the timekeeping clock (which is common
> on x86).
>
> So I suspect we need a special hook that grabs the best _SCHED_CLOCK
> clocksource (as computed at clocksource registration time) and provides
> it to the generic sched_clock() interface.
this is not about x86 and its inferiour timer hardware
implementation. We talk about sane architectures which do not have
that problems at all. x86 takes a different code path and overrides
the generic weak sched_clock implememtation anyway. So what ?
Thanks,
tglx
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-26 23:08 ` Paul Mundt
2009-05-26 23:13 ` Paul Mundt
2009-05-26 23:25 ` john stultz
@ 2009-05-26 23:49 ` Thomas Gleixner
2009-05-27 0:15 ` Paul Mundt
2 siblings, 1 reply; 57+ messages in thread
From: Thomas Gleixner @ 2009-05-26 23:49 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Linus Walleij, Ingo Molnar, Andrew Victor,
Haavard Skinnemoen, Andrew Morton, linux-kernel, linux-sh,
linux-arm-kernel, John Stultz
On Wed, 27 May 2009, Paul Mundt wrote:
> On Tue, May 26, 2009 at 10:17:02PM +0200, Thomas Gleixner wrote:
> > On Tue, 26 May 2009, Peter Zijlstra wrote:
> > > On Tue, 2009-05-26 at 16:31 +0200, Linus Walleij wrote:
> > > > The definition of "rating" from the kerneldoc does not
> > > > seem to imply that, it's a subjective measure AFAICT.
> >
> > Right, there is no rating threshold defined, which allows to deduce
> > that. The TSC on x86 which might be unreliable, but usable as
> > sched_clock has an initial rating of 300 which can be changed later
> > on to 0 when the TSC is unusable as a time of day source. In that
> > case clock is replaced by HPET which has a rating > 100 but is
> > definitely not a good choice for sched_clock
> >
> > > > Else you might want an additional criteria, like
> > > > cyc2ns(1) (much less than) jiffies_to_usecs(1)*1000
> > > > (however you do that the best way)
> > > > so you don't pick something
> > > > that isn't substantially faster than the jiffy counter atleast?
> >
> > What we can do is add another flag to the clocksource e.g.
> > CLOCK_SOURCE_USE_FOR_SCHED_CLOCK and check this instead of the
> > rating.
> >
> Ok, so based on this and John's locking concerns, how about something
> like this? It doesn't handle the wrapping cases, but I wonder if we
> really want to add that amount of logic to sched_clock() in the first
> place. Clocksources that wrap frequently could either leave the flag
> unset, or do something similar to the TSC code where the cyc2ns shift is
> used. If this is something we want to handle generically, then I'll have
> a go at generalizing the TSC cyc2ns scaling bits for the next spin.
Gah. There is no locking issue. As Peter explained before the
scheduler code can cope with some inaccurate value.
The wrap issue is completly academic. If the current clock source has
a wrap issue then it needs to be addressed anyway by frequent enough
wakeups to assure correctness of timekeeping and that makes it
suitable for the sched clock domain as well. Also the scheduler can
not hit a value which has not gone through the irq_enter() based
update after a long idle sleep.
So changing your previous patch from
if (clock && clock->rating > 100)
to
if (clock && (clock->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK))
is sufficient.
Thanks,
tglx
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-26 23:49 ` Thomas Gleixner
@ 2009-05-27 0:15 ` Paul Mundt
2009-05-27 16:25 ` Daniel Walker
0 siblings, 1 reply; 57+ messages in thread
From: Paul Mundt @ 2009-05-27 0:15 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Peter Zijlstra, Linus Walleij, Ingo Molnar, Andrew Victor,
Haavard Skinnemoen, Andrew Morton, linux-kernel, linux-sh,
linux-arm-kernel, John Stultz
On Wed, May 27, 2009 at 01:49:33AM +0200, Thomas Gleixner wrote:
> On Wed, 27 May 2009, Paul Mundt wrote:
> > Ok, so based on this and John's locking concerns, how about something
> > like this? It doesn't handle the wrapping cases, but I wonder if we
> > really want to add that amount of logic to sched_clock() in the first
> > place. Clocksources that wrap frequently could either leave the flag
> > unset, or do something similar to the TSC code where the cyc2ns shift is
> > used. If this is something we want to handle generically, then I'll have
> > a go at generalizing the TSC cyc2ns scaling bits for the next spin.
>
> Gah. There is no locking issue. As Peter explained before the
> scheduler code can cope with some inaccurate value.
>
> The wrap issue is completly academic. If the current clock source has
> a wrap issue then it needs to be addressed anyway by frequent enough
> wakeups to assure correctness of timekeeping and that makes it
> suitable for the sched clock domain as well. Also the scheduler can
> not hit a value which has not gone through the irq_enter() based
> update after a long idle sleep.
>
> So changing your previous patch from
>
> if (clock && clock->rating > 100)
>
> to
>
> if (clock && (clock->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK))
>
> is sufficient.
>
Works for me.. here's v3 with an updated changelog.
--
sched: Support current clocksource handling in fallback sched_clock(), v3.
There are presently a number of issues and limitations with how the
clocksource and sched_clock() interaction works today. Configurations
tend to be grouped in to one of the following:
- Platform provides a clocksource unsuitable for sched_clock()
and prefers to use the generic jiffies-backed implementation.
- Platform provides its own clocksource and sched_clock() that
wraps in to it.
- Platform uses a generic clocksource (ie, drivers/clocksource/)
combined with the generic jiffies-backed sched_clock().
- Platform supports multiple sched_clock()-capable clocksources.
This patch adds a new CLOCK_SOURCE_USE_FOR_SCHED_CLOCK flag to address
these issues. The first case simply doesn't set the flag at all (or
clears it, if a clocksource is unstable), while the second case is made
redundant for any sched_clock() implementation that just does the
cyc2ns() case, which tends to be the vast majority of the embedded
platforms.
The remaining cases are handled transparently, in that sched_clock() will
always read from whatever the current clocksource is, as long as it is
has the flag set. This permits switching between multiple clocksources
which may or may not support being used by sched_clock(), and while some
inaccuracy may occur in these corner cases, the scheduler can live with
this.
Signed-off-by: Paul Mundt <lethal@linux-sh.org>
---
include/linux/clocksource.h | 1 +
kernel/sched_clock.c | 9 +++++++++
2 files changed, 10 insertions(+)
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);
}
^ permalink raw reply related [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-27 0:15 ` Paul Mundt
@ 2009-05-27 16:25 ` Daniel Walker
2009-05-28 8:44 ` Paul Mundt
2009-05-28 9:19 ` Paul Mundt
0 siblings, 2 replies; 57+ messages in thread
From: Daniel Walker @ 2009-05-27 16:25 UTC (permalink / raw)
To: Paul Mundt
Cc: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
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
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-27 16:25 ` Daniel Walker
@ 2009-05-28 8:44 ` Paul Mundt
2009-05-28 9:19 ` Paul Mundt
1 sibling, 0 replies; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 8:44 UTC (permalink / raw)
To: Daniel Walker
Cc: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
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.
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-27 16:25 ` Daniel Walker
2009-05-28 8:44 ` Paul Mundt
@ 2009-05-28 9:19 ` Paul Mundt
2009-05-28 9:34 ` Peter Zijlstra
1 sibling, 1 reply; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 9:19 UTC (permalink / raw)
To: Daniel Walker
Cc: Thomas Gleixner, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
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));
> }
>
Ok, there were some ordering problems with the early platform code, but
I've played with this a bit more and got it to the point where this now
also works. I can live with this over the v3 version if people prefer
this approach instead.
--
include/linux/clocksource.h | 4 +++-
kernel/sched_clock.c | 4 ++--
kernel/time/clocksource.c | 4 ++++
kernel/time/jiffies.c | 2 +-
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index c56457c..2109940 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -202,7 +202,8 @@ struct clocksource {
#endif
};
-extern struct clocksource *clock; /* current clocksource */
+extern struct clocksource *clock; /* current clocksource */
+extern struct clocksource *sched_clocksource; /* sched_clock() clocksource */
/*
* Clock source flags bits::
@@ -212,6 +213,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..c06c285 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,8 +39,7 @@
*/
unsigned long long __attribute__((weak)) sched_clock(void)
{
- return (unsigned long long)(jiffies - INITIAL_JIFFIES)
- * (NSEC_PER_SEC / HZ);
+ return cyc2ns(sched_clocksource, clocksource_read(sched_clocksource));
}
static __read_mostly int sched_clock_running;
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 80189f6..d148a75 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -109,6 +109,7 @@ EXPORT_SYMBOL(timecounter_cyc2time);
/* XXX - Would like a better way for initializing curr_clocksource */
extern struct clocksource clocksource_jiffies;
+struct clocksource *sched_clocksource = &clocksource_jiffies;
/*[Clocksource internal variables]---------
* curr_clocksource:
@@ -362,6 +363,9 @@ static struct clocksource *select_clocksource(void)
if (next == curr_clocksource)
return NULL;
+ if (next->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK)
+ sched_clocksource = next;
+
return next;
}
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index c3f6c30..727d881 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -52,7 +52,7 @@
static cycle_t jiffies_read(struct clocksource *cs)
{
- return (cycle_t) jiffies;
+ return (cycle_t) (jiffies - INITIAL_JIFFIES);
}
struct clocksource clocksource_jiffies = {
^ permalink raw reply related [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 9:19 ` Paul Mundt
@ 2009-05-28 9:34 ` Peter Zijlstra
2009-05-28 11:09 ` Paul Mundt
0 siblings, 1 reply; 57+ messages in thread
From: Peter Zijlstra @ 2009-05-28 9:34 UTC (permalink / raw)
To: Paul Mundt
Cc: Daniel Walker, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 2009-05-28 at 18:19 +0900, Paul Mundt wrote:
> Ok, there were some ordering problems with the early platform code, but
> I've played with this a bit more and got it to the point where this now
> also works. I can live with this over the v3 version if people prefer
> this approach instead.
>
> --
> @@ -38,8 +39,7 @@
> */
> unsigned long long __attribute__((weak)) sched_clock(void)
> {
> - return (unsigned long long)(jiffies - INITIAL_JIFFIES)
> - * (NSEC_PER_SEC / HZ);
> + return cyc2ns(sched_clocksource, clocksource_read(sched_clocksource));
> }
>
> static __read_mostly int sched_clock_running;
> @@ -362,6 +363,9 @@ static struct clocksource *select_clocksource(void)
> if (next == curr_clocksource)
> return NULL;
>
> + if (next->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK)
> + sched_clocksource = next;
> +
> return next;
> }
>
That's a single assignment, vs two reads on use. Should we be worried
about the SMP race where we observe two different sched_clocksource
pointers on read?
I would suggest we write it as:
u64 __weak sched_clock(void)
{
struct clocksource *clock = ACCESS_ONCE(sched_clocksource);
return cyc2ns(clock, clocksource_read(clock));
}
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 9:34 ` Peter Zijlstra
@ 2009-05-28 11:09 ` Paul Mundt
2009-05-28 12:22 ` Thomas Gleixner
0 siblings, 1 reply; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 11:09 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Daniel Walker, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 11:34:41AM +0200, Peter Zijlstra wrote:
> That's a single assignment, vs two reads on use. Should we be worried
> about the SMP race where we observe two different sched_clocksource
> pointers on read?
>
>
> I would suggest we write it as:
>
> u64 __weak sched_clock(void)
> {
> struct clocksource *clock = ACCESS_ONCE(sched_clocksource);
>
> return cyc2ns(clock, clocksource_read(clock));
> }
Here's an updated version, also with an added sanity check in the
unregister path..
--
include/linux/clocksource.h | 4 +++-
kernel/sched_clock.c | 6 ++++--
kernel/time/clocksource.c | 13 +++++++++++++
kernel/time/jiffies.c | 2 +-
4 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index c56457c..2109940 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -202,7 +202,8 @@ struct clocksource {
#endif
};
-extern struct clocksource *clock; /* current clocksource */
+extern struct clocksource *clock; /* current clocksource */
+extern struct clocksource *sched_clocksource; /* sched_clock() clocksource */
/*
* Clock source flags bits::
@@ -212,6 +213,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..b91190e 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,8 +39,9 @@
*/
unsigned long long __attribute__((weak)) sched_clock(void)
{
- return (unsigned long long)(jiffies - INITIAL_JIFFIES)
- * (NSEC_PER_SEC / HZ);
+ struct clocksource *clock = ACCESS_ONCE(sched_clocksource);
+
+ return cyc2ns(clock, clocksource_read(clock));
}
static __read_mostly int sched_clock_running;
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 80189f6..57b011a 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -109,6 +109,7 @@ EXPORT_SYMBOL(timecounter_cyc2time);
/* XXX - Would like a better way for initializing curr_clocksource */
extern struct clocksource clocksource_jiffies;
+struct clocksource *sched_clocksource = &clocksource_jiffies;
/*[Clocksource internal variables]---------
* curr_clocksource:
@@ -362,6 +363,9 @@ static struct clocksource *select_clocksource(void)
if (next == curr_clocksource)
return NULL;
+ if (next->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK)
+ sched_clocksource = next;
+
return next;
}
@@ -437,10 +441,19 @@ void clocksource_unregister(struct clocksource *cs)
unsigned long flags;
spin_lock_irqsave(&clocksource_lock, flags);
+
+ if (sched_clocksource == cs) {
+ printk(KERN_WARNING "Refusing to unregister "
+ "scheduler clocksource %s", cs->name);
+ goto out;
+ }
+
list_del(&cs->list);
if (clocksource_override == cs)
clocksource_override = NULL;
next_clocksource = select_clocksource();
+
+out:
spin_unlock_irqrestore(&clocksource_lock, flags);
}
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index c3f6c30..727d881 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -52,7 +52,7 @@
static cycle_t jiffies_read(struct clocksource *cs)
{
- return (cycle_t) jiffies;
+ return (cycle_t) (jiffies - INITIAL_JIFFIES);
}
struct clocksource clocksource_jiffies = {
^ permalink raw reply related [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 11:09 ` Paul Mundt
@ 2009-05-28 12:22 ` Thomas Gleixner
2009-05-28 12:40 ` Peter Zijlstra
2009-05-28 12:42 ` Paul Mundt
0 siblings, 2 replies; 57+ messages in thread
From: Thomas Gleixner @ 2009-05-28 12:22 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Daniel Walker, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 28 May 2009, Paul Mundt wrote:
> @@ -437,10 +441,19 @@ void clocksource_unregister(struct clocksource *cs)
> unsigned long flags;
>
> spin_lock_irqsave(&clocksource_lock, flags);
> +
> + if (sched_clocksource == cs) {
> + printk(KERN_WARNING "Refusing to unregister "
> + "scheduler clocksource %s", cs->name);
Hmm, isn't that dangerous ? The clocksource might be in a module or
in kmalloced memory which is going to be freed.
Thanks,
tglx
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 12:22 ` Thomas Gleixner
@ 2009-05-28 12:40 ` Peter Zijlstra
2009-05-28 12:42 ` Paul Mundt
1 sibling, 0 replies; 57+ messages in thread
From: Peter Zijlstra @ 2009-05-28 12:40 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Paul Mundt, Daniel Walker, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 2009-05-28 at 14:22 +0200, Thomas Gleixner wrote:
> On Thu, 28 May 2009, Paul Mundt wrote:
> > @@ -437,10 +441,19 @@ void clocksource_unregister(struct clocksource *cs)
> > unsigned long flags;
> >
> > spin_lock_irqsave(&clocksource_lock, flags);
> > +
> > + if (sched_clocksource == cs) {
> > + printk(KERN_WARNING "Refusing to unregister "
> > + "scheduler clocksource %s", cs->name);
>
> Hmm, isn't that dangerous ? The clocksource might be in a module or
> in kmalloced memory which is going to be freed.
One could play dirty tricks with 'leaking' module ref counts and such so
as to avoid that. The alternative is making sched_clock() look something
like:
u64 __weak sched_clock(void)
{
struct clocksource *clock;
u64 time;
rcu_read_lock();
clock = rcu_dereference(sched_clocksource);
time = cyc2ns(clock, read_clocksource(clock));
rcu_read_unlock;
return time;
}
and make the module unload do a sync_rcu -- but this might be a little
overkill
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 12:22 ` Thomas Gleixner
2009-05-28 12:40 ` Peter Zijlstra
@ 2009-05-28 12:42 ` Paul Mundt
2009-05-28 12:53 ` Thomas Gleixner
2009-05-28 12:59 ` Peter Zijlstra
1 sibling, 2 replies; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 12:42 UTC (permalink / raw)
To: Thomas Gleixner
Cc: Peter Zijlstra, Daniel Walker, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 02:22:17PM +0200, Thomas Gleixner wrote:
> On Thu, 28 May 2009, Paul Mundt wrote:
> > @@ -437,10 +441,19 @@ void clocksource_unregister(struct clocksource *cs)
> > unsigned long flags;
> >
> > spin_lock_irqsave(&clocksource_lock, flags);
> > +
> > + if (sched_clocksource == cs) {
> > + printk(KERN_WARNING "Refusing to unregister "
> > + "scheduler clocksource %s", cs->name);
>
> Hmm, isn't that dangerous ? The clocksource might be in a module or
> in kmalloced memory which is going to be freed.
>
Perhaps the saner thing to do is see if select_clocksource() manages to
find something suitable, otherwise switch back to jiffies..
--
include/linux/clocksource.h | 4 +++-
kernel/sched_clock.c | 6 ++++--
kernel/time/clocksource.c | 14 ++++++++++++++
kernel/time/jiffies.c | 2 +-
4 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index c56457c..2109940 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -202,7 +202,8 @@ struct clocksource {
#endif
};
-extern struct clocksource *clock; /* current clocksource */
+extern struct clocksource *clock; /* current clocksource */
+extern struct clocksource *sched_clocksource; /* sched_clock() clocksource */
/*
* Clock source flags bits::
@@ -212,6 +213,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..b91190e 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,8 +39,9 @@
*/
unsigned long long __attribute__((weak)) sched_clock(void)
{
- return (unsigned long long)(jiffies - INITIAL_JIFFIES)
- * (NSEC_PER_SEC / HZ);
+ struct clocksource *clock = ACCESS_ONCE(sched_clocksource);
+
+ return cyc2ns(clock, clocksource_read(clock));
}
static __read_mostly int sched_clock_running;
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 80189f6..19c72d0 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -109,6 +109,7 @@ EXPORT_SYMBOL(timecounter_cyc2time);
/* XXX - Would like a better way for initializing curr_clocksource */
extern struct clocksource clocksource_jiffies;
+struct clocksource *sched_clocksource = &clocksource_jiffies;
/*[Clocksource internal variables]---------
* curr_clocksource:
@@ -362,6 +363,9 @@ static struct clocksource *select_clocksource(void)
if (next == curr_clocksource)
return NULL;
+ if (next->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK)
+ sched_clocksource = next;
+
return next;
}
@@ -440,7 +444,17 @@ void clocksource_unregister(struct clocksource *cs)
list_del(&cs->list);
if (clocksource_override == cs)
clocksource_override = NULL;
+
next_clocksource = select_clocksource();
+
+ /*
+ * If select_clocksource() fails to find another suitable
+ * clocksource for sched_clocksource and we are unregistering
+ * it, switch back to jiffies.
+ */
+ if (sched_clocksource == cs)
+ sched_clocksource = &clocksource_jiffies;
+
spin_unlock_irqrestore(&clocksource_lock, flags);
}
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index c3f6c30..727d881 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -52,7 +52,7 @@
static cycle_t jiffies_read(struct clocksource *cs)
{
- return (cycle_t) jiffies;
+ return (cycle_t) (jiffies - INITIAL_JIFFIES);
}
struct clocksource clocksource_jiffies = {
^ permalink raw reply related [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 12:42 ` Paul Mundt
@ 2009-05-28 12:53 ` Thomas Gleixner
2009-05-28 12:59 ` Peter Zijlstra
1 sibling, 0 replies; 57+ messages in thread
From: Thomas Gleixner @ 2009-05-28 12:53 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Daniel Walker, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 28 May 2009, Paul Mundt wrote:
> On Thu, May 28, 2009 at 02:22:17PM +0200, Thomas Gleixner wrote:
> > On Thu, 28 May 2009, Paul Mundt wrote:
> > > @@ -437,10 +441,19 @@ void clocksource_unregister(struct clocksource *cs)
> > > unsigned long flags;
> > >
> > > spin_lock_irqsave(&clocksource_lock, flags);
> > > +
> > > + if (sched_clocksource == cs) {
> > > + printk(KERN_WARNING "Refusing to unregister "
> > > + "scheduler clocksource %s", cs->name);
> >
> > Hmm, isn't that dangerous ? The clocksource might be in a module or
> > in kmalloced memory which is going to be freed.
> >
> Perhaps the saner thing to do is see if select_clocksource() manages to
> find something suitable, otherwise switch back to jiffies..
That makes sense. The scheduler should be able handle that, if not ... :)
Thanks,
tglx
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 12:42 ` Paul Mundt
2009-05-28 12:53 ` Thomas Gleixner
@ 2009-05-28 12:59 ` Peter Zijlstra
2009-05-28 13:20 ` Paul Mundt
2009-05-28 16:13 ` Daniel Walker
1 sibling, 2 replies; 57+ messages in thread
From: Peter Zijlstra @ 2009-05-28 12:59 UTC (permalink / raw)
To: Paul Mundt
Cc: Thomas Gleixner, Daniel Walker, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 2009-05-28 at 21:42 +0900, Paul Mundt wrote:
> unsigned long long __attribute__((weak)) sched_clock(void)
> {
> - return (unsigned long long)(jiffies - INITIAL_JIFFIES)
> - * (NSEC_PER_SEC / HZ);
> + struct clocksource *clock = ACCESS_ONCE(sched_clocksource);
> +
> + return cyc2ns(clock, clocksource_read(clock));
> }
>
> @@ -440,7 +444,17 @@ void clocksource_unregister(struct clocksource *cs)
> list_del(&cs->list);
> if (clocksource_override == cs)
> clocksource_override = NULL;
> +
> next_clocksource = select_clocksource();
> +
> + /*
> + * If select_clocksource() fails to find another suitable
> + * clocksource for sched_clocksource and we are unregistering
> + * it, switch back to jiffies.
> + */
> + if (sched_clocksource == cs)
> + sched_clocksource = &clocksource_jiffies;
> +
> spin_unlock_irqrestore(&clocksource_lock, flags);
> }
CPU0 CPU1
clock = ACCESS_ONCE(sched_clocksource);
unload module
clocksource_unregister()
sched_clocksource = jiffies
unmap data/text
cyc2ns(clock, clocksource_read(clock)) <--- fireworks
^ permalink raw reply [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 12:59 ` Peter Zijlstra
@ 2009-05-28 13:20 ` Paul Mundt
2009-05-28 16:13 ` Daniel Walker
1 sibling, 0 replies; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 13:20 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Thomas Gleixner, Daniel Walker, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 02:59:30PM +0200, Peter Zijlstra wrote:
> On Thu, 2009-05-28 at 21:42 +0900, Paul Mundt wrote:
>
> > unsigned long long __attribute__((weak)) sched_clock(void)
> > {
> > - return (unsigned long long)(jiffies - INITIAL_JIFFIES)
> > - * (NSEC_PER_SEC / HZ);
> > + struct clocksource *clock = ACCESS_ONCE(sched_clocksource);
> > +
> > + return cyc2ns(clock, clocksource_read(clock));
> > }
> >
>
> > @@ -440,7 +444,17 @@ void clocksource_unregister(struct clocksource *cs)
> > list_del(&cs->list);
> > if (clocksource_override == cs)
> > clocksource_override = NULL;
> > +
> > next_clocksource = select_clocksource();
> > +
> > + /*
> > + * If select_clocksource() fails to find another suitable
> > + * clocksource for sched_clocksource and we are unregistering
> > + * it, switch back to jiffies.
> > + */
> > + if (sched_clocksource == cs)
> > + sched_clocksource = &clocksource_jiffies;
> > +
> > spin_unlock_irqrestore(&clocksource_lock, flags);
> > }
>
>
> CPU0 CPU1
>
> clock = ACCESS_ONCE(sched_clocksource);
>
> unload module
> clocksource_unregister()
> sched_clocksource = jiffies
> unmap data/text
>
> cyc2ns(clock, clocksource_read(clock)) <--- fireworks
>
Right, lets try that again..
--
include/linux/clocksource.h | 4 +++-
kernel/sched_clock.c | 13 +++++++++++--
kernel/time/clocksource.c | 19 +++++++++++++++++++
kernel/time/jiffies.c | 2 +-
4 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index c56457c..2109940 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -202,7 +202,8 @@ struct clocksource {
#endif
};
-extern struct clocksource *clock; /* current clocksource */
+extern struct clocksource *clock; /* current clocksource */
+extern struct clocksource *sched_clocksource; /* sched_clock() clocksource */
/*
* Clock source flags bits::
@@ -212,6 +213,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..b51d48d 100644
--- a/kernel/sched_clock.c
+++ b/kernel/sched_clock.c
@@ -30,6 +30,8 @@
#include <linux/percpu.h>
#include <linux/ktime.h>
#include <linux/sched.h>
+#include <linux/clocksource.h>
+#include <linux/rcupdate.h>
/*
* Scheduler clock - returns current time in nanosec units.
@@ -38,8 +40,15 @@
*/
unsigned long long __attribute__((weak)) sched_clock(void)
{
- return (unsigned long long)(jiffies - INITIAL_JIFFIES)
- * (NSEC_PER_SEC / HZ);
+ unsigned long long time;
+ struct clocksource *clock;
+
+ rcu_read_lock();
+ clock = rcu_dereference(sched_clocksource);
+ time = cyc2ns(clock, clocksource_read(clock));
+ rcu_read_unlock();
+
+ return time;
}
static __read_mostly int sched_clock_running;
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 80189f6..3795954 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -25,6 +25,7 @@
*/
#include <linux/clocksource.h>
+#include <linux/rcupdate.h>
#include <linux/sysdev.h>
#include <linux/init.h>
#include <linux/module.h>
@@ -109,6 +110,7 @@ EXPORT_SYMBOL(timecounter_cyc2time);
/* XXX - Would like a better way for initializing curr_clocksource */
extern struct clocksource clocksource_jiffies;
+struct clocksource *sched_clocksource = &clocksource_jiffies;
/*[Clocksource internal variables]---------
* curr_clocksource:
@@ -362,6 +364,9 @@ static struct clocksource *select_clocksource(void)
if (next == curr_clocksource)
return NULL;
+ if (next->flags & CLOCK_SOURCE_USE_FOR_SCHED_CLOCK)
+ sched_clocksource = next;
+
return next;
}
@@ -440,7 +445,21 @@ void clocksource_unregister(struct clocksource *cs)
list_del(&cs->list);
if (clocksource_override == cs)
clocksource_override = NULL;
+
next_clocksource = select_clocksource();
+
+ /*
+ * If select_clocksource() fails to find another suitable
+ * clocksource for sched_clocksource and we are unregistering
+ * it, switch back to jiffies.
+ */
+ if (sched_clocksource == cs) {
+ rcu_assign_pointer(sched_clocksource, &clocksource_jiffies);
+ spin_unlock_irqrestore(&clocksource_lock, flags);
+ synchronize_rcu();
+ return;
+ }
+
spin_unlock_irqrestore(&clocksource_lock, flags);
}
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index c3f6c30..727d881 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -52,7 +52,7 @@
static cycle_t jiffies_read(struct clocksource *cs)
{
- return (cycle_t) jiffies;
+ return (cycle_t) (jiffies - INITIAL_JIFFIES);
}
struct clocksource clocksource_jiffies = {
^ permalink raw reply related [flat|nested] 57+ messages in thread* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 12:59 ` Peter Zijlstra
2009-05-28 13:20 ` Paul Mundt
@ 2009-05-28 16:13 ` Daniel Walker
2009-05-28 16:32 ` Peter Zijlstra
1 sibling, 1 reply; 57+ messages in thread
From: Daniel Walker @ 2009-05-28 16:13 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Paul Mundt, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 2009-05-28 at 14:59 +0200, Peter Zijlstra wrote:
>
>
> CPU0 CPU1
>
> clock = ACCESS_ONCE(sched_clocksource);
>
> unload module
> clocksource_unregister()
> sched_clocksource = jiffies
> unmap data/text
>
> cyc2ns(clock, clocksource_read(clock)) <--- fireworks
>
>
Do any module based clocksources even exist right now?
clocksource_unregister only seems to be used 3 times..
Daniel
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 16:13 ` Daniel Walker
@ 2009-05-28 16:32 ` Peter Zijlstra
2009-05-28 16:40 ` Paul Mundt
0 siblings, 1 reply; 57+ messages in thread
From: Peter Zijlstra @ 2009-05-28 16:32 UTC (permalink / raw)
To: Daniel Walker
Cc: Paul Mundt, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 2009-05-28 at 09:13 -0700, Daniel Walker wrote:
> On Thu, 2009-05-28 at 14:59 +0200, Peter Zijlstra wrote:
>
> >
> >
> > CPU0 CPU1
> >
> > clock = ACCESS_ONCE(sched_clocksource);
> >
> > unload module
> > clocksource_unregister()
> > sched_clocksource = jiffies
> > unmap data/text
> >
> > cyc2ns(clock, clocksource_read(clock)) <--- fireworks
> >
> >
>
> Do any module based clocksources even exist right now?
> clocksource_unregister only seems to be used 3 times..
Good point, it appears its not even exported.
Thomas mentioned modules, I assumed.
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 16:32 ` Peter Zijlstra
@ 2009-05-28 16:40 ` Paul Mundt
2009-05-28 16:52 ` Daniel Walker
2009-05-28 17:07 ` John Stultz
0 siblings, 2 replies; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 16:40 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Daniel Walker, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 06:32:09PM +0200, Peter Zijlstra wrote:
> On Thu, 2009-05-28 at 09:13 -0700, Daniel Walker wrote:
> > On Thu, 2009-05-28 at 14:59 +0200, Peter Zijlstra wrote:
> > > CPU0 CPU1
> > >
> > > clock = ACCESS_ONCE(sched_clocksource);
> > >
> > > unload module
> > > clocksource_unregister()
> > > sched_clocksource = jiffies
> > > unmap data/text
> > >
> > > cyc2ns(clock, clocksource_read(clock)) <--- fireworks
> > >
> > >
> >
> > Do any module based clocksources even exist right now?
> > clocksource_unregister only seems to be used 3 times..
>
> Good point, it appears its not even exported.
>
> Thomas mentioned modules, I assumed.
>
The drivers/clocksource/ drivers in theory could be modular anyways.
Handling this transition properly is at least one less barrier to modular
clocksources, so I think it's progress regardless. I don't remember what
all of the other issues were though, John probably remembers.
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 16:40 ` Paul Mundt
@ 2009-05-28 16:52 ` Daniel Walker
2009-05-28 16:58 ` Paul Mundt
2009-05-28 17:00 ` Thomas Gleixner
2009-05-28 17:07 ` John Stultz
1 sibling, 2 replies; 57+ messages in thread
From: Daniel Walker @ 2009-05-28 16:52 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Fri, 2009-05-29 at 01:40 +0900, Paul Mundt wrote:
> On Thu, May 28, 2009 at 06:32:09PM +0200, Peter Zijlstra wrote:
> > On Thu, 2009-05-28 at 09:13 -0700, Daniel Walker wrote:
> > > On Thu, 2009-05-28 at 14:59 +0200, Peter Zijlstra wrote:
> > > > CPU0 CPU1
> > > >
> > > > clock = ACCESS_ONCE(sched_clocksource);
> > > >
> > > > unload module
> > > > clocksource_unregister()
> > > > sched_clocksource = jiffies
> > > > unmap data/text
> > > >
> > > > cyc2ns(clock, clocksource_read(clock)) <--- fireworks
> > > >
> > > >
> > >
> > > Do any module based clocksources even exist right now?
> > > clocksource_unregister only seems to be used 3 times..
> >
> > Good point, it appears its not even exported.
> >
> > Thomas mentioned modules, I assumed.
> >
> The drivers/clocksource/ drivers in theory could be modular anyways.
> Handling this transition properly is at least one less barrier to modular
> clocksources, so I think it's progress regardless. I don't remember what
> all of the other issues were though, John probably remembers.
I don't think it's an important case to consider right now ..
clocksources are usually so integral to the system putting one in a
module seems counterintuitive.
Daniel
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 16:52 ` Daniel Walker
@ 2009-05-28 16:58 ` Paul Mundt
2009-05-28 17:38 ` Daniel Walker
2009-05-28 17:00 ` Thomas Gleixner
1 sibling, 1 reply; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 16:58 UTC (permalink / raw)
To: Daniel Walker
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 09:52:27AM -0700, Daniel Walker wrote:
> On Fri, 2009-05-29 at 01:40 +0900, Paul Mundt wrote:
> > On Thu, May 28, 2009 at 06:32:09PM +0200, Peter Zijlstra wrote:
> > > On Thu, 2009-05-28 at 09:13 -0700, Daniel Walker wrote:
> > > > On Thu, 2009-05-28 at 14:59 +0200, Peter Zijlstra wrote:
> > > > > CPU0 CPU1
> > > > >
> > > > > clock = ACCESS_ONCE(sched_clocksource);
> > > > >
> > > > > unload module
> > > > > clocksource_unregister()
> > > > > sched_clocksource = jiffies
> > > > > unmap data/text
> > > > >
> > > > > cyc2ns(clock, clocksource_read(clock)) <--- fireworks
> > > > >
> > > > >
> > > >
> > > > Do any module based clocksources even exist right now?
> > > > clocksource_unregister only seems to be used 3 times..
> > >
> > > Good point, it appears its not even exported.
> > >
> > > Thomas mentioned modules, I assumed.
> > >
> > The drivers/clocksource/ drivers in theory could be modular anyways.
> > Handling this transition properly is at least one less barrier to modular
> > clocksources, so I think it's progress regardless. I don't remember what
> > all of the other issues were though, John probably remembers.
>
> I don't think it's an important case to consider right now ..
> clocksources are usually so integral to the system putting one in a
> module seems counterintuitive.
>
I would not have mentioned it if it weren't something we already had use
cases for. For the SH timers alone we have 3 that can be used as
clocksources in any combination, excluding the differences in timer
channels per block. These tend to have different implications for
performance, power management, etc.
The only reason they are not modular today is because more work needs to
be done to handle clocksources going away, or at least there was the last
time we tried it.
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 16:58 ` Paul Mundt
@ 2009-05-28 17:38 ` Daniel Walker
2009-05-28 17:46 ` Thomas Gleixner
2009-05-28 17:53 ` Paul Mundt
0 siblings, 2 replies; 57+ messages in thread
From: Daniel Walker @ 2009-05-28 17:38 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Fri, 2009-05-29 at 01:58 +0900, Paul Mundt wrote:
> On Thu, May 28, 2009 at 09:52:27AM -0700, Daniel Walker wrote:
> > On Fri, 2009-05-29 at 01:40 +0900, Paul Mundt wrote:
> > > On Thu, May 28, 2009 at 06:32:09PM +0200, Peter Zijlstra wrote:
> > > > On Thu, 2009-05-28 at 09:13 -0700, Daniel Walker wrote:
> > > > > On Thu, 2009-05-28 at 14:59 +0200, Peter Zijlstra wrote:
> > > > > > CPU0 CPU1
> > > > > >
> > > > > > clock = ACCESS_ONCE(sched_clocksource);
> > > > > >
> > > > > > unload module
> > > > > > clocksource_unregister()
> > > > > > sched_clocksource = jiffies
> > > > > > unmap data/text
> > > > > >
> > > > > > cyc2ns(clock, clocksource_read(clock)) <--- fireworks
> > > > > >
> > > > > >
> > > > >
> > > > > Do any module based clocksources even exist right now?
> > > > > clocksource_unregister only seems to be used 3 times..
> > > >
> > > > Good point, it appears its not even exported.
> > > >
> > > > Thomas mentioned modules, I assumed.
> > > >
> > > The drivers/clocksource/ drivers in theory could be modular anyways.
> > > Handling this transition properly is at least one less barrier to modular
> > > clocksources, so I think it's progress regardless. I don't remember what
> > > all of the other issues were though, John probably remembers.
> >
> > I don't think it's an important case to consider right now ..
> > clocksources are usually so integral to the system putting one in a
> > module seems counterintuitive.
> >
> I would not have mentioned it if it weren't something we already had use
> cases for. For the SH timers alone we have 3 that can be used as
> clocksources in any combination, excluding the differences in timer
> channels per block. These tend to have different implications for
> performance, power management, etc.
>
> The only reason they are not modular today is because more work needs to
> be done to handle clocksources going away, or at least there was the last
> time we tried it.
I don't know the details of SH so I can't speak specifically to that ..
My experience is that usually one clock gets selected as the clocksource
for a given system , and it rarely changes.. We have a sysfs facility to
allow a user to switch clocksources, but I doubt that's used for more
than debugging..
Can you imagine a general case on SH where the users know enough about
the different clocksources that they can switch between them optimally
without an SH expert sitting next to them telling them what to do?
Daniel
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 17:38 ` Daniel Walker
@ 2009-05-28 17:46 ` Thomas Gleixner
2009-05-28 17:53 ` Paul Mundt
1 sibling, 0 replies; 57+ messages in thread
From: Thomas Gleixner @ 2009-05-28 17:46 UTC (permalink / raw)
To: Daniel Walker
Cc: Paul Mundt, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 28 May 2009, Daniel Walker wrote:
> > I would not have mentioned it if it weren't something we already had use
> > cases for. For the SH timers alone we have 3 that can be used as
> > clocksources in any combination, excluding the differences in timer
> > channels per block. These tend to have different implications for
> > performance, power management, etc.
> >
> > The only reason they are not modular today is because more work needs to
> > be done to handle clocksources going away, or at least there was the last
> > time we tried it.
>
> I don't know the details of SH so I can't speak specifically to that ..
> My experience is that usually one clock gets selected as the clocksource
> for a given system , and it rarely changes.. We have a sysfs facility to
> allow a user to switch clocksources, but I doubt that's used for more
> than debugging..
>
> Can you imagine a general case on SH where the users know enough about
> the different clocksources that they can switch between them optimally
> without an SH expert sitting next to them telling them what to do?
Paul explained already that:
> > ... These tend to have different implications for
> > performance, power management, etc.
So the use case for this is pretty obvious. In operational state you
want something fast and easy to access (which might use more power
e.g. because it runs at a higher clock frequency). When you go into
power saving modes you switch over to a clocksource which might be
slower to access but uses less power.
And there is no user interaction at all, it's selected as part of a
power state transition from the kernel.
Thanks,
tglx
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 17:38 ` Daniel Walker
2009-05-28 17:46 ` Thomas Gleixner
@ 2009-05-28 17:53 ` Paul Mundt
2009-05-28 18:10 ` Daniel Walker
1 sibling, 1 reply; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 17:53 UTC (permalink / raw)
To: Daniel Walker
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 10:38:44AM -0700, Daniel Walker wrote:
> On Fri, 2009-05-29 at 01:58 +0900, Paul Mundt wrote:
> > On Thu, May 28, 2009 at 09:52:27AM -0700, Daniel Walker wrote:
> > > I don't think it's an important case to consider right now ..
> > > clocksources are usually so integral to the system putting one in a
> > > module seems counterintuitive.
> > >
> > I would not have mentioned it if it weren't something we already had use
> > cases for. For the SH timers alone we have 3 that can be used as
> > clocksources in any combination, excluding the differences in timer
> > channels per block. These tend to have different implications for
> > performance, power management, etc.
> >
> > The only reason they are not modular today is because more work needs to
> > be done to handle clocksources going away, or at least there was the last
> > time we tried it.
>
> I don't know the details of SH so I can't speak specifically to that ..
> My experience is that usually one clock gets selected as the clocksource
> for a given system , and it rarely changes.. We have a sysfs facility to
> allow a user to switch clocksources, but I doubt that's used for more
> than debugging..
>
> Can you imagine a general case on SH where the users know enough about
> the different clocksources that they can switch between them optimally
> without an SH expert sitting next to them telling them what to do?
>
As I already stated, yes.
We have multiple clock sources for most CPUs. These can be set up in any
sort of configuration, and there are pros and cons to using different
ones. The ones that are available can in turn be cycled between. I don't
know what exactly is difficult to understand about this.
Yes, we want to be able to use modular clocksources. The only reason we
don't right now is because some more preparatory work is needed first.
Any attempt to remove support for modular clocksources means we will just
have to add it in back later.
That and the fact there are already in-tree users using the
unregistration path suggests that there is no benefit in trying to
prevent modular clocksources in the first place. If you have no intention
to use modular clocksources, then don't.
If you have any technical concerns, then raise them, otherwise this is
pointless.
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 17:53 ` Paul Mundt
@ 2009-05-28 18:10 ` Daniel Walker
2009-05-28 18:27 ` Paul Mundt
2009-05-28 18:44 ` Thomas Gleixner
0 siblings, 2 replies; 57+ messages in thread
From: Daniel Walker @ 2009-05-28 18:10 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Fri, 2009-05-29 at 02:53 +0900, Paul Mundt wrote:
> As I already stated, yes.
>
> We have multiple clock sources for most CPUs. These can be set up in any
> sort of configuration, and there are pros and cons to using different
> ones. The ones that are available can in turn be cycled between. I don't
> know what exactly is difficult to understand about this.
I understand that cpu's can have multiple clocks, that's not a hard concept to grasp.
> Yes, we want to be able to use modular clocksources. The only reason we
> don't right now is because some more preparatory work is needed first.
> Any attempt to remove support for modular clocksources means we will just
> have to add it in back later.
This is what's difficult to understand.. You have multiple clocks ok,
fine.. You have multiple clocks that you want the kernel to switch
between, ok that's fine too.. What's missing is the case where
clocksource modules being loaded/unload via the user becomes a valuable
use case..
If you have a valuable use case for that, fine, I won't stand in the
way ..
Daniel
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 18:10 ` Daniel Walker
@ 2009-05-28 18:27 ` Paul Mundt
2009-05-28 19:04 ` Daniel Walker
2009-05-28 18:44 ` Thomas Gleixner
1 sibling, 1 reply; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 18:27 UTC (permalink / raw)
To: Daniel Walker
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 11:10:52AM -0700, Daniel Walker wrote:
> On Fri, 2009-05-29 at 02:53 +0900, Paul Mundt wrote:
> > Yes, we want to be able to use modular clocksources. The only reason we
> > don't right now is because some more preparatory work is needed first.
> > Any attempt to remove support for modular clocksources means we will just
> > have to add it in back later.
>
> This is what's difficult to understand.. You have multiple clocks ok,
> fine.. You have multiple clocks that you want the kernel to switch
> between, ok that's fine too.. What's missing is the case where
> clocksource modules being loaded/unload via the user becomes a valuable
> use case..
>
> If you have a valuable use case for that, fine, I won't stand in the
> way ..
>
Ah, ok, I suppose I could have explained that better. There are a couple
of different considerations really. The timer blocks are often in
different clock and power domains, meaning that only certain ones can be
used for wakeups. These tend not to be ideal for general use, and so we
only switch to them when we have to.
To make matters more convoluted, the availability of different timer
channels on different CPUs will depend on current pin state, and more
importantly, what sort of states we are able to achieve. It is not
uncommon to have some of the pins required by these channels locked down
by other drivers during regular operation, which we in turn need to
unload before the pin state can be reconfigured and the timer can
succeed, all which needs to happen before certain power state transitions
can take place. We implement dynamic pinmux for most of the SH CPUs
precisely to deal with these sorts of problems. In the case of some of
the microcontrollers that are timer heavy and low on pincount, it is not
uncommon to have upwards of 16 different functions per pin.
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 18:27 ` Paul Mundt
@ 2009-05-28 19:04 ` Daniel Walker
2009-05-28 19:34 ` Paul Mundt
0 siblings, 1 reply; 57+ messages in thread
From: Daniel Walker @ 2009-05-28 19:04 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Fri, 2009-05-29 at 03:27 +0900, Paul Mundt wrote:
> Ah, ok, I suppose I could have explained that better. There are a couple
> of different considerations really. The timer blocks are often in
> different clock and power domains, meaning that only certain ones can be
> used for wakeups. These tend not to be ideal for general use, and so we
> only switch to them when we have to.
>
> To make matters more convoluted, the availability of different timer
> channels on different CPUs will depend on current pin state, and more
> importantly, what sort of states we are able to achieve. It is not
> uncommon to have some of the pins required by these channels locked down
> by other drivers during regular operation, which we in turn need to
> unload before the pin state can be reconfigured and the timer can
> succeed, all which needs to happen before certain power state transitions
> can take place. We implement dynamic pinmux for most of the SH CPUs
> precisely to deal with these sorts of problems. In the case of some of
> the microcontrollers that are timer heavy and low on pincount, it is not
> uncommon to have upwards of 16 different functions per pin.
I'm still a little confused how kernel modules fit in here.. Are you
saying a user would unload some certain driver which has a pin locked
down and prevents the clocksource from working. Then the user would load
the clocksource module which would now function, and that all would have
to happen in order to enter a certain power state?
Daniel
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 19:04 ` Daniel Walker
@ 2009-05-28 19:34 ` Paul Mundt
2009-05-28 19:41 ` Daniel Walker
0 siblings, 1 reply; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 19:34 UTC (permalink / raw)
To: Daniel Walker
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 12:04:23PM -0700, Daniel Walker wrote:
> On Fri, 2009-05-29 at 03:27 +0900, Paul Mundt wrote:
>
> > Ah, ok, I suppose I could have explained that better. There are a couple
> > of different considerations really. The timer blocks are often in
> > different clock and power domains, meaning that only certain ones can be
> > used for wakeups. These tend not to be ideal for general use, and so we
> > only switch to them when we have to.
> >
> > To make matters more convoluted, the availability of different timer
> > channels on different CPUs will depend on current pin state, and more
> > importantly, what sort of states we are able to achieve. It is not
> > uncommon to have some of the pins required by these channels locked down
> > by other drivers during regular operation, which we in turn need to
> > unload before the pin state can be reconfigured and the timer can
> > succeed, all which needs to happen before certain power state transitions
> > can take place. We implement dynamic pinmux for most of the SH CPUs
> > precisely to deal with these sorts of problems. In the case of some of
> > the microcontrollers that are timer heavy and low on pincount, it is not
> > uncommon to have upwards of 16 different functions per pin.
>
> I'm still a little confused how kernel modules fit in here.. Are you
> saying a user would unload some certain driver which has a pin locked
> down and prevents the clocksource from working. Then the user would load
> the clocksource module which would now function, and that all would have
> to happen in order to enter a certain power state?
>
Yes.
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 19:34 ` Paul Mundt
@ 2009-05-28 19:41 ` Daniel Walker
2009-05-28 23:37 ` Paul Mundt
0 siblings, 1 reply; 57+ messages in thread
From: Daniel Walker @ 2009-05-28 19:41 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Fri, 2009-05-29 at 04:34 +0900, Paul Mundt wrote:
> > I'm still a little confused how kernel modules fit in here.. Are you
> > saying a user would unload some certain driver which has a pin locked
> > down and prevents the clocksource from working. Then the user would load
> > the clocksource module which would now function, and that all would have
> > to happen in order to enter a certain power state?
> >
> Yes.
I'm assuming this isn't a low power state, this would be something more
like suspend or hibernate right?
Daniel
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 19:41 ` Daniel Walker
@ 2009-05-28 23:37 ` Paul Mundt
0 siblings, 0 replies; 57+ messages in thread
From: Paul Mundt @ 2009-05-28 23:37 UTC (permalink / raw)
To: Daniel Walker
Cc: Peter Zijlstra, Thomas Gleixner, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, May 28, 2009 at 12:41:03PM -0700, Daniel Walker wrote:
> On Fri, 2009-05-29 at 04:34 +0900, Paul Mundt wrote:
> > > I'm still a little confused how kernel modules fit in here.. Are you
> > > saying a user would unload some certain driver which has a pin locked
> > > down and prevents the clocksource from working. Then the user would load
> > > the clocksource module which would now function, and that all would have
> > > to happen in order to enter a certain power state?
> > >
> > Yes.
>
> I'm assuming this isn't a low power state, this would be something more
> like suspend or hibernate right?
>
Right, with the amount of hassle involved, it makes no sense for run-time
PM at least. So the suspend/hibernate use cases are mostly where it makes
sense.
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 18:10 ` Daniel Walker
2009-05-28 18:27 ` Paul Mundt
@ 2009-05-28 18:44 ` Thomas Gleixner
1 sibling, 0 replies; 57+ messages in thread
From: Thomas Gleixner @ 2009-05-28 18:44 UTC (permalink / raw)
To: Daniel Walker
Cc: Paul Mundt, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 28 May 2009, Daniel Walker wrote:
> On Fri, 2009-05-29 at 02:53 +0900, Paul Mundt wrote:
>
> > As I already stated, yes.
> >
> > We have multiple clock sources for most CPUs. These can be set up in any
> > sort of configuration, and there are pros and cons to using different
> > ones. The ones that are available can in turn be cycled between. I don't
> > know what exactly is difficult to understand about this.
>
> I understand that cpu's can have multiple clocks, that's not a hard concept to grasp.
>
> > Yes, we want to be able to use modular clocksources. The only reason we
> > don't right now is because some more preparatory work is needed first.
> > Any attempt to remove support for modular clocksources means we will just
> > have to add it in back later.
>
> This is what's difficult to understand.. You have multiple clocks ok,
> fine.. You have multiple clocks that you want the kernel to switch
> between, ok that's fine too.. What's missing is the case where
> clocksource modules being loaded/unload via the user becomes a valuable
> use case..
Did you actually read what people wrote ? This is not about modules or
not, it's about safe switching of clocksources when they are used for
sched_clock as well.
> If you have a valuable use case for that, fine, I won't stand in the
> way ..
Sigh,
tglx
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 16:52 ` Daniel Walker
2009-05-28 16:58 ` Paul Mundt
@ 2009-05-28 17:00 ` Thomas Gleixner
1 sibling, 0 replies; 57+ messages in thread
From: Thomas Gleixner @ 2009-05-28 17:00 UTC (permalink / raw)
To: Daniel Walker
Cc: Paul Mundt, Peter Zijlstra, Linus Walleij, Ingo Molnar,
Andrew Victor, Haavard Skinnemoen, Andrew Morton, linux-kernel,
linux-sh, linux-arm-kernel, John Stultz
On Thu, 28 May 2009, Daniel Walker wrote:
> > > > Do any module based clocksources even exist right now?
> > > > clocksource_unregister only seems to be used 3 times..
> > >
> > > Good point, it appears its not even exported.
> > >
> > > Thomas mentioned modules, I assumed.
> > >
> > The drivers/clocksource/ drivers in theory could be modular anyways.
> > Handling this transition properly is at least one less barrier to modular
> > clocksources, so I think it's progress regardless. I don't remember what
> > all of the other issues were though, John probably remembers.
>
> I don't think it's an important case to consider right now ..
> clocksources are usually so integral to the system putting one in a
> module seems counterintuitive.
That does not matter at all. If we have an unregister call then we
have to be prepared for
- the memory which contained the clocksource is freed
- the underlying hardware is going away.
It does not matter at all if that happens in a compiled in or in a
modular driver.
Thanks,
tglx
^ permalink raw reply [flat|nested] 57+ messages in thread
* Re: [PATCH] sched: Support current clocksource handling in fallback sched_clock().
2009-05-28 16:40 ` Paul Mundt
2009-05-28 16:52 ` Daniel Walker
@ 2009-05-28 17:07 ` John Stultz
1 sibling, 0 replies; 57+ messages in thread
From: John Stultz @ 2009-05-28 17:07 UTC (permalink / raw)
To: Paul Mundt
Cc: Peter Zijlstra, Daniel Walker, Thomas Gleixner, Linus Walleij,
Ingo Molnar, Andrew Victor, Haavard Skinnemoen, Andrew Morton,
linux-kernel, linux-sh, linux-arm-kernel, John Stultz
On Fri, 2009-05-29 at 01:40 +0900, Paul Mundt wrote:
> On Thu, May 28, 2009 at 06:32:09PM +0200, Peter Zijlstra wrote:
> > On Thu, 2009-05-28 at 09:13 -0700, Daniel Walker wrote:
> > > On Thu, 2009-05-28 at 14:59 +0200, Peter Zijlstra wrote:
> > > > CPU0 CPU1
> > > >
> > > > clock = ACCESS_ONCE(sched_clocksource);
> > > >
> > > > unload module
> > > > clocksource_unregister()
> > > > sched_clocksource = jiffies
> > > > unmap data/text
> > > >
> > > > cyc2ns(clock, clocksource_read(clock)) <--- fireworks
> > > >
> > > >
> > >
> > > Do any module based clocksources even exist right now?
> > > clocksource_unregister only seems to be used 3 times..
> >
> > Good point, it appears its not even exported.
> >
> > Thomas mentioned modules, I assumed.
> >
> The drivers/clocksource/ drivers in theory could be modular anyways.
> Handling this transition properly is at least one less barrier to modular
> clocksources, so I think it's progress regardless. I don't remember what
> all of the other issues were though, John probably remembers.
Yea. Its always been something I'd want to have as a capability, but we
haven't actually had a user of. I still think its something we should
allow, even if there aren't upstream users, as if you only have to
backport a module to an old distro kernel to get some oddball bit of
hardware working, that can be really useful.
So I think the locking fix is the way to go.
thanks
-john
^ permalink raw reply [flat|nested] 57+ messages in thread