From: Josh Cartwright <joshc@codeaurora.org>
To: linux-usb@vger.kernel.org, linux-pm@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH 0/3] introduce assign_if() macros in attempt to reduce ifdeffery
Date: Mon, 24 Feb 2014 11:08:24 -0600 [thread overview]
Message-ID: <1393261707-30565-1-git-send-email-joshc@codeaurora.org> (raw)
Based on the observation that given the following:
static void my_callback(void)
{
}
void (*callback)(void) = 0 ? my_callback : NULL;
GCC will,
1.) Not emit 'defined but unused' warnings for 'my_callback'
2.) Typecheck my_callback against typeof(*callback)
3.) Eliminate my_callback as dead code (assuming it's unused elsewhere)
this patchset explores where/how this might be used to reduce the amount of
ifdeffed code in device drivers.
Patch 1 in this series introduces two friendly-named helper macros:
assign_if(const_expr, fn): A friendlier form of (const_expr ? fn : NULL)
assign_if_enabled(conf, fn): Composition of assign_if() and IS_ENABLED().
In order to show a good target usecase for these macros, patch 2 introduces a
new set of PM-related macros, similar to SET_*_PM_OPS, using
assign_if_enabled() under the hood.
In particular, this is aimed at reducing code like the following:
#ifdef CONFIG_PM_SLEEP
static int foo_suspend(struct device *dev)
{
/* ... */
}
#else
#define foo_suspend NULL
#endif
static const struct dev_pm_ops foo_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(foo_suspend, NULL)
};
With the ifdefless:
static int foo_suspend(struct device *dev)
{
/* ... */
}
static const struct dev_pm_ops foo_pm_ops = {
ASSIGN_SYSTEM_SLEEP_PM_OPS(foo_suspend, NULL),
};
For patch 3, an existing consumer of SET_*_PM_OPS(), the MSM USB phy driver[1]
is modified to use the newly introduced ASSIGN_*_PM_OPS() macros to show in a
real case what simplifications could be gained.
For testing that GCC is actually eliminating the PM-related callbacks when it
can, the MSM USB phy driver was built before and after patch 3, in 4 different
configurations, and object sizes compared[2]:
text data bss dec hex filename
11008 488 20 11516 2cfc phy_objects_before/phy-msm-usb.nopm.o
11008 488 20 11516 2cfc phy_objects_after/phy-msm-usb.nopm.o
13528 584 20 14132 3734 phy_objects_before/phy-msm-usb.runtime.o
13528 584 20 14132 3734 phy_objects_after/phy-msm-usb.runtime.o
13828 632 20 14480 3890 phy_objects_before/phy-msm-usb.runtime+sleep.o
13828 632 20 14480 3890 phy_objects_after/phy-msm-usb.runtime+sleep.o
13072 560 20 13652 3554 phy_objects_before/phy-msm-usb.sleep.o
13072 560 20 13652 3554 phy_objects_after/phy-msm-usb.sleep.o
[1]: Chosen because it has recently broken randconfig builds due to improper
#ifdeffery using CONFIG_PM* defines
[2]:
$ ${CROSS_COMPILE}gcc --version
arm-linux-gnueabihf-gcc (crosstool-NG linaro-1.13.1-4.8-2013.07-1 - Linaro GCC 2013.07) 4.8.2 20130624 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Josh Cartwright (3):
typecheck: introduce assign_if() and assign_if_enabled()
PM: define new ASSIGN_*_PM_OPS macros based on assign_if
usb: phy: msm: use ASSIGN_*_PM_OPS variants
drivers/usb/phy/phy-msm-usb.c | 13 +++----------
include/linux/pm.h | 39 +++++++++++++++++++++++++++++++++++++++
include/linux/typecheck.h | 18 ++++++++++++++++++
3 files changed, 60 insertions(+), 10 deletions(-)
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
next reply other threads:[~2014-02-24 17:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-24 17:08 Josh Cartwright [this message]
2014-02-24 17:08 ` [PATCH 1/3] typecheck: introduce assign_if() and assign_if_enabled() Josh Cartwright
2014-02-27 19:00 ` Greg Kroah-Hartman
2014-02-27 23:48 ` Josh Cartwright
2014-02-24 17:08 ` [PATCH 2/3] PM: define new ASSIGN_*_PM_OPS macros based on assign_if Josh Cartwright
2014-02-27 19:02 ` Greg Kroah-Hartman
2014-03-01 11:06 ` Pavel Machek
2014-03-01 16:02 ` Greg Kroah-Hartman
2014-03-01 16:26 ` Pavel Machek
2014-02-24 17:08 ` [PATCH 3/3] usb: phy: msm: use ASSIGN_*_PM_OPS variants Josh Cartwright
[not found] ` <1393261707-30565-4-git-send-email-joshc-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2014-02-25 18:33 ` Felipe Balbi
2014-02-27 19:03 ` Greg Kroah-Hartman
2014-02-27 23:41 ` David Cohen
2014-02-27 23:44 ` Greg Kroah-Hartman
[not found] ` <20140227234425.GA32426-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2014-02-27 23:52 ` David Cohen
2014-02-28 8:48 ` Ulf Hansson
2014-02-28 16:52 ` Greg Kroah-Hartman
2014-03-01 11:24 ` Ulf Hansson
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=1393261707-30565-1-git-send-email-joshc@codeaurora.org \
--to=joshc@codeaurora.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).