ocfs2: reduce object size of mlog uses
authorJoe Perches <joe@perches.com>
Wed, 24 Jun 2015 23:54:53 +0000 (16:54 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 25 Jun 2015 00:49:39 +0000 (17:49 -0700)
Using a function for __mlog_printk instead of a macro reduces the object
size of built-in.o by about 190KB, or ~18% overall (x86-64 defconfig
with all ocfs2 options)

  $ size fs/ocfs2/built-in.o*
     text    data     bss     dec     hex filename
   870954  118471  134408 1123833  1125f9 fs/ocfs2/built-in.o,new
  1064081  118071  134408 1316560  1416d0 fs/ocfs2/built-in.o.old

Miscellanea:

 - Move the used-once __mlog_cpu_guess statement expression macro to the
   masklog.c file above the use in __mlog_printk function

 - Simplify the mlog macro moving the and/or logic and level code into
   __mlog_printk

[akpm@linux-foundation.org: export __mlog_printk() to other ocfs2 modules]
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mfasheh@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/ocfs2/cluster/masklog.c
fs/ocfs2/cluster/masklog.h

index af7598bff1b51364affd08eba9cfedba8b3acf16..c2182ba1013cbca159bea346d7769eb4b03843a7 100644 (file)
@@ -64,6 +64,53 @@ static ssize_t mlog_mask_store(u64 mask, const char *buf, size_t count)
        return count;
 }
 
+/*
+ * smp_processor_id() "helpfully" screams when called outside preemptible
+ * regions in current kernels.  sles doesn't have the variants that don't
+ * scream.  just do this instead of trying to guess which we're building
+ * against.. *sigh*.
+ */
+#define __mlog_cpu_guess                                               \
+({                                                                     \
+       unsigned long _cpu = get_cpu();                                 \
+       put_cpu();                                                      \
+       _cpu;                                                           \
+})
+
+void __mlog_printk(const u64 *mask, const char *func, int line,
+                  const char *fmt, ...)
+{
+       struct va_format vaf;
+       va_list args;
+       const char *level;
+       const char *prefix = "";
+
+       if (!__mlog_test_u64(*mask, mlog_and_bits) ||
+           __mlog_test_u64(*mask, mlog_not_bits))
+               return;
+
+       if (*mask & ML_ERROR) {
+               level = KERN_ERR;
+               prefix = "ERROR: ";
+       } else if (*mask & ML_NOTICE) {
+               level = KERN_NOTICE;
+       } else {
+               level = KERN_INFO;
+       }
+
+       va_start(args, fmt);
+
+       vaf.fmt = fmt;
+       vaf.va = &args;
+
+       printk("%s(%s,%u,%lu):%s:%d %s%pV",
+              level, current->comm, task_pid_nr(current), __mlog_cpu_guess,
+              func, line, prefix, &vaf);
+
+       va_end(args);
+}
+EXPORT_SYMBOL_GPL(__mlog_printk);
+
 struct mlog_attribute {
        struct attribute attr;
        u64 mask;
index 7fdc25a4d8c0e76af574c505d83eb86f1f452e31..308ea0eb35fd112f29a5546c23dba6f80e60c787 100644 (file)
@@ -162,38 +162,20 @@ extern struct mlog_bits mlog_and_bits, mlog_not_bits;
 
 #endif
 
-/*
- * smp_processor_id() "helpfully" screams when called outside preemptible
- * regions in current kernels.  sles doesn't have the variants that don't
- * scream.  just do this instead of trying to guess which we're building
- * against.. *sigh*.
- */
-#define __mlog_cpu_guess ({            \
-       unsigned long _cpu = get_cpu(); \
-       put_cpu();                      \
-       _cpu;                           \
-})
+__printf(4, 5)
+void __mlog_printk(const u64 *m, const char *func, int line,
+                  const char *fmt, ...);
 
-/* In the following two macros, the whitespace after the ',' just
- * before ##args is intentional. Otherwise, gcc 2.95 will eat the
- * previous token if args expands to nothing.
+/*
+ * Testing before the __mlog_printk call lets the compiler eliminate the
+ * call completely when (m & ML_ALLOWED_BITS) is 0.
  */
-#define __mlog_printk(level, fmt, args...)                             \
-       printk(level "(%s,%u,%lu):%s:%d " fmt, current->comm,           \
-              task_pid_nr(current), __mlog_cpu_guess,                  \
-              __PRETTY_FUNCTION__, __LINE__ , ##args)
-
-#define mlog(mask, fmt, args...) do {                                  \
-       u64 __m = MLOG_MASK_PREFIX | (mask);                            \
-       if ((__m & ML_ALLOWED_BITS) &&                                  \
-           __mlog_test_u64(__m, mlog_and_bits) &&                      \
-           !__mlog_test_u64(__m, mlog_not_bits)) {                     \
-               if (__m & ML_ERROR)                                     \
-                       __mlog_printk(KERN_ERR, "ERROR: "fmt , ##args); \
-               else if (__m & ML_NOTICE)                               \
-                       __mlog_printk(KERN_NOTICE, fmt , ##args);       \
-               else __mlog_printk(KERN_INFO, fmt , ##args);            \
-       }                                                               \
+#define mlog(mask, fmt, ...)                                           \
+do {                                                                   \
+       u64 _m = MLOG_MASK_PREFIX | (mask);                             \
+       if (_m & ML_ALLOWED_BITS)                                       \
+               __mlog_printk(&_m, __func__, __LINE__, fmt,             \
+                             ##__VA_ARGS__);                           \
 } while (0)
 
 #define mlog_errno(st) ({                                              \