2021-08-01 03:41:14

by Jim Cromie

[permalink] [raw]
Subject: [PATCH] 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)

Signed-off-by: Jim Cromie <[email protected]>
---
include/linux/dynamic_debug.h | 7 ++++++-
lib/dynamic_debug.c | 22 +++++++++++++++++++---
2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 677ad176b167..0d068e8ed7aa 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -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)
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 045e1cf92c44..7bbdedabe6f1 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -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);
--
2.31.1



2021-08-01 05:56:18

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] dyndbg: add special aux_print framework

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
Reported-by: kernel test robot <[email protected]>

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/[email protected]


Attachments:
(No filename) (2.90 kB)
.config.gz (31.68 kB)
Download all attachments

2021-08-01 06:03:40

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] dyndbg: add special aux_print framework

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
Reported-by: kernel test robot <[email protected]>

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/[email protected]


Attachments:
(No filename) (3.15 kB)
.config.gz (36.66 kB)
Download all attachments