hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/include/linux/dynamic_debug.h
....@@ -47,10 +47,11 @@
4747 } __attribute__((aligned(8)));
4848
4949
50
+
51
+#if defined(CONFIG_DYNAMIC_DEBUG_CORE)
52
+
5053 int ddebug_add_module(struct _ddebug *tab, unsigned int n,
5154 const char *modname);
52
-
53
-#if defined(CONFIG_DYNAMIC_DEBUG)
5455 extern int ddebug_remove_module(const char *mod_name);
5556 extern __printf(2, 3)
5657 void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
....@@ -71,44 +72,43 @@
7172 const struct net_device *dev,
7273 const char *fmt, ...);
7374
74
-#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, key, init) \
75
+struct ib_device;
76
+
77
+extern __printf(3, 4)
78
+void __dynamic_ibdev_dbg(struct _ddebug *descriptor,
79
+ const struct ib_device *ibdev,
80
+ const char *fmt, ...);
81
+
82
+#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
7583 static struct _ddebug __aligned(8) \
76
- __attribute__((section("__verbose"))) name = { \
84
+ __section("__dyndbg") name = { \
7785 .modname = KBUILD_MODNAME, \
7886 .function = __func__, \
7987 .filename = __FILE__, \
8088 .format = (fmt), \
8189 .lineno = __LINE__, \
8290 .flags = _DPRINTK_FLAGS_DEFAULT, \
83
- dd_key_init(key, init) \
91
+ _DPRINTK_KEY_INIT \
8492 }
8593
8694 #ifdef CONFIG_JUMP_LABEL
8795
88
-#define dd_key_init(key, init) key = (init)
89
-
9096 #ifdef DEBUG
91
-#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
92
- DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_true, \
93
- (STATIC_KEY_TRUE_INIT))
97
+
98
+#define _DPRINTK_KEY_INIT .key.dd_key_true = (STATIC_KEY_TRUE_INIT)
9499
95100 #define DYNAMIC_DEBUG_BRANCH(descriptor) \
96101 static_branch_likely(&descriptor.key.dd_key_true)
97102 #else
98
-#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
99
- DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_false, \
100
- (STATIC_KEY_FALSE_INIT))
103
+#define _DPRINTK_KEY_INIT .key.dd_key_false = (STATIC_KEY_FALSE_INIT)
101104
102105 #define DYNAMIC_DEBUG_BRANCH(descriptor) \
103106 static_branch_unlikely(&descriptor.key.dd_key_false)
104107 #endif
105108
106
-#else
109
+#else /* !CONFIG_JUMP_LABEL */
107110
108
-#define dd_key_init(key, init)
109
-
110
-#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
111
- DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, 0, 0)
111
+#define _DPRINTK_KEY_INIT
112112
113113 #ifdef DEBUG
114114 #define DYNAMIC_DEBUG_BRANCH(descriptor) \
....@@ -118,47 +118,72 @@
118118 unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)
119119 #endif
120120
121
-#endif
121
+#endif /* CONFIG_JUMP_LABEL */
122
+
123
+#define __dynamic_func_call(id, fmt, func, ...) do { \
124
+ DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \
125
+ if (DYNAMIC_DEBUG_BRANCH(id)) \
126
+ func(&id, ##__VA_ARGS__); \
127
+} while (0)
128
+
129
+#define __dynamic_func_call_no_desc(id, fmt, func, ...) do { \
130
+ DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \
131
+ if (DYNAMIC_DEBUG_BRANCH(id)) \
132
+ func(__VA_ARGS__); \
133
+} while (0)
134
+
135
+/*
136
+ * "Factory macro" for generating a call to func, guarded by a
137
+ * DYNAMIC_DEBUG_BRANCH. The dynamic debug descriptor will be
138
+ * initialized using the fmt argument. The function will be called with
139
+ * the address of the descriptor as first argument, followed by all
140
+ * the varargs. Note that fmt is repeated in invocations of this
141
+ * macro.
142
+ */
143
+#define _dynamic_func_call(fmt, func, ...) \
144
+ __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
145
+/*
146
+ * A variant that does the same, except that the descriptor is not
147
+ * passed as the first argument to the function; it is only called
148
+ * with precisely the macro's varargs.
149
+ */
150
+#define _dynamic_func_call_no_desc(fmt, func, ...) \
151
+ __dynamic_func_call_no_desc(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__)
122152
123153 #define dynamic_pr_debug(fmt, ...) \
124
-do { \
125
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
126
- if (DYNAMIC_DEBUG_BRANCH(descriptor)) \
127
- __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \
128
- ##__VA_ARGS__); \
129
-} while (0)
154
+ _dynamic_func_call(fmt, __dynamic_pr_debug, \
155
+ pr_fmt(fmt), ##__VA_ARGS__)
130156
131157 #define dynamic_dev_dbg(dev, fmt, ...) \
132
-do { \
133
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
134
- if (DYNAMIC_DEBUG_BRANCH(descriptor)) \
135
- __dynamic_dev_dbg(&descriptor, dev, fmt, \
136
- ##__VA_ARGS__); \
137
-} while (0)
158
+ _dynamic_func_call(fmt,__dynamic_dev_dbg, \
159
+ dev, fmt, ##__VA_ARGS__)
138160
139161 #define dynamic_netdev_dbg(dev, fmt, ...) \
140
-do { \
141
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
142
- if (DYNAMIC_DEBUG_BRANCH(descriptor)) \
143
- __dynamic_netdev_dbg(&descriptor, dev, fmt, \
144
- ##__VA_ARGS__); \
145
-} while (0)
162
+ _dynamic_func_call(fmt, __dynamic_netdev_dbg, \
163
+ dev, fmt, ##__VA_ARGS__)
146164
147
-#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
148
- groupsize, buf, len, ascii) \
149
-do { \
150
- DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \
151
- __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\
152
- if (DYNAMIC_DEBUG_BRANCH(descriptor)) \
153
- print_hex_dump(KERN_DEBUG, prefix_str, \
154
- prefix_type, rowsize, groupsize, \
155
- buf, len, ascii); \
156
-} while (0)
165
+#define dynamic_ibdev_dbg(dev, fmt, ...) \
166
+ _dynamic_func_call(fmt, __dynamic_ibdev_dbg, \
167
+ dev, fmt, ##__VA_ARGS__)
157168
158
-#else
169
+#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
170
+ groupsize, buf, len, ascii) \
171
+ _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \
172
+ print_hex_dump, \
173
+ KERN_DEBUG, prefix_str, prefix_type, \
174
+ rowsize, groupsize, buf, len, ascii)
175
+
176
+#else /* !CONFIG_DYNAMIC_DEBUG_CORE */
159177
160178 #include <linux/string.h>
161179 #include <linux/errno.h>
180
+#include <linux/printk.h>
181
+
182
+static inline int ddebug_add_module(struct _ddebug *tab, unsigned int n,
183
+ const char *modname)
184
+{
185
+ return 0;
186
+}
162187
163188 static inline int ddebug_remove_module(const char *mod)
164189 {
....@@ -168,7 +193,7 @@
168193 static inline int ddebug_dyndbg_module_param_cb(char *param, char *val,
169194 const char *modname)
170195 {
171
- if (strstr(param, "dyndbg")) {
196
+ if (!strcmp(param, "dyndbg")) {
172197 /* avoid pr_warn(), which wants pr_fmt() fully defined */
173198 printk(KERN_WARNING "dyndbg param is supported only in "
174199 "CONFIG_DYNAMIC_DEBUG builds\n");
....@@ -181,6 +206,13 @@
181206 do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
182207 #define dynamic_dev_dbg(dev, fmt, ...) \
183208 do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
184
-#endif
209
+#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
210
+ groupsize, buf, len, ascii) \
211
+ do { if (0) \
212
+ print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, \
213
+ rowsize, groupsize, buf, len, ascii); \
214
+ } while (0)
215
+
216
+#endif /* !CONFIG_DYNAMIC_DEBUG_CORE */
185217
186218 #endif