mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/3] drm/print,dyndbg: __drm_debug __read_mostly, restore it to uint, printer fix
@ 2026-11-24 23:38 Jim Cromie via B4 Relay
  2026-11-24 23:38 ` [PATCH v4 1/3] drm/print: Mark __drm_debug as __read_mostly Jim Cromie via B4 Relay
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jim Cromie via B4 Relay @ 2026-11-24 23:38 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Jason Baron, Greg Kroah-Hartman,
	Andrew Morton, Luca Coelho, Jani Nikula
  Cc: dri-devel, linux-kernel, Jim Cromie

This series improves __drm_debug placement/sizing and fixes a
drm_dbg_printer() bypass exposed when CONFIG_DRM_USE_DYNAMIC_DEBUG=y:

1. Mark __drm_debug as __read_mostly to move it out of the cacheline
   it currently shares with frequently written locks and structures. In
   a 12-vkcube test, its read rate is ~83 kHz.

2. Shrink __drm_debug and struct ddebug_class_param.bits from unsigned
   long back to (original) unsigned int, updating lib/dynamic_debug.c
   and lib/test_dynamic_debug.c callers accordingly.

3. Fix __drm_printfn_dbg() use of __drm_debug_enabled(), which always
   prints when CONFIG_DRM_USE_DYNAMIC_DEBUG=y, disregarding p->category.

NOTES:

drm and dyndbg are coupled on __drm_debug's size and type, so changing
the size requires coordination between DRM and dyndbg. The coupling
allows dyndbg to keep state in __drm_debug while letting drm use it in
cases where static-key drm_*dbg() macros do not fit.

Build-tested with BROKEN locally removed from DRM_USE_DYNAMIC_DEBUG to
cover both Y/N cases. That un-BROKEN patch is intentionally excluded
here as drm.debug still needs classmap fixes patchset.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
Changes in v4:
- Replace unused-variable workaround with proper __drm_printfn_dbg()
  fix (per Sashiko review).
- Drop drivers/gpu/drm/Makefile and DONT_APPLY un-BROKEN patches from
  this series (deferred to classmap-inheritance series).
- Link to v3: https://lore.kernel.org/r/20261121-rd-mostly-v3-0-89e74b23b491@gmail.com

Changes in v3:
- dont need both ccflags-y and subdir-ccflags-y, latter covers former.
- Link to v2: https://lore.kernel.org/r/20261120-rd-mostly-v2-0-88056ede02a8@gmail.com

Changes in v2:
- Add subdir-ccflags- propagation in drivers/gpu/drm/Makefile (patch 2).
- Add unused `category` warning fix under CONFIG_DRM_USE_DYNAMIC_DEBUG=y
  (patch 3).
- Add __drm_debug and ddebug_class_param.bits shrink to unsigned int
  (patch 4).
- Link to v1: https://lore.kernel.org/r/20260926-rd-mostly-v1-0-28b7d714ed2c@gmail.com

---
Jim Cromie (3):
      drm/print: Mark __drm_debug as __read_mostly
      drm/print,dyndbg: restore __drm_debug to uint from ulong
      drm/print: fix drm_printer dynamic debug bit-test bypass

 drivers/gpu/drm/drm_print.c   | 7 +++----
 include/drm/drm_print.h       | 2 +-
 include/linux/dynamic_debug.h | 2 +-
 lib/dynamic_debug.c           | 8 +++++---
 lib/test_dynamic_debug.c      | 2 +-
 5 files changed, 11 insertions(+), 10 deletions(-)
---
base-commit: b6a9fa34ce4187cb69d3c588a4bbffc31ce5db8f
change-id: 20260925-rd-mostly-6a2fc0cd6fd6

Best regards,
-- 
Jim Cromie <jim.cromie@gmail.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 1/3] drm/print: Mark __drm_debug as __read_mostly
  2026-11-24 23:38 [PATCH v4 0/3] drm/print,dyndbg: __drm_debug __read_mostly, restore it to uint, printer fix Jim Cromie via B4 Relay
@ 2026-11-24 23:38 ` Jim Cromie via B4 Relay
  2026-11-24 23:38 ` [PATCH v4 2/3] drm/print,dyndbg: restore __drm_debug to uint from ulong Jim Cromie via B4 Relay
  2026-11-24 23:38 ` [PATCH v4 3/3] drm/print: fix drm_printer dynamic debug bit-test bypass Jim Cromie via B4 Relay
  2 siblings, 0 replies; 4+ messages in thread
