This patchset tests/demonstrates using dynamic_debug_exec_queries() to alter 2 drivers' pr_debugs without a user directly using >control.
For drm.core, I copied drm.debug module parameter model, adding drm.debug2 as a POC user interface to control 2 pr_debug additions to drm_printk:drm_dbg,dev_dbg, allowing both category and >control to work in parallel. This patch makes no attempt to integrate drm's category mechanism with the "format=^class" callsite selection; thats the "theory", but it needs testing.
For i915/gvt, I repeated the pattern. I focussed on gvt only, because it had the most compelling use of format strings as pr_debug classes; ~120 pr_debugs in 9 classes. These are mapped onto bits of the param.
bash-5.0# echo 0x0 > /sys/module/i915/parameters/debug_dyn [ 3137.044185] set_dyndbg: result:0x0 from 0x0 [ 3137.044185] [ 3137.047370] dyndbg: query 0: "format='^gvt: cmd: ' -p" [ 3137.050302] dyndbg: entry, buf:'format='^gvt: cmd: ' -p' [ 3137.053331] dyndbg: start-of-word:0 'format='^gvt: cmd: ' -p'
These patches were the test/use case for-59 fixes: https://lore.kernel.org/lkml/20200825173339.2082585-1-jim.cromie@gmail.com/
Jim Cromie (4): drm-printk: POC caller of dynamic-debug-exec-queries drm-printk: call pr_debug() from drm_dev_dbg, __drm_dbg i915: add -DDYNAMIC_DEBUG_MODULE to i915/gvt/Makefile i915: POC use dynamic_debug_exec_queries to control pr_debugs in gvt
drivers/gpu/drm/drm_print.c | 54 ++++++++++++++++++--- drivers/gpu/drm/i915/gvt/Makefile | 5 +- drivers/gpu/drm/i915/i915_params.c | 76 ++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 8 deletions(-)
Hi Jim,
I love your patch! Yet something to improve:
[auto build test ERROR on drm-intel/for-linux-next] [also build test ERROR on linux/master tegra-drm/drm/tegra/for-next drm-tip/drm-tip linus/master v5.9-rc2 next-20200826] [cannot apply to drm/drm-next] [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-POC-use-dynamic_d... base: git://anongit.freedesktop.org/drm-intel for-linux-next config: x86_64-allyesconfig (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot lkp@intel.com
All errors (new ones prefixed by >>):
drivers/gpu/drm/i915/i915_params.c: In function 'param_set_dyndbg':
drivers/gpu/drm/i915/i915_params.c:307:11: error: implicit declaration of function 'dynamic_debug_exec_queries' [-Werror=implicit-function-declaration]
307 | chgct = dynamic_debug_exec_queries(query, "i915"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors
# https://github.com/0day-ci/linux/commit/1b9bcd2cceed427d96bc9bf4eae6619201d6... git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Jim-Cromie/dyndbg-POC-use-dynamic_debug_exec_queries-in-DRM/20200827-010409 git checkout 1b9bcd2cceed427d96bc9bf4eae6619201d645d6 vim +/dynamic_debug_exec_queries +307 drivers/gpu/drm/i915/i915_params.c
283 284 static int param_set_dyndbg(const char *instr, const struct kernel_param *kp) 285 { 286 static unsigned long int old_val; 287 unsigned int val; 288 unsigned long int changes, result; 289 int rc, chgct = 0, totct = 0, bitpos; 290 char query[OUR_QUERY_SIZE]; 291 292 rc = kstrtouint(instr, 0, &val); 293 if (rc) { 294 pr_err("set_dyndbg: failed\n"); 295 return -EINVAL; 296 } 297 result = val; 298 pr_info("set_dyndbg: result:0x%lx from %s\n", result, instr); 299 300 changes = result ^ old_val; 301 302 for_each_set_bit(bitpos, &changes, NUM_CLASSES) { 303 304 sprintf(query, "format='^%s' %cp", pr_debug_classes[bitpos], 305 test_bit(bitpos, &result) ? '+' : '-'); 306
307 chgct = dynamic_debug_exec_queries(query, "i915");
308 totct += chgct; 309 pr_info("change ct:%d on format='%s'\n", chgct, 310 pr_debug_classes[bitpos]); 311 } 312 old_val = result; 313 pr_info("change ct:%d\n", totct); 314 return 0; 315 } 316 static int param_get_dyndbg(char *buffer, const struct kernel_param *kp) 317 { 318 return scnprintf(buffer, PAGE_SIZE, "%u\n", 319 *((unsigned int *)kp->arg)); 320 } 321 static const struct kernel_param_ops param_ops_dyndbg = { 322 .set = param_set_dyndbg, 323 .get = param_get_dyndbg, 324 }; 325
--- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Export of dynamic-debug-exec-queries exists for users like drm.
This commit is a 1st user-test; it adds a 2nd knob, __drm_debug2, similar in function to __drm_debug. module_param_cb wires it to a callback which maps the input value to one of: "module=drm* +/-p".
The include is needed to see the exported function prototype.
Notes:
The define DEBUG at top of drm-printk enables all pr_debug()s, independent of CONFIG_DYNAMIC_DEBUG_CORE.
drm-printk is an independent print control system using __drm_debug bits. The plan is to find the low-level macros in which to insert a pr_debug call, their eventual callsites will have distinct METADATA, so will be itemized in control, and individually selectable.
Signed-off-by: Jim Cromie jim.cromie@gmail.com --- drivers/gpu/drm/drm_print.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c index 111b932cf2a9..52abaf2ae053 100644 --- a/drivers/gpu/drm/drm_print.c +++ b/drivers/gpu/drm/drm_print.c @@ -27,6 +27,7 @@
#include <stdarg.h>
+#include <linux/dynamic_debug.h> #include <linux/io.h> #include <linux/moduleparam.h> #include <linux/seq_file.h> @@ -54,6 +55,40 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat "\t\tBit 8 (0x100) will enable DP messages (displayport code)"); module_param_named(debug, __drm_debug, int, 0600);
+/* POC for callback -> ddebug_exec_queries */ +unsigned int __drm_debug2; +EXPORT_SYMBOL(__drm_debug2); + +static int param_set_dyndbg(const char *val, const struct kernel_param *kp) +{ + int chgct, result; + + result = kstrtouint(val, 0, (unsigned int *)kp->arg); + pr_warn("set_dyndbg: result:%d from %s\n", result, val); + + if (result) + chgct = dynamic_debug_exec_queries("module=drm* +p", NULL); + else + chgct = dynamic_debug_exec_queries("module=drm* -p", NULL); + + pr_warn("change ct:%d\n", chgct); + return 0; +} +static int param_get_dyndbg(char *buffer, const struct kernel_param *kp) +{ + return scnprintf(buffer, PAGE_SIZE, "%u\n", + *((unsigned int *)kp->arg)); +} +static const struct kernel_param_ops param_ops_dyndbg = { + .set = param_set_dyndbg, + .get = param_get_dyndbg, +}; + +MODULE_PARM_DESC(debug_dyn, "Enable debug output, where each bit enables a debug category.\n" + "\t\tthese wont work yet\n"); +module_param_cb(debug_dyn, ¶m_ops_dyndbg, &__drm_debug2, 0644); + + void __drm_puts_coredump(struct drm_printer *p, const char *str) { struct drm_print_iterator *iterator = p->arg;
Hi Jim,
I love your patch! Yet something to improve:
[auto build test ERROR on drm-intel/for-linux-next] [also build test ERROR on linux/master tegra-drm/drm/tegra/for-next drm-tip/drm-tip linus/master v5.9-rc2 next-20200826] [cannot apply to drm/drm-next] [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-POC-use-dynamic_d... base: git://anongit.freedesktop.org/drm-intel for-linux-next config: microblaze-randconfig-r006-20200826 (attached as .config) compiler: microblaze-linux-gcc (GCC) 9.3.0 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 # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=microblaze
If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot lkp@intel.com
All errors (new ones prefixed by >>):
In file included from drivers/gpu/drm/drm_print.c:30: include/linux/dynamic_debug.h: In function 'ddebug_dyndbg_module_param_cb':
include/linux/dynamic_debug.h:196:3: error: implicit declaration of function 'printk'; did you mean 'bprintf'? [-Werror=implicit-function-declaration]
196 | printk(KERN_WARNING "dyndbg param is supported only in " | ^~~~~~ | bprintf
include/linux/dynamic_debug.h:196:10: error: 'KERN_WARNING' undeclared (first use in this function)
196 | printk(KERN_WARNING "dyndbg param is supported only in " | ^~~~~~~~~~~~ include/linux/dynamic_debug.h:196:10: note: each undeclared identifier is reported only once for each function it appears in
include/linux/dynamic_debug.h:196:22: error: expected ')' before string constant
196 | printk(KERN_WARNING "dyndbg param is supported only in " | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ) In file included from include/linux/kernel.h:15, from include/asm-generic/bug.h:19, from ./arch/microblaze/include/generated/asm/bug.h:1, from include/linux/bug.h:5, from include/linux/io.h:11, from drivers/gpu/drm/drm_print.c:31: include/linux/printk.h: At top level:
include/linux/printk.h:171:5: error: conflicting types for 'printk'
171 | int printk(const char *fmt, ...); | ^~~~~~ include/linux/printk.h:171:1: note: a parameter list with an ellipsis can't match an empty parameter name list declaration 171 | int printk(const char *fmt, ...); | ^~~ In file included from drivers/gpu/drm/drm_print.c:30: include/linux/dynamic_debug.h:196:3: note: previous implicit declaration of 'printk' was here 196 | printk(KERN_WARNING "dyndbg param is supported only in " | ^~~~~~ drivers/gpu/drm/drm_print.c: In function 'param_set_dyndbg':
drivers/gpu/drm/drm_print.c:70:11: error: implicit declaration of function 'dynamic_debug_exec_queries' [-Werror=implicit-function-declaration]
70 | chgct = dynamic_debug_exec_queries("module=drm* +p", NULL); | ^~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors
# https://github.com/0day-ci/linux/commit/ad959a93dccb8fe5deb5a7da3e2204977957... git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Jim-Cromie/dyndbg-POC-use-dynamic_debug_exec_queries-in-DRM/20200827-010409 git checkout ad959a93dccb8fe5deb5a7da3e22049779571b9b vim +196 include/linux/dynamic_debug.h
e9d376f0fa66bd6 Jason Baron 2009-02-05 190 b48420c1d3019ce Jim Cromie 2012-04-27 191 static inline int ddebug_dyndbg_module_param_cb(char *param, char *val, b48420c1d3019ce Jim Cromie 2012-04-27 192 const char *modname) b48420c1d3019ce Jim Cromie 2012-04-27 193 { b48420c1d3019ce Jim Cromie 2012-04-27 194 if (strstr(param, "dyndbg")) { 516cf1be07cf3ab Jim Cromie 2012-05-01 195 /* avoid pr_warn(), which wants pr_fmt() fully defined */ 516cf1be07cf3ab Jim Cromie 2012-05-01 @196 printk(KERN_WARNING "dyndbg param is supported only in " b48420c1d3019ce Jim Cromie 2012-04-27 197 "CONFIG_DYNAMIC_DEBUG builds\n"); b48420c1d3019ce Jim Cromie 2012-04-27 198 return 0; /* allow and ignore */ b48420c1d3019ce Jim Cromie 2012-04-27 199 } b48420c1d3019ce Jim Cromie 2012-04-27 200 return -EINVAL; b48420c1d3019ce Jim Cromie 2012-04-27 201 } b48420c1d3019ce Jim Cromie 2012-04-27 202
--- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Hi Jim,
I love your patch! Yet something to improve:
[auto build test ERROR on drm-intel/for-linux-next] [also build test ERROR on linux/master drm-tip/drm-tip linus/master v5.9-rc2 next-20200826] [cannot apply to drm/drm-next] [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-POC-use-dynamic_d... base: git://anongit.freedesktop.org/drm-intel for-linux-next config: arm64-randconfig-r002-20200826 (attached as .config) compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 7cfcecece0e0430937cf529ce74d3a071a4dedc6) 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 # install arm64 cross compiling tool for clang build # apt-get install binutils-aarch64-linux-gnu # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm64
If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot lkp@intel.com
All errors (new ones prefixed by >>):
In file included from drivers/gpu/drm/drm_print.c:30:
include/linux/dynamic_debug.h:196:3: error: implicit declaration of function 'printk' [-Werror,-Wimplicit-function-declaration]
printk(KERN_WARNING "dyndbg param is supported only in " ^
include/linux/dynamic_debug.h:196:10: error: use of undeclared identifier 'KERN_WARNING'
printk(KERN_WARNING "dyndbg param is supported only in " ^ In file included from drivers/gpu/drm/drm_print.c:31: In file included from include/linux/io.h:11: In file included from include/linux/bug.h:5: In file included from arch/arm64/include/asm/bug.h:26: In file included from include/asm-generic/bug.h:19: In file included from include/linux/kernel.h:15: include/linux/printk.h:171:5: error: conflicting types for 'printk' int printk(const char *fmt, ...); ^ include/linux/dynamic_debug.h:196:3: note: previous implicit declaration is here printk(KERN_WARNING "dyndbg param is supported only in " ^
drivers/gpu/drm/drm_print.c:70:11: error: implicit declaration of function 'dynamic_debug_exec_queries' [-Werror,-Wimplicit-function-declaration]
chgct = dynamic_debug_exec_queries("module=drm* +p", NULL); ^ 4 errors generated.
# https://github.com/0day-ci/linux/commit/ad959a93dccb8fe5deb5a7da3e2204977957... git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Jim-Cromie/dyndbg-POC-use-dynamic_debug_exec_queries-in-DRM/20200827-010409 git checkout ad959a93dccb8fe5deb5a7da3e22049779571b9b vim +/printk +196 include/linux/dynamic_debug.h
e9d376f0fa66bd6 Jason Baron 2009-02-05 190 b48420c1d3019ce Jim Cromie 2012-04-27 191 static inline int ddebug_dyndbg_module_param_cb(char *param, char *val, b48420c1d3019ce Jim Cromie 2012-04-27 192 const char *modname) b48420c1d3019ce Jim Cromie 2012-04-27 193 { b48420c1d3019ce Jim Cromie 2012-04-27 194 if (strstr(param, "dyndbg")) { 516cf1be07cf3ab Jim Cromie 2012-05-01 195 /* avoid pr_warn(), which wants pr_fmt() fully defined */ 516cf1be07cf3ab Jim Cromie 2012-05-01 @196 printk(KERN_WARNING "dyndbg param is supported only in " b48420c1d3019ce Jim Cromie 2012-04-27 197 "CONFIG_DYNAMIC_DEBUG builds\n"); b48420c1d3019ce Jim Cromie 2012-04-27 198 return 0; /* allow and ignore */ b48420c1d3019ce Jim Cromie 2012-04-27 199 } b48420c1d3019ce Jim Cromie 2012-04-27 200 return -EINVAL; b48420c1d3019ce Jim Cromie 2012-04-27 201 } b48420c1d3019ce Jim Cromie 2012-04-27 202
--- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Put the pr_debug() after the vaf setup work, so as to use it. And move the if-category-disabled-return after both, so the pr_debug() runs unconditionally.
This lets both debug-printers execute independently, according to their respective controls, allowing later comparison to each other.
#> echo module=drm +pmftl > /proc/dynamic_debug/control yields logging like:
[1772] drm:drm_dev_dbg:305: i915 0000:00:02.0: [drm:intel_atomic_get_global_obj_state [i915]] Cat:16 Added new global object 000000006fa51dd6 state 00000000bbddcf9d to 000000005f6e1bc3 [1772] drm:drm_dev_dbg:305: i915 0000:00:02.0: [drm:intel_atomic_get_global_obj_state [i915]] Cat:16 Added new global object 000000002a5e020a state 000000002b3685ed to 000000005f6e1bc3 [198] drm:drm_dev_dbg:305: i915 0000:00:02.0: [drm:drm_update_vblank_count [drm]] Cat:32 updating vblank count on crtc 0: current=260920, diff=0, hw=192024 hw_last=192024 [1772] drm:__drm_dbg:331: [drm:drm_atomic_nonblocking_commit [drm]] Cat:16 committing 000000005f6e1bc3 nonblocking [1772] drm:__drm_dbg:331: [drm:drm_mode_object_put.part.0 [drm]] Cat:1 OBJ ID: 113 (4) [1772] drm:__drm_dbg:331: [drm:drm_ioctl [drm]] Cat:1 comm="gnome-shell" pid=1772, dev=0xe200, auth=1, I915_GEM_CREATE [1772] drm:__drm_dbg:331: [drm:drm_ioctl [drm]] Cat:1 comm="gnome-shell" pid=1772, dev=0xe200, auth=1, I915_GEM_SET_DOMAIN [1772] drm:__drm_dbg:331: [drm:drm_ioctl [drm]] Cat:1 comm="gnome-shell" pid=1772, dev=0xe200, auth=1, I915_GEM_SET_TILING [1772] drm:__drm_dbg:331: [drm:drm_ioctl [drm]] Cat:1 comm="gnome-shell" pid=1772, dev=0xe200, auth=1, I915_GEM_MMAP_OFFSET
Clearly, the mflt flags arent very helpful here, and callsite control is all or nothing (since theres only 2 callsites handling all the categories). We are 1 below the function layer of interest, but theres room for optimism.
Signed-off-by: Jim Cromie jim.cromie@gmail.com --- drivers/gpu/drm/drm_print.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c index 52abaf2ae053..fa2bcf4ec475 100644 --- a/drivers/gpu/drm/drm_print.c +++ b/drivers/gpu/drm/drm_print.c @@ -27,6 +27,7 @@
#include <stdarg.h>
+#define DYNAMIC_DEBUG_MODULE #include <linux/dynamic_debug.h> #include <linux/io.h> #include <linux/moduleparam.h> @@ -61,17 +62,17 @@ EXPORT_SYMBOL(__drm_debug2);
static int param_set_dyndbg(const char *val, const struct kernel_param *kp) { - int chgct, result; + int chgct, rc, result;
- result = kstrtouint(val, 0, (unsigned int *)kp->arg); - pr_warn("set_dyndbg: result:%d from %s\n", result, val); + rc = kstrtouint(val, 0, &result); + pr_debug("set_dyndbg: rc:%d got:%d from %s\n", rc, result, val);
if (result) chgct = dynamic_debug_exec_queries("module=drm* +p", NULL); else chgct = dynamic_debug_exec_queries("module=drm* -p", NULL);
- pr_warn("change ct:%d\n", chgct); + pr_debug("change ct:%d\n", chgct); return 0; } static int param_get_dyndbg(char *buffer, const struct kernel_param *kp) @@ -297,13 +298,16 @@ void drm_dev_dbg(const struct device *dev, enum drm_debug_category category, struct va_format vaf; va_list args;
- if (!drm_debug_enabled(category)) - return; - va_start(args, format); vaf.fmt = format; vaf.va = &args;
+ dev_dbg(dev, "[" DRM_NAME ":%ps] Cat:%d %pV", + __builtin_return_address(0), category, &vaf); + + if (!drm_debug_enabled(category)) + return; + if (dev) dev_printk(KERN_DEBUG, dev, "[" DRM_NAME ":%ps] %pV", __builtin_return_address(0), &vaf); @@ -320,13 +324,16 @@ void __drm_dbg(enum drm_debug_category category, const char *format, ...) struct va_format vaf; va_list args;
- if (!drm_debug_enabled(category)) - return; - va_start(args, format); vaf.fmt = format; vaf.va = &args;
+ pr_debug("[" DRM_NAME ":%ps] Cat:%d %pV", + __builtin_return_address(0), category, &vaf); + + if (!drm_debug_enabled(category)) + return; + printk(KERN_DEBUG "[" DRM_NAME ":%ps] %pV", __builtin_return_address(0), &vaf);
This addition to cflags enables dyndbg in the gvt component of the i915 module, on a CONFIG_DYNAMIC_DEBUG_CORE build.
So here are the message classifications that the gvt driver uses.
cut -d= -f2 | cut -d\ -f2,3 | \ perl -ne 'chomp $_ && $h{$_}++; END{print "$_" \tseen $h{$_}\n" for sort keys %h}'
"gvt: cmd:" seen 11 "gvt: core:" seen 48 "gvt: dpy:" seen 4 "gvt: el:" seen 21 "gvt: irq:" seen 1 "gvt: mm:" seen 6 "gvt: mmio:" seen 9 "gvt: render:" seen 1 "gvt: sched:" seen 15
Signed-off-by: Jim Cromie jim.cromie@gmail.com --- drivers/gpu/drm/i915/gvt/Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/i915/gvt/Makefile b/drivers/gpu/drm/i915/gvt/Makefile index ea8324abc784..2c581e910688 100644 --- a/drivers/gpu/drm/i915/gvt/Makefile +++ b/drivers/gpu/drm/i915/gvt/Makefile @@ -5,5 +5,6 @@ GVT_SOURCE := gvt.o aperture_gm.o handlers.o vgpu.o trace_points.o firmware.o \ execlist.o scheduler.o sched_policy.o mmio_context.o cmd_parser.o debugfs.o \ fb_decoder.o dmabuf.o page_track.o
-ccflags-y += -I $(srctree)/$(src) -I $(srctree)/$(src)/$(GVT_DIR)/ -i915-y += $(addprefix $(GVT_DIR)/, $(GVT_SOURCE)) +ccflags-y += -I $(srctree)/$(src) -I $(srctree)/$(src)/$(GVT_DIR)/ +ccflags-y += -DDYNAMIC_DEBUG_MODULE +i915-y += $(addprefix $(GVT_DIR)/, $(GVT_SOURCE))
The gvt component of this driver has ~120 pr_debugs, in 9 "classes". Add a "knob", like drm.debug, to map bits to these classes.
bash-5.0# echo 0x01 > /sys/module/i915/parameters/debug_dyn set_dyndbg: result:0x1 from 0x01 dyndbg: query 0: "format='^gvt: cmd: ' +p" dyndbg: entry, buf:'format='^gvt: cmd: ' +p' dyndbg: start-of-word:0 'format='^gvt: cmd: ' +p' dyndbg: start-of-word:1 ''^gvt: cmd: ' +p' dyndbg: start-of-word:2 '+p' dyndbg: split into words: "format" "^gvt: cmd: " "+p" dyndbg: op='+' dyndbg: flags=0x1 dyndbg: *flagsp=0x1 *maskp=0xffffffff dyndbg: key:'format' arg:'^gvt: cmd: ' dyndbg: parsed: func="" file="" module="i915" format="^gvt: cmd: " lineno=0-0 dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:3081 [i915]init_cmd_table =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:1376 [i915]gen8_check_mi_display_flip =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:1373 [i915]gen8_check_mi_display_flip =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:745 [i915]parser_exec_state_dump =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:744 [i915]parser_exec_state_dump =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:742 [i915]parser_exec_state_dump =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:733 [i915]parser_exec_state_dump =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:729 [i915]parser_exec_state_dump =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:722 [i915]parser_exec_state_dump =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:716 [i915]parser_exec_state_dump =p dyndbg: changed drivers/gpu/drm/i915/gvt/cmd_parser.c:691 [i915]print_opcode =p dyndbg: applied: func="" file="" module="i915" format="^gvt: cmd: " lineno=0-0 dyndbg: processed 1 queries, with 11 matches, 0 errs change ct:11 on format='gvt: cmd: ' change ct:11
Signed-off-by: Jim Cromie jim.cromie@gmail.com --- drivers/gpu/drm/i915/i915_params.c | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c index 8d8db9ff0a48..4e1f01ab4865 100644 --- a/drivers/gpu/drm/i915/i915_params.c +++ b/drivers/gpu/drm/i915/i915_params.c @@ -255,3 +255,79 @@ void i915_params_free(struct i915_params *params) I915_PARAMS_FOR_EACH(FREE); #undef FREE } + +/* POC for callback -> dynamic_debug_exec_queries */ +unsigned long __new_knob; +EXPORT_SYMBOL(__new_knob); + +static char *pr_debug_classes[] = { + "gvt: cmd: ", + "gvt: core: ", + "gvt: dpy: ", + "gvt: el: ", + "gvt: irq: ", + "gvt: mm: ", + "gvt: mmio: ", + "gvt: render: ", + "gvt: sched: " +}; +#define NUM_CLASSES ARRAY_SIZE(pr_debug_classes) +#define OUR_QUERY_SIZE 128 /* we need about 20 */ + +#include <linux/module.h> + +static int param_set_dyndbg(const char *instr, const struct kernel_param *kp) +{ + static unsigned long int old_val; + unsigned int val; + unsigned long int changes, result; + int rc, chgct = 0, totct = 0, bitpos; + char query[OUR_QUERY_SIZE]; + + rc = kstrtouint(instr, 0, &val); + if (rc) { + pr_err("set_dyndbg: failed\n"); + return -EINVAL; + } + result = val; + pr_info("set_dyndbg: result:0x%lx from %s\n", result, instr); + + changes = result ^ old_val; + + for_each_set_bit(bitpos, &changes, NUM_CLASSES) { + + sprintf(query, "format='^%s' %cp", pr_debug_classes[bitpos], + test_bit(bitpos, &result) ? '+' : '-'); + + chgct = dynamic_debug_exec_queries(query, "i915"); + totct += chgct; + pr_info("change ct:%d on format='%s'\n", chgct, + pr_debug_classes[bitpos]); + } + old_val = result; + pr_info("change ct:%d\n", totct); + return 0; +} +static int param_get_dyndbg(char *buffer, const struct kernel_param *kp) +{ + return scnprintf(buffer, PAGE_SIZE, "%u\n", + *((unsigned int *)kp->arg)); +} +static const struct kernel_param_ops param_ops_dyndbg = { + .set = param_set_dyndbg, + .get = param_get_dyndbg, +}; + +MODULE_PARM_DESC(debug_dyn, " enable dynamic-debug by format-string classifications.\n" + "\t\twhich are:" + "\n\t\t gvt: cmd:" + "\n\t\t gvt: core:" + "\n\t\t gvt: dpy:" + "\n\t\t gvt: el:" + "\n\t\t gvt: irq:" + "\n\t\t gvt: mm:" + "\n\t\t gvt: mmio:" + "\n\t\t gvt: render:" + "\n\t\t gvt: sched:" "\n"); + +module_param_cb(debug_dyn, ¶m_ops_dyndbg, &__new_knob, 0644);
dri-devel@lists.freedesktop.org