diff options
Diffstat (limited to 'include/linux/dynamic_debug.h')
| -rw-r--r-- | include/linux/dynamic_debug.h | 172 | 
1 files changed, 145 insertions, 27 deletions
| diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h index dce631e678dd..41682278d2e8 100644 --- a/include/linux/dynamic_debug.h +++ b/include/linux/dynamic_debug.h @@ -6,6 +6,8 @@  #include <linux/jump_label.h>  #endif +#include <linux/build_bug.h> +  /*   * An instance of this structure is created in a special   * ELF section at every dynamic debug callsite.  At runtime, @@ -21,6 +23,9 @@ struct _ddebug {  	const char *filename;  	const char *format;  	unsigned int lineno:18; +#define CLS_BITS 6 +	unsigned int class_id:CLS_BITS; +#define _DPRINTK_CLASS_DFLT		((1 << CLS_BITS) - 1)  	/*  	 * The flags field controls the behaviour at the callsite.  	 * The bits here are changed dynamically when the user @@ -51,15 +56,82 @@ struct _ddebug {  #endif  } __attribute__((aligned(8))); +enum class_map_type { +	DD_CLASS_TYPE_DISJOINT_BITS, +	/** +	 * DD_CLASS_TYPE_DISJOINT_BITS: classes are independent, one per bit. +	 * expecting hex input. Built for drm.debug, basis for other types. +	 */ +	DD_CLASS_TYPE_LEVEL_NUM, +	/** +	 * DD_CLASS_TYPE_LEVEL_NUM: input is numeric level, 0-N. +	 * N turns on just bits N-1 .. 0, so N=0 turns all bits off. +	 */ +	DD_CLASS_TYPE_DISJOINT_NAMES, +	/** +	 * DD_CLASS_TYPE_DISJOINT_NAMES: input is a CSV of [+-]CLASS_NAMES, +	 * classes are independent, like _DISJOINT_BITS. +	 */ +	DD_CLASS_TYPE_LEVEL_NAMES, +	/** +	 * DD_CLASS_TYPE_LEVEL_NAMES: input is a CSV of [+-]CLASS_NAMES, +	 * intended for names like: INFO,DEBUG,TRACE, with a module prefix +	 * avoid EMERG,ALERT,CRIT,ERR,WARNING: they're not debug +	 */ +}; + +struct ddebug_class_map { +	struct list_head link; +	struct module *mod; +	const char *mod_name;	/* needed for builtins */ +	const char **class_names; +	const int length; +	const int base;		/* index of 1st .class_id, allows split/shared space */ +	enum class_map_type map_type; +}; +/** + * DECLARE_DYNDBG_CLASSMAP - declare classnames known by a module + * @_var:   a struct ddebug_class_map, passed to module_param_cb + * @_type:  enum class_map_type, chooses bits/verbose, numeric/symbolic + * @_base:  offset of 1st class-name. splits .class_id space + * @classes: class-names used to control class'd prdbgs + */ +#define DECLARE_DYNDBG_CLASSMAP(_var, _maptype, _base, ...)		\ +	static const char *_var##_classnames[] = { __VA_ARGS__ };	\ +	static struct ddebug_class_map __aligned(8) __used		\ +		__section("__dyndbg_classes") _var = {			\ +		.mod = THIS_MODULE,					\ +		.mod_name = KBUILD_MODNAME,				\ +		.base = _base,						\ +		.map_type = _maptype,					\ +		.length = NUM_TYPE_ARGS(char*, __VA_ARGS__),		\ +		.class_names = _var##_classnames,			\ +	} +#define NUM_TYPE_ARGS(eltype, ...)				\ +        (sizeof((eltype[]){__VA_ARGS__}) / sizeof(eltype)) + +/* encapsulate linker provided built-in (or module) dyndbg data */ +struct _ddebug_info { +	struct _ddebug *descs; +	struct ddebug_class_map *classes; +	unsigned int num_descs; +	unsigned int num_classes; +}; + +struct ddebug_class_param { +	union { +		unsigned long *bits; +		unsigned int *lvl; +	}; +	char flags[8]; +	const struct ddebug_class_map *map; +};  #if defined(CONFIG_DYNAMIC_DEBUG_CORE) -/* exported for module authors to exercise >control */ -int dynamic_debug_exec_queries(const char *query, const char *modname); +int ddebug_add_module(struct _ddebug_info *dyndbg, const char *modname); -int ddebug_add_module(struct _ddebug *tab, unsigned int n, -				const char *modname);  extern int ddebug_remove_module(const char *mod_name);  extern __printf(2, 3)  void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...); @@ -87,7 +159,7 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,  			 const struct ib_device *ibdev,  			 const char *fmt, ...); -#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt)		\ +#define DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, cls, fmt)	\  	static struct _ddebug  __aligned(8)			\  	__section("__dyndbg") name = {				\  		.modname = KBUILD_MODNAME,			\ @@ -96,8 +168,14 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,  		.format = (fmt),				\  		.lineno = __LINE__,				\  		.flags = _DPRINTK_FLAGS_DEFAULT,		\ +		.class_id = cls,				\  		_DPRINTK_KEY_INIT				\ -	} +	};							\ +	BUILD_BUG_ON_MSG(cls > _DPRINTK_CLASS_DFLT,		\ +			 "classid value overflow") + +#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt)		\ +	DEFINE_DYNAMIC_DEBUG_METADATA_CLS(name, _DPRINTK_CLASS_DFLT, fmt)  #ifdef CONFIG_JUMP_LABEL @@ -128,17 +206,34 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,  #endif /* CONFIG_JUMP_LABEL */ -#define __dynamic_func_call(id, fmt, func, ...) do {	\ -	DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt);		\ -	if (DYNAMIC_DEBUG_BRANCH(id))			\ -		func(&id, ##__VA_ARGS__);		\ +/* + * Factory macros: ($prefix)dynamic_func_call($suffix) + * + * Lower layer (with __ prefix) gets the callsite metadata, and wraps + * the func inside a debug-branch/static-key construct.  Upper layer + * (with _ prefix) does the UNIQUE_ID once, so that lower can ref the + * name/label multiple times, and tie the elements together. + * Multiple flavors: + * (|_cls):	adds in _DPRINT_CLASS_DFLT as needed + * (|_no_desc):	former gets callsite descriptor as 1st arg (for prdbgs) + */ +#define __dynamic_func_call_cls(id, cls, fmt, func, ...) do {	\ +	DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt);	\ +	if (DYNAMIC_DEBUG_BRANCH(id))				\ +		func(&id, ##__VA_ARGS__);			\  } while (0) +#define __dynamic_func_call(id, fmt, func, ...)				\ +	__dynamic_func_call_cls(id, _DPRINTK_CLASS_DFLT, fmt,		\ +				func, ##__VA_ARGS__) -#define __dynamic_func_call_no_desc(id, fmt, func, ...) do {	\ -	DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt);			\ -	if (DYNAMIC_DEBUG_BRANCH(id))				\ -		func(__VA_ARGS__);				\ +#define __dynamic_func_call_cls_no_desc(id, cls, fmt, func, ...) do {	\ +	DEFINE_DYNAMIC_DEBUG_METADATA_CLS(id, cls, fmt);		\ +	if (DYNAMIC_DEBUG_BRANCH(id))					\ +		func(__VA_ARGS__);					\  } while (0) +#define __dynamic_func_call_no_desc(id, fmt, func, ...)			\ +	__dynamic_func_call_cls_no_desc(id, _DPRINTK_CLASS_DFLT,	\ +					fmt, func, ##__VA_ARGS__)  /*   * "Factory macro" for generating a call to func, guarded by a @@ -148,22 +243,33 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,   * the varargs. Note that fmt is repeated in invocations of this   * macro.   */ +#define _dynamic_func_call_cls(cls, fmt, func, ...)			\ +	__dynamic_func_call_cls(__UNIQUE_ID(ddebug), cls, fmt, func, ##__VA_ARGS__)  #define _dynamic_func_call(fmt, func, ...)				\ -	__dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__) +	_dynamic_func_call_cls(_DPRINTK_CLASS_DFLT, fmt, func, ##__VA_ARGS__) +  /*   * A variant that does the same, except that the descriptor is not   * passed as the first argument to the function; it is only called   * with precisely the macro's varargs.   */ -#define _dynamic_func_call_no_desc(fmt, func, ...)	\ -	__dynamic_func_call_no_desc(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__) +#define _dynamic_func_call_cls_no_desc(cls, fmt, func, ...)		\ +	__dynamic_func_call_cls_no_desc(__UNIQUE_ID(ddebug), cls, fmt,	\ +					func, ##__VA_ARGS__) +#define _dynamic_func_call_no_desc(fmt, func, ...)			\ +	_dynamic_func_call_cls_no_desc(_DPRINTK_CLASS_DFLT, fmt,	\ +				       func, ##__VA_ARGS__) + +#define dynamic_pr_debug_cls(cls, fmt, ...)				\ +	_dynamic_func_call_cls(cls, fmt, __dynamic_pr_debug,		\ +			   pr_fmt(fmt), ##__VA_ARGS__)  #define dynamic_pr_debug(fmt, ...)				\ -	_dynamic_func_call(fmt,	__dynamic_pr_debug,		\ +	_dynamic_func_call(fmt, __dynamic_pr_debug,		\  			   pr_fmt(fmt), ##__VA_ARGS__)  #define dynamic_dev_dbg(dev, fmt, ...)				\ -	_dynamic_func_call(fmt,__dynamic_dev_dbg, 		\ +	_dynamic_func_call(fmt, __dynamic_dev_dbg, 		\  			   dev, fmt, ##__VA_ARGS__)  #define dynamic_netdev_dbg(dev, fmt, ...)			\ @@ -181,14 +287,24 @@ void __dynamic_ibdev_dbg(struct _ddebug *descriptor,  				   KERN_DEBUG, prefix_str, prefix_type,	\  				   rowsize, groupsize, buf, len, ascii) +struct kernel_param; +int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp); +int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp); + +/* for test only, generally expect drm.debug style macro wrappers */ +#define __pr_debug_cls(cls, fmt, ...) do {			\ +	BUILD_BUG_ON_MSG(!__builtin_constant_p(cls),		\ +			 "expecting constant class int/enum");	\ +	dynamic_pr_debug_cls(cls, fmt, ##__VA_ARGS__);		\ +	} while (0) +  #else /* !CONFIG_DYNAMIC_DEBUG_CORE */  #include <linux/string.h>  #include <linux/errno.h>  #include <linux/printk.h> -static inline int ddebug_add_module(struct _ddebug *tab, unsigned int n, -				    const char *modname) +static inline int ddebug_add_module(struct _ddebug_info *dinfo, const char *modname)  {  	return 0;  } @@ -201,7 +317,7 @@ static inline int ddebug_remove_module(const char *mod)  static inline int ddebug_dyndbg_module_param_cb(char *param, char *val,  						const char *modname)  { -	if (strstr(param, "dyndbg")) { +	if (!strcmp(param, "dyndbg")) {  		/* avoid pr_warn(), which wants pr_fmt() fully defined */  		printk(KERN_WARNING "dyndbg param is supported only in "  			"CONFIG_DYNAMIC_DEBUG builds\n"); @@ -221,12 +337,14 @@ static inline int ddebug_dyndbg_module_param_cb(char *param, char *val,  				rowsize, groupsize, buf, len, ascii);	\  	} while (0) -static inline int dynamic_debug_exec_queries(const char *query, const char *modname) -{ -	pr_warn("kernel not built with CONFIG_DYNAMIC_DEBUG_CORE\n"); -	return 0; -} +struct kernel_param; +static inline int param_set_dyndbg_classes(const char *instr, const struct kernel_param *kp) +{ return 0; } +static inline int param_get_dyndbg_classes(char *buffer, const struct kernel_param *kp) +{ return 0; }  #endif /* !CONFIG_DYNAMIC_DEBUG_CORE */ +extern const struct kernel_param_ops param_ops_dyndbg_classes; +  #endif | 
