public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] pm: Introduce __pm to mark power management code
@ 2013-05-09 17:09 Guenter Roeck
  2013-05-09 17:09 ` [PATCH 1/3] pm: Introduce __pm to mark power management functions and data Guenter Roeck
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Guenter Roeck @ 2013-05-09 17:09 UTC (permalink / raw)
  To: linux-pm
  Cc: linux-kernel, lm-sensors, Jean Delvare, Len Brown, Pavel Machek,
	Jingoo Han, 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.

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] pm: Introduce __pm to mark power management functions and data
  2013-05-09 17:09 [PATCH 0/3] pm: Introduce __pm to mark power management code Guenter Roeck
@ 2013-05-09 17:09 ` Guenter Roeck
  2013-05-09 17:09 ` [PATCH 2/3] hwmon: (tmp102) Convert to use __pm instead of #ifdef CONFIG_PM Guenter Roeck
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2013-05-09 17:09 UTC (permalink / raw)
  To: linux-pm
  Cc: linux-kernel, lm-sensors, Jean Delvare, Len Brown, Pavel Machek,
	Jingoo Han, Guenter Roeck

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.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 include/linux/pm.h |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/pm.h b/include/linux/pm.h
index fe70d9b..46df155 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -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 {
-- 
1.7.9.7


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] hwmon: (tmp102) Convert to use __pm instead of #ifdef CONFIG_PM
  2013-05-09 17:09 [PATCH 0/3] pm: Introduce __pm to mark power management code Guenter Roeck
  2013-05-09 17:09 ` [PATCH 1/3] pm: Introduce __pm to mark power management functions and data Guenter Roeck
@ 2013-05-09 17:09 ` Guenter Roeck
  2013-05-09 17:09 ` [PATCH 3/3] hwmon: (max6639) Convert to use __pm instead of #ifdef CONFIG_PM_SLEEP Guenter Roeck
  2013-05-10 10:54 ` [PATCH 0/3] pm: Introduce __pm to mark power management code Pavel Machek
  3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2013-05-09 17:09 UTC (permalink / raw)
  To: linux-pm
  Cc: linux-kernel, lm-sensors, Jean Delvare, Len Brown, Pavel Machek,
	Jingoo Han, 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.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/tmp102.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c
index 523dd89..8e5d267 100644
--- a/drivers/hwmon/tmp102.c
+++ b/drivers/hwmon/tmp102.c
@@ -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,
-- 
1.7.9.7


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] hwmon: (max6639) Convert to use __pm instead of #ifdef CONFIG_PM_SLEEP
  2013-05-09 17:09 [PATCH 0/3] pm: Introduce __pm to mark power management code Guenter Roeck
  2013-05-09 17:09 ` [PATCH 1/3] pm: Introduce __pm to mark power management functions and data Guenter Roeck
  2013-05-09 17:09 ` [PATCH 2/3] hwmon: (tmp102) Convert to use __pm instead of #ifdef CONFIG_PM Guenter Roeck
@ 2013-05-09 17:09 ` Guenter Roeck
  2013-05-10 10:54 ` [PATCH 0/3] pm: Introduce __pm to mark power management code Pavel Machek
  3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2013-05-09 17:09 UTC (permalink / raw)
  To: linux-pm
  Cc: linux-kernel, lm-sensors, Jean Delvare, Len Brown, Pavel Machek,
	Jingoo Han, 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.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/max6639.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/hwmon/max6639.c b/drivers/hwmon/max6639.c
index 3e7b426..6080913 100644
--- a/drivers/hwmon/max6639.c
+++ b/drivers/hwmon/max6639.c
@@ -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,
-- 
1.7.9.7


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] pm: Introduce __pm to mark power management code
  2013-05-09 17:09 [PATCH 0/3] pm: Introduce __pm to mark power management code Guenter Roeck
                   ` (2 preceding siblings ...)
  2013-05-09 17:09 ` [PATCH 3/3] hwmon: (max6639) Convert to use __pm instead of #ifdef CONFIG_PM_SLEEP Guenter Roeck
@ 2013-05-10 10:54 ` Pavel Machek
  3 siblings, 0 replies; 5+ messages in thread
From: Pavel Machek @ 2013-05-10 10:54 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-pm, linux-kernel, lm-sensors, Jean Delvare, Len Brown,
	Jingoo Han

On Thu 2013-05-09 10:09:48, Guenter Roeck wrote:
> 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
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-05-10 10:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-09 17:09 [PATCH 0/3] pm: Introduce __pm to mark power management code Guenter Roeck
2013-05-09 17:09 ` [PATCH 1/3] pm: Introduce __pm to mark power management functions and data Guenter Roeck
2013-05-09 17:09 ` [PATCH 2/3] hwmon: (tmp102) Convert to use __pm instead of #ifdef CONFIG_PM Guenter Roeck
2013-05-09 17:09 ` [PATCH 3/3] hwmon: (max6639) Convert to use __pm instead of #ifdef CONFIG_PM_SLEEP Guenter Roeck
2013-05-10 10:54 ` [PATCH 0/3] pm: Introduce __pm to mark power management code Pavel Machek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox