[PATCH v2 0/2] clocksource: don't suspend/resume when unused

STALE4250d

8 messages, 4 authors, 2015-01-20 · open the first message on its own page

[PATCH v2 0/2] clocksource: don't suspend/resume when unused

From: Alexandre Belloni <hidden>
Date: 2015-01-16 16:57:30

This is a quite naive implementation to track whether a clocksource 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.

Changes in v2:
 - removed the check on enable in timekeeping.c to ensure all clocksources are
   going through clocksource_enable
 - rework clocksource_enable to set CLOCK_SOURCE_USED when enable is successful
   if present

Alexandre Belloni (2):
  clocksource: track usage
  clocksource: don't suspend/resume when unused

 include/linux/clocksource.h |  4 ++++
 kernel/time/clocksource.c   | 34 ++++++++++++++++++++++++++++++++--
 kernel/time/timekeeping.c   |  8 +++-----
 3 files changed, 39 insertions(+), 7 deletions(-)

-- 
2.1.0

[PATCH v2 2/2] clocksource: don't suspend/resume when unused

From: Alexandre Belloni <hidden>
Date: 2015-01-16 16:57:39

There is no point in calling suspend/resume for unused
clocksources.

Signed-off-by: Alexandre Belloni <redacted>
---
 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 03cfc5a08e3b..da65b3b73a86 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

[PATCH v2 1/2] clocksource: track usage

From: Alexandre Belloni <hidden>
Date: 2015-01-16 16:57:55

Track whether the clocksource is enabled or disabled.

Signed-off-by: Alexandre Belloni <redacted>
---
 include/linux/clocksource.h |  4 ++++
 kernel/time/clocksource.c   | 30 ++++++++++++++++++++++++++++++
 kernel/time/timekeeping.c   |  8 +++-----
 3 files changed, 37 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..03cfc5a08e3b 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -889,6 +889,36 @@ 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)
+{
+	int ret = 0;
+
+	if (cs->enable)
+		ret = cs->enable(cs);
+
+	if (!ret)
+		cs->flags |= CLOCK_SOURCE_USED;
+
+	return ret;
+}
+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..82da6b94382c 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 (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

Re: [PATCH v2 0/2] clocksource: don't suspend/resume when unused

From: Boris Brezillon <hidden>
Date: 2015-01-16 17:45:20

On Fri, 16 Jan 2015 17:57:17 +0100
Alexandre Belloni [off-list ref] wrote:
This is a quite naive implementation to track whether a clocksource 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.
To the whole series:

Reviewed-by: Boris Brezillon <redacted>
Changes in v2:
 - removed the check on enable in timekeeping.c to ensure all clocksources are
   going through clocksource_enable
 - rework clocksource_enable to set CLOCK_SOURCE_USED when enable is successful
   if present

Alexandre Belloni (2):
  clocksource: track usage
  clocksource: don't suspend/resume when unused

 include/linux/clocksource.h |  4 ++++
 kernel/time/clocksource.c   | 34 ++++++++++++++++++++++++++++++++--
 kernel/time/timekeeping.c   |  8 +++-----
 3 files changed, 39 insertions(+), 7 deletions(-)


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

Re: [PATCH v2 1/2] clocksource: track usage

From: John Stultz <hidden>
Date: 2015-01-16 19:05:48

On Fri, Jan 16, 2015 at 8:57 AM, Alexandre Belloni
[off-list ref] wrote:
Track whether the clocksource is enabled or disabled.

So.. this commit message needs work. Why do we care to track the
clocksource enabled/disabled state?

thanks
-john

Re: [PATCH v2 1/2] clocksource: track usage

From: Alexandre Belloni <hidden>
Date: 2015-01-17 01:26:38

Hi,

On 16/01/2015 at 11:05:46 -0800, John Stultz wrote :
On Fri, Jan 16, 2015 at 8:57 AM, Alexandre Belloni
[off-list ref] wrote:
quoted
Track whether the clocksource is enabled or disabled.

So.. this commit message needs work. Why do we care to track the
clocksource enabled/disabled state?
What about:

Track whether the clocksource is enabled or disabled. This will allow to
select whether an action is necessary, for example suspend or resume.


-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

Re: [PATCH v2 1/2] clocksource: track usage

From: Thomas Gleixner <hidden>
Date: 2015-01-20 10:52:48

On Fri, 16 Jan 2015, Alexandre Belloni wrote:
quoted hunk
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
You track whether the clocksource is enabled or not, right?
quoted hunk
 /* 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 *);
This should be in kernel/time/timekeeping_internal.h
quoted hunk
 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..03cfc5a08e3b 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -889,6 +889,36 @@ 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)
+{
+	int ret = 0;
+
+	if (cs->enable)
+		ret = cs->enable(cs);
+
+	if (!ret)
+		cs->flags |= CLOCK_SOURCE_USED;
+
+	return ret;
+}
+EXPORT_SYMBOL(clocksource_enable);
Why on earth do you want to export that?
+/**
+ * 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);
Ditto.

Thanks,

	tglx

Re: [PATCH v2 2/2] clocksource: don't suspend/resume when unused

From: Thomas Gleixner <hidden>
Date: 2015-01-20 11:13:55

On Fri, 16 Jan 2015, Alexandre Belloni wrote:
There is no point in calling suspend/resume for unused
clocksources.
That's true, but ....
 
quoted hunk
Signed-off-by: Alexandre Belloni <redacted>
---
 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 03cfc5a08e3b..da65b3b73a86 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);
I had a deeper look at the clocksources which have a resume
callback. We have implementations, which rely on the resume callback
being called unconditionally. e.g.: arch/x86/kernel/hpet.c. And there
are a few others which have extra PM code in the suspend/resume path
independent of the fact whether the clocksource is enabled or not.

So we really need to make this opt-in with a per clocksource flag.

Thanks,

	tglx
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help