[PATCH v9 09/10] dyndbg: create DEFINE_DYNAMIC_DEBUG_TRACE_CATEGORIES

Jim Cromie jim.cromie at gmail.com
Wed Oct 27 04:36:44 UTC 2021


clone DEFINE_DYNAMIC_DEBUG_CATEGORIES interface to enable pr_debug
output to tracefs.

Extend DEFINE_DYNAMIC_DEBUG_CATEGORIES to work for tracing, by
renaming it (with _FLAGS suffix), adding _flags param, and using it
2x; in original and new names, with "p" and "T" flags respectively.

TODO: rethink this, consider combined trace/debug declaration.
good: single bitmap-spec for both trace,debug, no chance of divergence.
bad: arg-type & count checks are hard, and bitmap follows too!

to combine both, we need 4 args:
  sysfs_debug_name, __debug_var
  sysfs_trace_name, __trace_var	// these may be NULL, IFF !CONFIG_TRACE ??
then a bitmap:
  [0] = { "category1" }, ...)

My BUILD_BUG-fu is insufficient to protect a naive macro.

Signed-off-by: Jim Cromie <jim.cromie at gmail.com>
---
 include/linux/dynamic_debug.h | 19 ++++++++++++++-----
 lib/dynamic_debug.c           |  4 ++--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 896848f546e6..f273ba82cbb0 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -254,11 +254,20 @@ struct dyndbg_bitdesc {
 
 struct dyndbg_bitmap_param {
 	unsigned long *bits;		/* ref to shared state */
+	const char *flags;
 	struct dyndbg_bitdesc map[];	/* indexed by bitpos */
 };
 
 #if defined(CONFIG_DYNAMIC_DEBUG) || \
 	(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
+
+#define DEFINE_DYNAMIC_DEBUG_CATEGORIES_FLAGS(fsname, _var, _flags, desc, ...) \
+	MODULE_PARM_DESC(fsname, desc);					\
+	static struct dyndbg_bitmap_param ddcats_##_var =		\
+	{ .bits = &(_var), .flags = (_flags),				\
+	  .map = { __VA_ARGS__, { .match = NULL }}};			\
+	module_param_cb(fsname, &param_ops_dyndbg, &ddcats_##_var, 0644)
+
 /**
  * DEFINE_DYNAMIC_DEBUG_CATEGORIES() - bitmap control of categorized pr_debugs
  * @fsname: parameter basename under /sys
@@ -271,11 +280,11 @@ struct dyndbg_bitmap_param {
  * modules calling pr_debugs to control them in groups according to
  * those prefixes, and map them to bits 0-N of a sysfs control point.
  */
-#define DEFINE_DYNAMIC_DEBUG_CATEGORIES(fsname, _var, desc, ...)	\
-	MODULE_PARM_DESC(fsname, desc);					\
-	static struct dyndbg_bitmap_param ddcats_##_var =		\
-	{ .bits = &(_var), .map = { __VA_ARGS__, { .match = NULL }}};	\
-	module_param_cb(fsname, &param_ops_dyndbg, &ddcats_##_var, 0644)
+#define DEFINE_DYNAMIC_DEBUG_CATEGORIES(fsname, _var, desc, ...) \
+	DEFINE_DYNAMIC_DEBUG_CATEGORIES_FLAGS(fsname, _var, "p", desc, ##__VA_ARGS__)
+
+#define DEFINE_DYNAMIC_DEBUG_TRACE_CATEGORIES(fsname, _var, desc, ...) \
+	DEFINE_DYNAMIC_DEBUG_CATEGORIES_FLAGS(fsname, _var, "T", desc, ##__VA_ARGS__)
 
 extern const struct kernel_param_ops param_ops_dyndbg;
 
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index f19465b114cd..b4146178780f 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -629,8 +629,8 @@ int param_set_dyndbg(const char *instr, const struct kernel_param *kp)
 	for (i = 0; map->match && i < BITS_PER_LONG; map++, i++) {
 		if (test_bit(i, &inbits) == test_bit(i, p->bits))
 			continue;
-		snprintf(query, FMT_QUERY_SIZE, "format '%s' %cp", map->match,
-			 test_bit(i, &inbits) ? '+' : '-');
+		snprintf(query, FMT_QUERY_SIZE, "format '%s' %c%s", map->match,
+			 test_bit(i, &inbits) ? '+' : '-', p->flags);
 
 		matches = ddebug_exec_queries(query, KP_MOD_NAME);
 
-- 
2.31.1



More information about the amd-gfx mailing list