Skip to contentSkip to conversation

PM / Sleep: Suspend core code cleanups

PATCH In review Rafael J. Wysocki 2 participants 13 messages Feb 11, 2012 – Feb 13, 2012

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

cover PM / Sleep: Suspend core code cleanups

Hi,

The following three patches clean up the core system suspend code.

[1/3] - Unify and improve kerneldoc comments in kernel/power/suspend.c. [2/3] - Make enter_state() in kernel/power/suspend.c static. [3/3] - Drop suspend_stats_update() and move its code to the caller.

They are on top of the patch at:

http://marc.info/?l=linux-kernel&m=132891673021129&w=4

and are v3.4 candidates.

Thanks,
Rafael

#1 lore raw

PATCH 1/3 PM / Sleep: Unify kerneldoc comments in kernel/power/suspend.c

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

The kerneldoc comments in kernel/power/suspend.c are not formatted in the same way and the quality of some of them is questionable. Unify the formatting and improve the contents.

---
 kernel/power/suspend.c |   56 +++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 29 deletions(-)
kernel/power/suspend.c +27 -29
Index: linux/kernel/power/suspend.c
===================================================================
@@ -37,8 +37,8 @@ const char *const pm_states[PM_SUSPEND_M
 static const struct platform_suspend_ops *suspend_ops;
 
 /**
- *	suspend_set_ops - Set the global suspend method table.
- *	@ops:	Pointer to ops structure.
+ * suspend_set_ops - Set the global suspend method table.
+ * @ops: Suspend operations to use.
  */
 void suspend_set_ops(const struct platform_suspend_ops *ops)
 {
@@ -58,11 +58,11 @@ bool valid_state(suspend_state_t state)
 }
 
 /**
- * suspend_valid_only_mem - generic memory-only valid callback
+ * suspend_valid_only_mem - Generic memory-only valid callback.
  *
- * Platform drivers that implement mem suspend only and only need
- * to check for that in their .valid callback can use this instead
- * of rolling their own .valid callback.
+ * Platform drivers that implement mem suspend only and only need to check for
+ * that in their .valid() callback can use this instead of rolling their own
+ * .valid() callback.
  */
 int suspend_valid_only_mem(suspend_state_t state)
 {
@@ -83,10 +83,11 @@ static int suspend_test(int level)
 }
 
 /**
- *	suspend_prepare - Do prep work before entering low-power state.
+ * suspend_prepare - Prepare for entering system sleep state.
  *
- *	This is common code that is called for each state that we're entering.
- *	Run suspend notifiers, allocate a console and stop all processes.
+ * Common code run for every system sleep state that can be entered (except for
+ * hibernation).  Run suspend notifiers, allocate the "suspend" console and
+ * freeze processes.
  */
 static int suspend_prepare(void)
 {
@@ -131,9 +132,9 @@ void __attribute__ ((weak)) arch_suspend
 }
 
 /**
- * suspend_enter - enter the desired system sleep state.
- * @state: State to enter
- * @wakeup: Returns information that suspend should not be entered again.
+ * suspend_enter - Make the system enter the given sleep state.
+ * @state: System sleep state to enter.
+ * @wakeup: Returns information that the sleep state should not be re-entered.
  *
  * This function should be called after devices have been suspended.
  */
@@ -199,9 +200,8 @@ static int suspend_enter(suspend_state_t
 }
 
 /**
- *	suspend_devices_and_enter - suspend devices and enter the desired system
- *				    sleep state.
- *	@state:		  state to enter
+ * suspend_devices_and_enter - Suspend devices and enter system sleep state.
+ * @state: System sleep state to enter.
  */
 int suspend_devices_and_enter(suspend_state_t state)
 {
@@ -251,10 +251,10 @@ int suspend_devices_and_enter(suspend_st
 }
 
 /**
- *	suspend_finish - Do final work before exiting suspend sequence.
+ * suspend_finish - Clean up before finishing the suspend sequence.
  *
- *	Call platform code to clean up, restart processes, and free the
- *	console that we've allocated. This is not called for suspend-to-disk.
+ * Call platform code to clean up, restart processes, and free the console that
+ * we've allocated. This routine is not called for hibernation.
  */
 static void suspend_finish(void)
 {
@@ -265,14 +265,12 @@ static void suspend_finish(void)
 }
 
 /**
- *	enter_state - Do common work of entering low-power state.
- *	@state:		pm_state structure for state we're entering.
+ * enter_state - Do common work needed to enter system sleep state.
+ * @state: System sleep state to enter.
  *
- *	Make sure we're the only ones trying to enter a sleep state. Fail
- *	if someone has beat us to it, since we don't want anything weird to
- *	happen when we wake up.
- *	Then, do the setup for suspend, enter the state, and cleaup (after
- *	we've woken up).
+ * Make sure that no one else is trying to put the system into a sleep state.
+ * Fail if that's not the case.  Otherwise, prepare for system suspend, make the
+ * system enter the given sleep state and clean up after wakeup.
  */
 int enter_state(suspend_state_t state)
 {
@@ -310,11 +308,11 @@ int enter_state(suspend_state_t state)
 }
 
 /**
- *	pm_suspend - Externally visible function for suspending system.
- *	@state:		Enumerated value of state to enter.
+ * pm_suspend - Externally visible function for suspending the system.
+ * @state: System sleep state to enter.
  *
- *	Determine whether or not value is within range, get state
- *	structure, and enter (above).
+ * Check if the value of @state represents one of the supported states,
+ * execute enter_state() and update system suspend statistics.
  */
 int pm_suspend(suspend_state_t state)
 {
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] PM / Sleep: Unify kerneldoc comments in kernel/power/suspend.c

Quoted 8 lines · Rafael J. Wysocki

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

The kerneldoc comments in kernel/power/suspend.c are not formatted in the same way and the quality of some of them is questionable. Unify the formatting and improve the contents.

---

Regards,
Srivatsa S. Bhat

Quoted 125 lines
 kernel/power/suspend.c |   56 +++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 29 deletions(-)

Index: linux/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +27 -29
@@ -37,8 +37,8 @@ const char *const pm_states[PM_SUSPEND_M
 static const struct platform_suspend_ops *suspend_ops;
 
 /**
- *	suspend_set_ops - Set the global suspend method table.
- *	@ops:	Pointer to ops structure.
+ * suspend_set_ops - Set the global suspend method table.
+ * @ops: Suspend operations to use.
  */
 void suspend_set_ops(const struct platform_suspend_ops *ops)
 {
@@ -58,11 +58,11 @@ bool valid_state(suspend_state_t state)
 }
 
 /**
- * suspend_valid_only_mem - generic memory-only valid callback
+ * suspend_valid_only_mem - Generic memory-only valid callback.
  *
- * Platform drivers that implement mem suspend only and only need
- * to check for that in their .valid callback can use this instead
- * of rolling their own .valid callback.
+ * Platform drivers that implement mem suspend only and only need to check for
+ * that in their .valid() callback can use this instead of rolling their own
+ * .valid() callback.
  */
 int suspend_valid_only_mem(suspend_state_t state)
 {
@@ -83,10 +83,11 @@ static int suspend_test(int level)
 }
 
 /**
- *	suspend_prepare - Do prep work before entering low-power state.
+ * suspend_prepare - Prepare for entering system sleep state.
  *
- *	This is common code that is called for each state that we're entering.
- *	Run suspend notifiers, allocate a console and stop all processes.
+ * Common code run for every system sleep state that can be entered (except for
+ * hibernation).  Run suspend notifiers, allocate the "suspend" console and
+ * freeze processes.
  */
 static int suspend_prepare(void)
 {
@@ -131,9 +132,9 @@ void __attribute__ ((weak)) arch_suspend
 }
 
 /**
- * suspend_enter - enter the desired system sleep state.
- * @state: State to enter
- * @wakeup: Returns information that suspend should not be entered again.
+ * suspend_enter - Make the system enter the given sleep state.
+ * @state: System sleep state to enter.
+ * @wakeup: Returns information that the sleep state should not be re-entered.
  *
  * This function should be called after devices have been suspended.
  */
@@ -199,9 +200,8 @@ static int suspend_enter(suspend_state_t
 }
 
 /**
- *	suspend_devices_and_enter - suspend devices and enter the desired system
- *				    sleep state.
- *	@state:		  state to enter
+ * suspend_devices_and_enter - Suspend devices and enter system sleep state.
+ * @state: System sleep state to enter.
  */
 int suspend_devices_and_enter(suspend_state_t state)
 {
@@ -251,10 +251,10 @@ int suspend_devices_and_enter(suspend_st
 }
 
 /**
- *	suspend_finish - Do final work before exiting suspend sequence.
+ * suspend_finish - Clean up before finishing the suspend sequence.
  *
- *	Call platform code to clean up, restart processes, and free the
- *	console that we've allocated. This is not called for suspend-to-disk.
+ * Call platform code to clean up, restart processes, and free the console that
+ * we've allocated. This routine is not called for hibernation.
  */
 static void suspend_finish(void)
 {
@@ -265,14 +265,12 @@ static void suspend_finish(void)
 }
 
 /**
- *	enter_state - Do common work of entering low-power state.
- *	@state:		pm_state structure for state we're entering.
+ * enter_state - Do common work needed to enter system sleep state.
+ * @state: System sleep state to enter.
  *
- *	Make sure we're the only ones trying to enter a sleep state. Fail
- *	if someone has beat us to it, since we don't want anything weird to
- *	happen when we wake up.
- *	Then, do the setup for suspend, enter the state, and cleaup (after
- *	we've woken up).
+ * Make sure that no one else is trying to put the system into a sleep state.
+ * Fail if that's not the case.  Otherwise, prepare for system suspend, make the
+ * system enter the given sleep state and clean up after wakeup.
  */
 int enter_state(suspend_state_t state)
 {
@@ -310,11 +308,11 @@ int enter_state(suspend_state_t state)
 }
 
 /**
- *	pm_suspend - Externally visible function for suspending system.
- *	@state:		Enumerated value of state to enter.
+ * pm_suspend - Externally visible function for suspending the system.
+ * @state: System sleep state to enter.
  *
- *	Determine whether or not value is within range, get state
- *	structure, and enter (above).
+ * Check if the value of @state represents one of the supported states,
+ * execute enter_state() and update system suspend statistics.
  */
 int pm_suspend(suspend_state_t state)
 {
#3 lore raw

PATCH 2/3 PM / Sleep: Make enter_state() in kernel/power/suspend.c static

In reply to Rafael J. Wysocki

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

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    6 +-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)
kernel/power/main.c +1 -5
Index: linux/kernel/power/main.c
===================================================================
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobjec
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
 		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
-			break;
-	}
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+			error = pm_suspend(state);
 	}
 #endif
 
kernel/power/power.h +0 -2
Index: linux/kernel/power/power.h
===================================================================
@@ -177,13 +177,11 @@ extern const char *const pm_states[];
 
 extern bool valid_state(suspend_state_t state);
 extern int suspend_devices_and_enter(suspend_state_t state);
-extern int enter_state(suspend_state_t state);
 #else /* !CONFIG_SUSPEND */
 static inline int suspend_devices_and_enter(suspend_state_t state)
 {
 	return -ENOSYS;
 }
-static inline int enter_state(suspend_state_t state) { return -ENOSYS; }
 static inline bool valid_state(suspend_state_t state) { return false; }
 #endif /* !CONFIG_SUSPEND */
 
kernel/power/suspend.c +1 -1
Index: linux/kernel/power/suspend.c
===================================================================
@@ -272,7 +272,7 @@ static void suspend_finish(void)
  * Fail if that's not the case.  Otherwise, prepare for system suspend, make the
  * system enter the given sleep state and clean up after wakeup.
  */
-int enter_state(suspend_state_t state)
+static int enter_state(suspend_state_t state)
 {
 	int error;
 
#4 lore raw

Re: [PATCH 2/3] PM / Sleep: Make enter_state() in kernel/power/suspend.c static

Quoted 19 lines · Rafael J. Wysocki

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

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    6 +-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c static ssize_t state_store(struct kobjec · line 295

Quoted 9 lines
kernel/power/main.c +1 -5
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobjec
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
 		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
-			break;
-	}
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+			error = pm_suspend(state);

This code will not stop after calling pm_suspend(). It will try more iterations in the for loop right?

We can probably keep the 'for' loop as it is, and just replace the 'if' block following the 'for' loop by: error = pm_suspend(state);

Regards,
Srivatsa S. Bhat

#5 lore raw

Re: [PATCH 2/3] PM / Sleep: Make enter_state() in kernel/power/suspend.c static

Quoted 26 lines · Srivatsa S. Bhat
Quoted 24 lines · Rafael J. Wysocki

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

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    6 +-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c +0 -2
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobjec
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
 		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
-			break;
-	}
Quoted 8 lines

kernel/power/main.c static ssize_t state_store(struct kobjec · line 295

Quoted 4 lines
kernel/power/main.c +1 -3
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+			error = pm_suspend(state);

This code will not stop after calling pm_suspend(). It will try more iterations in the for loop right?

Well, only one string in pm_states[] can be matched at a time, but I agree that it doesn't make sense to continue the loop after we've found a match.

Quoted 2 lines

We can probably keep the 'for' loop as it is, and just replace the 'if' block following the 'for' loop by: error = pm_suspend(state);

I think the patch below is correct.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Make enter_state() in kernel/power/suspend.c static

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    8 +++-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 4 insertions(+), 8 deletions(-)
kernel/power/main.c +3 -5
Index: linux/kernel/power/main.c
===================================================================
@@ -291,12 +291,10 @@ static ssize_t state_store(struct kobjec
 
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
-		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
+		if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
+			error = pm_suspend(state);
 			break;
-	}
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+		}
 	}
 #endif
 
kernel/power/power.h +0 -2
Index: linux/kernel/power/power.h
===================================================================
@@ -177,13 +177,11 @@ extern const char *const pm_states[];
 
 extern bool valid_state(suspend_state_t state);
 extern int suspend_devices_and_enter(suspend_state_t state);
-extern int enter_state(suspend_state_t state);
 #else /* !CONFIG_SUSPEND */
 static inline int suspend_devices_and_enter(suspend_state_t state)
 {
 	return -ENOSYS;
 }
-static inline int enter_state(suspend_state_t state) { return -ENOSYS; }
 static inline bool valid_state(suspend_state_t state) { return false; }
 #endif /* !CONFIG_SUSPEND */
 
kernel/power/suspend.c +1 -1
Index: linux/kernel/power/suspend.c
===================================================================
@@ -272,7 +272,7 @@ static void suspend_finish(void)
  * Fail if that's not the case.  Otherwise, prepare for system suspend, make the
  * system enter the given sleep state and clean up after wakeup.
  */
-int enter_state(suspend_state_t state)
+static int enter_state(suspend_state_t state)
 {
 	int error;
 
#6 lore raw

Re: [PATCH 2/3] PM / Sleep: Make enter_state() in kernel/power/suspend.c static

Quoted 51 lines · Rafael J. Wysocki
Quoted 26 lines · Srivatsa S. Bhat
Quoted 24 lines · Rafael J. Wysocki

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

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    6 +-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c +0 -2
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobjec
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
 		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
-			break;
-	}
Quoted 8 lines

kernel/power/main.c static ssize_t state_store(struct kobjec

Quoted 4 lines
kernel/power/main.c +1 -3
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+			error = pm_suspend(state);

This code will not stop after calling pm_suspend(). It will try more iterations in the for loop right?

Well, only one string in pm_states[] can be matched at a time, but I agree that it doesn't make sense to continue the loop after we've found a match.

Quoted 2 lines

We can probably keep the 'for' loop as it is, and just replace the 'if' block following the 'for' loop by: error = pm_suspend(state);

I think the patch below is correct.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Make enter_state() in kernel/power/suspend.c static

Quoted 7 lines

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---

Yeah, this version of the patch will work fine.

Regards,
Srivatsa S. Bhat

Quoted 57 lines
 kernel/power/main.c    |    8 +++-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 4 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c +3 -5
@@ -291,12 +291,10 @@ static ssize_t state_store(struct kobjec
 
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
-		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
+		if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
+			error = pm_suspend(state);
 			break;
-	}
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+		}
 	}
 #endif
 

