Skip to contentSkip to conversation

PM: More suspend core modifications

RFC PATCH In review Rafael J. Wysocki 3 participants 9 messages Jun 10, 2007

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

cover PM: More suspend core modifications

Hi,

It seems that the core suspend code can be simplified even further. Namely, it's possible to reduce code duplication in drivers/base/power/suspend.c with the help of an auxiliary inline finction and it's possible to remove the suspend and resume support from struct device_type.

Comments welcome.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#1 lore raw

RFC PATCH 1/2 PM: Reduce code duplication in the core suspend code

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

Reduce code duplication in drivers/base/suspend.c by introducing an inline function for printing diagnostic messages.

---
 drivers/base/power/suspend.c |   49 +++++++++++++++----------------------------
 1 file changed, 18 insertions(+), 31 deletions(-)
drivers/base/power/suspend.c +18 -31
Index: linux-2.6.22-rc4/drivers/base/power/suspend.c
===================================================================
@@ -40,6 +40,14 @@ static inline char *suspend_verb(u32 eve
 }
 
 
+static inline void
+suspend_device_dbg(struct device * dev, pm_message_t state, char *info)
+{
+	dev_dbg(dev, "%s%s%s\n", info, suspend_verb(state.event),
+		((state.event == PM_EVENT_SUSPEND) && device_may_wakeup(dev)) ?
+		", may wakeup" : "");
+}
+
 /**
  *	suspend_device - Save state of one device.
  *	@dev:	Device.
@@ -66,37 +74,21 @@ int suspend_device(struct device * dev, 
 	dev->power.prev_state = dev->power.power_state;
 
 	if (dev->class && dev->class->suspend && !dev->power.power_state.event) {
-		dev_dbg(dev, "class %s%s\n",
-			suspend_verb(state.event),
-			((state.event == PM_EVENT_SUSPEND)
-					&& device_may_wakeup(dev))
-				? ", may wakeup"
-				: ""
-			);
+		suspend_device_dbg(dev, state, "class ");
 		error = dev->class->suspend(dev, state);
 		suspend_report_result(dev->class->suspend, error);
 	}
 
-	if (!error && dev->type && dev->type->suspend && !dev->power.power_state.event) {
-		dev_dbg(dev, "%s%s\n",
-			suspend_verb(state.event),
-			((state.event == PM_EVENT_SUSPEND)
-					&& device_may_wakeup(dev))
-				? ", may wakeup"
-				: ""
-			);
+	if (!error && dev->type && dev->type->suspend
+	    && !dev->power.power_state.event) {
+		suspend_device_dbg(dev, state, "type ");
 		error = dev->type->suspend(dev, state);
 		suspend_report_result(dev->type->suspend, error);
 	}
 
-	if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) {
-		dev_dbg(dev, "%s%s\n",
-			suspend_verb(state.event),
-			((state.event == PM_EVENT_SUSPEND)
-					&& device_may_wakeup(dev))
-				? ", may wakeup"
-				: ""
-			);
+	if (!error && dev->bus && dev->bus->suspend
+	    && !dev->power.power_state.event) {
+		suspend_device_dbg(dev, state, "");
 		error = dev->bus->suspend(dev, state);
 		suspend_report_result(dev->bus->suspend, error);
 	}
@@ -114,14 +106,9 @@ static int suspend_device_late(struct de
 {
 	int error = 0;
 
-	if (dev->bus && dev->bus->suspend_late && !dev->power.power_state.event) {
-		dev_dbg(dev, "LATE %s%s\n",
-			suspend_verb(state.event),
-			((state.event == PM_EVENT_SUSPEND)
-					&& device_may_wakeup(dev))
-				? ", may wakeup"
-				: ""
-			);
+	if (dev->bus && dev->bus->suspend_late
+	    && !dev->power.power_state.event) {
+		suspend_device_dbg(dev, state, "LATE ");
 		error = dev->bus->suspend_late(dev, state);
 		suspend_report_result(dev->bus->suspend_late, error);
 	}
#7 lore raw

RFC PATCH 2/2 PM: Remove suspend and resume support from struct device_type

In reply to Rafael J. Wysocki

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

The suspend and resume support in struct device_type (include/linux/device.h) is not used anywhere. It is also undocumented, so it can be removed.

---
 drivers/base/power/resume.c  |    5 -----
 drivers/base/power/suspend.c |    7 -------
 include/linux/device.h       |    2 --
 3 files changed, 14 deletions(-)
drivers/base/power/resume.c +0 -5
Index: linux-2.6.22-rc4/drivers/base/power/resume.c
===================================================================
@@ -41,11 +41,6 @@ int resume_device(struct device * dev)
 		error = dev->bus->resume(dev);
 	}
 
-	if (!error && dev->type && dev->type->resume) {
-		dev_dbg(dev,"resuming\n");
-		error = dev->type->resume(dev);
-	}
-
 	if (!error && dev->class && dev->class->resume) {
 		dev_dbg(dev,"class resume\n");
 		error = dev->class->resume(dev);
drivers/base/power/suspend.c +0 -7
Index: linux-2.6.22-rc4/drivers/base/power/suspend.c
===================================================================
@@ -79,13 +79,6 @@ int suspend_device(struct device * dev, 
 		suspend_report_result(dev->class->suspend, error);
 	}
 
-	if (!error && dev->type && dev->type->suspend
-	    && !dev->power.power_state.event) {
-		suspend_device_dbg(dev, state, "type ");
-		error = dev->type->suspend(dev, state);
-		suspend_report_result(dev->type->suspend, error);
-	}
-
 	if (!error && dev->bus && dev->bus->suspend
 	    && !dev->power.power_state.event) {
 		suspend_device_dbg(dev, state, "");
include/linux/device.h +0 -2
Index: linux-2.6.22-rc4/include/linux/device.h
===================================================================
@@ -343,8 +343,6 @@ struct device_type {
 	int (*uevent)(struct device *dev, char **envp, int num_envp,
 		      char *buffer, int buffer_size);
 	void (*release)(struct device *dev);
-	int (*suspend)(struct device * dev, pm_message_t state);
-	int (*resume)(struct device * dev);
 };
 
 /* interface for exporting device attributes */