From: Jim Cromie via B4 Relay @ 2026-11-24 23:38 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Jason Baron, Greg Kroah-Hartman,
	Andrew Morton, Luca Coelho, Jani Nikula
  Cc: dri-devel, linux-kernel, Jim Cromie

From: Jim Cromie <jim.cromie@gmail.com>

Under a multi-client workload of 12 concurrent vkcubes on AMD iGPU,
__drm_debug is read at ~83.3 kHz across multiple cores during atomic
and vblank checks.

But __drm_debug is written only when userspace does:
  echo 0xff > /sys/module/drm/parameters/debug

Currently the linker packs __drm_debug into .bss adjacent to hot
structures: drm_lease_idr_object, drm_class, and drm_global_mutex,
causing unnecessary cacheline invalidations.

Mark __drm_debug as __read_mostly to relocate it to .data..read_mostly.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 drivers/gpu/drm/drm_print.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
index 86cef1a37678..50cdeb1b15e2 100644
--- a/drivers/gpu/drm/drm_print.c
+++ b/drivers/gpu/drm/drm_print.c
@@ -40,7 +40,7 @@
  * __drm_debug: Enable debug output.
  * Bitmask of DRM_UT_x. See include/drm/drm_print.h for details.
  */
-unsigned long __drm_debug;
+unsigned long __drm_debug __read_mostly;
 EXPORT_SYMBOL(__drm_debug);
 
 MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug category.\n"

