[PATCH 10/36] driver core: Convert debug functions declared inline __attribute__((format (printf,x,y) to statement expression macros

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

From: Joe Perches <joe@perches.com>

When DEBUG is not defined, pr_debug and dev_dbg and some
other local debugging functions are specified as:

"inline __attribute__((format (printf, x, y)))"

This is done to validate printk arguments when not debugging.

Converting these functions to macros or statement expressions
"do { if (0) printk(fmt, ##arg); } while (0)"
or
"({ if (0) printk(fmt, ##arg); 0; })
makes at least gcc 4.2.2 produce smaller objects.

This has the additional benefit of allowing the optimizer to
avoid calling functions like print_mac that might have been
arguments to the printk.

defconfig x86 current:

$ size vmlinux
   text    data     bss     dec     hex filename
4716770  474560  618496 5809826  58a6a2 vmlinux

all converted: (More patches follow)

$ size vmlinux
   text    data     bss     dec     hex filename
4716642  474560  618496 5809698  58a622 vmlinux

Even kernel/sched.o, which doesn't even use these
functions, becomes smaller.

It appears that merely having an indirect include
of <linux/device.h> can cause bigger objects.

$ size sched.inline.o sched.if0.o
   text    data     bss     dec     hex filename
  31385    2854     328   34567    8707 sched.inline.o
  31366    2854     328   34548    86f4 sched.if0.o

The current preprocessed only kernel/sched.i file contains:

# 612 "include/linux/device.h"
static inline __attribute__((always_inline)) int __attribute__ ((format (printf, 2, 3)))
dev_dbg(struct device *dev, const char *fmt, ...)
{
 return 0;
}
# 628 "include/linux/device.h"
static inline __attribute__((always_inline)) int __attribute__ ((format (printf, 2, 3)))
dev_vdbg(struct device *dev, const char *fmt, ...)
{
 return 0;
}

Removing these unused inlines from sched.i shrinks sched.o

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 include/linux/device.h |   15 +++++----------
 include/linux/kernel.h |    6 ++----
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/include/linux/device.h b/include/linux/device.h
index 2258d89..d576611 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -608,21 +608,16 @@ extern const char *dev_driver_string(struct device *dev);
 #define dev_dbg(dev, format, arg...)		\
 	dev_printk(KERN_DEBUG , dev , format , ## arg)
 #else
-static inline int __attribute__ ((format (printf, 2, 3)))
-dev_dbg(struct device *dev, const char *fmt, ...)
-{
-	return 0;
-}
+#define dev_dbg(dev, format, arg...)		\
+	({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; })
 #endif
 
 #ifdef VERBOSE_DEBUG
 #define dev_vdbg	dev_dbg
 #else
-static inline int __attribute__ ((format (printf, 2, 3)))
-dev_vdbg(struct device *dev, const char *fmt, ...)
-{
-	return 0;
-}
+
+#define dev_vdbg(dev, format, arg...)		\
+	({ if (0) dev_printk(KERN_DEBUG, dev, format, ##arg); 0; })
 #endif
 
 /* Create alias, so I can be autoloaded. */
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 2df44e7..cd6d02c 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -293,10 +293,8 @@ extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
 #define pr_debug(fmt, arg...) \
 	printk(KERN_DEBUG fmt, ##arg)
 #else
-static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * fmt, ...)
-{
-	return 0;
-}
+#define pr_debug(fmt, arg...) \
+	({ if (0) printk(KERN_DEBUG fmt, ##arg); 0; })
 #endif
 
 /*
-- 
1.5.4.5

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 01/36] kobject: catch kobjects that are not initialized, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 02/36] uio: Kconfig improvements, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 03/36] uio: mark pci_device_id hilscher_pci_ids[] _ ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 04/36] UIO: arch/arm/Kconfig: Make UIO available on ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 05/36] UIO: Remove needless PCI_DEVICE_ID definitio ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 06/36] UIO: Implement a UIO interface for the SMX C ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 07/36] UIO: hold a reference to the device's owner ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 08/36] driver core: memory: semaphore to mutex, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 09/36] driver core: register_memory/unregister_memo ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 10/36] driver core: Convert debug functions declare ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 11/36] sysfs: small header file cleanup for SYSFS=n, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 12/36] firmware: move firmware_class from Documenta ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 13/36] firmware: clean up samples for coding style ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 14/36] PNP: add all PNP card device id's as individ ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 15/36] power_state: remove it from driver core, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 16/36] driver core: cpu: fix section mismatch in cp ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 17/36] sysdev: detect multiple driver registrations, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 19/36] PM: Handle device registrations during suspe ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 20/36] Driver core: Call device_pm_add() after bus_ ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 21/36] PM: Fix misuse of wakeup flag accessors in s ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 22/36] PM: Make wakeup flags available whenever CON ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 23/36] PM: Convert wakeup flag accessors to inline ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 24/36] Driver core: make device_is_registered() wor ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 25/36] SYSFS: Explicitly include required header fi ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 26/36] Kobject: Replace list_for_each() with list_f ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 27/36] PM: Remove legacy PM (fix), Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 28/36] Firmware: add iSCSI iBFT Support, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 29/36] PM: Remove destroy_suspended_device(), Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 30/36] sysfs: refill attribute buffer when reading ..., Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 31/36] driver core: replace remaining __FUNCTION__ ..., Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 32/36] memstick: convert struct class_device to str ..., Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 33/36] IB: convert struct class_device to struct device, Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 35/36] DRM: remove unused dev_class, Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 36/36] SCSI: convert struct class_device to struct ..., Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)