Skip to contentSkip to conversation

pm: Introduce __pm to mark power management code

PATCH In review Guenter Roeck 2 participants 5 messages May 9, 2013 – May 10, 2013

Subsystems (4)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

cover pm: Introduce __pm to mark power management code

The following patch series introduces a marker for power management functions and data. This this marker, #ifdef CONFIG_PM and #ifdef CONFIG_PM_SLEEP can be removed from most of the code. This ensures that the conditional code still compiles but is not included in the object file.

As a side effect, drivers declaring struct dev_pm_ops unconditionally get a bit smaller if CONFIG_PM_SLEEP is not configured.

The first patch in the series introduces the marker, the following two patches introduce the marker in two drivers to demonstrate its use.

The patch series depends on the "PM: Add pm_ops_ptr() macro" patch submitted by Jingoo Han.

author maintainer
#1 lore raw

PATCH 1/3 pm: Introduce __pm to mark power management functions and data

By marking power management functions and data with __pm, #ifdef CONFIG_PM and #ifdef CONFIG_PM_SLEEP is no longer necessary in most cases. This ensures that the power management code still compiles even if power management is disabled, but does not consume space in the object file. As a side effect, drivers declaring struct dev_pm_ops unconditionally get a bit smaller if CONFIG_PM_SLEEP is disabled.

---
 include/linux/pm.h |    2 ++
 1 file changed, 2 insertions(+)
include/linux/pm.h +2 -0
index fe70d9b..46df155 100644
@@ -43,9 +43,11 @@ struct device;
 #ifdef CONFIG_PM
 extern const char power_group_name[];		/* = "power" */
 #define pm_ops_ptr(_ptr)	(_ptr)
+#define __pm
 #else
 #define power_group_name	NULL
 #define pm_ops_ptr(_ptr)	NULL
+#define __pm			__section(.discard)
 #endif
 
 typedef struct pm_message {
Signature · 1 line
1.7.9.7
author maintainer
#2 lore raw

PATCH 2/3 hwmon: (tmp102) Convert to use __pm instead of #ifdef CONFIG_PM

In reply to Guenter Roeck

With this change, code only needed is power management is active still compiles if it is disabled, but does not consume space in the object file.

---
 drivers/hwmon/tmp102.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/hwmon/tmp102.c +4 -10
index 523dd89..8e5d267 100644
@@ -236,8 +236,7 @@ static int tmp102_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM
-static int tmp102_suspend(struct device *dev)
+static int __pm tmp102_suspend(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	int config;
@@ -250,7 +249,7 @@ static int tmp102_suspend(struct device *dev)
 	return i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, config);
 }
 
-static int tmp102_resume(struct device *dev)
+static int __pm tmp102_resume(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	int config;
@@ -263,16 +262,11 @@ static int tmp102_resume(struct device *dev)
 	return i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, config);
 }
 
-static const struct dev_pm_ops tmp102_dev_pm_ops = {
+static const struct dev_pm_ops __pm tmp102_dev_pm_ops = {
 	.suspend	= tmp102_suspend,
 	.resume		= tmp102_resume,
 };
 
-#define TMP102_DEV_PM_OPS (&tmp102_dev_pm_ops)
-#else
-#define	TMP102_DEV_PM_OPS NULL
-#endif /* CONFIG_PM */
-
 static const struct i2c_device_id tmp102_id[] = {
 	{ "tmp102", 0 },
 	{ }
@@ -281,7 +275,7 @@ MODULE_DEVICE_TABLE(i2c, tmp102_id);
 
 static struct i2c_driver tmp102_driver = {
 	.driver.name	= DRIVER_NAME,
-	.driver.pm	= TMP102_DEV_PM_OPS,
+	.driver.pm	= pm_ops_ptr(&tmp102_dev_pm_ops),
 	.probe		= tmp102_probe,
 	.remove		= tmp102_remove,
 	.id_table	= tmp102_id,
Signature · 1 line
1.7.9.7
author maintainer
#3 lore raw

PATCH 3/3 hwmon: (max6639) Convert to use __pm instead of #ifdef CONFIG_PM_SLEEP

In reply to Guenter Roeck

Drops #ifdef from code, and ensures that conditional code still compiles if power management is disabled. Resulting code is dropped from object file.

---
 drivers/hwmon/max6639.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/hwmon/max6639.c +6 -7
index 3e7b426..6080913 100644
@@ -591,8 +591,7 @@ static int max6639_remove(struct i2c_client *client)
 	return 0;
 }
 
-#ifdef CONFIG_PM_SLEEP
-static int max6639_suspend(struct device *dev)
+static int __pm max6639_suspend(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
@@ -603,7 +602,7 @@ static int max6639_suspend(struct device *dev)
 			MAX6639_REG_GCONFIG, data | MAX6639_GCONFIG_STANDBY);
 }
 
-static int max6639_resume(struct device *dev)
+static int __pm max6639_resume(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	int data = i2c_smbus_read_byte_data(client, MAX6639_REG_GCONFIG);
@@ -613,7 +612,6 @@ static int max6639_resume(struct device *dev)
 	return i2c_smbus_write_byte_data(client,
 			MAX6639_REG_GCONFIG, data & ~MAX6639_GCONFIG_STANDBY);
 }
-#endif /* CONFIG_PM_SLEEP */
 
 static const struct i2c_device_id max6639_id[] = {
 	{"max6639", 0},
@@ -622,15 +620,16 @@ static const struct i2c_device_id max6639_id[] = {
 
 MODULE_DEVICE_TABLE(i2c, max6639_id);
 
-static const struct dev_pm_ops max6639_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(max6639_suspend, max6639_resume)
+static const struct dev_pm_ops __pm max6639_pm_ops = {
+	.suspend = max6639_suspend,
+	.resume = max6639_resume,
 };
 
 static struct i2c_driver max6639_driver = {
 	.class = I2C_CLASS_HWMON,
 	.driver = {
 		   .name = "max6639",
-		   .pm = &max6639_pm_ops,
+		   .pm = pm_ops_ptr(&max6639_pm_ops),
 		   },
 	.probe = max6639_probe,
 	.remove = max6639_remove,
Signature · 1 line
1.7.9.7
#4 lore raw
In reply to Guenter Roeck
Quoted 4 lines · Guenter Roeck

The following patch series introduces a marker for power management functions and data. This this marker, #ifdef CONFIG_PM and #ifdef CONFIG_PM_SLEEP can be removed from most of the code. This ensures that the conditional code still compiles but is not included in the object file.

Was it compile-tested for both PM_SLEEP and !PM_SLEEP cases?

If driver wants to have pm-specific fields in its structures, this will make it harder.

Ifdefs are ugly, and this has better compiler coverage in !PM_SLEEP case. Good. OTOH most people are running with PM_SLEEP, so advantage is not great...
Pavel

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