Skip to contentSkip to conversation

dyndbg: add special aux_print framework

PATCH New Jim Cromie 3 participants 4 messages Aug 1, 2021

Subsystems (2)
lore
Share & tools
lore

Jim Cromie

author maintainer
#0 lore raw

PATCH 1/1 dyndbg: add special aux_print framework

Sean Paul [email protected] proposed, in
https://patchwork.freedesktop.org/series/78133/
drm/trace: Mirror DRM debug logs to tracefs

The problem with the approach is that its built upon splitting drm_debug_enabled() into syslog & trace flavors, which clashes rather profoundly with the strategy of obsoleting it using dyndbg.

Instead, this puts the print-to-trace decision after the is-it-enabled test (which is a noop), so it has near zero additional cost.

This is preliminary, Proof-of-Concept, and about 2 hrs old. But its surprisingly simple:

- add a new struct _ddebug member: (*aux_print)(char *format, ...)
- add a new S/special flag to check !!aux_print
- if S, invoke the function to handle the prepared vaf

It intrinsically allows any number of alternate printf-ish consumers, but only 1 active per callsite. I have another patchset that eliminates some of the data redundancies like this, it can be extended.

It may also prove to be a generic way to implement the netdev & ibdev variants of __dynamic_pr_debug.

It just needs a mechanism to set the per-callsite pointer to a printf-ish function to consume the pr_debug output, a tighter/better function prototype, and a wrapper on drm_trace_printf to bundle up the args and comport with the prototype, which can evolve to suit this 1st client.

it is on top of:
https://patchwork.freedesktop.org/series/92544/
(v4 on lkml, v2 in patchwork)

---
 include/linux/dynamic_debug.h |  7 ++++++-
 lib/dynamic_debug.c           | 22 +++++++++++++++++++---
 2 files changed, 25 insertions(+), 4 deletions(-)
