Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
drm_print: add choice to use dynamic debug in drm-debug
drm's debug system writes 10 enumerated categories of debug messages,
calling drm_debug_enabled(drm_debug_category) to determine at runtime
whether to printk.
DYNAMIC_DEBUG (with CONFIG_JUMP_LABEL) can eliminate those runtime
tests with kernel-patching, giving zero overhead for normal ops, in
trade for transient costs during rare toggles of the drm.debug bits.
dyndbg has no concept of categories, but if we can modify the exact
message format, we can prepend a prefix: "drm:core: ", "drm:kms: ",
etc to actual format.
Then we can use:
# echo module drm format "^drm:core: " +p > /proc/dynamic_debug/control
to enable the whole category with one query.
DEFINE_DYNAMIC_DEBUG_BITGRPS implements the bitmap interface for
/sys/module/drm/parameter/debug
This is CONFIG_DRM_USE_DYNAMIC_DEBUG dependent, since there are many
drm.debug callsites, with 56 bytes per site:
dyndbg: 207 debug prints in module drm_kms_helper
dyndbg: 376 debug prints in module drm
dyndbg: 1811 debug prints in module i915
dyndbg: 3917 debug prints in module amdgpu
CONFIG_JUMP_LABEL is also required, to get the promised optimizations.
The "basic" -> "dyndbg" switchover is layered into the macro scheme:
1. DRM_DBG_CAT_<CATs> are either: DRM_UT_<CATs>
or a string: "drm:core: ", "drm:kms: ", "drm:atomic: ", etc.
DRM_DBG_CAT_<CATs> is now used
2. drm_dev_dbg() & drm_debug() are interposed with macros, forwarding:
basic: to renamed __fns, with DRM_UT_<CAT> passed in
dyndbg: do cpp catenaton: DRM_DBG_CAT_<CAT> + format
and forward to pr_debug, dev_dbg
This is where drm_debug_enabled() is avoided. The prefix is prepended
at compile-time, no category exists at runtime.
3. all drm.debug API calls now use DRM_DBG_CAT_<CAT>: enum or string
DRM_UT_* are preserved, since theyre used elsewhere. Since the
callback maintains its state in __drm_debug, drm_debug_enabled() will
stay synchronized, and continue to work. We can address them
separately if they are called enough to be worth fixing.
4. use DEFINE_DYNAMIC_DEBUG_CATEGORIES()
This defines the dyndbg query-map using DRM_CAT_<CAT>s, and creates
the sysfs bitmap-node to control those categories.
LIMITATIONS:
dev_dbg(etal) effectively prepends twice, category then driver-name,
yielding format strings like so:
bash-5.1# grep amdgpu: /proc/dynamic_debug/control | grep drm: | cut -d= -f2-
_ "amdgpu: drm:core: fence driver on ring %s use gpu addr 0x%016llx\012"
_ "amdgpu: drm:kms: Cannot create framebuffer from imported dma_buf\012"
This means we cannot use anchored "^drm:kms: " to specify the
category, a small loss of precision. Searching on "format ^amdgpu: "
would work, but this is less valuable, because the same can be done
with "module amdgpu".
Fixing this order of prepending is possible, given that we're adding
"drm:core:" etc anyway, so can probably arrange for its proper
placement. This all requires buy-in anyway, due to the format change
to the debug messages.
NOTES:
CONFIG_DRM_USE_DYNAMIC_DEBUG is also used to adjust amdgpu, i915
makefiles to add -DDYNAMIC_DEBUG_MODULE; it includes the current
CONFIG_DYNAMIC_DEBUG_CORE and is enabled by the user.
Code Review is expected to catch the lack of correspondence between
bit=>prefix definitions (the selector) and the prefixes used in the
API[1] layer above pr_debug()
I've coded the categories with trailing spaces. This excludes any
sub-categories which might get added later. This convention protects
any "drm:atomic:fail:" callsites from getting stomped on by `echo 0 >
debug`. Other categories could differ, but we need some default.
Dyndbg requires that the prefix be in the compiled-in format string;
run-time prefixing evades callsite selection by category.
pr_debug("%s: ...", __func__, ...) // not ideal
Unfortunately __func__ is not a macro, and cannot be catenated at
preprocess/compile time.
If you want that, you might consider +mfl flags instead;)
Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
v5:
. use DEFINE_DYNAMIC_DEBUG_CATEGORIES in drm_print.c
. s/DRM_DBG_CLASS_/DRM_DBG_CAT_/ - dont need another term
. default=y in Kconfig entry - per @danvet
. move some commit-log prose to dyndbg commit
. add-prototyes to (param_get/set)_dyndbg
. more wrinkles found by <lkp@intel.com>
. relocate ratelimit chunk from elsewhere
v6:
. add kernel doc
. fix cpp paste, drop '#'
v7:
. change __drm_debug to long, to fit with DEFINE_DYNAMIC_DEBUG_CATEGORIES
. add -DDYNAMIC_DEBUG_MODULE to ccflags if DRM_USE_DYNAMIC_DEBUG
v8:
. adapt to altered ^ insertion
. add mem cost numbers to kconfig
. kdoc improvements (I hope)
v11:
. add,usse macro to evaluate to either enum-cat or cat-string- Loading branch information