tracing: add __print_flags_u64()
authorRoss Zwisler <ross.zwisler@linux.intel.com>
Wed, 22 Feb 2017 23:39:47 +0000 (15:39 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 23 Feb 2017 00:41:26 +0000 (16:41 -0800)
Patch series "DAX tracepoints, mm argument simplification", v4.

This contains both my DAX tracepoint code and Dave Jiang's MM argument
simplifications.  Dave's code was written with my tracepoint code as a
baseline, so it seemed simplest to keep them together in a single series.

This patch (of 7):

Add __print_flags_u64() and the helper trace_print_flags_seq_u64() in the
same spirit as __print_symbolic_u64() and trace_print_symbols_seq_u64().
These functions allow us to print symbols associated with flags that are
64 bits wide even on 32 bit machines.

These will be used by the DAX code so that we can print the flags set in a
pfn_t such as PFN_SG_CHAIN, PFN_SG_LAST, PFN_DEV and PFN_MAP.

Without this new function I was getting errors like the following when
compiling for i386:

  include/linux/pfn_t.h:13:22: warning: large integer implicitly truncated to unsigned type [-Woverflow]
   #define PFN_SG_CHAIN (1ULL << (BITS_PER_LONG_LONG - 1))
    ^

Link: http://lkml.kernel.org/r/1484085142-2297-2-git-send-email-ross.zwisler@linux.intel.com
Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Reviewed-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Dave Chinner <david@fromorbit.com>
Cc: Dave Jiang <dave.jiang@intel.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/trace_events.h
include/trace/trace_events.h
kernel/trace/trace_output.c

index 0f165507495c6e649c1942c982efa0d1be20befa..0af63c4381b9799151317bafc1a800815d85876b 100644 (file)
@@ -23,6 +23,10 @@ const char *trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
                                    const struct trace_print_flags *symbol_array);
 
 #if BITS_PER_LONG == 32
+const char *trace_print_flags_seq_u64(struct trace_seq *p, const char *delim,
+                     unsigned long long flags,
+                     const struct trace_print_flags_u64 *flag_array);
+
 const char *trace_print_symbols_seq_u64(struct trace_seq *p,
                                        unsigned long long val,
                                        const struct trace_print_flags_u64
index 5c06f4af8323032f78ba447f5f66cd31bcb28282..00f643164ca2f202702c21ffd6c57e6e7e90dd70 100644 (file)
@@ -283,8 +283,16 @@ TRACE_MAKE_SYSTEM_STR();
                trace_print_symbols_seq(p, value, symbols);             \
        })
 
+#undef __print_flags_u64
 #undef __print_symbolic_u64
 #if BITS_PER_LONG == 32
+#define __print_flags_u64(flag, delim, flag_array...)                  \
+       ({                                                              \
+               static const struct trace_print_flags_u64 __flags[] =   \
+                       { flag_array, { -1, NULL } };                   \
+               trace_print_flags_seq_u64(p, delim, flag, __flags);     \
+       })
+
 #define __print_symbolic_u64(value, symbol_array...)                   \
        ({                                                              \
                static const struct trace_print_flags_u64 symbols[] =   \
@@ -292,6 +300,9 @@ TRACE_MAKE_SYSTEM_STR();
                trace_print_symbols_seq_u64(p, value, symbols); \
        })
 #else
+#define __print_flags_u64(flag, delim, flag_array...)                  \
+                       __print_flags(flag, delim, flag_array)
+
 #define __print_symbolic_u64(value, symbol_array...)                   \
                        __print_symbolic(value, symbol_array)
 #endif
index aea6a1218c7db6bc7eb307a5ed4630d0b2542640..070866c32eb9d67ede52cfcb21c2c5e7c4433374 100644 (file)
@@ -123,6 +123,44 @@ trace_print_symbols_seq(struct trace_seq *p, unsigned long val,
 EXPORT_SYMBOL(trace_print_symbols_seq);
 
 #if BITS_PER_LONG == 32
+const char *
+trace_print_flags_seq_u64(struct trace_seq *p, const char *delim,
+                     unsigned long long flags,
+                     const struct trace_print_flags_u64 *flag_array)
+{
+       unsigned long long mask;
+       const char *str;
+       const char *ret = trace_seq_buffer_ptr(p);
+       int i, first = 1;
+
+       for (i = 0;  flag_array[i].name && flags; i++) {
+
+               mask = flag_array[i].mask;
+               if ((flags & mask) != mask)
+                       continue;
+
+               str = flag_array[i].name;
+               flags &= ~mask;
+               if (!first && delim)
+                       trace_seq_puts(p, delim);
+               else
+                       first = 0;
+               trace_seq_puts(p, str);
+       }
+
+       /* check for left over flags */
+       if (flags) {
+               if (!first && delim)
+                       trace_seq_puts(p, delim);
+               trace_seq_printf(p, "0x%llx", flags);
+       }
+
+       trace_seq_putc(p, 0);
+
+       return ret;
+}
+EXPORT_SYMBOL(trace_print_flags_seq_u64);
+
 const char *
 trace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
                         const struct trace_print_flags_u64 *symbol_array)