include/linux/dynamic_debug.h +6 -1
index 677ad176b167..0d068e8ed7aa 100644
@@ -22,6 +22,7 @@ struct _ddebug {
 	const char *function;
 	const char *filename;
 	const char *format;
+	int (*aux_print)(char *, void *, void *);
 	unsigned int lineno:18;
 	/*
 	 * The flags field controls the behaviour at the callsite.
@@ -29,7 +30,11 @@ struct _ddebug {
 	 * writes commands to <debugfs>/dynamic_debug/control
 	 */
 #define _DPRINTK_FLAGS_NONE	0
-#define _DPRINTK_FLAGS_PRINT	(1<<0) /* printk() a message using the format */
+#define _DPRINTK_FLAGS_PRINT		(1<<0) /* printk() a message */
+#define _DPRINTK_FLAGS_PRINT_AUX	(1<<5) /* call (*aux_print) */
+
+#define _DPRINTK_ENABLED (_DPRINTK_FLAGS_PRINT | _DPRINTK_FLAGS_PRINT_AUX)
+
 #define _DPRINTK_FLAGS_INCL_MODNAME	(1<<1)
 #define _DPRINTK_FLAGS_INCL_FUNCNAME	(1<<2)
 #define _DPRINTK_FLAGS_INCL_LINENO	(1<<3)
lib/dynamic_debug.c +19 -3
index 045e1cf92c44..7bbdedabe6f1 100644
@@ -85,6 +85,7 @@ static inline const char *trim_prefix(const char *path)
 
 static struct { unsigned flag:8; char opt_char; } opt_array[] = {
 	{ _DPRINTK_FLAGS_PRINT, 'p' },
+	{ _DPRINTK_FLAGS_PRINT_AUX, 'S' },
 	{ _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
 	{ _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
 	{ _DPRINTK_FLAGS_INCL_LINENO, 'l' },
@@ -206,10 +207,10 @@ static int ddebug_change(const struct ddebug_query *query,
 			if (newflags == dp->flags)
 				continue;
 #ifdef CONFIG_JUMP_LABEL
-			if (dp->flags & _DPRINTK_FLAGS_PRINT) {
-				if (!(modifiers->flags & _DPRINTK_FLAGS_PRINT))
+			if (dp->flags & _DPRINTK_ENABLED) {
+				if (!(modifiers->flags & _DPRINTK_ENABLED))
 					static_branch_disable(&dp->key.dd_key_true);
-			} else if (modifiers->flags & _DPRINTK_FLAGS_PRINT)
+			} else if (modifiers->flags & _DPRINTK_ENABLED)
 				static_branch_enable(&dp->key.dd_key_true);
 #endif
 			dp->flags = newflags;
@@ -639,6 +640,21 @@ void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
 
 	printk(KERN_DEBUG "%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf);
 
+	if (descriptor->flags & _DPRINTK_FLAGS_PRINT_AUX) {
+		/* our model:
+		drm_trace_printf("%s%s[" DRM_NAME ":%ps] %pV",
+				 dev ? dev_name(dev) : "", dev ? " " : "",
+				 __builtin_return_address(0), &vaf);
+		*/
+		pr_info("reached check aux\n");
+
+		if (descriptor->aux_channel) {
+			pr_info("calling aux\n");
+			(*descriptor->aux_channel)
+				("%s[DRM_mumble :%ps] %pV", buf,
+				 __builtin_return_address(0), &vaf);
+		}
+	}
 	va_end(args);
 }
 EXPORT_SYMBOL(__dynamic_pr_debug);
Signature · 1 line
2.31.1
#1 lore raw

[Intel-gfx] ✗ Fi.CI.BUILD: failure for dyndbg: add special aux_print framework (rev2)

== Series Details ==

== Series Details ==

Series: dyndbg: add special aux_print framework (rev2)
URL : https://patchwork.freedesktop.org/series/93269/
State : failure

== Summary ==

CALL scripts/checksyscalls.sh
CALL scripts/atomic/check-atomics.sh
DESCEND objtool

  CHK     include/generated/compile.h
  AR      lib/lib.a
  GEN     lib/crc32table.h
  CC      lib/crc32.o
  CC      lib/dynamic_debug.o
lib/dynamic_debug.c: In function ‘__dynamic_pr_debug’:
lib/dynamic_debug.c:651:17: error: ‘struct _ddebug’ has no member named ‘aux_channel’
   if (descriptor->aux_channel) {
                 ^~
lib/dynamic_debug.c:653:16: error: ‘struct _ddebug’ has no member named ‘aux_channel’
    (*descriptor->aux_channel)
                ^~

scripts/Makefile.build:271: recipe for target 'lib/dynamic_debug.o' failed make[1]: *** [lib/dynamic_debug.o] Error 1
Makefile:1842: recipe for target 'lib' failed
make: *** [lib] Error 2

#2 lore raw
In reply to Jim Cromie
I love your patch! Yet something to improve:

Hi Jim,

I love your patch! Yet something to improve:

[auto build test ERROR on tegra-drm/drm/tegra/for-next]
[also build test ERROR on linux/master linus/master v5.14-rc3 next-20210730] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jim-Cromie/dyndbg-add-special-aux_print-framework/20210801-113749
base:   git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next
config: i386-randconfig-r024-20210801 (attached as .config)
compiler: gcc-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/1bf22862d95adc83487ade34fe1c42707f94ac4d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jim-Cromie/dyndbg-add-special-aux_print-framework/20210801-113749 git checkout 1bf22862d95adc83487ade34fe1c42707f94ac4d
# save the attached .config to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

lib/dynamic_debug.c: In function '__dynamic_pr_debug':

>> lib/dynamic_debug.c:651:17: error: 'struct _ddebug' has no member named 'aux_channel'
     651 |   if (descriptor->aux_channel) {
         |                 ^~
   lib/dynamic_debug.c:653:16: error: 'struct _ddebug' has no member named 'aux_channel'
     653 |    (*descriptor->aux_channel)
         |                ^~

vim +651 lib/dynamic_debug.c

626
627 void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
628 {
629 va_list args;
630 struct va_format vaf;
631 char buf[PREFIX_SIZE] = "";
632
633 BUG_ON(!descriptor);
634 BUG_ON(!fmt);
635
636 va_start(args, fmt);
637
638 vaf.fmt = fmt;
639 vaf.va = &args;
640
641 printk(KERN_DEBUG "%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf);
642
643 if (descriptor->flags & _DPRINTK_FLAGS_PRINT_AUX) {
644 /* our model:
645 drm_trace_printf("%s%s[" DRM_NAME ":%ps] %pV",
646 dev ? dev_name(dev) : "", dev ? " " : "",
647 __builtin_return_address(0), &vaf);
648 */
649 pr_info("reached check aux\n");
650

 > 651			if (descriptor->aux_channel) {

652 pr_info("calling aux\n");
653 (*descriptor->aux_channel)
654 ("%s[DRM_mumble :%ps] %pV", buf,
655 __builtin_return_address(0), &vaf);
656 }
657 }
658 va_end(args);
659 }
660 EXPORT_SYMBOL(__dynamic_pr_debug);
661

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw
In reply to Jim Cromie
I love your patch! Yet something to improve:

Hi Jim,

I love your patch! Yet something to improve:

[auto build test ERROR on tegra-drm/drm/tegra/for-next]
[also build test ERROR on linux/master linus/master v5.14-rc3 next-20210730] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Jim-Cromie/dyndbg-add-special-aux_print-framework/20210801-113749
base:   git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next
config: x86_64-randconfig-a012-20210801 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 4f71f59bf3d9914188a11d0c41bedbb339d36ff5)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/1bf22862d95adc83487ade34fe1c42707f94ac4d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jim-Cromie/dyndbg-add-special-aux_print-framework/20210801-113749 git checkout 1bf22862d95adc83487ade34fe1c42707f94ac4d
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

>> lib/dynamic_debug.c:651:19: error: no member named 'aux_channel' in 'struct _ddebug'
                   if (descriptor->aux_channel) {
                       ~~~~~~~~~~  ^
   lib/dynamic_debug.c:653:18: error: no member named 'aux_channel' in 'struct _ddebug'
                           (*descriptor->aux_channel)
                             ~~~~~~~~~~  ^

2 errors generated.

vim +651 lib/dynamic_debug.c

626
627 void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
628 {
629 va_list args;
630 struct va_format vaf;
631 char buf[PREFIX_SIZE] = "";
632
633 BUG_ON(!descriptor);
634 BUG_ON(!fmt);
635
636 va_start(args, fmt);
637
638 vaf.fmt = fmt;
639 vaf.va = &args;
640
641 printk(KERN_DEBUG "%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf);
642
643 if (descriptor->flags & _DPRINTK_FLAGS_PRINT_AUX) {
644 /* our model:
645 drm_trace_printf("%s%s[" DRM_NAME ":%ps] %pV",
646 dev ? dev_name(dev) : "", dev ? " " : "",
647 __builtin_return_address(0), &vaf);
648 */
649 pr_info("reached check aux\n");
650

 > 651			if (descriptor->aux_channel) {

652 pr_info("calling aux\n");
653 (*descriptor->aux_channel)
654 ("%s[DRM_mumble :%ps] %pV", buf,
655 __builtin_return_address(0), &vaf);
656 }
657 }
658 va_end(args);
659 }
660 EXPORT_SYMBOL(__dynamic_pr_debug);
661

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org