Index: linux/kernel/power/power.h
===================================================================

kernel/power/power.h +0 -2
@@ -177,13 +177,11 @@ extern const char *const pm_states[];
 
 extern bool valid_state(suspend_state_t state);
 extern int suspend_devices_and_enter(suspend_state_t state);
-extern int enter_state(suspend_state_t state);
 #else /* !CONFIG_SUSPEND */
 static inline int suspend_devices_and_enter(suspend_state_t state)
 {
 	return -ENOSYS;
 }
-static inline int enter_state(suspend_state_t state) { return -ENOSYS; }
 static inline bool valid_state(suspend_state_t state) { return false; }
 #endif /* !CONFIG_SUSPEND */
 

Index: linux/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +1 -1
@@ -272,7 +272,7 @@ static void suspend_finish(void)
  * Fail if that's not the case.  Otherwise, prepare for system suspend, make the
  * system enter the given sleep state and clean up after wakeup.
  */
-int enter_state(suspend_state_t state)
+static int enter_state(suspend_state_t state)
 {
 	int error;
 
#7 lore raw

Re: [PATCH 2/3] PM / Sleep: Make enter_state() in kernel/power/suspend.c static

Quoted 58 lines · Srivatsa S. Bhat
Quoted 56 lines · Rafael J. Wysocki
Quoted 26 lines · Srivatsa S. Bhat
Quoted 24 lines · Rafael J. Wysocki

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

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    6 +-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c +0 -2
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobjec
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
 		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
-			break;
-	}
Quoted 8 lines

