Skip to content

Commit

Permalink
dyndbg: nouveau's got like levels man
Browse files Browse the repository at this point in the history
nouveau debug has levels man, other users will too; so add support.

With .class_id field already in struct _ddebug, its now easy to extend
the "class_match" test; formerly just site == input.

add enum class_map_type: with _DISJOINT, _VERBOSE, _PRIORITY.

_DISJOINT: site == input. (maybe _CATEGORY?). for drm.
_VERBOSE: site < input
_PRIORITY: site > input

in DYNAMIC_DEBUG_CLASSES, initialize it with _DISJOINT.
add DYNAMIC_DEBUG_LEVELS, = _VERBOSE
    DYNAMIC_DEBUG_PRIORITIES = _PRIORITY

test_dynamic_debug:

add new csysfs nodes: ddt_prio, ddt_verbose, using
DYNAMIC_DEBUG_PRIORITIES() and DYNAMIC_DEBUG_LEVELS() respectively.

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
  • Loading branch information
jimc committed May 28, 2022
1 parent 6a12644 commit 519000e
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 deletions.
13 changes: 13 additions & 0 deletions include/linux/dynamic_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ struct _ddebug {
#endif
} __attribute__((aligned(8)));

enum class_map_type { DD_CLS_DISJOINT, DD_CLS_VERBOSE, DD_CLS_PRIORITY };

