Skip to contentSkip to conversation

PM: Avoid building suspend-to-idle code when it is not necessary

PATCH In review Rafael J. Wysocki 4 participants 9 messages May 15, 2015 – May 19, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover PM: Avoid building suspend-to-idle code when it is not necessary

Hi,

As per the subject. Suspend-to-idle code is only used for CONFIG_SUSPEND set and it should not be built otherwise.

Thanks!

#1 lore raw

PATCH 1/2 PM / sleep: Make suspend-to-idle-specific code depend on CONFIG_SUSPEND

From: Rafael J. Wysocki <[email protected]>

Since idle_should_freeze() is defined to always return 'false' for CONFIG_SUSPEND unset, all of the code depending on it in cpuidle_idle_call() is not necessary in that case.

Make that code depend on CONFIG_SUSPEND too to avoid building it when it is not going to be used.

---
 drivers/cpuidle/cpuidle.c |    2 ++
 include/linux/cpuidle.h   |   16 ++++++++++------
 include/linux/tick.h      |   12 ++++++++----
 kernel/time/tick-common.c |    2 ++
 4 files changed, 22 insertions(+), 10 deletions(-)
include/linux/tick.h +8 -4
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -13,8 +13,6 @@
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
-extern void tick_freeze(void);
-extern void tick_unfreeze(void);
 /* Should be core only, but ARM BL switcher requires it */
 extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
@@ -23,14 +21,20 @@ extern void tick_handover_do_timer(void)
 extern void tick_cleanup_dead_cpu(int cpu);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
-static inline void tick_freeze(void) { }
-static inline void tick_unfreeze(void) { }
 static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
 static inline void tick_handover_do_timer(void) { }
 static inline void tick_cleanup_dead_cpu(int cpu) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
+#if defined(CONFIG_GENERIC_CLOCKEVENTS) && defined(CONFIG_SUSPEND)
+extern void tick_freeze(void);
+extern void tick_unfreeze(void);
+#else
+static inline void tick_freeze(void) { }
+static inline void tick_unfreeze(void) { }
+#endif
+
 #ifdef CONFIG_TICK_ONESHOT
 extern void tick_irq_enter(void);
 #  ifndef arch_needs_cpu
include/linux/cpuidle.h +10 -6
Index: linux-pm/include/linux/cpuidle.h
===================================================================
@@ -151,10 +151,6 @@ extern void cpuidle_resume(void);
 extern int cpuidle_enable_device(struct cpuidle_device *dev);
 extern void cpuidle_disable_device(struct cpuidle_device *dev);
 extern int cpuidle_play_dead(void);
-extern int cpuidle_find_deepest_state(struct cpuidle_driver *drv,
-				      struct cpuidle_device *dev);
-extern int cpuidle_enter_freeze(struct cpuidle_driver *drv,
-				struct cpuidle_device *dev);
 
 extern struct cpuidle_driver *cpuidle_get_cpu_driver(struct cpuidle_device *dev);
 #else
@@ -190,14 +186,22 @@ static inline int cpuidle_enable_device(
 {return -ENODEV; }
 static inline void cpuidle_disable_device(struct cpuidle_device *dev) { }
 static inline int cpuidle_play_dead(void) {return -ENODEV; }
+static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
+	struct cpuidle_device *dev) {return NULL; }
+#endif
+
+#if defined(CONFIG_CPU_IDLE) && defined(CONFIG_SUSPEND)
+extern int cpuidle_find_deepest_state(struct cpuidle_driver *drv,
+				      struct cpuidle_device *dev);
+extern int cpuidle_enter_freeze(struct cpuidle_driver *drv,
+				struct cpuidle_device *dev);
+#else
 static inline int cpuidle_find_deepest_state(struct cpuidle_driver *drv,
 					     struct cpuidle_device *dev)
 {return -ENODEV; }
 static inline int cpuidle_enter_freeze(struct cpuidle_driver *drv,
 				       struct cpuidle_device *dev)
 {return -ENODEV; }
-static inline struct cpuidle_driver *cpuidle_get_cpu_driver(
-	struct cpuidle_device *dev) {return NULL; }
 #endif
 
 /* kernel/sched/idle.c */
