* [RFC 0/2] clocksource: don't suspend/resume when unused
@ 2015-01-16 9:17 Alexandre Belloni
2015-01-16 9:17 ` [RFC 1/2] clocksource: track usage Alexandre Belloni
2015-01-16 9:17 ` [RFC 2/2] clocksource: don't suspend/resume when unused Alexandre Belloni
0 siblings, 2 replies; 14+ messages in thread
From: Alexandre Belloni @ 2015-01-16 9:17 UTC (permalink / raw)
To: Thomas Gleixner
Cc: John Stultz, Daniel Lezcano, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel, Alexandre Belloni
Hi,
This is a quite naive implementation to track whether a cloccksource is enabled.
I chose not to add a member in struct clocksource and use a flag instead.
I found that timekeeping.c is the only consumer for clocksource and I converted
it to use clocksource_enable and clocksource_disable.
Regards,
Alexandre Belloni (2):
clocksource: track usage
clocksource: don't suspend/resume when unused
include/linux/clocksource.h | 4 ++++
kernel/time/clocksource.c | 30 ++++++++++++++++++++++++++++--
kernel/time/timekeeping.c | 8 +++-----
3 files changed, 35 insertions(+), 7 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 14+ messages in thread
* [RFC 1/2] clocksource: track usage
2015-01-16 9:17 [RFC 0/2] clocksource: don't suspend/resume when unused Alexandre Belloni
@ 2015-01-16 9:17 ` Alexandre Belloni
2015-01-16 10:39 ` Boris Brezillon
2015-02-02 20:03 ` Kevin Hilman
2015-01-16 9:17 ` [RFC 2/2] clocksource: don't suspend/resume when unused Alexandre Belloni
1 sibling, 2 replies; 14+ messages in thread
From: Alexandre Belloni @ 2015-01-16 9:17 UTC (permalink / raw)
To: Thomas Gleixner
Cc: John Stultz, Daniel Lezcano, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel, Alexandre Belloni
Track whether the clocksource is enabled or disabled.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
include/linux/clocksource.h | 4 ++++
kernel/time/clocksource.c | 26 ++++++++++++++++++++++++++
kernel/time/timekeeping.c | 8 +++-----
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index abcafaa20b86..7735902fc5f6 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -210,6 +210,8 @@ struct clocksource {
#define CLOCK_SOURCE_SUSPEND_NONSTOP 0x80
#define CLOCK_SOURCE_RESELECT 0x100
+#define CLOCK_SOURCE_USED 0x200
+
/* simplify initialization of mask field */
#define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
@@ -282,6 +284,8 @@ static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
extern int clocksource_register(struct clocksource*);
extern int clocksource_unregister(struct clocksource*);
+extern int clocksource_enable(struct clocksource *);
+extern void clocksource_disable(struct clocksource *);
extern void clocksource_touch_watchdog(void);
extern struct clocksource* clocksource_get_next(void);
extern void clocksource_change_rating(struct clocksource *cs, int rating);
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index b79f39bda7e1..920a4da58eb0 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -889,6 +889,32 @@ int clocksource_unregister(struct clocksource *cs)
}
EXPORT_SYMBOL(clocksource_unregister);
+/**
+ * clocksource_enable - enable a registered clocksource
+ * @cs: clocksource to enable
+ */
+int clocksource_enable(struct clocksource *cs)
+{
+ cs->flags |= CLOCK_SOURCE_USED;
+ if (cs->enable)
+ return cs->enable(cs);
+
+ return 0;
+}
+EXPORT_SYMBOL(clocksource_enable);
+
+/**
+ * clocksource_disable - disable a registered clocksource
+ * @cs: clocksource to disable
+ */
+void clocksource_disable(struct clocksource *cs)
+{
+ cs->flags &= ~CLOCK_SOURCE_USED;
+ if (cs->disable)
+ cs->disable(cs);
+}
+EXPORT_SYMBOL(clocksource_disable);
+
#ifdef CONFIG_SYSFS
/**
* sysfs_show_current_clocksources - sysfs interface for current clocksource
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 6a931852082f..1c6ffd3d068c 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -915,11 +915,10 @@ static int change_clocksource(void *data)
* for built-in code (owner == NULL) as well.
*/
if (try_module_get(new->owner)) {
- if (!new->enable || new->enable(new) == 0) {
+ if (!new->enable || clocksource_enable(new) == 0) {
old = tk->tkr.clock;
tk_setup_internals(tk, new);
- if (old->disable)
- old->disable(old);
+ clocksource_disable(old);
module_put(old->owner);
} else {
module_put(new->owner);
@@ -1080,8 +1079,7 @@ void __init timekeeping_init(void)
ntp_init();
clock = clocksource_default_clock();
- if (clock->enable)
- clock->enable(clock);
+ clocksource_enable(clock);
tk_setup_internals(tk, clock);
tk_set_xtime(tk, &now);
--
2.1.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 9:17 [RFC 0/2] clocksource: don't suspend/resume when unused Alexandre Belloni
2015-01-16 9:17 ` [RFC 1/2] clocksource: track usage Alexandre Belloni
@ 2015-01-16 9:17 ` Alexandre Belloni
2015-01-16 10:23 ` Thomas Gleixner
1 sibling, 1 reply; 14+ messages in thread
From: Alexandre Belloni @ 2015-01-16 9:17 UTC (permalink / raw)
To: Thomas Gleixner
Cc: John Stultz, Daniel Lezcano, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel, Alexandre Belloni
There is no point in calling suspend/resume for unused
clocksources.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
kernel/time/clocksource.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index 920a4da58eb0..baea4e42ae90 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -493,7 +493,7 @@ void clocksource_suspend(void)
struct clocksource *cs;
list_for_each_entry_reverse(cs, &clocksource_list, list)
- if (cs->suspend)
+ if (cs->suspend && (cs->flags & CLOCK_SOURCE_USED))
cs->suspend(cs);
}
@@ -505,7 +505,7 @@ void clocksource_resume(void)
struct clocksource *cs;
list_for_each_entry(cs, &clocksource_list, list)
- if (cs->resume)
+ if (cs->resume && (cs->flags & CLOCK_SOURCE_USED))
cs->resume(cs);
clocksource_resume_watchdog();
--
2.1.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 9:17 ` [RFC 2/2] clocksource: don't suspend/resume when unused Alexandre Belloni
@ 2015-01-16 10:23 ` Thomas Gleixner
2015-01-16 10:35 ` Alexandre Belloni
0 siblings, 1 reply; 14+ messages in thread
From: Thomas Gleixner @ 2015-01-16 10:23 UTC (permalink / raw)
To: Alexandre Belloni
Cc: John Stultz, Daniel Lezcano, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel
On Fri, 16 Jan 2015, Alexandre Belloni wrote:
> There is no point in calling suspend/resume for unused
> clocksources.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
> kernel/time/clocksource.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
> index 920a4da58eb0..baea4e42ae90 100644
> --- a/kernel/time/clocksource.c
> +++ b/kernel/time/clocksource.c
> @@ -493,7 +493,7 @@ void clocksource_suspend(void)
> struct clocksource *cs;
>
> list_for_each_entry_reverse(cs, &clocksource_list, list)
> - if (cs->suspend)
> + if (cs->suspend && (cs->flags & CLOCK_SOURCE_USED))
> cs->suspend(cs);
This might be dangerous. If the clocksource has no enable/disable
callbacks, but suspend/resume, then you might leave it enabled across
suspend.
Thanks,
tglx
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 10:23 ` Thomas Gleixner
@ 2015-01-16 10:35 ` Alexandre Belloni
2015-01-16 10:39 ` Daniel Lezcano
2015-01-16 11:23 ` Russell King - ARM Linux
0 siblings, 2 replies; 14+ messages in thread
From: Alexandre Belloni @ 2015-01-16 10:35 UTC (permalink / raw)
To: Thomas Gleixner
Cc: John Stultz, Daniel Lezcano, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel
On 16/01/2015 at 11:23:32 +0100, Thomas Gleixner wrote :
> On Fri, 16 Jan 2015, Alexandre Belloni wrote:
>
> > There is no point in calling suspend/resume for unused
> > clocksources.
> >
> > Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> > ---
> > kernel/time/clocksource.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
> > index 920a4da58eb0..baea4e42ae90 100644
> > --- a/kernel/time/clocksource.c
> > +++ b/kernel/time/clocksource.c
> > @@ -493,7 +493,7 @@ void clocksource_suspend(void)
> > struct clocksource *cs;
> >
> > list_for_each_entry_reverse(cs, &clocksource_list, list)
> > - if (cs->suspend)
> > + if (cs->suspend && (cs->flags & CLOCK_SOURCE_USED))
> > cs->suspend(cs);
>
> This might be dangerous. If the clocksource has no enable/disable
> callbacks, but suspend/resume, then you might leave it enabled across
> suspend.
>
Isn't that already the case?
Right now, if you call clocksource_suspend, it doesn't matter whether
the clocksource has an enable or not, it will be suspended. Maybe I'm
mistaken but my patch doesn't seem to change that behaviour.
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 1/2] clocksource: track usage
2015-01-16 9:17 ` [RFC 1/2] clocksource: track usage Alexandre Belloni
@ 2015-01-16 10:39 ` Boris Brezillon
2015-02-02 20:03 ` Kevin Hilman
1 sibling, 0 replies; 14+ messages in thread
From: Boris Brezillon @ 2015-01-16 10:39 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Thomas Gleixner, John Stultz, Daniel Lezcano, Nicolas Ferre,
linux-arm-kernel, linux-kernel
Hi Alexandre,
On Fri, 16 Jan 2015 10:17:53 +0100
Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote:
> Track whether the clocksource is enabled or disabled.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
> include/linux/clocksource.h | 4 ++++
> kernel/time/clocksource.c | 26 ++++++++++++++++++++++++++
> kernel/time/timekeeping.c | 8 +++-----
> 3 files changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
> index abcafaa20b86..7735902fc5f6 100644
> --- a/include/linux/clocksource.h
> +++ b/include/linux/clocksource.h
> @@ -210,6 +210,8 @@ struct clocksource {
> #define CLOCK_SOURCE_SUSPEND_NONSTOP 0x80
> #define CLOCK_SOURCE_RESELECT 0x100
>
> +#define CLOCK_SOURCE_USED 0x200
> +
> /* simplify initialization of mask field */
> #define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
>
> @@ -282,6 +284,8 @@ static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
>
> extern int clocksource_register(struct clocksource*);
> extern int clocksource_unregister(struct clocksource*);
> +extern int clocksource_enable(struct clocksource *);
> +extern void clocksource_disable(struct clocksource *);
> extern void clocksource_touch_watchdog(void);
> extern struct clocksource* clocksource_get_next(void);
> extern void clocksource_change_rating(struct clocksource *cs, int rating);
> diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
> index b79f39bda7e1..920a4da58eb0 100644
> --- a/kernel/time/clocksource.c
> +++ b/kernel/time/clocksource.c
> @@ -889,6 +889,32 @@ int clocksource_unregister(struct clocksource *cs)
> }
> EXPORT_SYMBOL(clocksource_unregister);
>
> +/**
> + * clocksource_enable - enable a registered clocksource
> + * @cs: clocksource to enable
> + */
> +int clocksource_enable(struct clocksource *cs)
> +{
> + cs->flags |= CLOCK_SOURCE_USED;
> + if (cs->enable)
> + return cs->enable(cs);
I guess you should check cs->enable() return code before setting the
CLOCK_SOURCE_USED flag.
--
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 10:35 ` Alexandre Belloni
@ 2015-01-16 10:39 ` Daniel Lezcano
2015-01-16 10:48 ` Alexandre Belloni
2015-01-16 11:23 ` Russell King - ARM Linux
1 sibling, 1 reply; 14+ messages in thread
From: Daniel Lezcano @ 2015-01-16 10:39 UTC (permalink / raw)
To: Alexandre Belloni, Thomas Gleixner
Cc: John Stultz, Nicolas Ferre, Boris Brezillon, linux-arm-kernel,
linux-kernel
On 01/16/2015 11:35 AM, Alexandre Belloni wrote:
> On 16/01/2015 at 11:23:32 +0100, Thomas Gleixner wrote :
>> On Fri, 16 Jan 2015, Alexandre Belloni wrote:
>>
>>> There is no point in calling suspend/resume for unused
>>> clocksources.
>>>
>>> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
>>> ---
>>> kernel/time/clocksource.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
>>> index 920a4da58eb0..baea4e42ae90 100644
>>> --- a/kernel/time/clocksource.c
>>> +++ b/kernel/time/clocksource.c
>>> @@ -493,7 +493,7 @@ void clocksource_suspend(void)
>>> struct clocksource *cs;
>>>
>>> list_for_each_entry_reverse(cs, &clocksource_list, list)
>>> - if (cs->suspend)
>>> + if (cs->suspend && (cs->flags & CLOCK_SOURCE_USED))
>>> cs->suspend(cs);
>>
>> This might be dangerous. If the clocksource has no enable/disable
>> callbacks, but suspend/resume, then you might leave it enabled across
>> suspend.
>>
>
> Isn't that already the case?
> Right now, if you call clocksource_suspend, it doesn't matter whether
> the clocksource has an enable or not, it will be suspended. Maybe I'm
> mistaken but my patch doesn't seem to change that behaviour.
Actually, if there is no enable/disable callback, then CLOCK_SOURCE_USED
will be never set, hence the condition will always fail and the suspend
callback won't be called.
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 10:39 ` Daniel Lezcano
@ 2015-01-16 10:48 ` Alexandre Belloni
2015-01-16 10:59 ` Daniel Lezcano
0 siblings, 1 reply; 14+ messages in thread
From: Alexandre Belloni @ 2015-01-16 10:48 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Thomas Gleixner, John Stultz, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel
Hi,
On 16/01/2015 at 11:39:16 +0100, Daniel Lezcano wrote :
> >Isn't that already the case?
> >Right now, if you call clocksource_suspend, it doesn't matter whether
> >the clocksource has an enable or not, it will be suspended. Maybe I'm
> >mistaken but my patch doesn't seem to change that behaviour.
>
> Actually, if there is no enable/disable callback, then CLOCK_SOURCE_USED
> will be never set, hence the condition will always fail and the suspend
> callback won't be called.
>
It is set in clocksource_enable/disable, even if there is no
enable/disable callback. I only found direct calls to ->enable() in
timekeeper.c, did I miss some?
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 10:48 ` Alexandre Belloni
@ 2015-01-16 10:59 ` Daniel Lezcano
2015-01-16 11:07 ` Alexandre Belloni
0 siblings, 1 reply; 14+ messages in thread
From: Daniel Lezcano @ 2015-01-16 10:59 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Thomas Gleixner, John Stultz, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel
On 01/16/2015 11:48 AM, Alexandre Belloni wrote:
> Hi,
>
> On 16/01/2015 at 11:39:16 +0100, Daniel Lezcano wrote :
>>> Isn't that already the case?
>>> Right now, if you call clocksource_suspend, it doesn't matter whether
>>> the clocksource has an enable or not, it will be suspended. Maybe I'm
>>> mistaken but my patch doesn't seem to change that behaviour.
>>
>> Actually, if there is no enable/disable callback, then CLOCK_SOURCE_USED
>> will be never set, hence the condition will always fail and the suspend
>> callback won't be called.
>>
>
> It is set in clocksource_enable/disable, even if there is no
> enable/disable callback.
Ah, right. But shouldn't we set the flag only if the callback is present
and succeed as Boris mentioned it ?
> I only found direct calls to ->enable() in
> timekeeper.c, did I miss some?
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 10:59 ` Daniel Lezcano
@ 2015-01-16 11:07 ` Alexandre Belloni
2015-01-16 11:45 ` Alexandre Belloni
0 siblings, 1 reply; 14+ messages in thread
From: Alexandre Belloni @ 2015-01-16 11:07 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Thomas Gleixner, John Stultz, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel
On 16/01/2015 at 11:59:33 +0100, Daniel Lezcano wrote :
> On 01/16/2015 11:48 AM, Alexandre Belloni wrote:
> >Hi,
> >
> >On 16/01/2015 at 11:39:16 +0100, Daniel Lezcano wrote :
> >>>Isn't that already the case?
> >>>Right now, if you call clocksource_suspend, it doesn't matter whether
> >>>the clocksource has an enable or not, it will be suspended. Maybe I'm
> >>>mistaken but my patch doesn't seem to change that behaviour.
> >>
> >>Actually, if there is no enable/disable callback, then CLOCK_SOURCE_USED
> >>will be never set, hence the condition will always fail and the suspend
> >>callback won't be called.
> >>
> >
> >It is set in clocksource_enable/disable, even if there is no
> >enable/disable callback.
>
> Ah, right. But shouldn't we set the flag only if the callback is present and
> succeed as Boris mentioned it ?
>
What Boris was suggesting was that if the enable exist, set it only if
it succeed. Which gives something like that:
int clocksource_enable(struct clocksource *cs)
{
int ret = 0;
if (cs->enable)
ret = cs->enable(cs);
if (!ret)
cs->flags |= CLOCK_SOURCE_USED;
return 0;
}
I will use that version in v2.
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 10:35 ` Alexandre Belloni
2015-01-16 10:39 ` Daniel Lezcano
@ 2015-01-16 11:23 ` Russell King - ARM Linux
2015-01-16 11:28 ` Alexandre Belloni
1 sibling, 1 reply; 14+ messages in thread
From: Russell King - ARM Linux @ 2015-01-16 11:23 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Thomas Gleixner, Boris Brezillon, Daniel Lezcano, Nicolas Ferre,
linux-kernel, John Stultz, linux-arm-kernel
On Fri, Jan 16, 2015 at 11:35:30AM +0100, Alexandre Belloni wrote:
> On 16/01/2015 at 11:23:32 +0100, Thomas Gleixner wrote :
> > On Fri, 16 Jan 2015, Alexandre Belloni wrote:
> >
> > > There is no point in calling suspend/resume for unused
> > > clocksources.
> > >
> > > Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> > > ---
> > > kernel/time/clocksource.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
> > > index 920a4da58eb0..baea4e42ae90 100644
> > > --- a/kernel/time/clocksource.c
> > > +++ b/kernel/time/clocksource.c
> > > @@ -493,7 +493,7 @@ void clocksource_suspend(void)
> > > struct clocksource *cs;
> > >
> > > list_for_each_entry_reverse(cs, &clocksource_list, list)
> > > - if (cs->suspend)
> > > + if (cs->suspend && (cs->flags & CLOCK_SOURCE_USED))
> > > cs->suspend(cs);
> >
> > This might be dangerous. If the clocksource has no enable/disable
> > callbacks, but suspend/resume, then you might leave it enabled across
> > suspend.
> >
>
> Isn't that already the case?
> Right now, if you call clocksource_suspend, it doesn't matter whether
> the clocksource has an enable or not, it will be suspended. Maybe I'm
> mistaken but my patch doesn't seem to change that behaviour.
You change an "always suspend" problem to a "never suspend" problem
since those clocksources which are used, but do not have an ->enable
callback will not be marked with CLOCK_SOURCE_USED.
Look at patch 1:
- if (!new->enable || new->enable(new) == 0) {
+ if (!new->enable || clocksource_enable(new) == 0) {
If new->enable is NULL, clocksource_enable() won't be called, which
means there's nothing which sets CLOCK_SOURCE_USED, which in turn
means that ->suspend() will never be called.
--
FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up
according to speedtest.net.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 11:23 ` Russell King - ARM Linux
@ 2015-01-16 11:28 ` Alexandre Belloni
0 siblings, 0 replies; 14+ messages in thread
From: Alexandre Belloni @ 2015-01-16 11:28 UTC (permalink / raw)
To: Russell King - ARM Linux
Cc: Thomas Gleixner, Boris Brezillon, Daniel Lezcano, Nicolas Ferre,
linux-kernel, John Stultz, linux-arm-kernel
On 16/01/2015 at 11:23:24 +0000, Russell King - ARM Linux wrote :
> On Fri, Jan 16, 2015 at 11:35:30AM +0100, Alexandre Belloni wrote:
> > On 16/01/2015 at 11:23:32 +0100, Thomas Gleixner wrote :
> > > On Fri, 16 Jan 2015, Alexandre Belloni wrote:
> > >
> > > > There is no point in calling suspend/resume for unused
> > > > clocksources.
> > > >
> > > > Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> > > > ---
> > > > kernel/time/clocksource.c | 4 ++--
> > > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
> > > > index 920a4da58eb0..baea4e42ae90 100644
> > > > --- a/kernel/time/clocksource.c
> > > > +++ b/kernel/time/clocksource.c
> > > > @@ -493,7 +493,7 @@ void clocksource_suspend(void)
> > > > struct clocksource *cs;
> > > >
> > > > list_for_each_entry_reverse(cs, &clocksource_list, list)
> > > > - if (cs->suspend)
> > > > + if (cs->suspend && (cs->flags & CLOCK_SOURCE_USED))
> > > > cs->suspend(cs);
> > >
> > > This might be dangerous. If the clocksource has no enable/disable
> > > callbacks, but suspend/resume, then you might leave it enabled across
> > > suspend.
> > >
> >
> > Isn't that already the case?
> > Right now, if you call clocksource_suspend, it doesn't matter whether
> > the clocksource has an enable or not, it will be suspended. Maybe I'm
> > mistaken but my patch doesn't seem to change that behaviour.
>
> You change an "always suspend" problem to a "never suspend" problem
> since those clocksources which are used, but do not have an ->enable
> callback will not be marked with CLOCK_SOURCE_USED.
>
> Look at patch 1:
>
> - if (!new->enable || new->enable(new) == 0) {
> + if (!new->enable || clocksource_enable(new) == 0) {
>
> If new->enable is NULL, clocksource_enable() won't be called, which
> means there's nothing which sets CLOCK_SOURCE_USED, which in turn
> means that ->suspend() will never be called.
>
My mistake, I should have remove the check, this should be:
if (clocksource_enable(new) == 0)
And I'll do the change suggested by Boris which should solve that
issue.
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 2/2] clocksource: don't suspend/resume when unused
2015-01-16 11:07 ` Alexandre Belloni
@ 2015-01-16 11:45 ` Alexandre Belloni
0 siblings, 0 replies; 14+ messages in thread
From: Alexandre Belloni @ 2015-01-16 11:45 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Thomas Gleixner, John Stultz, Nicolas Ferre, Boris Brezillon,
linux-arm-kernel, linux-kernel
On 16/01/2015 at 12:07:42 +0100, Alexandre Belloni wrote :
> On 16/01/2015 at 11:59:33 +0100, Daniel Lezcano wrote :
> > On 01/16/2015 11:48 AM, Alexandre Belloni wrote:
> > >Hi,
> > >
> > >On 16/01/2015 at 11:39:16 +0100, Daniel Lezcano wrote :
> > >>>Isn't that already the case?
> > >>>Right now, if you call clocksource_suspend, it doesn't matter whether
> > >>>the clocksource has an enable or not, it will be suspended. Maybe I'm
> > >>>mistaken but my patch doesn't seem to change that behaviour.
> > >>
> > >>Actually, if there is no enable/disable callback, then CLOCK_SOURCE_USED
> > >>will be never set, hence the condition will always fail and the suspend
> > >>callback won't be called.
> > >>
> > >
> > >It is set in clocksource_enable/disable, even if there is no
> > >enable/disable callback.
> >
> > Ah, right. But shouldn't we set the flag only if the callback is present and
> > succeed as Boris mentioned it ?
> >
>
> What Boris was suggesting was that if the enable exist, set it only if
> it succeed. Which gives something like that:
>
> int clocksource_enable(struct clocksource *cs)
> {
> int ret = 0;
>
> if (cs->enable)
> ret = cs->enable(cs);
>
> if (!ret)
> cs->flags |= CLOCK_SOURCE_USED;
>
> return 0;
Obviously, that is
return ret;
> }
>
> I will use that version in v2.
>
>
> --
> Alexandre Belloni, Free Electrons
> Embedded Linux, Kernel and Android engineering
> http://free-electrons.com
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [RFC 1/2] clocksource: track usage
2015-01-16 9:17 ` [RFC 1/2] clocksource: track usage Alexandre Belloni
2015-01-16 10:39 ` Boris Brezillon
@ 2015-02-02 20:03 ` Kevin Hilman
1 sibling, 0 replies; 14+ messages in thread
From: Kevin Hilman @ 2015-02-02 20:03 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Thomas Gleixner, John Stultz, Daniel Lezcano, Nicolas Ferre,
Boris Brezillon, linux-arm-kernel, linux-kernel
Alexandre Belloni <alexandre.belloni@free-electrons.com> writes:
> Track whether the clocksource is enabled or disabled.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
> include/linux/clocksource.h | 4 ++++
> kernel/time/clocksource.c | 26 ++++++++++++++++++++++++++
> kernel/time/timekeeping.c | 8 +++-----
> 3 files changed, 33 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
> index abcafaa20b86..7735902fc5f6 100644
> --- a/include/linux/clocksource.h
> +++ b/include/linux/clocksource.h
> @@ -210,6 +210,8 @@ struct clocksource {
> #define CLOCK_SOURCE_SUSPEND_NONSTOP 0x80
> #define CLOCK_SOURCE_RESELECT 0x100
>
> +#define CLOCK_SOURCE_USED 0x200
minor nit: How about s/USED/ENABLED/ so the flag name is similar to the
function names.
Kevin
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2015-02-02 20:03 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-16 9:17 [RFC 0/2] clocksource: don't suspend/resume when unused Alexandre Belloni
2015-01-16 9:17 ` [RFC 1/2] clocksource: track usage Alexandre Belloni
2015-01-16 10:39 ` Boris Brezillon
2015-02-02 20:03 ` Kevin Hilman
2015-01-16 9:17 ` [RFC 2/2] clocksource: don't suspend/resume when unused Alexandre Belloni
2015-01-16 10:23 ` Thomas Gleixner
2015-01-16 10:35 ` Alexandre Belloni
2015-01-16 10:39 ` Daniel Lezcano
2015-01-16 10:48 ` Alexandre Belloni
2015-01-16 10:59 ` Daniel Lezcano
2015-01-16 11:07 ` Alexandre Belloni
2015-01-16 11:45 ` Alexandre Belloni
2015-01-16 11:23 ` Russell King - ARM Linux
2015-01-16 11:28 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).