drm/print,dyndbg: __drm_debug __read_mostly, uint shrink, build fixes
Subsystems (4)
Jim Cromie
maintainerv2 cover drm/print,dyndbg: __drm_debug __read_mostly, uint shrink, build fixes
This series improves __drm_debug placement/sizing and fixes two build issues exposed when CONFIG_DRM_USE_DYNAMIC_DEBUG=y is enabled:
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. Fix CFLAGS- -> ccflags- spelling error in drivers/gpu/drm/Makefile to add -DDYNAMIC_DEBUG_MODULE when CONFIG_DYNAMIC_DEBUG_CORE=y without CONFIG_DYNAMIC_DEBUG=y. Also add subdir-ccflags- so DRM subdirs (drivers and helpers) get the -Dflag too.
3. Drop the unused category local in __drm_printfn_dbg() when CONFIG_DRM_USE_DYNAMIC_DEBUG=y expands __drm_debug_enabled() to true.
4. Shrink __drm_debug and struct ddebug_class_param.bits from unsigned long back to unsigned int, updating lib/dynamic_debug.c and lib/test_dynamic_debug.c callers accordingly.
NOTES:
drm and dyndbg are coupled on __drm_debug's size and type, so changing the size requires coordination between DRM and core. The coupling allows dyndbg to use the var to keep 'state', and allows drm to continue using it in a few cases where drm_*dbg doesnt quite fit.
Because DRM_USE_DYNAMIC_DEBUG still depends on BROKEN, patches 2-4 were build-tested with that dependency locally removed. That un-BROKEN patch is intentionally excluded here, as modular DRM probe-time drm.debug support (and external users like drivers/accel/) still need the separate/pending classmap fixup series.
---
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/[email protected]
---
Jim Cromie (5):
drm/print: Mark __drm_debug as __read_mostly
drm: Fix incorrect CFLAGS-y spelling inside Makefile
drm: fix config dependent unused variable warning. drm/print,dyndbg: restore __drm_debug to uint from ulong
drm-dyndbg: drop BROKEN on DRM_USE_DYNAMIC_DEBUG for testing (DONT_APPLY)
drivers/gpu/drm/Kconfig.debug | 1 - drivers/gpu/drm/Makefile | 3 ++- 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 +- 7 files changed, 13 insertions(+), 12 deletions(-)
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20260925-rd-mostly-6a2fc0cd6fd6
Best regards,
Signature · 1 line
Jim Cromie <[email protected]>
Jim Cromie
maintainerPATCH v2 1/5 drm/print: Mark __drm_debug as __read_mostly
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.
__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.
--- drivers/gpu/drm/drm_print.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_print.c +1 -1
@@ -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"
Signature · 1 line
2.56.1
Jim Cromie
maintainerPATCH v2 2/5 drm: Fix incorrect CFLAGS-y spelling inside Makefile
In reply to Jim CromieDRM Makefile spelled CFLAGS-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) incorrectly, which kbuild ignores. So -DDYNAMIC_DEBUG_MODULE was omitted, breaking DRM dynamic debug callsites when CONFIG_DYNAMIC_DEBUG_CORE=y without CONFIG_DYNAMIC_DEBUG.
Replace CFLAGS- with ccflags-y, and also set subdir-ccflags-y so that -DDYNAMIC_DEBUG_MODULE propagates to DRM driver and helper subdirectories under drivers/gpu/drm/ (ccflags-y only applies to the current directory).
NOTE: When CONFIG_DYNAMIC_DEBUG=y, -DDYNAMIC_DEBUG_MODULE is redundant because defined(CONFIG_DYNAMIC_DEBUG) already enables callsites. Passing it unconditionally under CONFIG_DRM_USE_DYNAMIC_DEBUG avoids extra Makefile conditionals and keeps the preprocessor environment consistent across DYNAMIC_DEBUG=y and DYNAMIC_DEBUG_CORE=y builds.
--- drivers/gpu/drm/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/Makefile +2 -1
@@ -3,7 +3,8 @@ # Makefile for the drm device driver. This driver provides support for the # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. -CFLAGS-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE +ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE +subdir-ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE # Unconditionally enable W=1 warnings locally # --- begin copy-paste W=1 warnings from scripts/Makefile.warn
Signature · 1 line
2.56.1
Jim Cromie
maintainerPATCH v2 3/5 drm: fix config dependent unused variable warning.
In reply to Jim Cromie__drm_printfn_dbg() does:
enum drm_debug_category category = p->category;
then:
if (!__drm_debug_enabled(category))When CONFIG_DRM_USE_DYNAMIC_DEBUG=y, __drm_debug_enabled(category) expands to true without referencing category, causing an unused-variable warning/error. Silence it by passing p->category directly.
--- drivers/gpu/drm/drm_print.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/drm_print.c +1 -2
@@ -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 (p->category))return ;__drm_dev_vprintk (dev,KERN_DEBUG , p->origin, p->prefix, vaf);
Signature · 1 line
2.56.1
Jim Cromie
maintainerPATCH v2 4/5 drm/print,dyndbg: restore __drm_debug to uint from ulong
In reply to Jim CromieRestore __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 unwieldly 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.
dyndbg: fix dd for __drm_debug shrink
--- 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(-)
drivers/gpu/drm/drm_print.c +2 -2
@@ -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,
include/drm/drm_print.h +1 -1
@@ -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
include/linux/dynamic_debug.h +1 -1
@@ -124,7 +124,7 @@ struct _ddebug_info {struct ddebug_class_param {union { -unsigned long *bits; +unsigned int *bits;unsigned int *lvl; };char flags[8 ];
lib/dynamic_debug.c +5 -3
@@ -681,8 +681,9 @@ static int param_set_dyndbg_classnames(const char *instr, const struct kernel_pacontinue ; } 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 :
lib/test_dynamic_debug.c +1 -1
@@ -40,7 +40,7 @@ module_param_cb(do_prints, ¶m_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, \
Signature · 1 line
2.56.1
Jim Cromie
maintainerPATCH v2 5/5 drm-dyndbg: drop BROKEN on DRM_USE_DYNAMIC_DEBUG for testing (DONT_APPLY)
In reply to Jim Cromieremove BROKEN from DRM_USE_DYNAMIC_DEBUG, to facilitate testing with it enabled.
DO_NOT_APPLY - full functionality requires the (forthcoming) classmaps patchset, and drivers/accel/ uses drm_*dbg, and needs the ccflags additions like for drm/Makefile
--- drivers/gpu/drm/Kconfig.debug | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/Kconfig.debug +0 -1
@@ -1,7 +1,6 @@ config DRM_USE_DYNAMIC_DEBUG bool "use dynamic debug to implement drm.debug" default n - depends on BROKEN depends on DRM depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE depends on JUMP_LABEL
Signature · 1 line
2.56.1
[email protected]
AI reviewRe: [PATCH v2 2/5] drm: Fix incorrect CFLAGS-y spelling inside Makefile
In reply to Jim CromieThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm: redundant ccflags-y with subdir-ccflags-y duplicates compiler flag --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm: redundant ccflags-y with subdir-ccflags-y duplicates compiler flag
--
commit 3641ab8573c265c9f30c513b01ff9a6dc232bced
Author: Jim Cromie <[email protected]>
drm: Fix incorrect CFLAGS-y spelling inside Makefile
This commit replaces CFLAGS-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) with ccflags-y and subdir-ccflags-y in drivers/gpu/drm/Makefile so that -DDYNAMIC_DEBUG_MODULE is passed during compilation.
drivers/gpu/drm/Makefile line 7
Quoted 11 lines
drivers/gpu/drm/Makefile +2
-1@@ -3,7 +3,8 @@ # Makefile for the drm device driver. This driver provides support for the # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. -CFLAGS-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE +ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE +subdir-ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) += -DDYNAMIC_DEBUG_MODULE
[Severity: Low]
Is ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) redundant when subdir-ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG) is also set?
In scripts/Makefile.build, subdir-ccflags-y is appended to KBUILD_CFLAGS for both the current directory and its subdirectories:
scripts/Makefile.build {
...
# flags that take effect in current and sub directories
KBUILD_AFLAGS += $(subdir-asflags-y)
KBUILD_CFLAGS += $(subdir-ccflags-y)
...
}Setting both passes -DDYNAMIC_DEBUG_MODULE twice on the compiler command line for every object built directly in drivers/gpu/drm/. Keeping only subdir-ccflags-$(CONFIG_DRM_USE_DYNAMIC_DEBUG), matching the rest of this Makefile, covers both drivers/gpu/drm/ and its subdirectories.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v2 3/5] drm: fix config dependent unused variable warning.
In reply to Jim CromieThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/print: __drm_printfn_dbg() ignores category under DYNAMIC_DEBUG --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/print: __drm_printfn_dbg() ignores category under DYNAMIC_DEBUG
--
commit 86a692a9057b290b879237eb899a9b98e98de2c4
Author: Jim Cromie <[email protected]>
drm: fix config dependent unused variable warning.
This commit removes the local category variable in __drm_printfn_dbg() and passes p->category directly to __drm_debug_enabled() to avoid an unused-variable warning when CONFIG_DRM_USE_DYNAMIC_DEBUG=y.
drivers/gpu/drm/drm_print.c void __drm_printfn_dbg(struct drm_printer *p, struct va_format *vaf) · line 223
Quoted 13 lines
drivers/gpu/drm/drm_print.c +1
-2@@ -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 (p->category))return ;
[Severity: Medium]
Should __drm_printfn_dbg() call drm_debug_enabled(p->category) (or drm_debug_enabled_raw(p->category)) instead of __drm_debug_enabled()?
When CONFIG_DRM_USE_DYNAMIC_DEBUG=y, __drm_debug_enabled() expands to true without evaluating its argument because it assumes the callsite is already gated by a dynamic debug descriptor via _dynamic_func_call_cls(). drm_dbg_printer() wires __drm_printfn_dbg() as a function pointer without a dynamic debug callsite descriptor, so using __drm_debug_enabled() leaves p->category unchecked and causes all drm_dbg_printer() messages to be printed unconditionally even when drm.debug has that category disabled.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v2 5/5] drm-dyndbg: drop BROKEN on DRM_USE_DYNAMIC_DEBUG for testing (DONT_APPLY)
In reply to Jim CromieThank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] drm: build failure in drivers/accel/ with CONFIG_DRM_USE_DYNAMIC_DEBUG=y - [Medium] drm: broken…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] drm: build failure in drivers/accel/ with CONFIG_DRM_USE_DYNAMIC_DEBUG=y
- [Medium] drm: broken debug logging in ddebug_change() and ddebug_add_module()
- [Medium] drm/print: unconditional debug output in __drm_printfn_dbg() --
commit e718019be2a4836ac3663a62da5e819f0a591c63
Author: Jim Cromie <[email protected]>
drm-dyndbg: drop BROKEN on DRM_USE_DYNAMIC_DEBUG for testing (DONT_APPLY)
This commit removes the BROKEN dependency from CONFIG_DRM_USE_DYNAMIC_DEBUG so the option can be enabled for testing.
drivers/gpu/drm/Kconfig.debug line 6
Quoted 12 lines
drivers/gpu/drm/Kconfig.debug +0
-1@@ -1,7 +1,6 @@ config DRM_USE_DYNAMIC_DEBUG bool "use dynamic debug to implement drm.debug" default n - depends on BROKEN depends on DRM depends on DYNAMIC_DEBUG || DYNAMIC_DEBUG_CORE depends on JUMP_LABEL
[Severity: High]
Does enabling CONFIG_DRM_USE_DYNAMIC_DEBUG=y with CONFIG_DYNAMIC_DEBUG_CORE=y and CONFIG_DYNAMIC_DEBUG=n break the build for drivers under drivers/accel/ that call drm_dbg() (such as amdxdna, ethosu, and rocket)?
When CONFIG_DRM_USE_DYNAMIC_DEBUG=y, include/drm/drm_print.h expands drm_dev_dbg() and __drm_dbg() to _dynamic_func_call_cls(). In include/linux/dynamic_debug.h, _dynamic_func_call_cls() is only defined when CONFIG_DYNAMIC_DEBUG is set or when both CONFIG_DYNAMIC_DEBUG_CORE and DYNAMIC_DEBUG_MODULE are defined, with no fallback stub in the #else branch. Unlike drivers/gpu/drm/Makefile, drivers/accel/Makefile does not add -DDYNAMIC_DEBUG_MODULE to ccflags-y or subdir-ccflags-y, leaving _dynamic_func_call_cls undeclared.
[Severity: Medium]
Does enabling CONFIG_DRM_USE_DYNAMIC_DEBUG=y leave drm_dbg*() callsites impossible to enable in most DRM modules, and suppress debug output during module probe when drm.debug is set prior to loading a driver module?
With CONFIG_DRM_USE_DYNAMIC_DEBUG=y, drm_dev_dbg() and __drm_dbg() tag descriptors with DRM_UT_* class IDs rather than _DPRINTK_CLASS_DFLT. In ddebug_change(), class-tagged descriptors only match when the module has a registered classmap in dt->maps, which currently only drm, drm_kms_helper, drm_display_helper, amdgpu, i915, and nouveau declare via DECLARE_DYNDBG_CLASSMAP. In addition, ddebug_add_module() -> ddebug_attach_module_classes() attaches a newly loaded module's classmap without applying the active __drm_debug bitmap to its callsites.
[Severity: Medium]
Does enabling CONFIG_DRM_USE_DYNAMIC_DEBUG=y cause __drm_printfn_dbg() to emit KERN_DEBUG messages unconditionally even when drm.debug is 0?
include/drm/drm_print.h defines __drm_debug_enabled(category) as true when CONFIG_DRM_USE_DYNAMIC_DEBUG=y, assuming callsites are gated by a dynamic debug jump label. However, drm_dbg_printer() uses __drm_printfn_dbg() directly without a jump label:
drivers/gpu/drm/drm_print.c:__drm_printfn_dbg() {
...
if (!__drm_debug_enabled(p->category))
return;
__drm_dev_vprintk(dev, KERN_DEBUG, p->origin, p->prefix, vaf);
}As a result, any drm_printf() or drm_vprintf() call on a drm_dbg_printer() without an external check (such as in intel_display_driver_register() or ttm_bo_mem_space_debug()) always prints to the kernel log.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5