LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Anton Vorontsov <cbouatmailru@gmail.com>
To: Pavel Machek <pavel@ucw.cz>
Cc: linux-kernel@vger.kernel.org, linux-pm@lists.linux-foundation.org
Subject: Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM
Date: Tue, 4 Mar 2008 01:42:21 +0300	[thread overview]
Message-ID: <20080303224221.GA27395@zarina> (raw)
In-Reply-To: <20080303141818.GE12606@elf.ucw.cz>

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


  reply	other threads:[~2008-03-03 23:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-02 23:43 Anton Vorontsov
2008-03-03  0:08 ` Arjan van de Ven
2008-03-03  0:29   ` Rafael J. Wysocki
2008-03-03 23:26   ` Anton Vorontsov
2008-03-03 14:18 ` Pavel Machek
2008-03-03 22:42   ` Anton Vorontsov [this message]
2008-03-03 22:56   ` [linux-pm] " David Brownell
2008-03-03 23:16     ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080303224221.GA27395@zarina \
    --to=cbouatmailru@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=pavel@ucw.cz \
    --subject='Re: [PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).