All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@akamai.com, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gvt-dev@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Cc: gregkh@linuxfoundation.org, daniel.vetter@ffwll.ch,
	seanpaul@chromium.org, robdclark@gmail.com, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, quic_saipraka@quicinc.com,
	will@kernel.org, catalin.marinas@arm.com,
	quic_psodagud@quicinc.com, maz@kernel.org, arnd@arndb.de,
	linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org, mingo@redhat.com,
	jim.cromie@gmail.com
Subject: [PATCH v2 14/27] dyndbg: add test_dynamic_debug module
Date: Mon, 16 May 2022 16:56:27 -0600	[thread overview]
Message-ID: <20220516225640.3102269-15-jim.cromie@gmail.com> (raw)
In-Reply-To: <20220516225640.3102269-1-jim.cromie@gmail.com>

Demonstrate dyndbg's "class FOO" and bitmap-to-classes support.  This
support is meant to plug into drm.debug system, and largely replace
the use of drm_debug_enabled(category) with JUMP_LABELs.

Recap:
  #> echo class DRM_UT_CORE +p > /proc/dynamic_debug/control

This is made "safe" because dyndbg skips it for any modules which
don't know that class (havent called dynamic_debug_register_classes).

Other modules may use the same .class_id for a separate classified
debug scheme.

Use the API:

- DYNAMIC_DEBUG_CLASSES(_var, classes), to declare static _var by name
- dynamic_debug_register_classes(_var)
- dynamic_debug_unregister_classes(_var)

Use these 3 times; with base = 0,8,16 respectively, to demonstrate the
segmenting of the module's .class_id range [0..30]

For each of those 3 class-name-sets, add 2 sysfs-node-bitmaps, one
each for p-syslog, and T-tracefs, the latter will work once dyndbg
gets that patchset.

  #> modprobe test_dynamic_debug dyndbg=+pfm
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints
  #> echo class FOO +pf  > /proc/dynamic_debug/control
  #> echo class Foo +pfm > /proc/dynamic_debug/control
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints

RFC:

This use case exposes a weak point in the api; the 2nd query command
given in the dyndbg option will not work like the 1st:

  #> modprobe test_dynamic_debug dyndbg='+pfm; class FOO +pfm'

This is because the option is processed early in module-load, well
before the registration can attach the class-map to the module's
ddebug_table entry.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 MAINTAINERS              |   1 +
 lib/Kconfig.debug        |  11 +++
 lib/Makefile             |   1 +
 lib/test_dynamic_debug.c | 172 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 185 insertions(+)
 create mode 100644 lib/test_dynamic_debug.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e8c52d0192a6..bf615853be47 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6918,6 +6918,7 @@ M:	Jason Baron <jbaron@akamai.com>
 S:	Maintained
 F:	include/linux/dynamic_debug.h
 F:	lib/dynamic_debug.c
+F:	lib/test_dynamic_debug.c
 
 DYNAMIC INTERRUPT MODERATION
 M:	Tal Gilboa <talgi@nvidia.com>
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 075cd25363ac..c88d691d3df1 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2601,6 +2601,17 @@ config TEST_STATIC_KEYS
 
 	  If unsure, say N.
 
+config TEST_DYNAMIC_DEBUG
+	tristate "Test DYNAMIC_DEBUG"
+	depends on m
+	depends on DYNAMIC_DEBUG
+	help
+	  This module registers a tracer callback to count enabled
+	  pr_debugs in a 'do_debugging' function, then alters their
+	  enablements, calls the function, and compares counts.
+
+	  If unsure, say N.
+
 config TEST_KMOD
 	tristate "kmod stress tester"
 	depends on m
diff --git a/lib/Makefile b/lib/Makefile
index 6b9ffc1bd1ee..e5727fbbfc7d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o
 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
+obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
 obj-$(CONFIG_TEST_PRINTF) += test_printf.o
 obj-$(CONFIG_TEST_SCANF) += test_scanf.o
 obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