kernel/power/main.c static ssize_t state_store(struct kobjec

Quoted 4 lines
kernel/power/main.c +1 -3
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+			error = pm_suspend(state);

This code will not stop after calling pm_suspend(). It will try more iterations in the for loop right?

Well, only one string in pm_states[] can be matched at a time, but I agree that it doesn't make sense to continue the loop after we've found a match.

Quoted 2 lines

We can probably keep the 'for' loop as it is, and just replace the 'if' block following the 'for' loop by: error = pm_suspend(state);

I think the patch below is correct.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Make enter_state() in kernel/power/suspend.c static

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

Quoted 7 lines
Quoted 2 lines

---

Yeah, this version of the patch will work fine.

Thanks!

I wonder if that should be Reviewed-by, tough? You evidently have reviewed the patch (actually, all three of them).

Rafael

Quoted 60 lines
Quoted 57 lines
 kernel/power/main.c    |    8 +++-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 4 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c +3 -5
@@ -291,12 +291,10 @@ static ssize_t state_store(struct kobjec
 
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
-		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
+		if (*s && len == strlen(*s) && !strncmp(buf, *s, len)) {
+			error = pm_suspend(state);
 			break;
-	}
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+		}
 	}
 #endif
 

Index: linux/kernel/power/power.h
===================================================================