kernel/time/tick-common.c +2 -0
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -441,6 +441,7 @@ void tick_resume(void)
 	tick_resume_local();
 }
 
+#ifdef CONFIG_SUSPEND
 static DEFINE_RAW_SPINLOCK(tick_freeze_lock);
 static unsigned int tick_freeze_depth;
 
@@ -494,6 +495,7 @@ void tick_unfreeze(void)
 
 	raw_spin_unlock(&tick_freeze_lock);
 }
+#endif /* CONFIG_SUSPEND */
 
 /**
  * tick_init - initialize the tick control
drivers/cpuidle/cpuidle.c +2 -0
Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================
@@ -97,6 +97,7 @@ static int find_deepest_state(struct cpu
 	return ret;
 }
 
+#ifdef CONFIG_SUSPEND
 /**
  * cpuidle_find_deepest_state - Find the deepest available idle state.
  * @drv: cpuidle driver for the given CPU.
@@ -150,6 +151,7 @@ int cpuidle_enter_freeze(struct cpuidle_
 
 	return index;
 }
+#endif /* CONFIG_SUSPEND */
 
 /**
  * cpuidle_enter_state - enter the state and update stats
#2 lore raw

Re: [PATCH 1/2] PM / sleep: Make suspend-to-idle-specific code depend on CONFIG_SUSPEND

Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Since idle_should_freeze() is defined to always return 'false' for CONFIG_SUSPEND unset, all of the code depending on it in cpuidle_idle_call() is not necessary in that case.

Make that code depend on CONFIG_SUSPEND too to avoid building it when it is not going to be used.

ACK for the tick part.

#3 lore raw

Re: [PATCH 1/2] PM / sleep: Make suspend-to-idle-specific code depend on CONFIG_SUSPEND

Quoted 8 lines · Thomas Gleixner
Quoted 6 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Since idle_should_freeze() is defined to always return 'false' for CONFIG_SUSPEND unset, all of the code depending on it in cpuidle_idle_call() is not necessary in that case.

Quoted 6 lines
Quoted 4 lines

Make that code depend on CONFIG_SUSPEND too to avoid building it when it is not going to be used.

ACK for the tick part.

Thanks!

Acked-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] PM / sleep: Make suspend-to-idle-specific code depend on CONFIG_SUSPEND

In reply to Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Since idle_should_freeze() is defined to always return 'false' for CONFIG_SUSPEND unset, all of the code depending on it in cpuidle_idle_call() is not necessary in that case.

Make that code depend on CONFIG_SUSPEND too to avoid building it when it is not going to be used.

Signature · 5 lines
 <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
#5 lore raw

PATCH 2/2 PM / sleep: Make ->enter_freeze callbacks depend on CONFIG_SUSPEND

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

The ->enter_freeze callbacks of cpuidle drivers are only used if CONFIG_SUSPEND is set, so make them explicitly depend on that Kconfig option.

---
 drivers/acpi/processor_idle.c |   11 ++
 drivers/cpuidle/cpuidle.c     |    2 
 drivers/idle/intel_idle.c     |  186 +++++++++++++++---------------------------
 include/linux/cpuidle.h       |   14 +++
 4 files changed, 93 insertions(+), 120 deletions(-)
include/linux/cpuidle.h +14 -0
Index: linux-pm/include/linux/cpuidle.h
===================================================================
@@ -51,6 +51,7 @@ struct cpuidle_state {
 
 	int (*enter_dead) (struct cpuidle_device *dev, int index);
 
+#ifdef CONFIG_SUSPEND
 	/*
 	 * CPUs execute ->enter_freeze with the local tick or entire timekeeping
 	 * suspended, so it must not re-enable interrupts at any point (even
@@ -59,6 +60,7 @@ struct cpuidle_state {
 	void (*enter_freeze) (struct cpuidle_device *dev,
 			      struct cpuidle_driver *drv,
 			      int index);
+#endif
 };
 
 /* Idle State Flags */