new file mode 100644
index 000000000000..65c37ba6c0da
--- /dev/null
+++ b/lib/test_dynamic_debug.c
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Kernel module for testing dynamic_debug
+ *
+ * Authors:
+ *      Jim Cromie	<jim.cromie@gmail.com>
+ */
+
+#define pr_fmt(fmt) "test_dd: " fmt
+
+#include <linux/module.h>
+
+static void do_prints(void); /* device under test */
+
+/* run tests by reading or writing sysfs node */
+
+int param_set_do_prints(const char *instr, const struct kernel_param *kp)
+{
+	do_prints();
+	return 0;
+}
+EXPORT_SYMBOL(param_set_do_prints);
+
+int param_get_do_prints(char *buffer, const struct kernel_param *kp)
+{
+	do_prints();
+	return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
+}
+EXPORT_SYMBOL(param_get_do_prints);
+
+const struct kernel_param_ops param_ops_do_prints = {
+	.set = param_set_do_prints,
+	.get = param_get_do_prints,
+};
+EXPORT_SYMBOL(param_ops_do_prints);
+
+module_param_cb(do_prints, &param_ops_do_prints, NULL, 0600);
+
+/*
+ * Declare 3 groups of classes, with different .class_id[] ranges,
+ * each with 2 sysfs-node bitmaps controlling p,T flags respectively
+ * for those named classes.  This example is rather more involved than
+ * anyone will likely use.
+
+ * The T-bitmap sysfs-node functionality will need a few patches which
+ * add trace-events to dyndbg.
+
+ * Rules:
+ * - enum symbols must match/correlate with class-name strings
+ * - base must equal enum's 1st value
+ */
+
+enum cat1 { FOO, BAR, BUZZ };
+DYNAMIC_DEBUG_CLASSES(ddt_classes1, 0,
+		      "FOO", "BAR", "BUZZ");
+
+unsigned long bits_1p, bits_1t;
+EXPORT_SYMBOL(bits_1p);
+EXPORT_SYMBOL(bits_1t);
+
+static struct ddebug_classes_bitmap_param p1_bitmap = {
+	.bits = &bits_1p,
+	.flags = "p",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_syslog_bits, &param_ops_dyndbg_classes, &p1_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t1_bitmap = {
+	.bits = &bits_1t,
+	.flags = "T",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_trace_bits, &param_ops_dyndbg_classes, &t1_bitmap, 0600);
+
+
+enum cat2 { Foo = 8, Bar, Buzz };
+DYNAMIC_DEBUG_CLASSES(ddt_classes2, 8,
+		      "Foo", "Bar", "Buzz");
+
+unsigned long bits_2p, bits_2t;
+EXPORT_SYMBOL(bits_2p);
+EXPORT_SYMBOL(bits_2t);
+
+static struct ddebug_classes_bitmap_param p2_bitmap = {
+	.bits = &bits_2p,
+	.flags = "p",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_syslog_bits, &param_ops_dyndbg_classes, &p2_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t2_bitmap = {
+	.bits = &bits_2t,
+	.flags = "T",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_trace_bits, &param_ops_dyndbg_classes, &t2_bitmap, 0600);
+
+
+enum cat3 { bing = 16, bong, boom };
+DYNAMIC_DEBUG_CLASSES(ddt_classes3, 16,
+		      "bing", "bong", "boom");
+
+unsigned long bits_3p, bits_3t;
+EXPORT_SYMBOL(bits_3p);
+EXPORT_SYMBOL(bits_3t);
+
+static struct ddebug_classes_bitmap_param p3_bitmap = {
+	.bits = &bits_3p,
+	.flags = "p",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_syslog_bits, &param_ops_dyndbg_classes, &p3_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t3_bitmap = {
+	.bits = &bits_3t,
+	.flags = "T",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_trace_bits, &param_ops_dyndbg_classes, &t3_bitmap, 0600);
+
+static void do_prints(void)
+{
+	/* raw integer classes */
+	__pr_debug_cls(0, "class 0");
+	__pr_debug_cls(1, "class 1");
+	__pr_debug_cls(2, "class 2");
+
+	/* enum ints */
+	__pr_debug_cls(FOO, "class FOO");
+	__pr_debug_cls(BAR, "class BAR");
+	__pr_debug_cls(BUZZ, "class BUZZ");
+
+	__pr_debug_cls(Foo, "class Foo");
+	__pr_debug_cls(Bar, "class Bar");
+	__pr_debug_cls(Buzz, "class Buzz");
+
+	__pr_debug_cls(bing, "class bing");
+	__pr_debug_cls(bong, "class bong");
+	__pr_debug_cls(boom, "class boom");
+}
+
+static int __init test_dynamic_debug_init(void)
+{
+	pr_debug("module-init\n");
+	/*
+	 * these are too late to enable class FOO at module load time:
+	 * #> modprobe test_dynamic_debug dyndbg='class FOO +p'
+	 */
+	dynamic_debug_register_classes(&ddt_classes1);
+	dynamic_debug_register_classes(&ddt_classes2);
+	dynamic_debug_register_classes(&ddt_classes3);
+
+	do_prints();
+
+	pr_debug("module-init done\n");
+	return 0;
+}
+
+static void __exit test_dynamic_debug_exit(void)
+{
+	dynamic_debug_unregister_classes(&ddt_classes1);
+	dynamic_debug_unregister_classes(&ddt_classes2);
+	dynamic_debug_unregister_classes(&ddt_classes3);
+
+	pr_debug("module-exit\n");
+}
+
+module_init(test_dynamic_debug_init);
+module_exit(test_dynamic_debug_exit);
+
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.35.3


WARNING: multiple messages have this Message-ID (diff)
From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@akamai.com, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gvt-dev@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Cc: maz@kernel.org, quic_saipraka@quicinc.com,
	catalin.marinas@arm.com, arnd@arndb.de,
	gregkh@linuxfoundation.org, linux-arm-msm@vger.kernel.org,
	rostedt@goodmis.org, mingo@redhat.com,
	mathieu.desnoyers@efficios.com, quic_psodagud@quicinc.com,
	daniel.vetter@ffwll.ch, seanpaul@chromium.org, will@kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 14/27] dyndbg: add test_dynamic_debug module
Date: Mon, 16 May 2022 16:56:27 -0600	[thread overview]
Message-ID: <20220516225640.3102269-15-jim.cromie@gmail.com> (raw)
In-Reply-To: <20220516225640.3102269-1-jim.cromie@gmail.com>

Demonstrate dyndbg's "class FOO" and bitmap-to-classes support.  This
support is meant to plug into drm.debug system, and largely replace
the use of drm_debug_enabled(category) with JUMP_LABELs.

Recap:
  #> echo class DRM_UT_CORE +p > /proc/dynamic_debug/control

This is made "safe" because dyndbg skips it for any modules which
don't know that class (havent called dynamic_debug_register_classes).

Other modules may use the same .class_id for a separate classified
debug scheme.

Use the API:

- DYNAMIC_DEBUG_CLASSES(_var, classes), to declare static _var by name
- dynamic_debug_register_classes(_var)
- dynamic_debug_unregister_classes(_var)

Use these 3 times; with base = 0,8,16 respectively, to demonstrate the
segmenting of the module's .class_id range [0..30]

For each of those 3 class-name-sets, add 2 sysfs-node-bitmaps, one
each for p-syslog, and T-tracefs, the latter will work once dyndbg
gets that patchset.

  #> modprobe test_dynamic_debug dyndbg=+pfm
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints
  #> echo class FOO +pf  > /proc/dynamic_debug/control
  #> echo class Foo +pfm > /proc/dynamic_debug/control
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints

RFC:

This use case exposes a weak point in the api; the 2nd query command
given in the dyndbg option will not work like the 1st:

  #> modprobe test_dynamic_debug dyndbg='+pfm; class FOO +pfm'

This is because the option is processed early in module-load, well
before the registration can attach the class-map to the module's
ddebug_table entry.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 MAINTAINERS              |   1 +
 lib/Kconfig.debug        |  11 +++
 lib/Makefile             |   1 +
 lib/test_dynamic_debug.c | 172 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 185 insertions(+)
 create mode 100644 lib/test_dynamic_debug.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e8c52d0192a6..bf615853be47 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6918,6 +6918,7 @@ M:	Jason Baron <jbaron@akamai.com>
 S:	Maintained
 F:	include/linux/dynamic_debug.h
 F:	lib/dynamic_debug.c
+F:	lib/test_dynamic_debug.c
 
 DYNAMIC INTERRUPT MODERATION
 M:	Tal Gilboa <talgi@nvidia.com>
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 075cd25363ac..c88d691d3df1 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2601,6 +2601,17 @@ config TEST_STATIC_KEYS
 
 	  If unsure, say N.
 
+config TEST_DYNAMIC_DEBUG
+	tristate "Test DYNAMIC_DEBUG"
+	depends on m
+	depends on DYNAMIC_DEBUG
+	help
+	  This module registers a tracer callback to count enabled
+	  pr_debugs in a 'do_debugging' function, then alters their
+	  enablements, calls the function, and compares counts.
+
+	  If unsure, say N.
+
 config TEST_KMOD
 	tristate "kmod stress tester"
 	depends on m
diff --git a/lib/Makefile b/lib/Makefile
index 6b9ffc1bd1ee..e5727fbbfc7d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o
 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
+obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
 obj-$(CONFIG_TEST_PRINTF) += test_printf.o
 obj-$(CONFIG_TEST_SCANF) += test_scanf.o
 obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
new file mode 100644
index 000000000000..65c37ba6c0da
--- /dev/null
+++ b/lib/test_dynamic_debug.c
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Kernel module for testing dynamic_debug
+ *
+ * Authors:
+ *      Jim Cromie	<jim.cromie@gmail.com>
+ */
+
+#define pr_fmt(fmt) "test_dd: " fmt
+
+#include <linux/module.h>
+
+static void do_prints(void); /* device under test */
+
+/* run tests by reading or writing sysfs node */
+
+int param_set_do_prints(const char *instr, const struct kernel_param *kp)
+{
+	do_prints();
+	return 0;
+}
+EXPORT_SYMBOL(param_set_do_prints);
+
+int param_get_do_prints(char *buffer, const struct kernel_param *kp)
+{
+	do_prints();
+	return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
+}
+EXPORT_SYMBOL(param_get_do_prints);
+
+const struct kernel_param_ops param_ops_do_prints = {
+	.set = param_set_do_prints,
+	.get = param_get_do_prints,
+};
+EXPORT_SYMBOL(param_ops_do_prints);
+
+module_param_cb(do_prints, &param_ops_do_prints, NULL, 0600);
+
+/*
+ * Declare 3 groups of classes, with different .class_id[] ranges,
+ * each with 2 sysfs-node bitmaps controlling p,T flags respectively
+ * for those named classes.  This example is rather more involved than
+ * anyone will likely use.
+
+ * The T-bitmap sysfs-node functionality will need a few patches which
+ * add trace-events to dyndbg.
+
+ * Rules:
+ * - enum symbols must match/correlate with class-name strings
+ * - base must equal enum's 1st value
+ */
+
+enum cat1 { FOO, BAR, BUZZ };
+DYNAMIC_DEBUG_CLASSES(ddt_classes1, 0,
+		      "FOO", "BAR", "BUZZ");
+
+unsigned long bits_1p, bits_1t;
+EXPORT_SYMBOL(bits_1p);
+EXPORT_SYMBOL(bits_1t);
+
+static struct ddebug_classes_bitmap_param p1_bitmap = {
+	.bits = &bits_1p,
+	.flags = "p",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_syslog_bits, &param_ops_dyndbg_classes, &p1_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t1_bitmap = {
+	.bits = &bits_1t,
+	.flags = "T",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_trace_bits, &param_ops_dyndbg_classes, &t1_bitmap, 0600);
+
+
+enum cat2 { Foo = 8, Bar, Buzz };
+DYNAMIC_DEBUG_CLASSES(ddt_classes2, 8,
+		      "Foo", "Bar", "Buzz");
+
+unsigned long bits_2p, bits_2t;
+EXPORT_SYMBOL(bits_2p);
+EXPORT_SYMBOL(bits_2t);
+
+static struct ddebug_classes_bitmap_param p2_bitmap = {
+	.bits = &bits_2p,
+	.flags = "p",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_syslog_bits, &param_ops_dyndbg_classes, &p2_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t2_bitmap = {
+	.bits = &bits_2t,
+	.flags = "T",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_trace_bits, &param_ops_dyndbg_classes, &t2_bitmap, 0600);
+
+
+enum cat3 { bing = 16, bong, boom };
+DYNAMIC_DEBUG_CLASSES(ddt_classes3, 16,
+		      "bing", "bong", "boom");
+
+unsigned long bits_3p, bits_3t;
+EXPORT_SYMBOL(bits_3p);
+EXPORT_SYMBOL(bits_3t);
+
+static struct ddebug_classes_bitmap_param p3_bitmap = {
+	.bits = &bits_3p,
+	.flags = "p",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_syslog_bits, &param_ops_dyndbg_classes, &p3_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t3_bitmap = {
+	.bits = &bits_3t,
+	.flags = "T",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_trace_bits, &param_ops_dyndbg_classes, &t3_bitmap, 0600);
+
+static void do_prints(void)
+{
+	/* raw integer classes */
+	__pr_debug_cls(0, "class 0");
+	__pr_debug_cls(1, "class 1");
+	__pr_debug_cls(2, "class 2");
+
+	/* enum ints */
+	__pr_debug_cls(FOO, "class FOO");
+	__pr_debug_cls(BAR, "class BAR");
+	__pr_debug_cls(BUZZ, "class BUZZ");
+
+	__pr_debug_cls(Foo, "class Foo");
+	__pr_debug_cls(Bar, "class Bar");
+	__pr_debug_cls(Buzz, "class Buzz");
+
+	__pr_debug_cls(bing, "class bing");
+	__pr_debug_cls(bong, "class bong");
+	__pr_debug_cls(boom, "class boom");
+}
+
+static int __init test_dynamic_debug_init(void)
+{
+	pr_debug("module-init\n");
+	/*
+	 * these are too late to enable class FOO at module load time:
+	 * #> modprobe test_dynamic_debug dyndbg='class FOO +p'
+	 */
+	dynamic_debug_register_classes(&ddt_classes1);
+	dynamic_debug_register_classes(&ddt_classes2);
+	dynamic_debug_register_classes(&ddt_classes3);
+
+	do_prints();
+
+	pr_debug("module-init done\n");
+	return 0;
+}
+
+static void __exit test_dynamic_debug_exit(void)
+{
+	dynamic_debug_unregister_classes(&ddt_classes1);
+	dynamic_debug_unregister_classes(&ddt_classes2);
+	dynamic_debug_unregister_classes(&ddt_classes3);
+
+	pr_debug("module-exit\n");
+}
+
+module_init(test_dynamic_debug_init);
+module_exit(test_dynamic_debug_exit);
+
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.35.3


WARNING: multiple messages have this Message-ID (diff)
From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@akamai.com, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gvt-dev@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Cc: maz@kernel.org, quic_saipraka@quicinc.com,
	catalin.marinas@arm.com, arnd@arndb.de, jim.cromie@gmail.com,
	gregkh@linuxfoundation.org, linux-arm-msm@vger.kernel.org,
	rostedt@goodmis.org, mingo@redhat.com,
	mathieu.desnoyers@efficios.com, quic_psodagud@quicinc.com,
	daniel.vetter@ffwll.ch, seanpaul@chromium.org, will@kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [Intel-gfx] [PATCH v2 14/27] dyndbg: add test_dynamic_debug module
Date: Mon, 16 May 2022 16:56:27 -0600	[thread overview]
Message-ID: <20220516225640.3102269-15-jim.cromie@gmail.com> (raw)
In-Reply-To: <20220516225640.3102269-1-jim.cromie@gmail.com>

Demonstrate dyndbg's "class FOO" and bitmap-to-classes support.  This
support is meant to plug into drm.debug system, and largely replace
the use of drm_debug_enabled(category) with JUMP_LABELs.

Recap:
  #> echo class DRM_UT_CORE +p > /proc/dynamic_debug/control

This is made "safe" because dyndbg skips it for any modules which
don't know that class (havent called dynamic_debug_register_classes).

Other modules may use the same .class_id for a separate classified
debug scheme.

Use the API:

- DYNAMIC_DEBUG_CLASSES(_var, classes), to declare static _var by name
- dynamic_debug_register_classes(_var)
- dynamic_debug_unregister_classes(_var)

Use these 3 times; with base = 0,8,16 respectively, to demonstrate the
segmenting of the module's .class_id range [0..30]

For each of those 3 class-name-sets, add 2 sysfs-node-bitmaps, one
each for p-syslog, and T-tracefs, the latter will work once dyndbg
gets that patchset.

  #> modprobe test_dynamic_debug dyndbg=+pfm
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints
  #> echo class FOO +pf  > /proc/dynamic_debug/control
  #> echo class Foo +pfm > /proc/dynamic_debug/control
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints

RFC:

This use case exposes a weak point in the api; the 2nd query command
given in the dyndbg option will not work like the 1st:

  #> modprobe test_dynamic_debug dyndbg='+pfm; class FOO +pfm'

This is because the option is processed early in module-load, well
before the registration can attach the class-map to the module's
ddebug_table entry.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 MAINTAINERS              |   1 +
 lib/Kconfig.debug        |  11 +++
 lib/Makefile             |   1 +
 lib/test_dynamic_debug.c | 172 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 185 insertions(+)
 create mode 100644 lib/test_dynamic_debug.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e8c52d0192a6..bf615853be47 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6918,6 +6918,7 @@ M:	Jason Baron <jbaron@akamai.com>
 S:	Maintained
 F:	include/linux/dynamic_debug.h
 F:	lib/dynamic_debug.c
+F:	lib/test_dynamic_debug.c
 
 DYNAMIC INTERRUPT MODERATION
 M:	Tal Gilboa <talgi@nvidia.com>
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 075cd25363ac..c88d691d3df1 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2601,6 +2601,17 @@ config TEST_STATIC_KEYS
 
 	  If unsure, say N.
 
+config TEST_DYNAMIC_DEBUG
+	tristate "Test DYNAMIC_DEBUG"
+	depends on m
+	depends on DYNAMIC_DEBUG
+	help
+	  This module registers a tracer callback to count enabled
+	  pr_debugs in a 'do_debugging' function, then alters their
+	  enablements, calls the function, and compares counts.
+
+	  If unsure, say N.
+
 config TEST_KMOD
 	tristate "kmod stress tester"
 	depends on m
diff --git a/lib/Makefile b/lib/Makefile
index 6b9ffc1bd1ee..e5727fbbfc7d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o
 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
+obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
 obj-$(CONFIG_TEST_PRINTF) += test_printf.o
 obj-$(CONFIG_TEST_SCANF) += test_scanf.o
 obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
new file mode 100644
index 000000000000..65c37ba6c0da
--- /dev/null
+++ b/lib/test_dynamic_debug.c
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Kernel module for testing dynamic_debug
+ *
+ * Authors:
+ *      Jim Cromie	<jim.cromie@gmail.com>
+ */
+
+#define pr_fmt(fmt) "test_dd: " fmt
+
+#include <linux/module.h>
+
+static void do_prints(void); /* device under test */
+
+/* run tests by reading or writing sysfs node */
+
+int param_set_do_prints(const char *instr, const struct kernel_param *kp)
+{
+	do_prints();
+	return 0;
+}
+EXPORT_SYMBOL(param_set_do_prints);
+
+int param_get_do_prints(char *buffer, const struct kernel_param *kp)
+{
+	do_prints();
+	return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
+}
+EXPORT_SYMBOL(param_get_do_prints);
+
+const struct kernel_param_ops param_ops_do_prints = {
+	.set = param_set_do_prints,
+	.get = param_get_do_prints,
+};
+EXPORT_SYMBOL(param_ops_do_prints);
+
+module_param_cb(do_prints, &param_ops_do_prints, NULL, 0600);
+
+/*
+ * Declare 3 groups of classes, with different .class_id[] ranges,
+ * each with 2 sysfs-node bitmaps controlling p,T flags respectively
+ * for those named classes.  This example is rather more involved than
+ * anyone will likely use.
+
+ * The T-bitmap sysfs-node functionality will need a few patches which
+ * add trace-events to dyndbg.
+
+ * Rules:
+ * - enum symbols must match/correlate with class-name strings
+ * - base must equal enum's 1st value
+ */
+
+enum cat1 { FOO, BAR, BUZZ };
+DYNAMIC_DEBUG_CLASSES(ddt_classes1, 0,
+		      "FOO", "BAR", "BUZZ");
+
+unsigned long bits_1p, bits_1t;
+EXPORT_SYMBOL(bits_1p);
+EXPORT_SYMBOL(bits_1t);
+
+static struct ddebug_classes_bitmap_param p1_bitmap = {
+	.bits = &bits_1p,
+	.flags = "p",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_syslog_bits, &param_ops_dyndbg_classes, &p1_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t1_bitmap = {
+	.bits = &bits_1t,
+	.flags = "T",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_trace_bits, &param_ops_dyndbg_classes, &t1_bitmap, 0600);
+
+
+enum cat2 { Foo = 8, Bar, Buzz };
+DYNAMIC_DEBUG_CLASSES(ddt_classes2, 8,
+		      "Foo", "Bar", "Buzz");
+
+unsigned long bits_2p, bits_2t;
+EXPORT_SYMBOL(bits_2p);
+EXPORT_SYMBOL(bits_2t);
+
+static struct ddebug_classes_bitmap_param p2_bitmap = {
+	.bits = &bits_2p,
+	.flags = "p",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_syslog_bits, &param_ops_dyndbg_classes, &p2_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t2_bitmap = {
+	.bits = &bits_2t,
+	.flags = "T",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_trace_bits, &param_ops_dyndbg_classes, &t2_bitmap, 0600);
+
+
+enum cat3 { bing = 16, bong, boom };
+DYNAMIC_DEBUG_CLASSES(ddt_classes3, 16,
+		      "bing", "bong", "boom");
+
+unsigned long bits_3p, bits_3t;
+EXPORT_SYMBOL(bits_3p);
+EXPORT_SYMBOL(bits_3t);
+
+static struct ddebug_classes_bitmap_param p3_bitmap = {
+	.bits = &bits_3p,
+	.flags = "p",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_syslog_bits, &param_ops_dyndbg_classes, &p3_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t3_bitmap = {
+	.bits = &bits_3t,
+	.flags = "T",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_trace_bits, &param_ops_dyndbg_classes, &t3_bitmap, 0600);
+
+static void do_prints(void)
+{
+	/* raw integer classes */
+	__pr_debug_cls(0, "class 0");
+	__pr_debug_cls(1, "class 1");
+	__pr_debug_cls(2, "class 2");
+
+	/* enum ints */
+	__pr_debug_cls(FOO, "class FOO");
+	__pr_debug_cls(BAR, "class BAR");
+	__pr_debug_cls(BUZZ, "class BUZZ");
+
+	__pr_debug_cls(Foo, "class Foo");
+	__pr_debug_cls(Bar, "class Bar");
+	__pr_debug_cls(Buzz, "class Buzz");
+
+	__pr_debug_cls(bing, "class bing");
+	__pr_debug_cls(bong, "class bong");
+	__pr_debug_cls(boom, "class boom");
+}
+
+static int __init test_dynamic_debug_init(void)
+{
+	pr_debug("module-init\n");
+	/*
+	 * these are too late to enable class FOO at module load time:
+	 * #> modprobe test_dynamic_debug dyndbg='class FOO +p'
+	 */
+	dynamic_debug_register_classes(&ddt_classes1);
+	dynamic_debug_register_classes(&ddt_classes2);
+	dynamic_debug_register_classes(&ddt_classes3);
+
+	do_prints();
+
+	pr_debug("module-init done\n");
+	return 0;
+}
+
+static void __exit test_dynamic_debug_exit(void)
+{
+	dynamic_debug_unregister_classes(&ddt_classes1);
+	dynamic_debug_unregister_classes(&ddt_classes2);
+	dynamic_debug_unregister_classes(&ddt_classes3);
+
+	pr_debug("module-exit\n");
+}
+
+module_init(test_dynamic_debug_init);
+module_exit(test_dynamic_debug_exit);
+
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.35.3


WARNING: multiple messages have this Message-ID (diff)
From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@akamai.com, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gvt-dev@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Cc: maz@kernel.org, quic_saipraka@quicinc.com,
	catalin.marinas@arm.com, arnd@arndb.de, jim.cromie@gmail.com,
	gregkh@linuxfoundation.org, linux-arm-msm@vger.kernel.org,
	rostedt@goodmis.org, robdclark@gmail.com, mingo@redhat.com,
	mathieu.desnoyers@efficios.com, quic_psodagud@quicinc.com,
	daniel.vetter@ffwll.ch, seanpaul@chromium.org, will@kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 14/27] dyndbg: add test_dynamic_debug module
Date: Mon, 16 May 2022 16:56:27 -0600	[thread overview]
Message-ID: <20220516225640.3102269-15-jim.cromie@gmail.com> (raw)
In-Reply-To: <20220516225640.3102269-1-jim.cromie@gmail.com>

Demonstrate dyndbg's "class FOO" and bitmap-to-classes support.  This
support is meant to plug into drm.debug system, and largely replace
the use of drm_debug_enabled(category) with JUMP_LABELs.

Recap:
  #> echo class DRM_UT_CORE +p > /proc/dynamic_debug/control

This is made "safe" because dyndbg skips it for any modules which
don't know that class (havent called dynamic_debug_register_classes).

Other modules may use the same .class_id for a separate classified
debug scheme.

Use the API:

- DYNAMIC_DEBUG_CLASSES(_var, classes), to declare static _var by name
- dynamic_debug_register_classes(_var)
- dynamic_debug_unregister_classes(_var)

Use these 3 times; with base = 0,8,16 respectively, to demonstrate the
segmenting of the module's .class_id range [0..30]

For each of those 3 class-name-sets, add 2 sysfs-node-bitmaps, one
each for p-syslog, and T-tracefs, the latter will work once dyndbg
gets that patchset.

  #> modprobe test_dynamic_debug dyndbg=+pfm
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints
  #> echo class FOO +pf  > /proc/dynamic_debug/control
  #> echo class Foo +pfm > /proc/dynamic_debug/control
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints

RFC:

This use case exposes a weak point in the api; the 2nd query command
given in the dyndbg option will not work like the 1st:

  #> modprobe test_dynamic_debug dyndbg='+pfm; class FOO +pfm'

This is because the option is processed early in module-load, well
before the registration can attach the class-map to the module's
ddebug_table entry.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 MAINTAINERS              |   1 +
 lib/Kconfig.debug        |  11 +++
 lib/Makefile             |   1 +
 lib/test_dynamic_debug.c | 172 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 185 insertions(+)
 create mode 100644 lib/test_dynamic_debug.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e8c52d0192a6..bf615853be47 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6918,6 +6918,7 @@ M:	Jason Baron <jbaron@akamai.com>
 S:	Maintained
 F:	include/linux/dynamic_debug.h
 F:	lib/dynamic_debug.c
+F:	lib/test_dynamic_debug.c
 
 DYNAMIC INTERRUPT MODERATION
 M:	Tal Gilboa <talgi@nvidia.com>
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 075cd25363ac..c88d691d3df1 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2601,6 +2601,17 @@ config TEST_STATIC_KEYS
 
 	  If unsure, say N.
 
+config TEST_DYNAMIC_DEBUG
+	tristate "Test DYNAMIC_DEBUG"
+	depends on m
+	depends on DYNAMIC_DEBUG
+	help
+	  This module registers a tracer callback to count enabled
+	  pr_debugs in a 'do_debugging' function, then alters their
+	  enablements, calls the function, and compares counts.
+
+	  If unsure, say N.
+
 config TEST_KMOD
 	tristate "kmod stress tester"
 	depends on m
diff --git a/lib/Makefile b/lib/Makefile
index 6b9ffc1bd1ee..e5727fbbfc7d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o
 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
+obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
 obj-$(CONFIG_TEST_PRINTF) += test_printf.o
 obj-$(CONFIG_TEST_SCANF) += test_scanf.o
 obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
new file mode 100644
index 000000000000..65c37ba6c0da
--- /dev/null
+++ b/lib/test_dynamic_debug.c
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Kernel module for testing dynamic_debug
+ *
+ * Authors:
+ *      Jim Cromie	<jim.cromie@gmail.com>
+ */
+
+#define pr_fmt(fmt) "test_dd: " fmt
+
+#include <linux/module.h>
+
+static void do_prints(void); /* device under test */
+
+/* run tests by reading or writing sysfs node */
+
+int param_set_do_prints(const char *instr, const struct kernel_param *kp)
+{
+	do_prints();
+	return 0;
+}
+EXPORT_SYMBOL(param_set_do_prints);
+
+int param_get_do_prints(char *buffer, const struct kernel_param *kp)
+{
+	do_prints();
+	return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
+}
+EXPORT_SYMBOL(param_get_do_prints);
+
+const struct kernel_param_ops param_ops_do_prints = {
+	.set = param_set_do_prints,
+	.get = param_get_do_prints,
+};
+EXPORT_SYMBOL(param_ops_do_prints);
+
+module_param_cb(do_prints, &param_ops_do_prints, NULL, 0600);
+
+/*
+ * Declare 3 groups of classes, with different .class_id[] ranges,
+ * each with 2 sysfs-node bitmaps controlling p,T flags respectively
+ * for those named classes.  This example is rather more involved than
+ * anyone will likely use.
+
+ * The T-bitmap sysfs-node functionality will need a few patches which
+ * add trace-events to dyndbg.
+
+ * Rules:
+ * - enum symbols must match/correlate with class-name strings
+ * - base must equal enum's 1st value
+ */
+
+enum cat1 { FOO, BAR, BUZZ };
+DYNAMIC_DEBUG_CLASSES(ddt_classes1, 0,
+		      "FOO", "BAR", "BUZZ");
+
+unsigned long bits_1p, bits_1t;
+EXPORT_SYMBOL(bits_1p);
+EXPORT_SYMBOL(bits_1t);
+
+static struct ddebug_classes_bitmap_param p1_bitmap = {
+	.bits = &bits_1p,
+	.flags = "p",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_syslog_bits, &param_ops_dyndbg_classes, &p1_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t1_bitmap = {
+	.bits = &bits_1t,
+	.flags = "T",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_trace_bits, &param_ops_dyndbg_classes, &t1_bitmap, 0600);
+
+
+enum cat2 { Foo = 8, Bar, Buzz };
+DYNAMIC_DEBUG_CLASSES(ddt_classes2, 8,
+		      "Foo", "Bar", "Buzz");
+
+unsigned long bits_2p, bits_2t;
+EXPORT_SYMBOL(bits_2p);
+EXPORT_SYMBOL(bits_2t);
+
+static struct ddebug_classes_bitmap_param p2_bitmap = {
+	.bits = &bits_2p,
+	.flags = "p",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_syslog_bits, &param_ops_dyndbg_classes, &p2_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t2_bitmap = {
+	.bits = &bits_2t,
+	.flags = "T",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_trace_bits, &param_ops_dyndbg_classes, &t2_bitmap, 0600);
+
+
+enum cat3 { bing = 16, bong, boom };
+DYNAMIC_DEBUG_CLASSES(ddt_classes3, 16,
+		      "bing", "bong", "boom");
+
+unsigned long bits_3p, bits_3t;
+EXPORT_SYMBOL(bits_3p);
+EXPORT_SYMBOL(bits_3t);
+
+static struct ddebug_classes_bitmap_param p3_bitmap = {
+	.bits = &bits_3p,
+	.flags = "p",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_syslog_bits, &param_ops_dyndbg_classes, &p3_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t3_bitmap = {
+	.bits = &bits_3t,
+	.flags = "T",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_trace_bits, &param_ops_dyndbg_classes, &t3_bitmap, 0600);
+
+static void do_prints(void)
+{
+	/* raw integer classes */
+	__pr_debug_cls(0, "class 0");
+	__pr_debug_cls(1, "class 1");
+	__pr_debug_cls(2, "class 2");
+
+	/* enum ints */
+	__pr_debug_cls(FOO, "class FOO");
+	__pr_debug_cls(BAR, "class BAR");
+	__pr_debug_cls(BUZZ, "class BUZZ");
+
+	__pr_debug_cls(Foo, "class Foo");
+	__pr_debug_cls(Bar, "class Bar");
+	__pr_debug_cls(Buzz, "class Buzz");
+
+	__pr_debug_cls(bing, "class bing");
+	__pr_debug_cls(bong, "class bong");
+	__pr_debug_cls(boom, "class boom");
+}
+
+static int __init test_dynamic_debug_init(void)
+{
+	pr_debug("module-init\n");
+	/*
+	 * these are too late to enable class FOO at module load time:
+	 * #> modprobe test_dynamic_debug dyndbg='class FOO +p'
+	 */
+	dynamic_debug_register_classes(&ddt_classes1);
+	dynamic_debug_register_classes(&ddt_classes2);
+	dynamic_debug_register_classes(&ddt_classes3);
+
+	do_prints();
+
+	pr_debug("module-init done\n");
+	return 0;
+}
+
+static void __exit test_dynamic_debug_exit(void)
+{
+	dynamic_debug_unregister_classes(&ddt_classes1);
+	dynamic_debug_unregister_classes(&ddt_classes2);
+	dynamic_debug_unregister_classes(&ddt_classes3);
+
+	pr_debug("module-exit\n");
+}
+
+module_init(test_dynamic_debug_init);
+module_exit(test_dynamic_debug_exit);
+
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.35.3


WARNING: multiple messages have this Message-ID (diff)
From: Jim Cromie <jim.cromie@gmail.com>
To: jbaron@akamai.com, linux-kernel@vger.kernel.org,
	dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
	intel-gvt-dev@lists.freedesktop.org,
	intel-gfx@lists.freedesktop.org
Cc: gregkh@linuxfoundation.org, daniel.vetter@ffwll.ch,
	seanpaul@chromium.org, robdclark@gmail.com, rostedt@goodmis.org,
	mathieu.desnoyers@efficios.com, quic_saipraka@quicinc.com,
	will@kernel.org, catalin.marinas@arm.com,
	quic_psodagud@quicinc.com, maz@kernel.org, arnd@arndb.de,
	linux-arm-kernel@lists.infradead.org,
	linux-arm-msm@vger.kernel.org, mingo@redhat.com,
	jim.cromie@gmail.com
Subject: [PATCH v2 14/27] dyndbg: add test_dynamic_debug module
Date: Mon, 16 May 2022 16:56:27 -0600	[thread overview]
Message-ID: <20220516225640.3102269-15-jim.cromie@gmail.com> (raw)
In-Reply-To: <20220516225640.3102269-1-jim.cromie@gmail.com>

Demonstrate dyndbg's "class FOO" and bitmap-to-classes support.  This
support is meant to plug into drm.debug system, and largely replace
the use of drm_debug_enabled(category) with JUMP_LABELs.

Recap:
  #> echo class DRM_UT_CORE +p > /proc/dynamic_debug/control

This is made "safe" because dyndbg skips it for any modules which
don't know that class (havent called dynamic_debug_register_classes).

Other modules may use the same .class_id for a separate classified
debug scheme.

Use the API:

- DYNAMIC_DEBUG_CLASSES(_var, classes), to declare static _var by name
- dynamic_debug_register_classes(_var)
- dynamic_debug_unregister_classes(_var)

Use these 3 times; with base = 0,8,16 respectively, to demonstrate the
segmenting of the module's .class_id range [0..30]

For each of those 3 class-name-sets, add 2 sysfs-node-bitmaps, one
each for p-syslog, and T-tracefs, the latter will work once dyndbg
gets that patchset.

  #> modprobe test_dynamic_debug dyndbg=+pfm
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints
  #> echo class FOO +pf  > /proc/dynamic_debug/control
  #> echo class Foo +pfm > /proc/dynamic_debug/control
  #> cat /sys/module/test_dynamic_debug/parameters/do_prints

RFC:

This use case exposes a weak point in the api; the 2nd query command
given in the dyndbg option will not work like the 1st:

  #> modprobe test_dynamic_debug dyndbg='+pfm; class FOO +pfm'

This is because the option is processed early in module-load, well
before the registration can attach the class-map to the module's
ddebug_table entry.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 MAINTAINERS              |   1 +
 lib/Kconfig.debug        |  11 +++
 lib/Makefile             |   1 +
 lib/test_dynamic_debug.c | 172 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 185 insertions(+)
 create mode 100644 lib/test_dynamic_debug.c

diff --git a/MAINTAINERS b/MAINTAINERS
index e8c52d0192a6..bf615853be47 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6918,6 +6918,7 @@ M:	Jason Baron <jbaron@akamai.com>
 S:	Maintained
 F:	include/linux/dynamic_debug.h
 F:	lib/dynamic_debug.c
+F:	lib/test_dynamic_debug.c
 
 DYNAMIC INTERRUPT MODERATION
 M:	Tal Gilboa <talgi@nvidia.com>
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 075cd25363ac..c88d691d3df1 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2601,6 +2601,17 @@ config TEST_STATIC_KEYS
 
 	  If unsure, say N.
 
+config TEST_DYNAMIC_DEBUG
+	tristate "Test DYNAMIC_DEBUG"
+	depends on m
+	depends on DYNAMIC_DEBUG
+	help
+	  This module registers a tracer callback to count enabled
+	  pr_debugs in a 'do_debugging' function, then alters their
+	  enablements, calls the function, and compares counts.
+
+	  If unsure, say N.
+
 config TEST_KMOD
 	tristate "kmod stress tester"
 	depends on m
diff --git a/lib/Makefile b/lib/Makefile
index 6b9ffc1bd1ee..e5727fbbfc7d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -82,6 +82,7 @@ obj-$(CONFIG_TEST_SORT) += test_sort.o
 obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
+obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
 obj-$(CONFIG_TEST_PRINTF) += test_printf.o
 obj-$(CONFIG_TEST_SCANF) += test_scanf.o
 obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
new file mode 100644
index 000000000000..65c37ba6c0da
--- /dev/null
+++ b/lib/test_dynamic_debug.c
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Kernel module for testing dynamic_debug
+ *
+ * Authors:
+ *      Jim Cromie	<jim.cromie@gmail.com>
+ */
+
+#define pr_fmt(fmt) "test_dd: " fmt
+
+#include <linux/module.h>
+
+static void do_prints(void); /* device under test */
+
+/* run tests by reading or writing sysfs node */
+
+int param_set_do_prints(const char *instr, const struct kernel_param *kp)
+{
+	do_prints();
+	return 0;
+}
+EXPORT_SYMBOL(param_set_do_prints);
+
+int param_get_do_prints(char *buffer, const struct kernel_param *kp)
+{
+	do_prints();
+	return scnprintf(buffer, PAGE_SIZE, "did do_prints\n");
+}
+EXPORT_SYMBOL(param_get_do_prints);
+
+const struct kernel_param_ops param_ops_do_prints = {
+	.set = param_set_do_prints,
+	.get = param_get_do_prints,
+};
+EXPORT_SYMBOL(param_ops_do_prints);
+
+module_param_cb(do_prints, &param_ops_do_prints, NULL, 0600);
+
+/*
+ * Declare 3 groups of classes, with different .class_id[] ranges,
+ * each with 2 sysfs-node bitmaps controlling p,T flags respectively
+ * for those named classes.  This example is rather more involved than
+ * anyone will likely use.
+
+ * The T-bitmap sysfs-node functionality will need a few patches which
+ * add trace-events to dyndbg.
+
+ * Rules:
+ * - enum symbols must match/correlate with class-name strings
+ * - base must equal enum's 1st value
+ */
+
+enum cat1 { FOO, BAR, BUZZ };
+DYNAMIC_DEBUG_CLASSES(ddt_classes1, 0,
+		      "FOO", "BAR", "BUZZ");
+
+unsigned long bits_1p, bits_1t;
+EXPORT_SYMBOL(bits_1p);
+EXPORT_SYMBOL(bits_1t);
+
+static struct ddebug_classes_bitmap_param p1_bitmap = {
+	.bits = &bits_1p,
+	.flags = "p",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_syslog_bits, &param_ops_dyndbg_classes, &p1_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t1_bitmap = {
+	.bits = &bits_1t,
+	.flags = "T",
+	.map = &ddt_classes1
+};
+module_param_cb(c1_trace_bits, &param_ops_dyndbg_classes, &t1_bitmap, 0600);
+
+
+enum cat2 { Foo = 8, Bar, Buzz };
+DYNAMIC_DEBUG_CLASSES(ddt_classes2, 8,
+		      "Foo", "Bar", "Buzz");
+
+unsigned long bits_2p, bits_2t;
+EXPORT_SYMBOL(bits_2p);
+EXPORT_SYMBOL(bits_2t);
+
+static struct ddebug_classes_bitmap_param p2_bitmap = {
+	.bits = &bits_2p,
+	.flags = "p",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_syslog_bits, &param_ops_dyndbg_classes, &p2_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t2_bitmap = {
+	.bits = &bits_2t,
+	.flags = "T",
+	.map = &ddt_classes2
+};
+module_param_cb(c2_trace_bits, &param_ops_dyndbg_classes, &t2_bitmap, 0600);
+
+
+enum cat3 { bing = 16, bong, boom };
+DYNAMIC_DEBUG_CLASSES(ddt_classes3, 16,
+		      "bing", "bong", "boom");
+
+unsigned long bits_3p, bits_3t;
+EXPORT_SYMBOL(bits_3p);
+EXPORT_SYMBOL(bits_3t);
+
+static struct ddebug_classes_bitmap_param p3_bitmap = {
+	.bits = &bits_3p,
+	.flags = "p",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_syslog_bits, &param_ops_dyndbg_classes, &p3_bitmap, 0600);
+
+static struct ddebug_classes_bitmap_param t3_bitmap = {
+	.bits = &bits_3t,
+	.flags = "T",
+	.map = &ddt_classes3
+};
+module_param_cb(c3_trace_bits, &param_ops_dyndbg_classes, &t3_bitmap, 0600);
+
+static void do_prints(void)
+{
+	/* raw integer classes */
+	__pr_debug_cls(0, "class 0");
+	__pr_debug_cls(1, "class 1");
+	__pr_debug_cls(2, "class 2");
+
+	/* enum ints */
+	__pr_debug_cls(FOO, "class FOO");
+	__pr_debug_cls(BAR, "class BAR");
+	__pr_debug_cls(BUZZ, "class BUZZ");
+
+	__pr_debug_cls(Foo, "class Foo");
+	__pr_debug_cls(Bar, "class Bar");
+	__pr_debug_cls(Buzz, "class Buzz");
+
+	__pr_debug_cls(bing, "class bing");
+	__pr_debug_cls(bong, "class bong");
+	__pr_debug_cls(boom, "class boom");
+}
+
+static int __init test_dynamic_debug_init(void)
+{
+	pr_debug("module-init\n");
+	/*
+	 * these are too late to enable class FOO at module load time:
+	 * #> modprobe test_dynamic_debug dyndbg='class FOO +p'
+	 */
+	dynamic_debug_register_classes(&ddt_classes1);
+	dynamic_debug_register_classes(&ddt_classes2);
+	dynamic_debug_register_classes(&ddt_classes3);
+
+	do_prints();
+
+	pr_debug("module-init done\n");
+	return 0;
+}
+
+static void __exit test_dynamic_debug_exit(void)
+{
+	dynamic_debug_unregister_classes(&ddt_classes1);
+	dynamic_debug_unregister_classes(&ddt_classes2);
+	dynamic_debug_unregister_classes(&ddt_classes3);
+
+	pr_debug("module-exit\n");
+}
+
+module_init(test_dynamic_debug_init);
+module_exit(test_dynamic_debug_exit);
+
+MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
+MODULE_LICENSE("GPL");
-- 
2.35.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-05-16 22:57 UTC|newest]

Thread overview: 161+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 22:56 [RFC PATCH v2 00/27] DRM.debug on DYNAMIC_DEBUG, add trace events Jim Cromie
2022-05-16 22:56 ` Jim Cromie
2022-05-16 22:56 ` Jim Cromie
2022-05-16 22:56 ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56 ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 01/27] dyndbg: fix static_branch manipulation Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 02/27] dyndbg: show both old and new in change-info Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 03/27] dyndbg: fix module.dyndbg handling Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 04/27] dyndbg: drop EXPORTed dynamic_debug_exec_queries Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 05/27] dyndbg: add exclusive class_id to pr_debug callsites Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 06/27] dyndbg: add dynamic_debug_(un)register_classes Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 07/27] dyndbg: validate class FOO on module Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 08/27] dyndbg: add drm.debug style bitmap support Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 09/27] Doc/dyndbg: document new class class_name query support Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 10/27] dyndbg: let query-modname override defaulting modname Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 11/27] dyndbg: support symbolic class-names in bitmap Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 12/27] dyndbg: change zero-or-one classes-map to maps list Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 13/27] dyndbg: add __pr_debug_cls(class, fmt, ...) Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` Jim Cromie [this message]
2022-05-16 22:56   ` [PATCH v2 14/27] dyndbg: add test_dynamic_debug module Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 15/27] drm: POC drm on dyndbg - map class-names to drm_debug_category's Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 16/27] drm/print: POC drm on dyndbg - use bitmap Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 17/27] drm_print: condense enum drm_debug_category Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 18/27] drm_print: interpose drm_*dbg with forwarding macros Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56 ` [PATCH v2 19/27] drm_print: wrap drm_*_dbg in dyndbg descriptor factory macro Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56 ` [PATCH v2 20/27] drm_print: refine drm_debug_enabled for jump-label Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 21/27] drm_print: prefer bare printk KERN_DEBUG on generic fn Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 22/27] drm_print: add _ddebug desc to drm_*dbg prototypes Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 23/27] dyndbg: add _DPRINTK_FLAGS_ENABLED Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 24/27] dyndbg: add _DPRINTK_FLAGS_TRACE Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 25/27] dyndbg: add write-events-to-tracefs code Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56 ` [PATCH v2 26/27] dyndbg: 4 new trace-events: pr_debug, dev_dbg, drm_{,dev}debug Jim Cromie
2022-05-16 22:56   ` [PATCH v2 26/27] dyndbg: 4 new trace-events: pr_debug, dev_dbg, drm_{, dev}debug Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-06-29 20:30   ` [PATCH v2 26/27] dyndbg: 4 new trace-events: pr_debug, dev_dbg, drm_{,dev}debug Steven Rostedt
2022-06-29 20:30     ` Steven Rostedt
2022-06-29 20:30     ` Steven Rostedt
2022-06-29 20:30     ` [Intel-gfx] [PATCH v2 26/27] dyndbg: 4 new trace-events: pr_debug, dev_dbg, drm_{, dev}debug Steven Rostedt
2022-06-29 20:30     ` [PATCH v2 26/27] dyndbg: 4 new trace-events: pr_debug, dev_dbg, drm_{,dev}debug Steven Rostedt
2022-05-16 22:56 ` [PATCH v2 27/27] dyndbg/drm: POC add tracebits sysfs-knob Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-16 22:56   ` [Intel-gfx] " Jim Cromie
2022-05-16 22:56   ` Jim Cromie
2022-05-17  0:20 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for DRM.debug on DYNAMIC_DEBUG, add trace events Patchwork
2022-05-17  0:21 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2022-05-17  0:37 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-05-17  4:52 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2022-05-25 15:02 ` [RFC PATCH v2 00/27] " Daniel Vetter
2022-05-25 15:02   ` Daniel Vetter
2022-05-25 15:02   ` Daniel Vetter
2022-05-25 15:02   ` Daniel Vetter
2022-05-25 15:02   ` [Intel-gfx] " Daniel Vetter
2022-06-06 14:59   ` jim.cromie
2022-06-06 14:59     ` [Intel-gfx] " jim.cromie
2022-06-08 15:56     ` Daniel Vetter
2022-06-08 15:56       ` Daniel Vetter
2022-06-08 15:56       ` Daniel Vetter
2022-06-08 15:56       ` [Intel-gfx] " Daniel Vetter
2022-06-08 15:56       ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220516225640.3102269-15-jim.cromie@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=daniel.vetter@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-gvt-dev@lists.freedesktop.org \
    --cc=jbaron@akamai.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=maz@kernel.org \
    --cc=mingo@redhat.com \
    --cc=quic_psodagud@quicinc.com \
    --cc=quic_saipraka@quicinc.com \
    --cc=robdclark@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=seanpaul@chromium.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.