kernel/power/power.h +0 -2
@@ -177,13 +177,11 @@ extern const char *const pm_states[];
 
 extern bool valid_state(suspend_state_t state);
 extern int suspend_devices_and_enter(suspend_state_t state);
-extern int enter_state(suspend_state_t state);
 #else /* !CONFIG_SUSPEND */
 static inline int suspend_devices_and_enter(suspend_state_t state)
 {
 	return -ENOSYS;
 }
-static inline int enter_state(suspend_state_t state) { return -ENOSYS; }
 static inline bool valid_state(suspend_state_t state) { return false; }
 #endif /* !CONFIG_SUSPEND */
 

Index: linux/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +1 -1
@@ -272,7 +272,7 @@ static void suspend_finish(void)
  * Fail if that's not the case.  Otherwise, prepare for system suspend, make the
  * system enter the given sleep state and clean up after wakeup.
  */
-int enter_state(suspend_state_t state)
+static int enter_state(suspend_state_t state)
 {
 	int error;
 
#8 lore raw

Re: [PATCH 2/3] PM / Sleep: Make enter_state() in kernel/power/suspend.c static

Quoted 63 lines · Rafael J. Wysocki
Quoted 62 lines · Srivatsa S. Bhat
Quoted 58 lines · Rafael J. Wysocki
Quoted 26 lines · Srivatsa S. Bhat
Quoted 24 lines · Rafael J. Wysocki

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

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    6 +-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c +0 -2
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobjec
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
 		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
-			break;
-	}
Quoted 8 lines