-- 
2.56.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 2/3] drm/print,dyndbg: restore __drm_debug to uint from ulong
  2026-11-24 23:38 [PATCH v4 0/3] drm/print,dyndbg: __drm_debug __read_mostly, restore it to uint, printer fix Jim Cromie via B4 Relay
  2026-11-24 23:38 ` [PATCH v4 1/3] drm/print: Mark __drm_debug as __read_mostly Jim Cromie via B4 Relay
@ 2026-11-24 23:38 ` Jim Cromie via B4 Relay
  2026-11-24 23:38 ` [PATCH v4 3/3] drm/print: fix drm_printer dynamic debug bit-test bypass Jim Cromie via B4 Relay
  2 siblings, 0 replies; 4+ messages in thread
From: Jim Cromie via B4 Relay @ 2026-11-24 23:38 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Jason Baron, Greg Kroah-Hartman,
	Andrew Morton, Luca Coelho, Jani Nikula
  Cc: dri-devel, linux-kernel, Jim Cromie

From: Jim Cromie <jim.cromie@gmail.com>

Restore __drm_debug and struct ddebug_class_param.bits to uint from
ulong; 64 flags is more than we will ever need, and is not effectively
usable with the interface:

  # 64 bits would be unwieldy here
  echo 0x12345678 > /sys/module/drm/parameters/debug

drm_debug_bitmap.bits points at extern __drm_debug so dyndbg updates
it as shared state for drm_debug_enabled() and other ad-hoc debug
checks outside classmaps' remit. That pointer coupling requires
__drm_debug, module_param_named(..., uint), and
ddebug_class_param.bits to change together in one commit.

Accordingly, update lib/dynamic_debug.c to pass the local unsigned
long `old_bits` to ddebug_apply_class_bitmap() (which uses
test_bit()), format with 0x%x in param_get_dyndbg_classes(), and
shrink DD_SYS_WRAP's backing variable in lib/test_dynamic_debug.c to
unsigned int.

Fixes: b9400852c080 ("dyndbg: add drm.debug style (drm/parameters/debug) bitmap support")
Fixes: f158936b60a7 ("drm: POC drm on dyndbg - use in core, 2 helpers, 3 drivers.")
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 drivers/gpu/drm/drm_print.c   | 4 ++--
 include/drm/drm_print.h       | 2 +-
 include/linux/dynamic_debug.h | 2 +-
 lib/dynamic_debug.c           | 8 +++++---
 lib/test_dynamic_debug.c      | 2 +-
 5 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
index 50cdeb1b15e2..2e7685849f44 100644
--- a/drivers/gpu/drm/drm_print.c
+++ b/drivers/gpu/drm/drm_print.c
@@ -40,7 +40,7 @@
  * __drm_debug: Enable debug output.
  * Bitmask of DRM_UT_x. See include/drm/drm_print.h for details.
  */
-unsigned long __drm_debug __read_mostly;
+unsigned int __drm_debug __read_mostly;
 EXPORT_SYMBOL(__drm_debug);
 
 MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug category.\n"
@@ -56,7 +56,7 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat
 "\t\tBit 9 (0x200) will enable DRMRES messages (managed resources code)");
 
 #if !defined(CONFIG_DRM_USE_DYNAMIC_DEBUG)
-module_param_named(debug, __drm_debug, ulong, 0600);
+module_param_named(debug, __drm_debug, uint, 0600);
 #else
 /* classnames must match vals of enum drm_debug_category */
 DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0,
diff --git a/include/drm/drm_print.h b/include/drm/drm_print.h
index 0805903c093b..d3c302a770e9 100644
--- a/include/drm/drm_print.h
+++ b/include/drm/drm_print.h
@@ -39,7 +39,7 @@ struct drm_device;
 struct seq_file;
 
 /* Do *not* use outside of drm_print.[ch]! */
-extern unsigned long __drm_debug;
+extern unsigned int __drm_debug;
 
 /**
  * DOC: print
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 05743900a116..dc21e3a8e86f 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -124,7 +124,7 @@ struct _ddebug_info {
 
 struct ddebug_class_param {
 	union {
-		unsigned long *bits;
+		unsigned int *bits;
 		unsigned int *lvl;
 	};
 	char flags[8];
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index 18a71a9108d3..644f87d6969c 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -681,8 +681,9 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pa
 				continue;
 			}
 			curr_bits ^= BIT(cls_id);
-			totct += ddebug_apply_class_bitmap(dcp, &curr_bits, dcp->bits);
+			totct += ddebug_apply_class_bitmap(dcp, &curr_bits, &old_bits);
 			*dcp->bits = curr_bits;
+			old_bits = curr_bits;
 			v2pr_info("%s: changed bit %d:%s\n", KP_NAME(kp), cls_id,
 				  map->class_names[cls_id]);
 			break;
@@ -754,7 +755,8 @@ int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp)
 			inrep &= CLASSMAP_BITMASK(map->length);
 		}
 		v2pr_info("bits:%lx > %s\n", inrep, KP_NAME(kp));
-		totct += ddebug_apply_class_bitmap(dcp, &inrep, dcp->bits);
+		old_bits = *dcp->bits;
+		totct += ddebug_apply_class_bitmap(dcp, &inrep, &old_bits);
 		*dcp->bits = inrep;
 		break;
 	case DD_CLASS_TYPE_LEVEL_NUM:
@@ -796,7 +798,7 @@ int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp)
 
 	case DD_CLASS_TYPE_DISJOINT_NAMES:
 	case DD_CLASS_TYPE_DISJOINT_BITS:
-		return scnprintf(buffer, PAGE_SIZE, "0x%lx\n", *dcp->bits);
+		return scnprintf(buffer, PAGE_SIZE, "0x%x\n", *dcp->bits);
 
 	case DD_CLASS_TYPE_LEVEL_NAMES:
 	case DD_CLASS_TYPE_LEVEL_NUM:
diff --git a/lib/test_dynamic_debug.c b/lib/test_dynamic_debug.c
index 77c2a669b6af..2fb9b3889f67 100644
--- a/lib/test_dynamic_debug.c
+++ b/lib/test_dynamic_debug.c
@@ -40,7 +40,7 @@ module_param_cb(do_prints, &param_ops_do_prints, NULL, 0600);
  * - tie together sysname, mapname, bitsname, flagsname
  */
 #define DD_SYS_WRAP(_model, _flags)					\
-	static unsigned long bits_##_model;				\
+	static unsigned int bits_##_model;				\
 	static struct ddebug_class_param _flags##_model = {		\
 		.bits = &bits_##_model,					\
 		.flags = #_flags,					\

-- 
2.56.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v4 3/3] drm/print: fix drm_printer dynamic debug bit-test bypass
  2026-11-24 23:38 [PATCH v4 0/3] drm/print,dyndbg: __drm_debug __read_mostly, restore it to uint, printer fix Jim Cromie via B4 Relay
  2026-11-24 23:38 ` [PATCH v4 1/3] drm/print: Mark __drm_debug as __read_mostly Jim Cromie via B4 Relay
  2026-11-24 23:38 ` [PATCH v4 2/3] drm/print,dyndbg: restore __drm_debug to uint from ulong Jim Cromie via B4 Relay
@ 2026-11-24 23:38 ` Jim Cromie via B4 Relay
  2 siblings, 0 replies; 4+ messages in thread