@@ -67,6 +69,18 @@ struct cpuidle_state {
 
 #define CPUIDLE_DRIVER_FLAGS_MASK (0xFFFF0000)
 
+#ifdef CONFIG_SUSPEND
+static inline bool cpuidle_has_enter_freeze(struct cpuidle_state *state)
+{
+	return !!state->enter_freeze;
+}
+#else
+static inline bool cpuidle_has_enter_freeze(struct cpuidle_state *state)
+{
+	return false;
+}
+#endif
+
 struct cpuidle_device_kobj;
 struct cpuidle_state_kobj;
 struct cpuidle_driver_kobj;
drivers/acpi/processor_idle.c +10 -1
Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================
@@ -827,6 +827,7 @@ static int acpi_idle_enter(struct cpuidl
 	return index;
 }
 
+#ifdef CONFIG_SUSPEND
 static void acpi_idle_enter_freeze(struct cpuidle_device *dev,
 				   struct cpuidle_driver *drv, int index)
 {
@@ -848,6 +849,14 @@ static void acpi_idle_enter_freeze(struc
 	acpi_idle_do_entry(cx);
 }
 
+static inline void set_enter_freeze(struct cpuidle_state *state)
+{
+	state->enter_freeze = acpi_idle_enter_freeze;
+}
+#else
+static inline void set_enter_freeze(struct cpuidle_state *state) {}
+#endif
+
 struct cpuidle_driver acpi_idle_driver = {
 	.name =		"acpi_idle",
 	.owner =	THIS_MODULE,
@@ -954,7 +963,7 @@ static int acpi_processor_setup_cpuidle_
 		 * to it altogether.
 		 */
 		if (cx->type != ACPI_STATE_C1 && !acpi_idle_fallback_to_c1(pr))
-			state->enter_freeze = acpi_idle_enter_freeze;
+			set_enter_freeze(state);
 
 		count++;
 		if (count == CPUIDLE_STATE_MAX)
drivers/idle/intel_idle.c +68 -118

558 lines not on this page · raw message

drivers/cpuidle/cpuidle.c +1 -1
Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================
@@ -88,7 +88,7 @@ static int find_deepest_state(struct cpu
 		if (s->disabled || su->disable || s->exit_latency <= latency_req
 		    || s->exit_latency > max_latency
 		    || (s->flags & forbidden_flags)
-		    || (freeze && !s->enter_freeze))
+		    || (freeze && !cpuidle_has_enter_freeze(s)))
 			continue;
 
 		latency_req = s->exit_latency;
#6 lore raw

Re: [PATCH 2/2] PM / sleep: Make ->enter_freeze callbacks depend on CONFIG_SUSPEND

Quoted 5 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

The ->enter_freeze callbacks of cpuidle drivers are only used if CONFIG_SUSPEND is set, so make them explicitly depend on that Kconfig option.

No real objection, but is it worth it to sprinkle that CONFIG stuff over all drivers?

#7 lore raw

Re: [PATCH 2/2] PM / sleep: Make ->enter_freeze callbacks depend on CONFIG_SUSPEND

Quoted 9 lines · Peter Zijlstra
Quoted 5 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

The ->enter_freeze callbacks of cpuidle drivers are only used if CONFIG_SUSPEND is set, so make them explicitly depend on that Kconfig option.

No real objection, but is it worth it to sprinkle that CONFIG stuff over all drivers?

Well, you maybe right that it isn't. The footprint is small anyway.

What about [1/2]?

#8 lore raw

Re: [PATCH 2/2] PM / sleep: Make ->enter_freeze callbacks depend on CONFIG_SUSPEND

Quoted 8 lines · Rafael J. Wysocki
Quoted 7 lines · Peter Zijlstra
Quoted 5 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

The ->enter_freeze callbacks of cpuidle drivers are only used if CONFIG_SUSPEND is set, so make them explicitly depend on that Kconfig option.

Quoted 6 lines
Quoted 2 lines

No real objection, but is it worth it to sprinkle that CONFIG stuff over all drivers?

Well, you maybe right that it isn't. The footprint is small anyway.

What about [1/2]?

1/2 looks fine to me.