kernel/power/main.c static ssize_t state_store(struct kobjec

Quoted 4 lines
kernel/power/main.c +1 -3
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+			error = pm_suspend(state);

This code will not stop after calling pm_suspend(). It will try more iterations in the for loop right?

Well, only one string in pm_states[] can be matched at a time, but I agree that it doesn't make sense to continue the loop after we've found a match.

Quoted 2 lines

We can probably keep the 'for' loop as it is, and just replace the 'if' block following the 'for' loop by: error = pm_suspend(state);

I think the patch below is correct.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Make enter_state() in kernel/power/suspend.c static

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---

Quoted 9 lines
Quoted 3 lines

Yeah, this version of the patch will work fine.

Thanks!

I wonder if that should be Reviewed-by, tough? You evidently have reviewed the patch (actually, all three of them).

Anything is fine :-) It is not very clear to me when to use Reviewed-by and when to use Acked-by.. so I randomly chose one of them.. :-)
But please enlighten me as to when to use which one, so that in the future, I can use the right one :-)

Regards,
Srivatsa S. Bhat

#9 lore raw

Re: [PATCH 2/3] PM / Sleep: Make enter_state() in kernel/power/suspend.c static

Quoted 76 lines · Srivatsa S. Bhat
Quoted 63 lines · Rafael J. Wysocki
Quoted 62 lines · Srivatsa S. Bhat
Quoted 58 lines · Rafael J. Wysocki
Quoted 26 lines · Srivatsa S. Bhat
Quoted 24 lines · Rafael J. Wysocki

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

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    6 +-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c +0 -2
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobjec
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
 		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
