* [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM
@ 2008-03-02 23:43 Anton Vorontsov
2008-03-03 0:08 ` Arjan van de Ven
` (3 more replies)
0 siblings, 4 replies; 16+ messages in thread
From: Anton Vorontsov @ 2008-03-02 23:43 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-pm
Currently drivers handle CONFIG_PM this way:
#ifdef CONFIG_PM
drv_suspend() {}
drv_resume() {}
#else
#define drv_suspend NULL
#define drv_resume NULL
#endif
struct driver drv = {
.suspend = drv_suspend,
.resume = drv_resume,
};
With this patch, the code above converts into:
drv_suspend() {}
drv_resume() {}
struct driver drv = {
.suspend = pm_call(drv_suspend),
.resume = pm_call(drv_resume),
};
GCC will optimize away suspend/resume calls if they're really
not used.
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
---
include/linux/pm.h | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 015b735..6e0b9c2 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -114,6 +114,13 @@ typedef struct pm_message {
int event;
} pm_message_t;
+#ifdef CONFIG_PM
+#define pm_call(x) (x)
+#else
+/* avoid `defined but not used' warning */
+#define pm_call(x) ((x) - 1 ? NULL : NULL)
+#endif /* CONFIG_PM */
+
/*
* Several driver power state transitions are externally visible, affecting
* the state of pending I/O queues and (for drivers that touch hardware)
--
1.5.4.3
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-02 23:43 [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM Anton Vorontsov @ 2008-03-03 0:08 ` Arjan van de Ven 2008-03-03 0:29 ` Rafael J. Wysocki ` (3 more replies) 2008-03-03 0:08 ` Arjan van de Ven ` (2 subsequent siblings) 3 siblings, 4 replies; 16+ messages in thread From: Arjan van de Ven @ 2008-03-03 0:08 UTC (permalink / raw) To: Anton Vorontsov; +Cc: linux-kernel, linux-pm On Mon, 3 Mar 2008 02:43:08 +0300 Anton Vorontsov <cbouatmailru@gmail.com> wrote: > Currently drivers handle CONFIG_PM this way: > > #ifdef CONFIG_PM > drv_suspend() {} > drv_resume() {} > #else > #define drv_suspend NULL > #define drv_resume NULL > #endif > > struct driver drv = { > .suspend = drv_suspend, > .resume = drv_resume, > }; > > With this patch, the code above converts into: > > drv_suspend() {} > drv_resume() {} > > struct driver drv = { > .suspend = pm_call(drv_suspend), > .resume = pm_call(drv_resume), > }; > > GCC will optimize away suspend/resume calls if they're really > not used. > to be honest, at this point I would think it's time to remove CONFIG_PM, or rather, just make it always be there and just get rid of the ifdefs. We're saving 2 words and a bit of code, but only a case that not even the embedded guys use. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 0:08 ` Arjan van de Ven @ 2008-03-03 0:29 ` Rafael J. Wysocki 2008-03-03 0:29 ` Rafael J. Wysocki ` (2 subsequent siblings) 3 siblings, 0 replies; 16+ messages in thread From: Rafael J. Wysocki @ 2008-03-03 0:29 UTC (permalink / raw) To: Arjan van de Ven; +Cc: linux-pm, linux-kernel, Anton Vorontsov On Monday, 3 of March 2008, Arjan van de Ven wrote: > On Mon, 3 Mar 2008 02:43:08 +0300 > Anton Vorontsov <cbouatmailru@gmail.com> wrote: > > > Currently drivers handle CONFIG_PM this way: > > > > #ifdef CONFIG_PM > > drv_suspend() {} > > drv_resume() {} > > #else > > #define drv_suspend NULL > > #define drv_resume NULL > > #endif > > > > struct driver drv = { > > .suspend = drv_suspend, > > .resume = drv_resume, > > }; > > > > With this patch, the code above converts into: > > > > drv_suspend() {} > > drv_resume() {} > > > > struct driver drv = { > > .suspend = pm_call(drv_suspend), > > .resume = pm_call(drv_resume), > > }; > > > > GCC will optimize away suspend/resume calls if they're really > > not used. > > > > > to be honest, at this point I would think it's time to remove CONFIG_PM, or rather, > just make it always be there and just get rid of the ifdefs. We're saving 2 words and a bit of code, > but only a case that not even the embedded guys use. All of the drivers' ->suspend() and ->resume() callbacks currently depend on CONFIG_PM, which they shouldn't. Still, we're going to introduce new callbacks for suspend/hibernation and the $subject change will probably get us in the way. Also, it won't be necessary afterwards. Thanks, Rafael ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 0:08 ` Arjan van de Ven 2008-03-03 0:29 ` Rafael J. Wysocki @ 2008-03-03 0:29 ` Rafael J. Wysocki 2008-03-03 23:26 ` Anton Vorontsov 2008-03-03 23:26 ` Anton Vorontsov 3 siblings, 0 replies; 16+ messages in thread From: Rafael J. Wysocki @ 2008-03-03 0:29 UTC (permalink / raw) To: Arjan van de Ven; +Cc: Anton Vorontsov, linux-kernel, linux-pm On Monday, 3 of March 2008, Arjan van de Ven wrote: > On Mon, 3 Mar 2008 02:43:08 +0300 > Anton Vorontsov <cbouatmailru@gmail.com> wrote: > > > Currently drivers handle CONFIG_PM this way: > > > > #ifdef CONFIG_PM > > drv_suspend() {} > > drv_resume() {} > > #else > > #define drv_suspend NULL > > #define drv_resume NULL > > #endif > > > > struct driver drv = { > > .suspend = drv_suspend, > > .resume = drv_resume, > > }; > > > > With this patch, the code above converts into: > > > > drv_suspend() {} > > drv_resume() {} > > > > struct driver drv = { > > .suspend = pm_call(drv_suspend), > > .resume = pm_call(drv_resume), > > }; > > > > GCC will optimize away suspend/resume calls if they're really > > not used. > > > > > to be honest, at this point I would think it's time to remove CONFIG_PM, or rather, > just make it always be there and just get rid of the ifdefs. We're saving 2 words and a bit of code, > but only a case that not even the embedded guys use. All of the drivers' ->suspend() and ->resume() callbacks currently depend on CONFIG_PM, which they shouldn't. Still, we're going to introduce new callbacks for suspend/hibernation and the $subject change will probably get us in the way. Also, it won't be necessary afterwards. Thanks, Rafael ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 0:08 ` Arjan van de Ven 2008-03-03 0:29 ` Rafael J. Wysocki 2008-03-03 0:29 ` Rafael J. Wysocki @ 2008-03-03 23:26 ` Anton Vorontsov 2008-03-03 23:26 ` Anton Vorontsov 3 siblings, 0 replies; 16+ messages in thread From: Anton Vorontsov @ 2008-03-03 23:26 UTC (permalink / raw) To: Arjan van de Ven; +Cc: linux-pm, linux-kernel On Sun, Mar 02, 2008 at 04:08:20PM -0800, Arjan van de Ven wrote: > On Mon, 3 Mar 2008 02:43:08 +0300 > Anton Vorontsov <cbouatmailru@gmail.com> wrote: > > > Currently drivers handle CONFIG_PM this way: > > > > #ifdef CONFIG_PM > > drv_suspend() {} > > drv_resume() {} > > #else > > #define drv_suspend NULL > > #define drv_resume NULL > > #endif > > > > struct driver drv = { > > .suspend = drv_suspend, > > .resume = drv_resume, > > }; > > > > With this patch, the code above converts into: > > > > drv_suspend() {} > > drv_resume() {} > > > > struct driver drv = { > > .suspend = pm_call(drv_suspend), > > .resume = pm_call(drv_resume), > > }; > > > > GCC will optimize away suspend/resume calls if they're really > > not used. > > > > > to be honest, at this point I would think it's time to remove > CONFIG_PM, or rather, > just make it always be there and just get rid of the ifdefs. Don't be so CONFIG_PM-centric :-) $ zcat /proc/config.gz | grep CONFIG_PM # CONFIG_PM is not set This is machine I use at home. > We're saving 2 words and a bit of code, > but only a case that not even the embedded guys use. Well, on my ARM machine, with CONFIG_PM=y vmlinux grows by 30KB, half of that is in drivers/. 30KB is 1% of the vmlinux. Is it enough to worth saving? I don't know. On a x86 box, CONFIG_PM=y grows the vmlinux by 400KB (yeah, it's including ACPI and stuff), though here I didn't count drivers' suspend/resume hooks contribution share. -- Anton Vorontsov email: cbouatmailru@gmail.com irc://irc.freenode.net/bd2 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 0:08 ` Arjan van de Ven ` (2 preceding siblings ...) 2008-03-03 23:26 ` Anton Vorontsov @ 2008-03-03 23:26 ` Anton Vorontsov 3 siblings, 0 replies; 16+ messages in thread From: Anton Vorontsov @ 2008-03-03 23:26 UTC (permalink / raw) To: Arjan van de Ven; +Cc: linux-kernel, linux-pm On Sun, Mar 02, 2008 at 04:08:20PM -0800, Arjan van de Ven wrote: > On Mon, 3 Mar 2008 02:43:08 +0300 > Anton Vorontsov <cbouatmailru@gmail.com> wrote: > > > Currently drivers handle CONFIG_PM this way: > > > > #ifdef CONFIG_PM > > drv_suspend() {} > > drv_resume() {} > > #else > > #define drv_suspend NULL > > #define drv_resume NULL > > #endif > > > > struct driver drv = { > > .suspend = drv_suspend, > > .resume = drv_resume, > > }; > > > > With this patch, the code above converts into: > > > > drv_suspend() {} > > drv_resume() {} > > > > struct driver drv = { > > .suspend = pm_call(drv_suspend), > > .resume = pm_call(drv_resume), > > }; > > > > GCC will optimize away suspend/resume calls if they're really > > not used. > > > > > to be honest, at this point I would think it's time to remove > CONFIG_PM, or rather, > just make it always be there and just get rid of the ifdefs. Don't be so CONFIG_PM-centric :-) $ zcat /proc/config.gz | grep CONFIG_PM # CONFIG_PM is not set This is machine I use at home. > We're saving 2 words and a bit of code, > but only a case that not even the embedded guys use. Well, on my ARM machine, with CONFIG_PM=y vmlinux grows by 30KB, half of that is in drivers/. 30KB is 1% of the vmlinux. Is it enough to worth saving? I don't know. On a x86 box, CONFIG_PM=y grows the vmlinux by 400KB (yeah, it's including ACPI and stuff), though here I didn't count drivers' suspend/resume hooks contribution share. -- Anton Vorontsov email: cbouatmailru@gmail.com irc://irc.freenode.net/bd2 ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-02 23:43 [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM Anton Vorontsov 2008-03-03 0:08 ` Arjan van de Ven @ 2008-03-03 0:08 ` Arjan van de Ven 2008-03-03 14:18 ` Pavel Machek 2008-03-03 14:18 ` Pavel Machek 3 siblings, 0 replies; 16+ messages in thread From: Arjan van de Ven @ 2008-03-03 0:08 UTC (permalink / raw) To: Anton Vorontsov; +Cc: linux-pm, linux-kernel On Mon, 3 Mar 2008 02:43:08 +0300 Anton Vorontsov <cbouatmailru@gmail.com> wrote: > Currently drivers handle CONFIG_PM this way: > > #ifdef CONFIG_PM > drv_suspend() {} > drv_resume() {} > #else > #define drv_suspend NULL > #define drv_resume NULL > #endif > > struct driver drv = { > .suspend = drv_suspend, > .resume = drv_resume, > }; > > With this patch, the code above converts into: > > drv_suspend() {} > drv_resume() {} > > struct driver drv = { > .suspend = pm_call(drv_suspend), > .resume = pm_call(drv_resume), > }; > > GCC will optimize away suspend/resume calls if they're really > not used. > to be honest, at this point I would think it's time to remove CONFIG_PM, or rather, just make it always be there and just get rid of the ifdefs. We're saving 2 words and a bit of code, but only a case that not even the embedded guys use. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-02 23:43 [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM Anton Vorontsov 2008-03-03 0:08 ` Arjan van de Ven 2008-03-03 0:08 ` Arjan van de Ven @ 2008-03-03 14:18 ` Pavel Machek 2008-03-03 22:42 ` Anton Vorontsov ` (3 more replies) 2008-03-03 14:18 ` Pavel Machek 3 siblings, 4 replies; 16+ messages in thread From: Pavel Machek @ 2008-03-03 14:18 UTC (permalink / raw) To: Anton Vorontsov; +Cc: linux-kernel, linux-pm Hi! > diff --git a/include/linux/pm.h b/include/linux/pm.h > index 015b735..6e0b9c2 100644 > --- a/include/linux/pm.h > +++ b/include/linux/pm.h > @@ -114,6 +114,13 @@ typedef struct pm_message { > int event; > } pm_message_t; > > +#ifdef CONFIG_PM > +#define pm_call(x) (x) > +#else > +/* avoid `defined but not used' warning */ > +#define pm_call(x) ((x) - 1 ? NULL : NULL) > +#endif /* CONFIG_PM */ > + This is evil. Maybe your gcc is smart enough to optimize this away, but I'm not sure mine is. 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] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 14:18 ` Pavel Machek @ 2008-03-03 22:42 ` Anton Vorontsov 2008-03-03 22:42 ` Anton Vorontsov ` (2 subsequent siblings) 3 siblings, 0 replies; 16+ messages in thread From: Anton Vorontsov @ 2008-03-03 22:42 UTC (permalink / raw) To: Pavel Machek; +Cc: linux-kernel, linux-pm On Mon, Mar 03, 2008 at 03:18:18PM +0100, Pavel Machek wrote: > Hi! > > > diff --git a/include/linux/pm.h b/include/linux/pm.h > > index 015b735..6e0b9c2 100644 > > --- a/include/linux/pm.h > > +++ b/include/linux/pm.h > > @@ -114,6 +114,13 @@ typedef struct pm_message { > > int event; > > } pm_message_t; > > > > +#ifdef CONFIG_PM > > +#define pm_call(x) (x) > > +#else > > +/* avoid `defined but not used' warning */ > > +#define pm_call(x) ((x) - 1 ? NULL : NULL) > > +#endif /* CONFIG_PM */ > > + > > This is evil. Maybe your gcc is smart enough to optimize this away, > but I'm not sure mine is. No problem. Let's use __maybe_unsed then, it gives the same effect. - - - - Subject: introduce pm_call() macro to get rid of most #ifdef CONFIG_PM Currently drivers handle CONFIG_PM this way: #ifdef CONFIG_PM drv_suspend() {} drv_resume() {} #else #define drv_suspend NULL #define drv_resume NULL #endif struct driver drv = { .suspend = drv_suspend, .resume = drv_resume, }; With this patch, the code above converts into: __maybe_unused drv_suspend() {} __maybe_unused drv_resume() {} struct driver drv = { .suspend = pm_call(drv_suspend), .resume = pm_call(drv_resume), }; GCC will optimize away suspend/resume calls if they're really not used. Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com> --- include/linux/pm.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/include/linux/pm.h b/include/linux/pm.h index 015b735..a3932c7 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -114,6 +114,12 @@ typedef struct pm_message { int event; } pm_message_t; +#ifdef CONFIG_PM +#define pm_call(x) (x) +#else +#define pm_call(x) NULL +#endif /* CONFIG_PM */ + /* * Several driver power state transitions are externally visible, affecting * the state of pending I/O queues and (for drivers that touch hardware) -- 1.5.4.3 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 14:18 ` Pavel Machek 2008-03-03 22:42 ` Anton Vorontsov @ 2008-03-03 22:42 ` Anton Vorontsov 2008-03-03 22:56 ` [linux-pm] " David Brownell 2008-03-03 22:56 ` David Brownell 3 siblings, 0 replies; 16+ messages in thread From: Anton Vorontsov @ 2008-03-03 22:42 UTC (permalink / raw) To: Pavel Machek; +Cc: linux-pm, linux-kernel On Mon, Mar 03, 2008 at 03:18:18PM +0100, Pavel Machek wrote: > Hi! > > > diff --git a/include/linux/pm.h b/include/linux/pm.h > > index 015b735..6e0b9c2 100644 > > --- a/include/linux/pm.h > > +++ b/include/linux/pm.h > > @@ -114,6 +114,13 @@ typedef struct pm_message { > > int event; > > } pm_message_t; > > > > +#ifdef CONFIG_PM > > +#define pm_call(x) (x) > > +#else > > +/* avoid `defined but not used' warning */ > > +#define pm_call(x) ((x) - 1 ? NULL : NULL) > > +#endif /* CONFIG_PM */ > > + > > This is evil. Maybe your gcc is smart enough to optimize this away, > but I'm not sure mine is. No problem. Let's use __maybe_unsed then, it gives the same effect. - - - - Subject: introduce pm_call() macro to get rid of most #ifdef CONFIG_PM Currently drivers handle CONFIG_PM this way: #ifdef CONFIG_PM drv_suspend() {} drv_resume() {} #else #define drv_suspend NULL #define drv_resume NULL #endif struct driver drv = { .suspend = drv_suspend, .resume = drv_resume, }; With this patch, the code above converts into: __maybe_unused drv_suspend() {} __maybe_unused drv_resume() {} struct driver drv = { .suspend = pm_call(drv_suspend), .resume = pm_call(drv_resume), }; GCC will optimize away suspend/resume calls if they're really not used. Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com> --- include/linux/pm.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/include/linux/pm.h b/include/linux/pm.h index 015b735..a3932c7 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -114,6 +114,12 @@ typedef struct pm_message { int event; } pm_message_t; +#ifdef CONFIG_PM +#define pm_call(x) (x) +#else +#define pm_call(x) NULL +#endif /* CONFIG_PM */ + /* * Several driver power state transitions are externally visible, affecting * the state of pending I/O queues and (for drivers that touch hardware) -- 1.5.4.3 ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [linux-pm] [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 14:18 ` Pavel Machek 2008-03-03 22:42 ` Anton Vorontsov 2008-03-03 22:42 ` Anton Vorontsov @ 2008-03-03 22:56 ` David Brownell 2008-03-03 23:16 ` Pavel Machek 2008-03-03 23:16 ` [linux-pm] " Pavel Machek 2008-03-03 22:56 ` David Brownell 3 siblings, 2 replies; 16+ messages in thread From: David Brownell @ 2008-03-03 22:56 UTC (permalink / raw) To: linux-pm; +Cc: Pavel Machek, Anton Vorontsov, linux-kernel On Monday 03 March 2008, Pavel Machek wrote: > > +/* avoid `defined but not used' warning */ > > +#define pm_call(x) ((x) - 1 ? NULL : NULL) > > +#endif /* CONFIG_PM */ > > + > > This is evil. Ugly, yes. It might merit some casts too. > Maybe your gcc is smart enough to optimize this away, > but I'm not sure mine is. It'll be a constant expression; it certainly ought to be. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 22:56 ` [linux-pm] " David Brownell @ 2008-03-03 23:16 ` Pavel Machek 2008-03-03 23:16 ` [linux-pm] " Pavel Machek 1 sibling, 0 replies; 16+ messages in thread From: Pavel Machek @ 2008-03-03 23:16 UTC (permalink / raw) To: David Brownell; +Cc: linux-pm, linux-kernel, Anton Vorontsov Hi! > > > +/* avoid `defined but not used' warning */ > > > +#define pm_call(x) ((x) - 1 ? NULL : NULL) > > > +#endif /* CONFIG_PM */ > > > + > > > > This is evil. > > Ugly, yes. It might merit some casts too. > > > > Maybe your gcc is smart enough to optimize this away, > > but I'm not sure mine is. > > It'll be a constant expression; it certainly ought to be. Well, we have just fooler compiler to think that x is used, and now we want it to realize that x is unused and compile it out? Maybe it is smart enough, but... 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] 16+ messages in thread
* Re: [linux-pm] [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 22:56 ` [linux-pm] " David Brownell 2008-03-03 23:16 ` Pavel Machek @ 2008-03-03 23:16 ` Pavel Machek 1 sibling, 0 replies; 16+ messages in thread From: Pavel Machek @ 2008-03-03 23:16 UTC (permalink / raw) To: David Brownell; +Cc: linux-pm, Anton Vorontsov, linux-kernel Hi! > > > +/* avoid `defined but not used' warning */ > > > +#define pm_call(x) ((x) - 1 ? NULL : NULL) > > > +#endif /* CONFIG_PM */ > > > + > > > > This is evil. > > Ugly, yes. It might merit some casts too. > > > > Maybe your gcc is smart enough to optimize this away, > > but I'm not sure mine is. > > It'll be a constant expression; it certainly ought to be. Well, we have just fooler compiler to think that x is used, and now we want it to realize that x is unused and compile it out? Maybe it is smart enough, but... 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] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-03 14:18 ` Pavel Machek ` (2 preceding siblings ...) 2008-03-03 22:56 ` [linux-pm] " David Brownell @ 2008-03-03 22:56 ` David Brownell 3 siblings, 0 replies; 16+ messages in thread From: David Brownell @ 2008-03-03 22:56 UTC (permalink / raw) To: linux-pm; +Cc: linux-kernel, Anton Vorontsov On Monday 03 March 2008, Pavel Machek wrote: > > +/* avoid `defined but not used' warning */ > > +#define pm_call(x) ((x) - 1 ? NULL : NULL) > > +#endif /* CONFIG_PM */ > > + > > This is evil. Ugly, yes. It might merit some casts too. > Maybe your gcc is smart enough to optimize this away, > but I'm not sure mine is. It'll be a constant expression; it certainly ought to be. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM 2008-03-02 23:43 [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM Anton Vorontsov ` (2 preceding siblings ...) 2008-03-03 14:18 ` Pavel Machek @ 2008-03-03 14:18 ` Pavel Machek 3 siblings, 0 replies; 16+ messages in thread From: Pavel Machek @ 2008-03-03 14:18 UTC (permalink / raw) To: Anton Vorontsov; +Cc: linux-pm, linux-kernel Hi! > diff --git a/include/linux/pm.h b/include/linux/pm.h > index 015b735..6e0b9c2 100644 > --- a/include/linux/pm.h > +++ b/include/linux/pm.h > @@ -114,6 +114,13 @@ typedef struct pm_message { > int event; > } pm_message_t; > > +#ifdef CONFIG_PM > +#define pm_call(x) (x) > +#else > +/* avoid `defined but not used' warning */ > +#define pm_call(x) ((x) - 1 ? NULL : NULL) > +#endif /* CONFIG_PM */ > + This is evil. Maybe your gcc is smart enough to optimize this away, but I'm not sure mine is. 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] 16+ messages in thread
* [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM
@ 2008-03-02 23:43 Anton Vorontsov
0 siblings, 0 replies; 16+ messages in thread
From: Anton Vorontsov @ 2008-03-02 23:43 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-pm
Currently drivers handle CONFIG_PM this way:
#ifdef CONFIG_PM
drv_suspend() {}
drv_resume() {}
#else
#define drv_suspend NULL
#define drv_resume NULL
#endif
struct driver drv = {
.suspend = drv_suspend,
.resume = drv_resume,
};
With this patch, the code above converts into:
drv_suspend() {}
drv_resume() {}
struct driver drv = {
.suspend = pm_call(drv_suspend),
.resume = pm_call(drv_resume),
};
GCC will optimize away suspend/resume calls if they're really
not used.
Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
---
include/linux/pm.h | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 015b735..6e0b9c2 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -114,6 +114,13 @@ typedef struct pm_message {
int event;
} pm_message_t;
+#ifdef CONFIG_PM
+#define pm_call(x) (x)
+#else
+/* avoid `defined but not used' warning */
+#define pm_call(x) ((x) - 1 ? NULL : NULL)
+#endif /* CONFIG_PM */
+
/*
* Several driver power state transitions are externally visible, affecting
* the state of pending I/O queues and (for drivers that touch hardware)
--
1.5.4.3
^ permalink raw reply related [flat|nested] 16+ messages in threadend of thread, other threads:[~2008-03-03 23:48 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-03-02 23:43 [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM Anton Vorontsov 2008-03-03 0:08 ` Arjan van de Ven 2008-03-03 0:29 ` Rafael J. Wysocki 2008-03-03 0:29 ` Rafael J. Wysocki 2008-03-03 23:26 ` Anton Vorontsov 2008-03-03 23:26 ` Anton Vorontsov 2008-03-03 0:08 ` Arjan van de Ven 2008-03-03 14:18 ` Pavel Machek 2008-03-03 22:42 ` Anton Vorontsov 2008-03-03 22:42 ` Anton Vorontsov 2008-03-03 22:56 ` [linux-pm] " David Brownell 2008-03-03 23:16 ` Pavel Machek 2008-03-03 23:16 ` [linux-pm] " Pavel Machek 2008-03-03 22:56 ` David Brownell 2008-03-03 14:18 ` Pavel Machek -- strict thread matches above, loose matches on Subject: below -- 2008-03-02 23:43 Anton Vorontsov
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.