From: Jim Cromie via B4 Relay @ 2026-11-24 23:38 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, Jason Baron, Greg Kroah-Hartman,
	Andrew Morton, Luca Coelho, Jani Nikula
  Cc: dri-devel, linux-kernel, Jim Cromie

From: Jim Cromie <jim.cromie@gmail.com>

drm_debug_enabled() [$1] is the canonical bit-test for drm.debug.
Commit 6ce6fae84536 ("drm_print: optimize drm_debug_enabled for
jump-label") elaborated it into 4 names, controlled by
CONFIG_DRM_USE_DYNAMIC_DEBUG:

A- $1_raw() - rename of the original bit-test.
B- $1_instrumented() - like raw, but adds a pr_debug(), allowing us to
   count callsite frequency and consider optimizing them later.
C- __$1() - evaluates to 'true' when CONFIG_DRM_USE_DYNAMIC_DEBUG=y
   (avoiding the bit-test where callsites are already guarded by a
   dyndbg static-key), and forwards to A when =n.
D- $1() - forwards to B when CONFIG_DRM_USE_DYNAMIC_DEBUG=y, and to A
   when =n, for cases where an explicit bit-mask check is required.

Later, commit 9fd6f61a297e ("drm/print: add drm_dbg_printer() for drm
device specific printer") added a general-use __drm_printfn_dbg()
function, but used __$1() instead of $1(). When
CONFIG_DRM_USE_DYNAMIC_DEBUG=y, __$1() evaluates to 'true' and always
prints.  This went unnoticed because CONFIG_DRM_USE_DYNAMIC_DEBUG was
marked BROKEN.

With =y, this results in a flood of messages, and in CI-tests on slow
serial consoles, creates bottlenecks, as seen in DRM-CI on i915 CML
devices.  When IGT causes a mismatch in intel_pipe_config_compare(),
the resulting UART storm causes a hard timeout after 20 minutes.

NOTES:

Drop the single-use `category` local variable and pass p->category
directly (which previously also triggered an unused-variable warning
under the old __$1() bypass).

Because __drm_printfn_dbg() is a shared helper invoked via p->printfn
with a runtime p->category, the callsite cannot be guarded by a
static-key; we'd need a macro version and callsites where category is
a compile-time constant.

Replacing __$1() with $1() or $1_raw() would also work, but
$1_instrumented() adds the pr_debug() in both =y and =n configs; when
enabled it can provide call-freq data to inform further callsite
optimization choices.

Fixes: 9fd6f61a297e ("drm/print: add drm_dbg_printer() for drm device specific printer")
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 drivers/gpu/drm/drm_print.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_print.c b/drivers/gpu/drm/drm_print.c
index 2e7685849f44..3d26483975f2 100644
--- a/drivers/gpu/drm/drm_print.c
+++ b/drivers/gpu/drm/drm_print.c
@@ -218,9 +218,8 @@ void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf)
 {
 	const struct drm_device *drm = p->arg;
 	const struct device *dev = drm ? drm->dev : NULL;
-	enum drm_debug_category category = p->category;
 
-	if (!__drm_debug_enabled(category))
+	if (!drm_debug_enabled_instrumented(p->category))
 		return;
 
 	__drm_dev_vprintk(dev, KERN_DEBUG, p->origin, p->prefix, vaf);

-- 
2.56.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-24 23:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 23:38 [PATCH v4 0/3] drm/print,dyndbg: __drm_debug __read_mostly, restore it to uint, printer fix Jim Cromie via B4 Relay
2026-11-24 23:38 ` [PATCH v4 1/3] drm/print: Mark __drm_debug as __read_mostly Jim Cromie via B4 Relay
2026-11-24 23:38 ` [PATCH v4 2/3] drm/print,dyndbg: restore __drm_debug to uint from ulong Jim Cromie via B4 Relay
2026-11-24 23:38 ` [PATCH v4 3/3] drm/print: fix drm_printer dynamic debug bit-test bypass Jim Cromie via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®