-			break;
-	}
Quoted 8 lines

kernel/power/main.c static ssize_t state_store(struct kobjec

Quoted 4 lines
kernel/power/main.c +1 -3
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+			error = pm_suspend(state);

This code will not stop after calling pm_suspend(). It will try more iterations in the for loop right?

Well, only one string in pm_states[] can be matched at a time, but I agree that it doesn't make sense to continue the loop after we've found a match.

Quoted 2 lines

We can probably keep the 'for' loop as it is, and just replace the 'if' block following the 'for' loop by: error = pm_suspend(state);

I think the patch below is correct.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Make enter_state() in kernel/power/suspend.c static

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---

Quoted 9 lines
Quoted 3 lines

Yeah, this version of the patch will work fine.

Thanks!

I wonder if that should be Reviewed-by, tough? You evidently have reviewed the patch (actually, all three of them).

Quoted 4 lines

Anything is fine :-) It is not very clear to me when to use Reviewed-by and when to use Acked-by.. so I randomly chose one of them.. :-)
But please enlighten me as to when to use which one, so that in the future, I can use the right one :-)

"Acked-by" means, roughly, "I have no objection" or "looks good to me", depending on who's saying that, but it doesn't imply that you've had more than a cursory look at the patch in question. "Reviewied-by", in contrast, means something like "I have reviewed the patch in detail and haven't found anything wrong in it" (which obviously means that you have no objection too, because otherwise you'd have found _something_ wrong in the patch).