#2 lore raw

Re: [RFC][PATCH 1/2] PM: Reduce code duplication in the core suspend code

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

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

Reduce code duplication in drivers/base/suspend.c by introducing an inline function for printing diagnostic messages.

Could you save object-code space by making the function non-inline? It looks complicated enough.

Or is the compiler supposed to figure such things out for itself?

Alan Stern

#3 lore raw

Re: [RFC][PATCH 1/2] PM: Reduce code duplication in the core suspend code

Quoted 9 lines · Alan Stern
Quoted 4 lines · Rafael J. Wysocki

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

Reduce code duplication in drivers/base/suspend.c by introducing an inline function for printing diagnostic messages.

Could you save object-code space by making the function non-inline? It looks complicated enough.

I thought I would do that, but then I thought I'd want it to be compiled out if dev_dbg() were a noop (like when the debugging is off).

Quoted 1 line

Or is the compiler supposed to figure such things out for itself?

I think it is. I'll remove this 'inline'.

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#6 lore raw

Re: [RFC][PATCH 1/2] PM: Reduce code duplication in the core suspend code

In reply to Rafael J. Wysocki

Hi!

Quoted 4 lines

Reduce code duplication in drivers/base/suspend.c by introducing an inline function for printing diagnostic messages.

Looks ok to me.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#8 lore raw

Re: [RFC][PATCH 2/2] PM: Remove suspend and resume support from struct device_type

In reply to Rafael J. Wysocki

Hi!

Quoted 2 lines

The suspend and resume support in struct device_type (include/linux/device.h) is not used anywhere. It is also undocumented, so it can be removed.

I guess you should cc gregkh on this one.. and the previous series that touches driver model. And perhaps cc lkml is good idea.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#4 lore raw

Re: [RFC][PATCH 1/2] PM: Reduce code duplication in the core suspend code

In reply to Rafael J. Wysocki
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki

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

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Reduce code duplication in drivers/base/suspend.c by introducing an inline function for printing diagnostic messages.

Could you save object-code space by making the function non-inline? It looks complicated enough.

I thought I would do that, but then I thought I'd want it to be compiled out if dev_dbg() were a noop (like when the debugging is off).

You can always do something like this:

#ifdef DEBUG

static void print_msg(...)
{
...
}

#else

static inline void print_msg(...)
{ }
#endif

Alan Stern

#5 lore raw

Re: [RFC][PATCH 1/2] PM: Reduce code duplication in the core suspend code

Quoted 25 lines · Alan Stern
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Alan Stern
Quoted 2 lines · Rafael J. Wysocki

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

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Reduce code duplication in drivers/base/suspend.c by introducing an inline function for printing diagnostic messages.

Could you save object-code space by making the function non-inline? It looks complicated enough.

I thought I would do that, but then I thought I'd want it to be compiled out if dev_dbg() were a noop (like when the debugging is off).

You can always do something like this:

#ifdef DEBUG

static void print_msg(...)
{
...
}

Quoted 5 lines

#else

static inline void print_msg(...)
{ }
#endif

Well, IMHO, that doesn't look very nice. ;-)

Greetings,
Rafael

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth