Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
dyndbg: add print-once and print-ratelimited features. RFC.
Expand ddebug.flags to 11 bits, and define new flags to support
pr_debug_once() and pr_debug_ratelimited() semantics:
echo file init/main.c +o > control # init/main runs just once anyway
echo module foo +r > control # turn on ratelimiting
echo module foo +g > control # turn on group flag
Test these conditions in bool is_onced_or_ratelimited(), and call it
from __dynamic_pr_debug and others (which are behind the '+p'
enablement test).
print-once: can be done with just 2 bits in flags;
.o _DPRINTK_FLAGS_ONCE enables state test and set
.P _DPRINTK_FLAGS_PRINTED state bit
Just adding the flags lets the existing code operate on them.
We will need new code to enforce constraints on flag combos;
'+ro' is nonsense, but this can wait, or can take a new meaning.
+oP behavior is testable using module module +o vs +oP > control
rate-limiting:
.r _DPRINTK_FLAGS_RATELIMITED - track & limit prdbgs callrate
We wait until a prdebug is called, and if RATELIMITED is set, THEN
lookup a RateLimitState (RL) for it. If found, bump its state and
return true/false, otherwise create & initialize one and return false.
group-flag: RFC
.g _DPRINTK_FLAGS_GROUPED
Currently, the hash-key is just the prdebug descriptor, so is unique
per prdebug. With the 'g' flag, we could use a different key, for
example desc->site.function, to get a shared ratelimit for whole
functions.
This gets subtly different behavior at the ratelimit transition, but
it is predictable for a given function (except perhaps recursive, but
thats not done anyway).
Note also that any function can have a single group of prdebugs, plus
any number of prdbgs without 'g', either with or without 'r'. So
grouping should be flexible enough to use advantageously.
TLDR: older key thinking
That lookup is basically a hash, with 2 part key:
. &builtin-vector-base OR &module
or the hash(s) could hang off the header struct
. ._back OR ._map
chosen by _DPRINTK_FLAGS_GROUPED
choice dictates per-site OR sharing across function
print more debug context for verbose=4
bash-5.1# modprobe test_static_keys
[ 407.563410] dyndbg: found ffffffff8313efd0
[ 407.564180] is_onced_or_limited: 8 callbacks suppressed
[ 407.564194] dyndbg: RLstate{solo}=1 on module.layout_sections.2438
[ 407.565806] dyndbg: found ffffffff8313efb0
[ 407.566459] is_onced_or_limited: 348 callbacks suppressed
[ 407.566464] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.568214] dyndbg: found ffffffff8313efb0
[ 407.568777] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.569727] dyndbg: found ffffffff8313efb0
[ 407.570355] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.571226] dyndbg: found ffffffff8313efb0
[ 407.571797] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.572686] dyndbg: found ffffffff8313efb0
[ 407.573284] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.574214] dyndbg: found ffffffff8313efb0
[ 407.574791] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.575749] dyndbg: found ffffffff8313efb0
[ 407.576409] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.577415] dyndbg: found ffffffff8313efb0
[ 407.578221] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.579622] dyndbg: found ffffffff8313efb0
[ 407.580391] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.581553] dyndbg: found ffffffff8313efb0
[ 407.582273] dyndbg: RLstate{solo}=1 on module.layout_sections.2450
[ 407.583174] dyndbg: found ffffffff8313efb0
[ 407.583745] dyndbg: RLstate{solo}=0 on module.layout_sections.2450
[ 407.584722] dyndbg: found ffffffff8313efb0
[ 407.585310] dyndbg: RLstate{solo}=0 on module.layout_sections.2450
[ 407.586228] dyndbg: found ffffffff8313efb0
[ 407.586880] dyndbg: RLstate{solo}=0 on module.layout_sections.2450
[ 407.587870] dyndbg: found ffffffff8313efb0
[ 407.588559] dyndbg: RLstate{solo}=0 on module.layout_sections.2450
[ 407.589515] dyndbg: found ffffffff8313efb0
[ 407.590254] dyndbg: RLstate{solo}=0 on module.layout_sections.2450
[ 407.591200] dyndbg: found ffffffff8313efb0
[ 407.591845] dyndbg: RLstate{solo}=0 on module.layout_sections.2450
[ 407.592957] dyndbg: found ffffffff8313ef90
[ 407.593755] is_onced_or_limited: 8 callbacks suppressed
[ 407.593765] dyndbg: RLstate{solo}=1 on module.layout_sections.2471
[ 407.595770] dyndbg: found ffffffff8313ef70
[ 407.596536] is_onced_or_limited: 34 callbacks suppressed
[ 407.596542] dyndbg: RLstate{solo}=1 on module.layout_symtab.2484
[ 407.598350] dyndbg: found ffffffff8313ef70
[ 407.598932] dyndbg: RLstate{solo}=1 on module.layout_symtab.2484
[ 407.599849] dyndbg: found ffffffff8313ef50
[ 407.600559] is_onced_or_limited: 8 callbacks suppressed
[ 407.600563] dyndbg: RLstate{solo}=1 on module.layout_symtab.2703
[ 407.602366] dyndbg: found ffffffff8313ef30
[ 407.603074] is_onced_or_limited: 8 callbacks suppressed
[ 407.603079] dyndbg: RLstate{solo}=1 on module.move_module.2730
[ 407.604776] dyndbg: found ffffffff8313ef10
[ 407.605455] is_onced_or_limited: 8 callbacks suppressed
[ 407.605461] dyndbg: RLstate{solo}=1 on module.move_module.3390
[ 407.607497] dyndbg: found ffffffff8313eef0
[ 407.608206] is_onced_or_limited: 428 callbacks suppressed
[ 407.608211] dyndbg: RLstate{solo}=1 on module.__do_sys_init_module.3408
[ 407.610280] dyndbg: found ffffffff8313eef0
[ 407.610935] dyndbg: RLstate{solo}=1 on module.__do_sys_init_module.3408
[ 407.612012] dyndbg: found ffffffff8313eef0
[ 407.612641] dyndbg: RLstate{solo}=1 on module.__do_sys_init_module.3408- Loading branch information