So, "Acked-by" from anyone other than the relevant maintainer is just an "I'm for" declaration, while "Reviewied-by" from _anyone_ carries some actual weight.

Thanks,
Rafael

#10 lore raw

Re: [PATCH 2/3] PM / Sleep: Make enter_state() in kernel/power/suspend.c static

Quoted 89 lines · Rafael J. Wysocki
Quoted 76 lines · Srivatsa S. Bhat
Quoted 63 lines · Rafael J. Wysocki
Quoted 62 lines · Srivatsa S. Bhat
Quoted 58 lines · Rafael J. Wysocki
Quoted 26 lines · Srivatsa S. Bhat
Quoted 24 lines · Rafael J. Wysocki

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

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---
 kernel/power/main.c    |    6 +-----
 kernel/power/power.h   |    2 --
 kernel/power/suspend.c |    2 +-
 3 files changed, 2 insertions(+), 8 deletions(-)

Index: linux/kernel/power/main.c
===================================================================

kernel/power/main.c +0 -2
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobjec
 #ifdef CONFIG_SUSPEND
 	for (s = &pm_states[state]; state < PM_SUSPEND_MAX; s++, state++) {
 		if (*s && len == strlen(*s) && !strncmp(buf, *s, len))
-			break;
-	}
Quoted 8 lines

kernel/power/main.c static ssize_t state_store(struct kobjec

Quoted 4 lines
kernel/power/main.c +1 -3
-	if (state < PM_SUSPEND_MAX && *s) {
-		error = enter_state(state);
-		suspend_stats_update(error);
+			error = pm_suspend(state);

This code will not stop after calling pm_suspend(). It will try more iterations in the for loop right?

Well, only one string in pm_states[] can be matched at a time, but I agree that it doesn't make sense to continue the loop after we've found a match.

Quoted 2 lines

We can probably keep the 'for' loop as it is, and just replace the 'if' block following the 'for' loop by: error = pm_suspend(state);

I think the patch below is correct.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: PM / Sleep: Make enter_state() in kernel/power/suspend.c static

The enter_state() function in kernel/power/suspend.c should be static and state_store() in kernel/power/suspend.c should call pm_suspend() instead of it, so make that happen (which also reduces code duplication related to suspend statistics).

---

Quoted 9 lines
Quoted 3 lines

Yeah, this version of the patch will work fine.

Thanks!

I wonder if that should be Reviewed-by, tough? You evidently have reviewed the patch (actually, all three of them).

Quoted 4 lines

Anything is fine :-) It is not very clear to me when to use Reviewed-by and when to use Acked-by.. so I randomly chose one of them.. :-)
But please enlighten me as to when to use which one, so that in the future, I can use the right one :-)

"Acked-by" means, roughly, "I have no objection" or "looks good to me", depending on who's saying that, but it doesn't imply that you've had more than a cursory look at the patch in question. "Reviewied-by", in contrast, means something like "I have reviewed the patch in detail and haven't found anything wrong in it" (which obviously means that you have no objection too, because otherwise you'd have found _something_ wrong in the patch).

Quoted 4 lines

So, "Acked-by" from anyone other than the relevant maintainer is just an "I'm for" declaration, while "Reviewied-by" from _anyone_ carries some actual weight.

Wow! Nice :-) Thanks for the great explanation! I'll keep this in mind from the next time onwards :-)

Regards,
Srivatsa S. Bhat

#11 lore raw

PATCH 3/3 PM / Sleep: Drop suspend_stats_update()

In reply to Rafael J. Wysocki

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

Since suspend_stats_update() is only called from pm_suspend(), move its code directly into that function and remove the static inline definition from include/linux/suspend.h. Clean up pm_suspend() in the process.