struct ddebug_known_classes_map {
struct list_head link;
struct module *mod;
const char *mod_name; /* needed for builtins */
const int base; /* index of 1st .class_id, allows split/shared space */
enum class_map_type map_type;
const int length;
const char *classes[]; /* index maps .class_id */
};
Expand All @@ -77,9 +80,19 @@ struct ddebug_known_classes_map {
* accepts "class <name>" commands if <name> is known and registered.
*/
#define DYNAMIC_DEBUG_CLASSES(_var, _base, ...) \
DYNAMIC_DEBUG_CLASSES_TYPE(_var, _base, DD_CLS_DISJOINT, ##__VA_ARGS__)

#define DYNAMIC_DEBUG_LEVELS(_var, _base, ...) \
DYNAMIC_DEBUG_CLASSES_TYPE(_var, _base, DD_CLS_VERBOSE, ##__VA_ARGS__)

#define DYNAMIC_DEBUG_PRIORITIES(_var, _base, ...) \
DYNAMIC_DEBUG_CLASSES_TYPE(_var, _base, DD_CLS_PRIORITY, ##__VA_ARGS__)

#define DYNAMIC_DEBUG_CLASSES_TYPE(_var, _base, _mtyp, ...) \
static __maybe_unused struct ddebug_known_classes_map _var = { \
.mod = THIS_MODULE, \
.mod_name = KBUILD_MODNAME, \
.map_type = _mtyp, \
.base = _base, \
.length = NUM_TYPE_ARGS(char*, __VA_ARGS__), \
.classes = { __VA_ARGS__ } \
Expand Down
38 changes: 32 additions & 6 deletions lib/dynamic_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ static void vpr_info_dq(const struct ddebug_query *query, const char *msg)
query->first_lineno, query->last_lineno, query->class_string);
}

/* return <0 if class-name is unknown/invalid, 0..CLASS_DFLT otherwise */
static int ddebug_validate_classname(struct ddebug_table *dt, const char *class_string)
/* return <0 if class-name is unknown/invalid; otherwise 0..CLASS_DFLT, and outvar */
static int ddebug_validate_classname(struct ddebug_table *dt, const char *class_string,
struct ddebug_known_classes_map **mapout)
{
struct ddebug_known_classes_map *map;
int idx;
Expand All @@ -155,9 +156,12 @@ static int ddebug_validate_classname(struct ddebug_table *dt, const char *class_

list_for_each_entry(map, &dt->maps, link) {
idx = match_string(map->classes, map->length, class_string);
if (idx >= 0)
if (idx >= 0) {
*mapout = map;
return idx + map->base;
}
}
*mapout = NULL;
return -ENOENT;
}

Expand All @@ -175,6 +179,7 @@ static int ddebug_change(const struct ddebug_query *query,
unsigned int newflags;
unsigned int nfound = 0;
struct flagsbuf fbuf, nbuf;
struct ddebug_known_classes_map *map;
int query_class;

/* search for matching ddebugs */
Expand All @@ -187,16 +192,37 @@ static int ddebug_change(const struct ddebug_query *query,
continue;

/* validate class-string against module's known classes */
query_class = ddebug_validate_classname(dt, query->class_string);
query_class = ddebug_validate_classname(dt, query->class_string, &map);
if (query_class < 0)
continue;

for (i = 0; i < dt->num_ddebugs; i++) {
struct _ddebug *dp = &dt->ddebugs[i];

/* match against query-class, either valid input or default */
if (query_class != dp->class_id)
continue;
if (!map) {
if (query_class != dp->class_id)
continue;
} else {
switch (map->map_type) {
case DD_CLS_DISJOINT:
if (query_class != dp->class_id)
continue;
break;
case DD_CLS_VERBOSE:
if (query_class < dp->class_id &&
query_class >= map->base)
continue;
break;
case DD_CLS_PRIORITY:
if (query_class > dp->class_id &&
query_class < map->base + map->length)
continue;
break;
default:
BUG_ON("illegal enum value\n");
}
}

/* match against the source filename */
if (query->filename &&
Expand Down
41 changes: 41 additions & 0 deletions lib/test_dynamic_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ static struct ddebug_classes_bitmap_param t3_bitmap = {
};
module_param_cb(c3_trace_bits, &param_ops_dyndbg_classes, &t3_bitmap, 0600);

unsigned long verboseness;
enum verbosity { ONE = 20, TWO, THREE };
DYNAMIC_DEBUG_LEVELS(ddt_verbose, 20,
"ONE", "TWO", "THREE");

static struct ddebug_classes_bitmap_param verbose_bitmap = {
.bits = &verboseness,
.flags = "p",
.map = &ddt_verbose
};
module_param_cb(ddt_verbose, &param_ops_dyndbg_classes, &verbose_bitmap, 0600);

unsigned long priorities;
enum priority { EMERG = 24, DANGER, ERROR, WARNING, NOTICE, INFO, DEBUG };
DYNAMIC_DEBUG_PRIORITIES(ddt_prio, 24,
"EMERG", "DANGER", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG");

static struct ddebug_classes_bitmap_param prio_bitmap = {
.bits = &priorities,
.flags = "p",
.map = &ddt_prio
};
module_param_cb(ddt_prio, &param_ops_dyndbg_classes, &prio_bitmap, 0600);


static void do_alpha(void)
{
Expand All @@ -132,6 +156,12 @@ static void do_alpha(void)
__pr_debug_cls(FOO, "class FOO");
__pr_debug_cls(BAR, "class BAR");
__pr_debug_cls(BUZZ, "class BUZZ");

/* use priorities */
__pr_debug_cls(DANGER, "will robinson\n");
__pr_debug_cls(WARNING, "trouble ahead\n");
__pr_debug_cls(NOTICE, "you must be this tall to ride\n");
__pr_debug_cls(INFO, "rest rooms ahead\n");
}

static void do_beta(void)
Expand All @@ -145,6 +175,11 @@ static void do_beta(void)
__pr_debug_cls(bing, "class bing");
__pr_debug_cls(bong, "class bong");
__pr_debug_cls(boom, "class boom");

/* use levels */
__pr_debug_cls(ONE, "one message\n");
__pr_debug_cls(TWO, "2 message\n");
__pr_debug_cls(THREE, "3 message\n");
}

static void do_prints(void)
Expand All @@ -167,6 +202,9 @@ static int __init test_dynamic_debug_init(void)
dynamic_debug_register_classes(&ddt_classes2);
dynamic_debug_register_classes(&ddt_classes3);

dynamic_debug_register_classes(&ddt_prio);
dynamic_debug_register_classes(&ddt_verbose);

do_prints();

pr_debug("init done\n");
Expand All @@ -181,6 +219,9 @@ static void __exit test_dynamic_debug_exit(void)
dynamic_debug_unregister_classes(&ddt_classes2);
dynamic_debug_unregister_classes(&ddt_classes3);

dynamic_debug_unregister_classes(&ddt_prio);
dynamic_debug_unregister_classes(&ddt_verbose);

pr_debug("exited\n");
}

Expand Down

0 comments on commit 519000e

Please sign in to comment.