---
 include/linux/suspend.h |   16 ----------------
 kernel/power/suspend.c  |   18 ++++++++++++------
 2 files changed, 12 insertions(+), 22 deletions(-)
include/linux/suspend.h +0 -16
Index: linux/include/linux/suspend.h
===================================================================
@@ -95,22 +95,6 @@ static inline void dpm_save_failed_step(
 }
 
 /**
- * suspend_stats_update - Update success/failure statistics of suspend-to-ram
- *
- * @error: Value returned by enter_state() function
- */
-static inline void suspend_stats_update(int error)
-{
-	if (error) {
-		suspend_stats.fail++;
-		dpm_save_failed_errno(error);
-	} else {
-		suspend_stats.success++;
-	}
-}
-
-
-/**
  * struct platform_suspend_ops - Callbacks for managing platform dependent
  *	system sleep states.
  *
kernel/power/suspend.c +12 -6
Index: linux/kernel/power/suspend.c
===================================================================
@@ -316,12 +316,18 @@ static int enter_state(suspend_state_t s
  */
 int pm_suspend(suspend_state_t state)
 {
-	int ret;
-	if (state > PM_SUSPEND_ON && state < PM_SUSPEND_MAX) {
-		ret = enter_state(state);
-		suspend_stats_update(ret);
-		return ret;
+	int error;
+
+	if (state <= PM_SUSPEND_ON || state >= PM_SUSPEND_MAX)
+		return -EINVAL;
+
+	error = enter_state(state);
+	if (error) {
+		suspend_stats.fail++;
+		dpm_save_failed_errno(error);
+	} else {
+		suspend_stats.success++;
 	}
-	return -EINVAL;
+	return error;
 }
 EXPORT_SYMBOL(pm_suspend);
Acked-by on v1 3/3
#12 lore raw

Re: [PATCH 3/3] PM / Sleep: Drop suspend_stats_update()

Quoted 9 lines · Rafael J. Wysocki

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

Since suspend_stats_update() is only called from pm_suspend(), move its code directly into that function and remove the static inline definition from include/linux/suspend.h. Clean up pm_suspend() in the process.

---

Regards,
Srivatsa S. Bhat

Quoted 61 lines
 include/linux/suspend.h |   16 ----------------
 kernel/power/suspend.c  |   18 ++++++++++++------
 2 files changed, 12 insertions(+), 22 deletions(-)

Index: linux/include/linux/suspend.h
===================================================================

include/linux/suspend.h +0 -16
@@ -95,22 +95,6 @@ static inline void dpm_save_failed_step(
 }
 
 /**
- * suspend_stats_update - Update success/failure statistics of suspend-to-ram
- *
- * @error: Value returned by enter_state() function
- */
-static inline void suspend_stats_update(int error)
-{
-	if (error) {
-		suspend_stats.fail++;
-		dpm_save_failed_errno(error);
-	} else {
-		suspend_stats.success++;
-	}
-}
-
-
-/**
  * struct platform_suspend_ops - Callbacks for managing platform dependent
  *	system sleep states.
  *

Index: linux/kernel/power/suspend.c
===================================================================

kernel/power/suspend.c +12 -6
@@ -316,12 +316,18 @@ static int enter_state(suspend_state_t s
  */
 int pm_suspend(suspend_state_t state)
 {
-	int ret;
-	if (state > PM_SUSPEND_ON && state < PM_SUSPEND_MAX) {
-		ret = enter_state(state);
-		suspend_stats_update(ret);
-		return ret;
+	int error;
+
+	if (state <= PM_SUSPEND_ON || state >= PM_SUSPEND_MAX)
+		return -EINVAL;
+
+	error = enter_state(state);
+	if (error) {
+		suspend_stats.fail++;
+		dpm_save_failed_errno(error);
+	} else {
+		suspend_stats.success++;
 	}
-	return -EINVAL;
+	return error;
 }
 EXPORT_SYMBOL(pm_suspend);