various dynamic_debug patches
Subsystems (11)
cover various dynamic_debug patches
This started as an experiment to see how hard it would be to change the four pointers in struct _ddebug into relative offsets, a la CONFIG_GENERIC_BUG_RELATIVE_POINTERS, thus saving 16 bytes per pr_debug site (and thus exactly making up for the extra space used by the introduction of jump labels in 9049fc74). I stumbled on a few things that are probably worth fixing regardless of whether the latter half of this series is deemed worthwhile.
Patch relationships: 1-2, 3-4, 5-6 and 15-16 can be applied individually, though 2, 4 and 6 probably makes most sense in the context of the final goal of the series.
7-12 I believe make sense on their own. Patch 13 again only makes sense if we go all the way, and 14 and 17 depend on 13.
18-21 are more preparatory patches, and finally 22 switch over x86-64 to use CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS. I've tested that the end result boots under virtme and that the dynamic_debug control file has the expected contents.
Rasmus Villemoes (22):
linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited linux/device.h: use unique identifier for each struct _ddebug linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited linux/net.h: use unique identifier for each struct _ddebug linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited linux/printk.h: use unique identifier for each struct _ddebug
dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions
dynamic_debug: don't duplicate modname in ddebug_add_module
dynamic_debug: use pointer comparison in ddebug_remove_module
dynamic_debug: remove unused EXPORT_SYMBOLs
dynamic_debug: move pr_err from module.c to ddebug_add_module
dynamic_debug: add static inline stub for ddebug_add_module
dynamic_debug: refactor dynamic_pr_debug and friends
btrfs: implement btrfs_debug* in terms of helper macro
ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
ACPI: remove unused __acpi_handle_debug macro
ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
dynamic_debug: introduce accessors for string members of struct
_ddebug
dynamic_debug: drop use of bitfields in struct _ddebug
dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS
x86: jump_label: introduce ASM_STATIC_KEY_INIT_{TRUE,FALSE}
x86_64: use relative pointers with dynamic debug
arch/x86/Kconfig | 1 + arch/x86/include/asm/dynamic_debug.h | 35 +++++++++ arch/x86/include/asm/jump_label.h | 18 +++++ fs/btrfs/ctree.h | 34 +++------ include/linux/acpi.h | 11 +-- include/linux/device.h | 6 +- include/linux/dynamic_debug.h | 126 +++++++++++++++++++-------------- include/linux/jump_label.h | 2 + include/linux/net.h | 6 +- include/linux/printk.h | 6 +- kernel/module.c | 6 +- lib/Kconfig.debug | 3 + lib/dynamic_debug.c | 133 ++++++++++++++++++++++++----------- 13 files changed, 251 insertions(+), 136 deletions(-) create mode 100644 arch/x86/include/asm/dynamic_debug.h
Signature · 1 line
2.16.4
PATCH 1/22 linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited
dev_dbg_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/device.h +1 -1
@@ -1503,7 +1503,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor, fmt); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \__dynamic_dev_dbg (&descriptor, dev,dev_fmt (fmt), \ ##__VA_ARGS__); \
Signature · 1 line
2.16.4
Re: [PATCH 01/22] linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited
Quoted 7 lines · Rasmus Villemoes
dev_dbg_ratelimitedtests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures thatHAVE_JUMP_LABEL. Use theDYNAMIC_DEBUG_BRANCHwhich is defined appropriately.Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Rasmus Villemoes <[email protected]>
PATCH 2/22 linux/device.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for dev_dbg_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/device.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/device.h +3 -1
@@ -1497,7 +1497,7 @@ do { \ dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)#if defined(CONFIG_DYNAMIC_DEBUG )/* descriptor check is first to prevent flooding with "callbacks suppressed" */ -#define dev_dbg_ratelimited (dev, fmt, ...) \ +#define _dev_dbg_ratelimited (descriptor, dev, fmt, ...) \ do { \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \
@@ -1508,6 +1508,8 @@ do { \__dynamic_dev_dbg (&descriptor, dev,dev_fmt (fmt), \ ##__VA_ARGS__); \ } while (0) +#define dev_dbg_ratelimited (dev, fmt, ...) \ + _dev_dbg_ratelimited(__UNIQUE_ID(ddebug), dev, fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define dev_dbg_ratelimited (dev, fmt, ...) \ do { \
Signature · 1 line
2.16.4
Re: [PATCH 02/22] linux/device.h: use unique identifier for each struct _ddebug
Quoted 9 lines · Rasmus Villemoes
Changes on x86-64 later in this series require that all struct
_ddebugdescriptors in a translation unit uses distinct identifiers. Realize that fordev_dbg_ratelimitedby generating such an identifier via__UNIQUE_IDand pass that to an extra level of macros.No functional change.
Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Rasmus Villemoes <[email protected]>
PATCH 3/22 linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited
In reply to Rasmus Villemoesnet_dbg_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/net.h +1 -1
@@ -263,7 +263,7 @@ do { \#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ + if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ net_ratelimit()) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ ##__VA_ARGS__); \
Signature · 1 line
2.16.4
PATCH 4/22 linux/net.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for net_dbg_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/net.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/net.h +3 -1
@@ -260,7 +260,7 @@ do { \#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)#if defined(CONFIG_DYNAMIC_DEBUG ) -#define net_dbg_ratelimited (fmt, ...) \ +#define _net_dbg_ratelimited (descriptor, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
@@ -268,6 +268,8 @@ do { \__dynamic_pr_debug (&descriptor,pr_fmt (fmt), \ ##__VA_ARGS__); \ } while (0) +#define net_dbg_ratelimited (fmt, ...) \ + _net_dbg_ratelimited(__UNIQUE_ID(ddebug), fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define net_dbg_ratelimited (fmt, ...) \ net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
Signature · 1 line
2.16.4
PATCH 5/22 linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited
In reply to Rasmus Villemoespr_debug_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/printk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/printk.h +1 -1
@@ -466,7 +466,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor,pr_fmt (fmt)); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ }while (0 )
Signature · 1 line
2.16.4
Re: [PATCH 05/22] linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited
Quoted 8 lines · Rasmus Villemoes
pr_debug_ratelimitedtests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures thatHAVE_JUMP_LABEL. Use theDYNAMIC_DEBUG_BRANCHwhich is defined appropriately.Cc Petr Mladek <[email protected]>Cc Steven Rostedt <[email protected]>Signed-off-by Rasmus Villemoes <[email protected]>
It is an independent fix. I am going to take it via printk.git unless anyone is against it.
Best Regards,
Petr
Quoted 20 lines
--- include/linux/printk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/printk.h +1
-1@@ -466,7 +466,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor,pr_fmt (fmt)); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ }while (0 )Signature · 1 line
2.16.4
PATCH 6/22 linux/printk.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for pr_debug_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/printk.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/printk.h +3 -1
@@ -460,7 +460,7 @@ extern int kptr_restrict;/* If you are writing a driver, please use dev_dbg instead */ #if defined(CONFIG_DYNAMIC_DEBUG )/* descriptor check is first to prevent flooding with "callbacks suppressed" */ -#define pr_debug_ratelimited (fmt, ...) \ +#define _pr_debug_ratelimited (descriptor, fmt, ...) \ do { \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \
@@ -470,6 +470,8 @@ do { \ __ratelimit(&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ } while (0) +#define pr_debug_ratelimited (fmt, ...) \ + _pr_debug_ratelimited(__UNIQUE_ID(ddebug), fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define pr_debug_ratelimited (fmt, ...) \ printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Signature · 1 line
2.16.4
Re: [PATCH 06/22] linux/printk.h: use unique identifier for each struct _ddebug
Quoted 10 lines · Rasmus Villemoes
Changes on x86-64 later in this series require that all struct
_ddebugdescriptors in a translation unit uses distinct identifiers. Realize that forpr_debug_ratelimitedby generating such an identifier via__UNIQUE_IDand pass that to an extra level of macros.No functional change.
Cc Petr Mladek <[email protected]>Cc Steven Rostedt <[email protected]>Signed-off-by Rasmus Villemoes <[email protected]>
My understanding is that this patch would go with the other changes via Andrew's tree.
Best Regards,
Petr
Re: [PATCH 06/22] linux/printk.h: use unique identifier for each struct _ddebug
Quoted 8 lines · Petr Mladek
Quoted 7 lines · Rasmus Villemoes
Changes on x86-64 later in this series require that all struct
_ddebugdescriptors in a translation unit uses distinct identifiers. Realize that forpr_debug_ratelimitedby generating such an identifier via__UNIQUE_IDand pass that to an extra level of macros.No functional change.
Quoted 8 lines
Quoted 3 lines
Cc Petr Mladek <[email protected]>Cc Steven Rostedt <[email protected]>Signed-off-by Rasmus Villemoes <[email protected]>Acked-by Petr Mladek <[email protected]>My understanding is that this patch would go with the other changes via Andrew's tree.
Yes. I'm still waiting for x86 folks to comment on the x86 parts, and if they get rejected, this patch (and others in the series) become pointless - unless some other 64 bit arch decides to play along.
Rasmus
PATCH 7/22 dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions
In reply to Rasmus VillemoesInstead of defining DEFINE_DYNAMIC_DEBUG_METADATA in terms of a helper DEFINE_DYNAMIC_DEBUG_METADATA_KEY, that needs another helper dd_key_init to be properly defined, just make the various #ifdef branches define a _DPRINTK_KEY_INIT that can be used directly, similar to _DPRINTK_FLAGS_DEFAULT.
--- include/linux/dynamic_debug.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
include/linux/dynamic_debug.h +7 -15
@@ -71,7 +71,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,const struct net_device *dev, const char *fmt, ...); -#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY (name, fmt, key, init) \ +#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ static struct _ddebug __aligned(8) \ __attribute__((section("__verbose"))) name = { \ .modname = KBUILD_MODNAME, \
@@ -80,35 +80,27 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .format = (fmt), \ .lineno = __LINE__, \ .flags = _DPRINTK_FLAGS_DEFAULT, \ - dd_key_init(key, init) \ + _DPRINTK_KEY_INIT \ }#ifdef HAVE_JUMP_LABEL -#define dd_key_init (key, init) key = (init) -#ifdef DEBUG -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_true, \ - (STATIC_KEY_TRUE_INIT)) + +#define _DPRINTK_KEY_INIT .key.dd_key_true = (STATIC_KEY_TRUE_INIT)#define DYNAMIC_DEBUG_BRANCH (descriptor) \ static_branch_likely(&descriptor.key.dd_key_true)#else -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_false, \ - (STATIC_KEY_FALSE_INIT)) +#define _DPRINTK_KEY_INIT .key.dd_key_false = (STATIC_KEY_FALSE_INIT)#define DYNAMIC_DEBUG_BRANCH (descriptor) \ static_branch_unlikely(&descriptor.key.dd_key_false)#endif -#else - -#define dd_key_init (key, init) +#else /* !HAVE_JUMP_LABEL */ -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, 0, 0) +#define _DPRINTK_KEY_INIT#ifdef DEBUG #define DYNAMIC_DEBUG_BRANCH (descriptor) \
Signature · 1 line
2.16.4
PATCH 8/22 dynamic_debug: don't duplicate modname in ddebug_add_module
In reply to Rasmus VillemoesFor built-in modules, we're already reusing the passed-in string via kstrdup_const(). But for actual modules (i.e. when we're called from dynamic_debug_setup in module.c), the passed-in string (which points at the name[] array inside struct module) is also guaranteed to live at least as long as the struct ddebug_table, since free_module() calls ddebug_remove_module().
--- lib/dynamic_debug.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
lib/dynamic_debug.c +7 -8
@@ -847,17 +847,17 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *name) {struct ddebug_table *dt; -const char *new_name; dt =kzalloc (sizeof (*dt),GFP_KERNEL );if (dt ==NULL )return -ENOMEM ; - new_name =kstrdup_const (name,GFP_KERNEL ); -if (new_name ==NULL ) { -kfree (dt); -return -ENOMEM ; - } - dt->mod_name = new_name; +/* +* For built-in modules, name lives in .rodata and is +* immortal. For loaded modules, name points at the name[] +* member of struct module, which lives at least as long as +* this struct ddebug_table. +*/ + dt->mod_name = name; dt->num_ddebugs = n; dt->ddebugs = tab;
@@ -913,7 +913,6 @@ int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)static void ddebug_table_free (struct ddebug_table *dt) {list_del_init (&dt->link); -kfree_const (dt->mod_name);kfree (dt); }
Signature · 1 line
2.16.4
PATCH 9/22 dynamic_debug: use pointer comparison in ddebug_remove_module
In reply to Rasmus VillemoesNow that we store the passed-in string directly in ddebug_add_module, we can use pointer equality instead of strcmp. This is a little more efficient, but more importantly, this also makes the code somewhat more correct:
Currently, if one loads and then unloads a module whose name happens to match the KBUILD_MODNAME of some built-in functionality (which need not even be modular at all), all of their dynamic debug entries vanish along with those of the actual module. For example, loading and unloading a core.ko hides all pr_debugs from drivers/base/core.c and other built-in files called core.c (incidentally, there is an in-tree module whose name is core, but I just tested this with an out-of-tree trivial one).
--- lib/dynamic_debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/dynamic_debug.c +2 -1
@@ -929,9 +929,10 @@ int ddebug_remove_module(const char *mod_name)mutex_lock (&ddebug_lock);list_for_each_entry_safe (dt, nextdt, &ddebug_tables, link) { -if (!strcmp (dt->mod_name, mod_name)) { +if (dt->mod_name == mod_name) {ddebug_table_free (dt); ret =0 ; +break ; } }mutex_unlock (&ddebug_lock);
Signature · 1 line
2.16.4
PATCH 10/22 dynamic_debug: remove unused EXPORT_SYMBOLs
In reply to Rasmus VillemoesThe only caller of ddebug_{add,remove}_module outside dynamic_debug.c is kernel/module.c, which is obviously not itself modular (though it would be an interesting exercise to make that happen...). I also fail to see how these interfaces can be used by modules, in-tree or not.
--- lib/dynamic_debug.c | 2 -- 1 file changed, 2 deletions(-)
lib/dynamic_debug.c +0 -2
@@ -868,7 +868,6 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,vpr_info ("%u debug prints in module %s\n" , n, dt->mod_name);return 0 ; } -EXPORT_SYMBOL_GPL (ddebug_add_module);/* helper for ddebug_dyndbg_(boot|module)_param_cb */ static int ddebug_dyndbg_param_cb(char *param, char *val,
@@ -938,7 +937,6 @@ int ddebug_remove_module(const char *mod_name)mutex_unlock (&ddebug_lock);return ret; } -EXPORT_SYMBOL_GPL (ddebug_remove_module);static void ddebug_remove_all_tables (void ) {
Signature · 1 line
2.16.4
PATCH 11/22 dynamic_debug: move pr_err from module.c to ddebug_add_module
In reply to Rasmus VillemoesThis serves two purposes: First, we get a diagnostic if (though extremely unlikely), any of the calls of ddebug_add_module for built-in code fails, effectively disabling dynamic_debug. Second, I want to make struct _ddebug opaque, and avoid accessing any of its members outside dynamic_debug.[ch].
--- kernel/module.c | 4 +--- lib/dynamic_debug.c | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/module.c +1 -3
@@ -2716,9 +2716,7 @@ static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigif (!debug)return ;#ifdef CONFIG_DYNAMIC_DEBUG -if (ddebug_add_module (debug, num, mod->name)) -pr_err ("dynamic debug error adding module: %s\n" , - debug->modname); +ddebug_add_module (debug, num, mod->name);#endif }
lib/dynamic_debug.c +3 -1
@@ -849,8 +849,10 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,struct ddebug_table *dt; dt =kzalloc (sizeof (*dt),GFP_KERNEL ); -if (dt ==NULL ) +if (dt ==NULL ) { +pr_err ("error adding module: %s\n" , name);return -ENOMEM ; + }/* * For built-in modules, name lives in .rodata and is * immortal. For loaded modules, name points at the name[]
Signature · 1 line
2.16.4
PATCH 12/22 dynamic_debug: add static inline stub for ddebug_add_module
In reply to Rasmus VillemoesFor symmetry with ddebug_remove_module, and to avoid a bit of ifdeffery in module.c, move the declaration of ddebug_add_module inside #if defined(CONFIG_DYNAMIC_DEBUG) and add a corresponding no-op stub in the #else branch.
--- include/linux/dynamic_debug.h | 10 ++++++++-- kernel/module.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)
include/linux/dynamic_debug.h +8 -2
@@ -47,10 +47,10 @@ struct _ddebug { } __attribute__((aligned(8))); -int ddebug_add_module (struct _ddebug *tab,unsigned int n, -const char *modname);#if defined(CONFIG_DYNAMIC_DEBUG ) +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, ...);
@@ -152,6 +152,12 @@ do { \#include <linux/string.h> #include <linux/errno.h> +static inline int ddebug_add_module (struct _ddebug *tab,unsigned int n, +const char *modname) +{ +return 0 ; +} +static inline int ddebug_remove_module (const char *mod) {return 0 ;
kernel/module.c +0 -2
@@ -2715,9 +2715,7 @@ static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsig {if (!debug)return ; -#ifdef CONFIG_DYNAMIC_DEBUG ddebug_add_module (debug, num, mod->name); -#endif }static void dynamic_debug_remove (struct module *mod,struct _ddebug *debug)
Signature · 1 line
2.16.4
PATCH 13/22 dynamic_debug: refactor dynamic_pr_debug and friends
In reply to Rasmus VillemoesFor the upcoming 'define the _ddebug descriptor in assembly', we need all the descriptors in a translation unit to have distinct names (because asm does not understand C scope). The easiest way to achieve that is as usual with an extra level of macros, passing the identifier to use to the innermost macro, generating it via __UNIQUE_ID or something.
However, instead of repeating that exercise for dynamic_pr_debug, dynamic_dev_dbg, dynamic_netdev_dbg and dynamic_hex_dump separately, we can use the similarity between their bodies to implement them via a common macro, _dynamic_func_call - though the hex_dump case requires a slight variant, since print_hex_dump does not take the _ddebug descriptor. We'll also get to use that variant elsewhere (btrfs).
--- include/linux/dynamic_debug.h | 72 ++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 29 deletions(-)
include/linux/dynamic_debug.h +43 -29
@@ -112,40 +112,54 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,#endif -#define dynamic_pr_debug (fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ - ##__VA_ARGS__); \ +#define __dynamic_func_call (id, fmt, func, ...) do { \ + DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ + if (DYNAMIC_DEBUG_BRANCH(id)) \ + func(&id, ##__VA_ARGS__); \ } while (0) -#define dynamic_dev_dbg (dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_dev_dbg(&descriptor, dev, fmt, \ - ##__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__); \ } while (0) -#define dynamic_netdev_dbg (dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_netdev_dbg(&descriptor, dev, fmt, \ - ##__VA_ARGS__); \ -} while (0) +/* +* "Factory macro" for generating a call to func, guarded by a +* DYNAMIC_DEBUG_BRANCH. The dynamic debug decriptor will be +* initialized using the fmt argument. The function will be called with +* the address of the descriptor as first argument, followed by all +* the varargs. Note that fmt is repeated in invocations of this +* macro. +*/ +#define _dynamic_func_call (fmt, func, ...) \ + __dynamic_func_call(__UNIQUE_ID(ddebug), 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_hex_dump (prefix_str, prefix_type, rowsize, \ - groupsize, buf, len, ascii) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \ - __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - print_hex_dump(KERN_DEBUG, prefix_str, \ - prefix_type, rowsize, groupsize, \ - buf, len, ascii); \ -} while (0) +#define dynamic_pr_debug (fmt, ...) \ + _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, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_netdev_dbg (dev, fmt, ...) \ + _dynamic_func_call(fmt, __dynamic_netdev_dbg, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_hex_dump (prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \ + print_hex_dump, \ + KERN_DEBUG, prefix_str, prefix_type, \ + rowsize, groupsize, buf, len, ascii)#else
Signature · 1 line
2.16.4
PATCH 14/22 btrfs: implement btrfs_debug* in terms of helper macro
In reply to Rasmus VillemoesFirst, the btrfs_debug macros open-code (one possible definition of) DYNAMIC_DEBUG_BRANCH, so they don't benefit from the HAVE_JUMP_LABEL optimization.
Second, changes on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit use distinct identifiers.
Using the new _dynamic_func_call_no_desc helper macro from dynamic_debug.h takes care of both of these.
--- fs/btrfs/ctree.h | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-)
fs/btrfs/ctree.h +10 -24
@@ -3353,31 +3353,17 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);#if defined(CONFIG_DYNAMIC_DEBUG ) #define btrfs_debug(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk(fs_info, KERN_DEBUG fmt, ##args); \ -} while (0) -#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args); \ -} while (0) + _dynamic_func_call_no_desc(fmt, btrfs_printk, \ + fs_info, KERN_DEBUG fmt, ##args) +#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ + _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \ + fs_info, KERN_DEBUG fmt, ##args) #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, \ - ##args);\ -} while (0) -#define btrfs_debug_rl(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, \ - ##args); \ -} while (0) + _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \ + fs_info, KERN_DEBUG fmt, ##args) +#define btrfs_debug_rl(fs_info, fmt, args...) \ + _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \ + fs_info, KERN_DEBUG fmt, ##args)#elif defined(DEBUG ) #define btrfs_debug(fs_info, fmt, args...) \ btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
Signature · 1 line
2.16.4
Re: [PATCH 14/22] btrfs: implement btrfs_debug* in terms of helper macro
Quoted 4 lines · Rasmus Villemoes
First, the
btrfs_debugmacros open-code (one possible definition of)DYNAMIC_DEBUG_BRANCH, so they don't benefit from theHAVE_JUMP_LABELoptimization.
Quoted 8 lines
Second, changes on x86-64 later in this series require that all struct
_ddebugdescriptors in a translation unit use distinct identifiers.Using the new
_dynamic_func_call_no_deschelper macro fromdynamic_debug.htakes care of both of these.Signed-off-by Rasmus Villemoes <[email protected]>
Per the cover letter, I assume you'll take it through your git tree.
Re: [PATCH 14/22] btrfs: implement btrfs_debug* in terms of helper macro
Quoted 11 lines · David Sterba
Quoted 10 lines · Rasmus Villemoes
First, the
btrfs_debugmacros open-code (one possible definition of)DYNAMIC_DEBUG_BRANCH, so they don't benefit from theHAVE_JUMP_LABELoptimization.Second, changes on x86-64 later in this series require that all struct
_ddebugdescriptors in a translation unit use distinct identifiers.Using the new
_dynamic_func_call_no_deschelper macro fromdynamic_debug.htakes care of both of these.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Rasmus Villemoes <[email protected]>Acked-by David Sterba <[email protected]>Per the cover letter, I assume you'll take it through your git tree.
Thanks. I don't have a git tree feeding to -next myself, but these will probably be routed through akpm or x86.
Rasmus
PATCH 15/22 ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
In reply to Rasmus Villemoesdynamic debug may be implemented via static keys, but ACPI is missing out on that runtime benefit since it open-codes one possible definition of DYNAMIC_DEBUG_BRANCH.
--- include/linux/acpi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/acpi.h +1 -1
@@ -982,7 +982,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#define acpi_handle_debug (handle, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ + if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ ##__VA_ARGS__); \ } while (0)
Signature · 1 line
2.16.4
PATCH 16/22 ACPI: remove unused __acpi_handle_debug macro
In reply to Rasmus VillemoesIf CONFIG_DYNAMIC_DEBUG is not set, acpi_handle_debug directly invokes acpi_handle_printk (if DEBUG) or does a no-printk (if !DEBUG). So this macro is never used.
--- include/linux/acpi.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/acpi.h +0 -3
@@ -948,9 +948,6 @@ acpi_handle_printk(const char *level, void *handle, const char *fmt, ...) {}#if defined(CONFIG_ACPI ) && defined(CONFIG_DYNAMIC_DEBUG ) __printf(3, 4)void __acpi_handle_debug (struct _ddebug *descriptor,acpi_handle handle,const char *fmt, ...); -#else -#define __acpi_handle_debug (descriptor, handle, fmt, ...) \ - acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__);#endif /*
Signature · 1 line
2.16.4
PATCH 17/22 ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
In reply to Rasmus VillemoesWith coming changes on x86-64, all dynamic debug descriptors in a translation unit must have distinct names. The macro _dynamic_func_call takes care of that. No functional change.
--- include/linux/acpi.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
include/linux/acpi.h +2 -6
@@ -977,12 +977,8 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#else #if defined(CONFIG_DYNAMIC_DEBUG )#define acpi_handle_debug (handle, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ - ##__VA_ARGS__); \ -} while (0) + _dynamic_func_call(fmt, __acpi_handle_debug, \ + handle, pr_fmt(fmt), ##__VA_ARGS__)#else #define acpi_handle_debug (handle, fmt, ...) \ ({ \
Signature · 1 line
2.16.4
Re: [PATCH 17/22] ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
Quoted 20 lines · CEST Rasmus Villemoes
With coming changes on x86-64, all dynamic debug descriptors in a translation unit must have distinct names. The macro
_dynamic_func_calltakes care of that. No functional change.Signed-off-by Rasmus Villemoes <[email protected]>--- include/linux/acpi.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)include/linux/acpi.h +0
-1@@ -977,12 +977,8 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#else #if defined(CONFIG_DYNAMIC_DEBUG )#define acpi_handle_debug (handle, fmt, ...) \ -do { \
include/linux/acpi.h void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c · line 984
Quoted 10 lines
include/linux/acpi.h +2
-5-DEFINE_DYNAMIC_DEBUG_METADATA (descriptor, fmt); \ -if (DYNAMIC_DEBUG_BRANCH (descriptor)) \ -__acpi_handle_debug (&descriptor, handle,pr_fmt (fmt), \ - ##__VA_ARGS__); \ -} while (0) +_dynamic_func_call (fmt, __acpi_handle_debug, \ + handle, pr_fmt(fmt), ##__VA_ARGS__)#else #define acpi_handle_debug (handle, fmt, ...) \ ({ \
PATCH 18/22 dynamic_debug: introduce accessors for string members of struct _ddebug
In reply to Rasmus VillemoesWhen we introduce compact versions of these pointers (a la CONFIG_GENERIC_BUG_RELATIVE_POINTERS), all access to these members must go via appropriate accessors. This just mass-converts dynamic_debug.c to use the new accessors.
--- lib/dynamic_debug.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-)
lib/dynamic_debug.c +34 -17
@@ -37,6 +37,23 @@#include <linux/device.h> #include <linux/netdevice.h> +static inline const char *dd_modname (const struct _ddebug *dd) +{ +return dd->modname; +} +static inline const char *dd_function (const struct _ddebug *dd) +{ +return dd->function; +} +static inline const char *dd_filename (const struct _ddebug *dd) +{ +return dd->filename; +} +static inline const char *dd_format (const struct _ddebug *dd) +{ +return dd->format; +} +extern struct _ddebug __start___verbose[];extern struct _ddebug __stop___verbose[];
@@ -158,21 +175,21 @@ static int ddebug_change(const struct ddebug_query *query,/* match against the source filename */ if (query->filename && - !match_wildcard (query->filename, dp->filename) && + !match_wildcard (query->filename,dd_filename (dp)) && !match_wildcard (query->filename, -kbasename (dp->filename)) && +kbasename (dd_filename (dp))) && !match_wildcard (query->filename, -trim_prefix (dp->filename))) +trim_prefix (dd_filename (dp))))continue ;/* match against the function */ if (query->function && - !match_wildcard (query->function, dp->function)) + !match_wildcard (query->function,dd_function (dp)))continue ;/* match against the format */ if (query->format && - !strstr (dp->format, query->format)) + !strstr (dd_format (dp), query->format))continue ;/* match against the line number range */
@@ -197,8 +214,8 @@ static int ddebug_change(const struct ddebug_query *query,#endif dp->flags = newflags;vpr_info ("changed %s:%d [%s]%s =%s\n" , -trim_prefix (dp->filename), dp->lineno, - dt->mod_name, dp->function, +trim_prefix (dd_filename (dp)), dp->lineno, + dt->mod_name,dd_function (dp),ddebug_describe_flags (dp, flagbuf,sizeof (flagbuf))); }
@@ -533,10 +550,10 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf) pos_after_tid = pos;if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME) pos +=snprintf (buf + pos,remaining (pos),"%s:" , - desc->modname); +dd_modname (desc));if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) pos +=snprintf (buf + pos,remaining (pos),"%s:" , - desc->function); +dd_function (desc));if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) pos +=snprintf (buf + pos,remaining (pos),"%d:" , desc->lineno);
@@ -790,10 +807,10 @@ static int ddebug_proc_show(struct seq_file *m, void *p) }seq_printf (m,"%s:%u [%s]%s =%s \"" , -trim_prefix (dp->filename), dp->lineno, - iter->table->mod_name, dp->function, +trim_prefix (dd_filename (dp)), dp->lineno, + iter->table->mod_name,dd_function (dp),ddebug_describe_flags (dp, flagsbuf,sizeof (flagsbuf))); -seq_escape (m, dp->format,"\t\r\n\"" ); +seq_escape (m,dd_format (dp),"\t\r\n\"" );seq_puts (m,"\"\n" );return 0 ;
@@ -987,20 +1004,20 @@ static int __init dynamic_debug_init(void)return 1 ; } iter = __start___verbose; - modname = iter->modname; + modname =dd_modname (iter); iter_start = iter;for (; iter < __stop___verbose; iter++) { entries++; - verbose_bytes +=strlen (iter->modname) +strlen (iter->function) - +strlen (iter->filename) +strlen (iter->format); + verbose_bytes +=strlen (dd_modname (iter)) +strlen (dd_function (iter)) + +strlen (dd_filename (iter)) +strlen (dd_format (iter)); -if (strcmp (modname, iter->modname)) { +if (strcmp (modname,dd_modname (iter))) { modct++; ret =ddebug_add_module (iter_start, n, modname);if (ret) goto out_err; n =0 ; - modname = iter->modname; + modname =dd_modname (iter); iter_start = iter; } n++;
Signature · 1 line
2.16.4
PATCH 19/22 dynamic_debug: drop use of bitfields in struct _ddebug
In reply to Rasmus VillemoesProperly initializing a struct containing bitfields in assembly is hard. Instead, merge lineno and flags to a single unsigned int, which we mask manually. This should not cause any worse code than what gcc would need to generate for accessing the bitfields anyway.
Actually, on 64 bit, there is a four byte hole after these fields, so we could just give flags and lineno each their own u32. But I don't think that's worth the ifdeffery.
--- include/linux/dynamic_debug.h | 12 +++++------- lib/dynamic_debug.c | 44 ++++++++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 22 deletions(-)
include/linux/dynamic_debug.h +5 -7
@@ -20,7 +20,6 @@ struct _ddebug {const char *function;const char *filename;const char *format; - unsigned int lineno:18;/* * The flags field controls the behaviour at the callsite. * The bits here are changed dynamically when the user
@@ -37,7 +36,7 @@ struct _ddebug {#else #define _DPRINTK_FLAGS_DEFAULT 0#endif - unsigned int flags:8; +unsigned int flags_lineno;/* flags in lower 8 bits, lineno in upper 24 */ #ifdef HAVE_JUMP_LABEL union { struct static_key_true dd_key_true;
@@ -46,7 +45,7 @@ struct _ddebug {#endif } __attribute__((aligned(8))); - +#define _DPRINTK_FLAGS_LINENO_INIT (((unsigned)__LINE__ << 8) | _DPRINTK_FLAGS_DEFAULT)#if defined(CONFIG_DYNAMIC_DEBUG ) int ddebug_add_module(struct _ddebug *tab, unsigned int n,
@@ -78,8 +77,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .function = __func__, \ .filename = __FILE__, \ .format = (fmt), \ - .lineno = __LINE__, \ - .flags = _DPRINTK_FLAGS_DEFAULT, \ + .flags_lineno = _DPRINTK_FLAGS_LINENO_INIT, \ _DPRINTK_KEY_INIT \ }
@@ -104,10 +102,10 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,#ifdef DEBUG #define DYNAMIC_DEBUG_BRANCH (descriptor) \ - likely(descriptor.flags & _DPRINTK_FLAGS_PRINT) + likely(descriptor.flags_lineno & _DPRINTK_FLAGS_PRINT)#else #define DYNAMIC_DEBUG_BRANCH (descriptor) \ - unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) + unlikely(descriptor.flags_lineno & _DPRINTK_FLAGS_PRINT)#endif #endif
lib/dynamic_debug.c +29 -15
108 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH 20/22 dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS
In reply to Rasmus VillemoesBased on the same idea for struct bug_entry, an architecture can opt-in to use relative pointers in struct _ddebug. It only makes sense for 64 bit architectures, where one saves 16 bytes per entry (out of 40 or 56, depending on CONFIG_JUMP_LABEL). The architecture is responsible for providing a suitable DEFINE_DYNAMIC_DEBUG_METADATA macro in <asm/dynamic_debug.h>.
--- include/linux/dynamic_debug.h | 14 ++++++++++++++ lib/Kconfig.debug | 3 +++ lib/dynamic_debug.c | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+)
include/linux/dynamic_debug.h +14 -0
@@ -16,10 +16,17 @@ struct _ddebug {* These fields are used to drive the user interface * for selecting and displaying debug callsites. */ +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +signed int modname_disp; +signed int function_disp; +signed int filename_disp; +signed int format_disp; +#else const char *modname;const char *function;const char *filename;const char *format; +#endif /* * The flags field controls the behaviour at the callsite. * The bits here are changed dynamically when the user
@@ -70,6 +77,12 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,const struct net_device *dev, const char *fmt, ...); +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +#include <asm/dynamic_debug.h> +#ifndef DEFINE_DYNAMIC_DEBUG_METADATA +# error "asm/dynamic_debug.h must provide definition of DEFINE_DYNAMIC_DEBUG_METADATA" +#endif +#else #define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ static struct _ddebug __aligned(8) \ __attribute__((section("__verbose"))) name = { \
@@ -80,6 +93,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .flags_lineno = _DPRINTK_FLAGS_LINENO_INIT, \ _DPRINTK_KEY_INIT \ } +#endif #ifdef HAVE_JUMP_LABEL
lib/Kconfig.debug +3 -0
@@ -146,6 +146,9 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DYNAMIC_DEBUG_RELATIVE_POINTERS + bool + endmenu # "printk and dmesg options" menu "Compile-time checks and compiler options"
lib/dynamic_debug.c +20 -0
@@ -37,6 +37,24 @@#include <linux/device.h> #include <linux/netdevice.h> +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +static inline const char *dd_modname (const struct _ddebug *dd) +{ +return (const char *)dd + dd->modname_disp; +} +static inline const char *dd_function (const struct _ddebug *dd) +{ +return (const char *)dd + dd->function_disp; +} +static inline const char *dd_filename (const struct _ddebug *dd) +{ +return (const char *)dd + dd->filename_disp; +} +static inline const char *dd_format (const struct _ddebug *dd) +{ +return (const char *)dd + dd->format_disp; +} +#else static inline const char *dd_modname (const struct _ddebug *dd) {return dd->modname;
@@ -53,6 +71,8 @@ static inline const char *dd_format(const struct _ddebug *dd) {return dd->format; } +#endif +static inline unsigned dd_lineno (const struct _ddebug *dd) {return dd->flags_lineno >>8 ;
Signature · 1 line
2.16.4
PATCH 21/22 x86: jump_label: introduce ASM_STATIC_KEY_INIT_{TRUE,FALSE}
In reply to Rasmus VillemoesThese will be useful when defining the contents of (a struct containing) a static key in inline assembly.
--- arch/x86/include/asm/jump_label.h | 18 ++++++++++++++++++ include/linux/jump_label.h | 2 ++ 2 files changed, 20 insertions(+)
arch/x86/include/asm/jump_label.h +18 -0
@@ -110,4 +110,22 @@ struct jump_entry {#endif /* __ASSEMBLY__ */ +#ifdef CONFIG_X86_64 +#define ASM_STATIC_KEY_INIT_TRUE \ + "\t.long 1 \t# .enabled\n" \ + "\t.long 0 \t# <padding>\n" \ + "\t.quad "__stringify(__JUMP_TYPE_TRUE)"\t# .type\n" +#define ASM_STATIC_KEY_INIT_FALSE \ + "\t.long 0 \t# .enabled\n" \ + "\t.long 0 \t# <padding>\n" \ + "\t.quad "__stringify(__JUMP_TYPE_FALSE)"\t# .type\n" +#else +#define ASM_STATIC_KEY_INIT_TRUE \ + "\t.long 1 \t# .enabled\n" \ + "\t.long "__stringify(__JUMP_TYPE_TRUE)"\t# .type\n" +#define ASM_STATIC_KEY_INIT_FALSE \ + "\t.long 0 \t# .enabled\n" \ + "\t.long "__stringify(__JUMP_TYPE_FALSE)"\t# .type\n" +#endif +#endif
include/linux/jump_label.h +2 -0
@@ -132,6 +132,8 @@ struct module;#ifdef HAVE_JUMP_LABEL +#define __JUMP_TYPE_FALSE 0 +#define __JUMP_TYPE_TRUE 1#define JUMP_TYPE_FALSE 0UL#define JUMP_TYPE_TRUE 1UL#define JUMP_TYPE_LINKED 2UL
Signature · 1 line
2.16.4
Re: [PATCH 21/22] x86: jump_label: introduce ASM_STATIC_KEY_INIT_{TRUE,FALSE}
Quoted 2 lines · Rasmus Villemoes
These will be useful when defining the contents of (a struct containing) a static key in inline assembly.
May I politely ask someone in the x86 camp to comment on patches 21,22,23 in this series? If the memory savings is deemed not-worth-the-asm-complexity, a number of preparatory patches become pointless, and I'd like to figure out which ones I should ask Andrew to pick up.
Thanks,
Rasmus
Re: [PATCH 21/22] x86: jump_label: introduce ASM_STATIC_KEY_INIT_{TRUE,FALSE}
In reply to Rasmus VillemoesQuoted 42 lines · Rasmus Villemoes
These will be useful when defining the contents of (a struct containing) a static key in inline assembly.
Signed-off-by Rasmus Villemoes <[email protected]>--- arch/x86/include/asm/jump_label.h | 18 ++++++++++++++++++ include/linux/jump_label.h | 2 ++ 2 files changed, 20 insertions(+)arch/x86/include/asm/jump_label.h +18
-0@@ -110,4 +110,22 @@ struct jump_entry {#endif /* __ASSEMBLY__ */ +#ifdef CONFIG_X86_64 +#define ASM_STATIC_KEY_INIT_TRUE \ + "\t.long 1 \t# .enabled\n" \ + "\t.long 0 \t# <padding>\n" \ + "\t.quad "__stringify(__JUMP_TYPE_TRUE)"\t# .type\n" +#define ASM_STATIC_KEY_INIT_FALSE \ + "\t.long 0 \t# .enabled\n" \ + "\t.long 0 \t# <padding>\n" \ + "\t.quad "__stringify(__JUMP_TYPE_FALSE)"\t# .type\n" +#else +#define ASM_STATIC_KEY_INIT_TRUE \ + "\t.long 1 \t# .enabled\n" \ + "\t.long "__stringify(__JUMP_TYPE_TRUE)"\t# .type\n" +#define ASM_STATIC_KEY_INIT_FALSE \ + "\t.long 0 \t# .enabled\n" \ + "\t.long "__stringify(__JUMP_TYPE_FALSE)"\t# .type\n" +#endif +#endif include/linux/jump_label.h +0
-0
include/linux/jump_label.h struct module; · line 139
Quoted 8 lines
include/linux/jump_label.h +2
-0@@ -132,6 +132,8 @@ struct module;#ifdef HAVE_JUMP_LABEL +#define __JUMP_TYPE_FALSE 0 +#define __JUMP_TYPE_TRUE 1#define JUMP_TYPE_FALSE 0UL#define JUMP_TYPE_TRUE 1UL#define JUMP_TYPE_LINKED 2UL
Looks sane!
Thanks,
Ingo
PATCH 22/22 x86_64: use relative pointers with dynamic debug
In reply to Rasmus VillemoesSimilar to how x86_64 uses bug_entry-relative pointers to reduce sizeof(struct bug_entry), the same thing can now be done for struct _ddebug, saving 16 bytes for each of those (i.e., each pr_debug, dev_dbg etc. in a CONFIG_DYNAMIC_DEBUG kernel).
Note the use of .ifndef/.endif in asm to avoid
fs/aio.c:1382: Error: symbol `__UNIQUE_ID_ddebug112' is already defined
This is due to uses of pr_debug et al in functions that get inlined. In such a case, __COUNTER__ is obviously only expanded once, but the asm() is repeated once for every inlined instance. Letting all instances share the same descriptor object is the right thing to do; that is also what happens when it is the compiler that defines a static object inside an inline(d) function.
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/dynamic_debug.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 arch/x86/include/asm/dynamic_debug.h
arch/x86/Kconfig +1 -0
@@ -90,6 +90,7 @@ config X86 select CLOCKSOURCE_WATCHDOG select DCACHE_WORD_ACCESS select DMA_DIRECT_OPS + select DYNAMIC_DEBUG_RELATIVE_POINTERS if X86_64 select EDAC_ATOMIC_SCRUB select EDAC_SUPPORT select GENERIC_CLOCKEVENTS
arch/x86/include/asm/dynamic_debug.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_DYNAMIC_DEBUG_H +#define _ASM_X86_DYNAMIC_DEBUG_H + +#ifdef HAVE_JUMP_LABEL +# ifdef DEBUG +# define _DPRINTK_ASM_KEY_INIT ASM_STATIC_KEY_INIT_TRUE +# else +# define _DPRINTK_ASM_KEY_INIT ASM_STATIC_KEY_INIT_FALSE +# endif +#else +# define _DPRINTK_ASM_KEY_INIT "" +#endif + +#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ + extern struct _ddebug name; \ + asm volatile(".ifndef " __stringify(name) "\n" \ + ".pushsection __verbose,\"aw\"\n" \ + "1:\n" \ + __stringify(name) ":\n" \ + "\t.long %c0 - 1b \t# _ddebug::modname_disp\n" \ + "\t.long %c1 - 1b \t# _ddebug::function_disp\n" \ + "\t.long %c2 - 1b \t# _ddebug::filename_disp\n" \ + "\t.long %c3 - 1b \t# _ddebug::format_disp\n" \ + "\t.long %c4 \t# _ddebug::flags_lineno\n" \ + "\t.long 0 \t# <padding>\n" \ + _DPRINTK_ASM_KEY_INIT \ + ".popsection\n" \ + ".endif\n" \ + : : "i" (KBUILD_MODNAME), "i" (__func__), \ + "i" (__FILE__), "i" (fmt), \ + "i" (_DPRINTK_FLAGS_LINENO_INIT)) + +#endif /* _ASM_X86_DYNAMIC_DEBUG_H */ +
Signature · 1 line
2.16.4
[PATCH 23/22] x86: dynamic_debug: protect against dynamic debug identifier reuse
Most invocations of DEFINE_DYNAMIC_DEBUG_METADATA happen through "public" macros such as pr_debug or netdev_dbg, which have been updated to ensure they pass a unique identifier to use as the name for the struct _ddebug instance. But it is still possible that someone invokes DEFINE_DYNAMIC_DEBUG_METADATA directly, or creates a new wrapper macro that does not do the extra-level-of-macros-passing-on-a__UNIQUE_ID dance. On x86-64, all subsequent uses of that same identifier would silently reuse the first instance, which is bad.
But we can catch such cases by defining a guard symbol that is unique per expansion of DEFINE_DYNAMIC_DEBUG_METADATA. This still allows gcc to emit multiple copies of some static inline function that has a pr_debug call (because all such copies would pass the same value of %5 to the assembler), but prevents repeated naked DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "bla") - even with a helpful error message saying that '"descriptor" used as _ddebug identifer more than once'.
---
Just in case it wasn't already ugly enough ;)
arch/x86/include/asm/dynamic_debug.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/include/asm/dynamic_debug.h +6 -1
@@ -26,10 +26,15 @@"\t.long 0 \t# <padding>\n" \ _DPRINTK_ASM_KEY_INIT \".popsection\n" \ + ".set "__stringify(name)".ddebug.once, %c5\n" \ + ".elseif "__stringify(name)".ddebug.once - %c5\n" \ + ".line "__stringify(__LINE__) " - 1\n" \ + ".error \"'"__stringify(name)"' used as _ddebug identifier more than once\"\n" \ ".endif\n" \ : : "i" (KBUILD_MODNAME), "i" (__func__), \ "i" (__FILE__), "i" (fmt), \ - "i" (_DPRINTK_FLAGS_LINENO_INIT)) + "i" (_DPRINTK_FLAGS_LINENO_INIT), \ + "i" (__COUNTER__))#endif /* _ASM_X86_DYNAMIC_DEBUG_H */
Signature · 1 line
2.16.4
Re: [PATCH 22/22] x86_64: use relative pointers with dynamic debug
In reply to Rasmus VillemoesQuoted 67 lines · Rasmus Villemoes
Similar to how
x86_64uses bug_entry-relative pointers to reducesizeof(struct bug_entry), the same thing can now be done for struct_ddebug, saving 16 bytes for each of those (i.e., eachpr_debug,dev_dbgetc. in aCONFIG_DYNAMIC_DEBUGkernel).Note the use of .ifndef/.endif in asm to avoid
fs/aio.c:1382: Error: symbol `__UNIQUE_ID_ddebug112' is already definedThis is due to uses of
pr_debuget al in functions that get inlined. In such a case,__COUNTER__is obviously only expanded once, but theasm()is repeated once for every inlined instance. Letting all instances share the same descriptor object is the right thing to do; that is also what happens when it is the compiler that defines a static object inside an inline(d) function.Signed-off-by Rasmus Villemoes <[email protected]>--- arch/x86/Kconfig | 1 + arch/x86/include/asm/dynamic_debug.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 arch/x86/include/asm/dynamic_debug.harch/x86/Kconfig +1
-0@@ -90,6 +90,7 @@ config X86 select CLOCKSOURCE_WATCHDOG select DCACHE_WORD_ACCESS select DMA_DIRECT_OPS + select DYNAMIC_DEBUG_RELATIVE_POINTERS if X86_64 select EDAC_ATOMIC_SCRUB select EDAC_SUPPORT select GENERIC_CLOCKEVENTSarch/x86/include/asm/dynamic_debug.h new file +25
-0@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_DYNAMIC_DEBUG_H +#define _ASM_X86_DYNAMIC_DEBUG_H + +#ifdef HAVE_JUMP_LABEL +# ifdef DEBUG +# define _DPRINTK_ASM_KEY_INIT ASM_STATIC_KEY_INIT_TRUE +# else +# define _DPRINTK_ASM_KEY_INIT ASM_STATIC_KEY_INIT_FALSE +# endif +#else +# define _DPRINTK_ASM_KEY_INIT "" +#endif + +#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ + extern struct _ddebug name; \ + asm volatile(".ifndef " __stringify(name) "\n" \ + ".pushsection __verbose,\"aw\"\n" \ + "1:\n" \ + __stringify(name) ":\n" \ + "\t.long %c0 - 1b \t# _ddebug::modname_disp\n" \ + "\t.long %c1 - 1b \t# _ddebug::function_disp\n" \ + "\t.long %c2 - 1b \t# _ddebug::filename_disp\n" \ + "\t.long %c3 - 1b \t# _ddebug::format_disp\n" \ + "\t.long %c4 \t# _ddebug::flags_lineno\n" \
arch/x86/include/asm/dynamic_debug.h line 35
Quoted 10 lines
arch/x86/include/asm/dynamic_debug.h new file +10
-0+"\t.long 0 \t# <padding>\n" \ + _DPRINTK_ASM_KEY_INIT \ +".popsection\n" \ +".endif\n" \ + : : "i" (KBUILD_MODNAME), "i" (__func__), \ +"i" (__FILE__),"i" (fmt), \ + "i" (_DPRINTK_FLAGS_LINENO_INIT)) + +#endif /* _ASM_X86_DYNAMIC_DEBUG_H */ +
Thanks,
Ingo
Re: [PATCH 22/22] x86_64: use relative pointers with dynamic debug
Quoted 9 lines · Ingo Molnar
Quoted 4 lines · Rasmus Villemoes
Similar to how
x86_64uses bug_entry-relative pointers to reducesizeof(struct bug_entry), the same thing can now be done for struct_ddebug, saving 16 bytes for each of those (i.e., eachpr_debug,dev_dbgetc. in aCONFIG_DYNAMIC_DEBUGkernel).Reviewed-by Ingo Molnar <[email protected]>
Thanks! Can I assume this also applies to the latecomer 23/22, which I think I'm gonna squash with 22/22? Then I'll resend the series with various tags included and ask Andrew to pick it up.
Rasmus
Quoted 11 lines · CEST Rasmus Villemoes
This started as an experiment to see how hard it would be to change the four pointers in struct
_ddebuginto relative offsets, a laCONFIG_GENERIC_BUG_RELATIVE_POINTERS, thus saving 16 bytes perpr_debugsite (and thus exactly making up for the extra space used by the introduction of jump labels in9049fc74). I stumbled on a few things that are probably worth fixing regardless of whether the latter half of this series is deemed worthwhile.Patch relationships: 1-2, 3-4, 5-6 and 15-16 can be applied individually, though 2, 4 and 6 probably makes most sense in the context of the final goal of the series.
OK, I can take the [15-16/22] separately.
Thanks,
Rafael
Quoted 9 lines · CEST Rafael J. Wysocki
Quoted 8 lines · CEST Rasmus Villemoes
This started as an experiment to see how hard it would be to change the four pointers in struct
_ddebuginto relative offsets, a laCONFIG_GENERIC_BUG_RELATIVE_POINTERS, thus saving 16 bytes perpr_debugsite (and thus exactly making up for the extra space used by the introduction of jump labels in9049fc74). I stumbled on a few things that are probably worth fixing regardless of whether the latter half of this series is deemed worthwhile.
Quoted 5 lines
Quoted 3 lines
Patch relationships: 1-2, 3-4, 5-6 and 15-16 can be applied individually, though 2, 4 and 6 probably makes most sense in the context of the final goal of the series.
OK, I can take the [15-16/22] separately.
And they have been applied now.
Thanks,
Rafael
Quoted 12 lines · Rasmus Villemoes
This started as an experiment to see how hard it would be to change the four pointers in struct
_ddebuginto relative offsets, a laCONFIG_GENERIC_BUG_RELATIVE_POINTERS, thus saving 16 bytes perpr_debugsite (and thus exactly making up for the extra space used by the introduction of jump labels in9049fc74). I stumbled on a few things that are probably worth fixing regardless of whether the latter half of this series is deemed worthwhile.Patch relationships: 1-2, 3-4, 5-6 and 15-16 can be applied individually, though 2, 4 and 6 probably makes most sense in the context of the final goal of the series.
Quoted 8 lines
7-12 I believe make sense on their own. Patch 13 again only makes sense if we go all the way, and 14 and 17 depend on 13.
18-21 are more preparatory patches, and finally 22 switch over x86-64 to use
CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS. I've tested that the end result boots under virtme and that thedynamic_debugcontrol file has the expected contents.
I would like to to see all these patches included. Feel free to add:
I've been wanting to add DYNAMIC_DEBUG_BRANCH to the [dev,net,pr].*ratelimited functions. That should reduce the size of the text as well.
Thanks,
-Jason
v2 cover various dynamic_debug patches
In reply to Rasmus Villemoesv2: Added various acks/reviews. I'll follow up with rewriting the x86 part as asm macros once that work is in mainline.
Patches 15, 16 are in next-20181009; in hindsight I should probably have asked Rafael not to pick those. Patch 17 textually depend on those, and patch 19 removes the .flags field, so depends on 15 so that there are no references to that field. I'm included all patches here hoping that the merge conflicts are trivial, given that it's just same patches present in multiple branches.
Andrew, can you pick up these to give them some time in -next?
v1 cover letter:
This started as an experiment to see how hard it would be to change the four pointers in struct _ddebug into relative offsets, a la CONFIG_GENERIC_BUG_RELATIVE_POINTERS, thus saving 16 bytes per pr_debug site (and thus exactly making up for the extra space used by the introduction of jump labels in 9049fc74). I stumbled on a few things that are probably worth fixing regardless of whether the latter half of this series is deemed worthwhile.
Patch relationships: 1-2, 3-4, 5-6 and 15-16 can be applied individually, though 2, 4 and 6 probably makes most sense in the context of the final goal of the series.
7-12 I believe make sense on their own. Patch 13 again only makes sense if we go all the way, and 14 and 17 depend on 13.
18-21 are more preparatory patches, and finally 22 switch over x86-64 to use CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS. I've tested that the end result boots under virtme and that the dynamic_debug control file has the expected contents.
Rasmus Villemoes (23):
linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited linux/device.h: use unique identifier for each struct _ddebug linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited linux/net.h: use unique identifier for each struct _ddebug linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited linux/printk.h: use unique identifier for each struct _ddebug
dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions
dynamic_debug: don't duplicate modname in ddebug_add_module
dynamic_debug: use pointer comparison in ddebug_remove_module
dynamic_debug: remove unused EXPORT_SYMBOLs
dynamic_debug: move pr_err from module.c to ddebug_add_module
dynamic_debug: add static inline stub for ddebug_add_module
dynamic_debug: refactor dynamic_pr_debug and friends
btrfs: implement btrfs_debug* in terms of helper macro
ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
ACPI: remove unused __acpi_handle_debug macro
ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
dynamic_debug: introduce accessors for string members of struct
_ddebug
dynamic_debug: drop use of bitfields in struct _ddebug
dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS
x86: jump_label: introduce ASM_STATIC_KEY_INIT_{TRUE,FALSE}
x86_64: use relative pointers with dynamic debug
x86: dynamic_debug: protect against dynamic debug identifier reuse
arch/x86/Kconfig | 1 + arch/x86/include/asm/dynamic_debug.h | 40 ++++++++ arch/x86/include/asm/jump_label.h | 18 ++++ fs/btrfs/ctree.h | 34 ++----- include/linux/acpi.h | 11 +-- include/linux/device.h | 6 +- include/linux/dynamic_debug.h | 126 +++++++++++++++---------- include/linux/jump_label.h | 2 + include/linux/net.h | 6 +- include/linux/printk.h | 6 +- kernel/module.c | 6 +- lib/Kconfig.debug | 3 + lib/dynamic_debug.c | 133 ++++++++++++++++++--------- 13 files changed, 256 insertions(+), 136 deletions(-) create mode 100644 arch/x86/include/asm/dynamic_debug.h
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 1/23 linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited
dev_dbg_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/device.h +1 -1
@@ -1503,7 +1503,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor, fmt); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \__dynamic_dev_dbg (&descriptor, dev,dev_fmt (fmt), \ ##__VA_ARGS__); \
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 2/23 linux/device.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for dev_dbg_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/device.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/device.h +3 -1
@@ -1497,7 +1497,7 @@ do { \ dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)#if defined(CONFIG_DYNAMIC_DEBUG )/* descriptor check is first to prevent flooding with "callbacks suppressed" */ -#define dev_dbg_ratelimited (dev, fmt, ...) \ +#define _dev_dbg_ratelimited (descriptor, dev, fmt, ...) \ do { \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \
@@ -1508,6 +1508,8 @@ do { \__dynamic_dev_dbg (&descriptor, dev,dev_fmt (fmt), \ ##__VA_ARGS__); \ } while (0) +#define dev_dbg_ratelimited (dev, fmt, ...) \ + _dev_dbg_ratelimited(__UNIQUE_ID(ddebug), dev, fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define dev_dbg_ratelimited (dev, fmt, ...) \ do { \
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 3/23 linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited
In reply to Rasmus Villemoesnet_dbg_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/net.h +1 -1
@@ -263,7 +263,7 @@ do { \#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ + if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ net_ratelimit()) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ ##__VA_ARGS__); \
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 4/23 linux/net.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for net_dbg_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/net.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/net.h +3 -1
@@ -260,7 +260,7 @@ do { \#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)#if defined(CONFIG_DYNAMIC_DEBUG ) -#define net_dbg_ratelimited (fmt, ...) \ +#define _net_dbg_ratelimited (descriptor, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
@@ -268,6 +268,8 @@ do { \__dynamic_pr_debug (&descriptor,pr_fmt (fmt), \ ##__VA_ARGS__); \ } while (0) +#define net_dbg_ratelimited (fmt, ...) \ + _net_dbg_ratelimited(__UNIQUE_ID(ddebug), fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define net_dbg_ratelimited (fmt, ...) \ net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 5/23 linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited
In reply to Rasmus Villemoespr_debug_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/printk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/printk.h +1 -1
@@ -466,7 +466,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor,pr_fmt (fmt)); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ }while (0 )
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 6/23 linux/printk.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for pr_debug_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/printk.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/printk.h +3 -1
@@ -460,7 +460,7 @@ extern int kptr_restrict;/* If you are writing a driver, please use dev_dbg instead */ #if defined(CONFIG_DYNAMIC_DEBUG )/* descriptor check is first to prevent flooding with "callbacks suppressed" */ -#define pr_debug_ratelimited (fmt, ...) \ +#define _pr_debug_ratelimited (descriptor, fmt, ...) \ do { \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \
@@ -470,6 +470,8 @@ do { \ __ratelimit(&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ } while (0) +#define pr_debug_ratelimited (fmt, ...) \ + _pr_debug_ratelimited(__UNIQUE_ID(ddebug), fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define pr_debug_ratelimited (fmt, ...) \ printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 7/23 dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions
In reply to Rasmus VillemoesInstead of defining DEFINE_DYNAMIC_DEBUG_METADATA in terms of a helper DEFINE_DYNAMIC_DEBUG_METADATA_KEY, that needs another helper dd_key_init to be properly defined, just make the various #ifdef branches define a _DPRINTK_KEY_INIT that can be used directly, similar to _DPRINTK_FLAGS_DEFAULT.
--- include/linux/dynamic_debug.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
include/linux/dynamic_debug.h +7 -15
@@ -71,7 +71,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,const struct net_device *dev, const char *fmt, ...); -#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY (name, fmt, key, init) \ +#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ static struct _ddebug __aligned(8) \ __attribute__((section("__verbose"))) name = { \ .modname = KBUILD_MODNAME, \
@@ -80,35 +80,27 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .format = (fmt), \ .lineno = __LINE__, \ .flags = _DPRINTK_FLAGS_DEFAULT, \ - dd_key_init(key, init) \ + _DPRINTK_KEY_INIT \ }#ifdef HAVE_JUMP_LABEL -#define dd_key_init (key, init) key = (init) -#ifdef DEBUG -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_true, \ - (STATIC_KEY_TRUE_INIT)) + +#define _DPRINTK_KEY_INIT .key.dd_key_true = (STATIC_KEY_TRUE_INIT)#define DYNAMIC_DEBUG_BRANCH (descriptor) \ static_branch_likely(&descriptor.key.dd_key_true)#else -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_false, \ - (STATIC_KEY_FALSE_INIT)) +#define _DPRINTK_KEY_INIT .key.dd_key_false = (STATIC_KEY_FALSE_INIT)#define DYNAMIC_DEBUG_BRANCH (descriptor) \ static_branch_unlikely(&descriptor.key.dd_key_false)#endif -#else - -#define dd_key_init (key, init) +#else /* !HAVE_JUMP_LABEL */ -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, 0, 0) +#define _DPRINTK_KEY_INIT#ifdef DEBUG #define DYNAMIC_DEBUG_BRANCH (descriptor) \
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 8/23 dynamic_debug: don't duplicate modname in ddebug_add_module
In reply to Rasmus VillemoesFor built-in modules, we're already reusing the passed-in string via kstrdup_const(). But for actual modules (i.e. when we're called from dynamic_debug_setup in module.c), the passed-in string (which points at the name[] array inside struct module) is also guaranteed to live at least as long as the struct ddebug_table, since free_module() calls ddebug_remove_module().
--- lib/dynamic_debug.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
lib/dynamic_debug.c +7 -8
@@ -847,17 +847,17 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *name) {struct ddebug_table *dt; -const char *new_name; dt =kzalloc (sizeof (*dt),GFP_KERNEL );if (dt ==NULL )return -ENOMEM ; - new_name =kstrdup_const (name,GFP_KERNEL ); -if (new_name ==NULL ) { -kfree (dt); -return -ENOMEM ; - } - dt->mod_name = new_name; +/* +* For built-in modules, name lives in .rodata and is +* immortal. For loaded modules, name points at the name[] +* member of struct module, which lives at least as long as +* this struct ddebug_table. +*/ + dt->mod_name = name; dt->num_ddebugs = n; dt->ddebugs = tab;
@@ -913,7 +913,6 @@ int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)static void ddebug_table_free (struct ddebug_table *dt) {list_del_init (&dt->link); -kfree_const (dt->mod_name);kfree (dt); }
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 9/23 dynamic_debug: use pointer comparison in ddebug_remove_module
In reply to Rasmus VillemoesNow that we store the passed-in string directly in ddebug_add_module, we can use pointer equality instead of strcmp. This is a little more efficient, but more importantly, this also makes the code somewhat more correct:
Currently, if one loads and then unloads a module whose name happens to match the KBUILD_MODNAME of some built-in functionality (which need not even be modular at all), all of their dynamic debug entries vanish along with those of the actual module. For example, loading and unloading a core.ko hides all pr_debugs from drivers/base/core.c and other built-in files called core.c (incidentally, there is an in-tree module whose name is core, but I just tested this with an out-of-tree trivial one).
--- lib/dynamic_debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/dynamic_debug.c +2 -1
@@ -929,9 +929,10 @@ int ddebug_remove_module(const char *mod_name)mutex_lock (&ddebug_lock);list_for_each_entry_safe (dt, nextdt, &ddebug_tables, link) { -if (!strcmp (dt->mod_name, mod_name)) { +if (dt->mod_name == mod_name) {ddebug_table_free (dt); ret =0 ; +break ; } }mutex_unlock (&ddebug_lock);
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 10/23 dynamic_debug: remove unused EXPORT_SYMBOLs
In reply to Rasmus VillemoesThe only caller of ddebug_{add,remove}_module outside dynamic_debug.c is kernel/module.c, which is obviously not itself modular (though it would be an interesting exercise to make that happen...). I also fail to see how these interfaces can be used by modules, in-tree or not.
--- lib/dynamic_debug.c | 2 -- 1 file changed, 2 deletions(-)
lib/dynamic_debug.c +0 -2
@@ -868,7 +868,6 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,vpr_info ("%u debug prints in module %s\n" , n, dt->mod_name);return 0 ; } -EXPORT_SYMBOL_GPL (ddebug_add_module);/* helper for ddebug_dyndbg_(boot|module)_param_cb */ static int ddebug_dyndbg_param_cb(char *param, char *val,
@@ -938,7 +937,6 @@ int ddebug_remove_module(const char *mod_name)mutex_unlock (&ddebug_lock);return ret; } -EXPORT_SYMBOL_GPL (ddebug_remove_module);static void ddebug_remove_all_tables (void ) {
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 11/23 dynamic_debug: move pr_err from module.c to ddebug_add_module
In reply to Rasmus VillemoesThis serves two purposes: First, we get a diagnostic if (though extremely unlikely), any of the calls of ddebug_add_module for built-in code fails, effectively disabling dynamic_debug. Second, I want to make struct _ddebug opaque, and avoid accessing any of its members outside dynamic_debug.[ch].
--- kernel/module.c | 4 +--- lib/dynamic_debug.c | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/module.c +1 -3
@@ -2716,9 +2716,7 @@ static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigif (!debug)return ;#ifdef CONFIG_DYNAMIC_DEBUG -if (ddebug_add_module (debug, num, mod->name)) -pr_err ("dynamic debug error adding module: %s\n" , - debug->modname); +ddebug_add_module (debug, num, mod->name);#endif }
lib/dynamic_debug.c +3 -1
@@ -849,8 +849,10 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,struct ddebug_table *dt; dt =kzalloc (sizeof (*dt),GFP_KERNEL ); -if (dt ==NULL ) +if (dt ==NULL ) { +pr_err ("error adding module: %s\n" , name);return -ENOMEM ; + }/* * For built-in modules, name lives in .rodata and is * immortal. For loaded modules, name points at the name[]
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 12/23 dynamic_debug: add static inline stub for ddebug_add_module
In reply to Rasmus VillemoesFor symmetry with ddebug_remove_module, and to avoid a bit of ifdeffery in module.c, move the declaration of ddebug_add_module inside #if defined(CONFIG_DYNAMIC_DEBUG) and add a corresponding no-op stub in the #else branch.
--- include/linux/dynamic_debug.h | 10 ++++++++-- kernel/module.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)
include/linux/dynamic_debug.h +8 -2
@@ -47,10 +47,10 @@ struct _ddebug { } __attribute__((aligned(8))); -int ddebug_add_module (struct _ddebug *tab,unsigned int n, -const char *modname);#if defined(CONFIG_DYNAMIC_DEBUG ) +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, ...);
@@ -152,6 +152,12 @@ do { \#include <linux/string.h> #include <linux/errno.h> +static inline int ddebug_add_module (struct _ddebug *tab,unsigned int n, +const char *modname) +{ +return 0 ; +} +static inline int ddebug_remove_module (const char *mod) {return 0 ;
kernel/module.c +0 -2
@@ -2715,9 +2715,7 @@ static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsig {if (!debug)return ; -#ifdef CONFIG_DYNAMIC_DEBUG ddebug_add_module (debug, num, mod->name); -#endif }static void dynamic_debug_remove (struct module *mod,struct _ddebug *debug)
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 13/23 dynamic_debug: refactor dynamic_pr_debug and friends
In reply to Rasmus VillemoesFor the upcoming 'define the _ddebug descriptor in assembly', we need all the descriptors in a translation unit to have distinct names (because asm does not understand C scope). The easiest way to achieve that is as usual with an extra level of macros, passing the identifier to use to the innermost macro, generating it via __UNIQUE_ID or something.
However, instead of repeating that exercise for dynamic_pr_debug, dynamic_dev_dbg, dynamic_netdev_dbg and dynamic_hex_dump separately, we can use the similarity between their bodies to implement them via a common macro, _dynamic_func_call - though the hex_dump case requires a slight variant, since print_hex_dump does not take the _ddebug descriptor. We'll also get to use that variant elsewhere (btrfs).
--- include/linux/dynamic_debug.h | 72 +++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 29 deletions(-)
include/linux/dynamic_debug.h +43 -29
@@ -112,40 +112,54 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,#endif -#define dynamic_pr_debug (fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ - ##__VA_ARGS__); \ +#define __dynamic_func_call (id, fmt, func, ...) do { \ + DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ + if (DYNAMIC_DEBUG_BRANCH(id)) \ + func(&id, ##__VA_ARGS__); \ } while (0) -#define dynamic_dev_dbg (dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_dev_dbg(&descriptor, dev, fmt, \ - ##__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__); \ } while (0) -#define dynamic_netdev_dbg (dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_netdev_dbg(&descriptor, dev, fmt, \ - ##__VA_ARGS__); \ -} while (0) +/* +* "Factory macro" for generating a call to func, guarded by a +* DYNAMIC_DEBUG_BRANCH. The dynamic debug decriptor will be +* initialized using the fmt argument. The function will be called with +* the address of the descriptor as first argument, followed by all +* the varargs. Note that fmt is repeated in invocations of this +* macro. +*/ +#define _dynamic_func_call (fmt, func, ...) \ + __dynamic_func_call(__UNIQUE_ID(ddebug), 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_hex_dump (prefix_str, prefix_type, rowsize, \ - groupsize, buf, len, ascii) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \ - __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - print_hex_dump(KERN_DEBUG, prefix_str, \ - prefix_type, rowsize, groupsize, \ - buf, len, ascii); \ -} while (0) +#define dynamic_pr_debug (fmt, ...) \ + _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, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_netdev_dbg (dev, fmt, ...) \ + _dynamic_func_call(fmt, __dynamic_netdev_dbg, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_hex_dump (prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \ + print_hex_dump, \ + KERN_DEBUG, prefix_str, prefix_type, \ + rowsize, groupsize, buf, len, ascii)#else
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 14/23 btrfs: implement btrfs_debug* in terms of helper macro
In reply to Rasmus VillemoesFirst, the btrfs_debug macros open-code (one possible definition of) DYNAMIC_DEBUG_BRANCH, so they don't benefit from the HAVE_JUMP_LABEL optimization.
Second, changes on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit use distinct identifiers.
Using the new _dynamic_func_call_no_desc helper macro from dynamic_debug.h takes care of both of these.
--- fs/btrfs/ctree.h | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-)
fs/btrfs/ctree.h +10 -24
@@ -3353,31 +3353,17 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);#if defined(CONFIG_DYNAMIC_DEBUG ) #define btrfs_debug(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk(fs_info, KERN_DEBUG fmt, ##args); \ -} while (0) -#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args); \ -} while (0) + _dynamic_func_call_no_desc(fmt, btrfs_printk, \ + fs_info, KERN_DEBUG fmt, ##args) +#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ + _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \ + fs_info, KERN_DEBUG fmt, ##args) #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, \ - ##args);\ -} while (0) -#define btrfs_debug_rl(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, \ - ##args); \ -} while (0) + _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \ + fs_info, KERN_DEBUG fmt, ##args) +#define btrfs_debug_rl(fs_info, fmt, args...) \ + _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \ + fs_info, KERN_DEBUG fmt, ##args)#elif defined(DEBUG ) #define btrfs_debug(fs_info, fmt, args...) \ btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 15/23 ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
In reply to Rasmus Villemoesdynamic debug may be implemented via static keys, but ACPI is missing out on that runtime benefit since it open-codes one possible definition of DYNAMIC_DEBUG_BRANCH.
--- include/linux/acpi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/acpi.h +1 -1
@@ -982,7 +982,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#define acpi_handle_debug (handle, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ + if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ ##__VA_ARGS__); \ } while (0)
Signature · 1 line
2.19.1.3.g1d92a00e68
Re: [PATCH v2 15/23] ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
Quoted 8 lines · Rasmus Villemoes
dynamic debug may be implemented via static keys, but ACPI is missing out on that runtime benefit since it open-codes one possible definition of
DYNAMIC_DEBUG_BRANCH.Acked-by Jason Baron <[email protected]>Signed-off-by Rasmus Villemoes <[email protected]>
Quoted 20 lines
--- include/linux/acpi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/acpi.h +1
-2@@ -982,7 +982,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#define acpi_handle_debug (handle, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ + if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ ##__VA_ARGS__); \ } while (0) --2.19.1.3.g1d92a00e68
PATCH v2 16/23 ACPI: remove unused __acpi_handle_debug macro
In reply to Rasmus VillemoesIf CONFIG_DYNAMIC_DEBUG is not set, acpi_handle_debug directly invokes acpi_handle_printk (if DEBUG) or does a no-printk (if !DEBUG). So this macro is never used.
--- include/linux/acpi.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/acpi.h +0 -3
@@ -948,9 +948,6 @@ acpi_handle_printk(const char *level, void *handle, const char *fmt, ...) {}#if defined(CONFIG_ACPI ) && defined(CONFIG_DYNAMIC_DEBUG ) __printf(3, 4)void __acpi_handle_debug (struct _ddebug *descriptor,acpi_handle handle,const char *fmt, ...); -#else -#define __acpi_handle_debug (descriptor, handle, fmt, ...) \ - acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__);#endif /*
Signature · 1 line
2.19.1.3.g1d92a00e68
Re: [PATCH v2 16/23] ACPI: remove unused __acpi_handle_debug macro
Quoted 8 lines · Rasmus Villemoes
If
CONFIG_DYNAMIC_DEBUGis not set,acpi_handle_debugdirectly invokesacpi_handle_printk(if DEBUG) or does a no-printk (if !DEBUG). So this macro is never used.Acked-by Jason Baron <[email protected]>Signed-off-by Rasmus Villemoes <[email protected]>
Quoted 21 lines
--- include/linux/acpi.h | 3 --- 1 file changed, 3 deletions(-)include/linux/acpi.h +0
-4@@ -948,9 +948,6 @@ acpi_handle_printk(const char *level, void *handle, const char *fmt, ...) {}#if defined(CONFIG_ACPI ) && defined(CONFIG_DYNAMIC_DEBUG ) __printf(3, 4)void __acpi_handle_debug (struct _ddebug *descriptor,acpi_handle handle,const char *fmt, ...); -#else -#define __acpi_handle_debug (descriptor, handle, fmt, ...) \ - acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__);#endif /* -- 2.19.1.3.g1d92a00e68
PATCH v2 17/23 ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
In reply to Rasmus VillemoesWith coming changes on x86-64, all dynamic debug descriptors in a translation unit must have distinct names. The macro _dynamic_func_call takes care of that. No functional change.
--- include/linux/acpi.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
include/linux/acpi.h +2 -6
@@ -977,12 +977,8 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#else #if defined(CONFIG_DYNAMIC_DEBUG )#define acpi_handle_debug (handle, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ - ##__VA_ARGS__); \ -} while (0) + _dynamic_func_call(fmt, __acpi_handle_debug, \ + handle, pr_fmt(fmt), ##__VA_ARGS__)#else #define acpi_handle_debug (handle, fmt, ...) \ ({ \
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 18/23 dynamic_debug: introduce accessors for string members of struct _ddebug
In reply to Rasmus VillemoesWhen we introduce compact versions of these pointers (a la CONFIG_GENERIC_BUG_RELATIVE_POINTERS), all access to these members must go via appropriate accessors. This just mass-converts dynamic_debug.c to use the new accessors.
--- lib/dynamic_debug.c | 51 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-)
lib/dynamic_debug.c +34 -17
@@ -37,6 +37,23 @@#include <linux/device.h> #include <linux/netdevice.h> +static inline const char *dd_modname (const struct _ddebug *dd) +{ +return dd->modname; +} +static inline const char *dd_function (const struct _ddebug *dd) +{ +return dd->function; +} +static inline const char *dd_filename (const struct _ddebug *dd) +{ +return dd->filename; +} +static inline const char *dd_format (const struct _ddebug *dd) +{ +return dd->format; +} +extern struct _ddebug __start___verbose[];extern struct _ddebug __stop___verbose[];
@@ -158,21 +175,21 @@ static int ddebug_change(const struct ddebug_query *query,/* match against the source filename */ if (query->filename && - !match_wildcard (query->filename, dp->filename) && + !match_wildcard (query->filename,dd_filename (dp)) && !match_wildcard (query->filename, -kbasename (dp->filename)) && +kbasename (dd_filename (dp))) && !match_wildcard (query->filename, -trim_prefix (dp->filename))) +trim_prefix (dd_filename (dp))))continue ;/* match against the function */ if (query->function && - !match_wildcard (query->function, dp->function)) + !match_wildcard (query->function,dd_function (dp)))continue ;/* match against the format */ if (query->format && - !strstr (dp->format, query->format)) + !strstr (dd_format (dp), query->format))continue ;/* match against the line number range */
@@ -197,8 +214,8 @@ static int ddebug_change(const struct ddebug_query *query,#endif dp->flags = newflags;vpr_info ("changed %s:%d [%s]%s =%s\n" , -trim_prefix (dp->filename), dp->lineno, - dt->mod_name, dp->function, +trim_prefix (dd_filename (dp)), dp->lineno, + dt->mod_name,dd_function (dp),ddebug_describe_flags (dp, flagbuf,sizeof (flagbuf))); }
@@ -533,10 +550,10 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf) pos_after_tid = pos;if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME) pos +=snprintf (buf + pos,remaining (pos),"%s:" , - desc->modname); +dd_modname (desc));if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) pos +=snprintf (buf + pos,remaining (pos),"%s:" , - desc->function); +dd_function (desc));if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) pos +=snprintf (buf + pos,remaining (pos),"%d:" , desc->lineno);
@@ -790,10 +807,10 @@ static int ddebug_proc_show(struct seq_file *m, void *p) }seq_printf (m,"%s:%u [%s]%s =%s \"" , -trim_prefix (dp->filename), dp->lineno, - iter->table->mod_name, dp->function, +trim_prefix (dd_filename (dp)), dp->lineno, + iter->table->mod_name,dd_function (dp),ddebug_describe_flags (dp, flagsbuf,sizeof (flagsbuf))); -seq_escape (m, dp->format,"\t\r\n\"" ); +seq_escape (m,dd_format (dp),"\t\r\n\"" );seq_puts (m,"\"\n" );return 0 ;
@@ -987,20 +1004,20 @@ static int __init dynamic_debug_init(void)return 1 ; } iter = __start___verbose; - modname = iter->modname; + modname =dd_modname (iter); iter_start = iter;for (; iter < __stop___verbose; iter++) { entries++; - verbose_bytes +=strlen (iter->modname) +strlen (iter->function) - +strlen (iter->filename) +strlen (iter->format); + verbose_bytes +=strlen (dd_modname (iter)) +strlen (dd_function (iter)) + +strlen (dd_filename (iter)) +strlen (dd_format (iter)); -if (strcmp (modname, iter->modname)) { +if (strcmp (modname,dd_modname (iter))) { modct++; ret =ddebug_add_module (iter_start, n, modname);if (ret) goto out_err; n =0 ; - modname = iter->modname; + modname =dd_modname (iter); iter_start = iter; } n++;
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 19/23 dynamic_debug: drop use of bitfields in struct _ddebug
In reply to Rasmus VillemoesProperly initializing a struct containing bitfields in assembly is hard. Instead, merge lineno and flags to a single unsigned int, which we mask manually. This should not cause any worse code than what gcc would need to generate for accessing the bitfields anyway.
Actually, on 64 bit, there is a four byte hole after these fields, so we could just give flags and lineno each their own u32. But I don't think that's worth the ifdeffery.
--- include/linux/dynamic_debug.h | 12 ++++------ lib/dynamic_debug.c | 44 +++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 22 deletions(-)
include/linux/dynamic_debug.h +5 -7
@@ -20,7 +20,6 @@ struct _ddebug {const char *function;const char *filename;const char *format; - unsigned int lineno:18;/* * The flags field controls the behaviour at the callsite. * The bits here are changed dynamically when the user
@@ -37,7 +36,7 @@ struct _ddebug {#else #define _DPRINTK_FLAGS_DEFAULT 0#endif - unsigned int flags:8; +unsigned int flags_lineno;/* flags in lower 8 bits, lineno in upper 24 */ #ifdef HAVE_JUMP_LABEL union { struct static_key_true dd_key_true;
@@ -46,7 +45,7 @@ struct _ddebug {#endif } __attribute__((aligned(8))); - +#define _DPRINTK_FLAGS_LINENO_INIT (((unsigned)__LINE__ << 8) | _DPRINTK_FLAGS_DEFAULT)#if defined(CONFIG_DYNAMIC_DEBUG ) int ddebug_add_module(struct _ddebug *tab, unsigned int n,
@@ -78,8 +77,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .function = __func__, \ .filename = __FILE__, \ .format = (fmt), \ - .lineno = __LINE__, \ - .flags = _DPRINTK_FLAGS_DEFAULT, \ + .flags_lineno = _DPRINTK_FLAGS_LINENO_INIT, \ _DPRINTK_KEY_INIT \ }
@@ -104,10 +102,10 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,#ifdef DEBUG #define DYNAMIC_DEBUG_BRANCH (descriptor) \ - likely(descriptor.flags & _DPRINTK_FLAGS_PRINT) + likely(descriptor.flags_lineno & _DPRINTK_FLAGS_PRINT)#else #define DYNAMIC_DEBUG_BRANCH (descriptor) \ - unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) + unlikely(descriptor.flags_lineno & _DPRINTK_FLAGS_PRINT)#endif #endif
lib/dynamic_debug.c +29 -15
108 lines not on this page · raw message
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 20/23 dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS
In reply to Rasmus VillemoesBased on the same idea for struct bug_entry, an architecture can opt-in to use relative pointers in struct _ddebug. It only makes sense for 64 bit architectures, where one saves 16 bytes per entry (out of 40 or 56, depending on CONFIG_JUMP_LABEL). The architecture is responsible for providing a suitable DEFINE_DYNAMIC_DEBUG_METADATA macro in <asm/dynamic_debug.h>.
--- include/linux/dynamic_debug.h | 14 ++++++++++++++ lib/Kconfig.debug | 3 +++ lib/dynamic_debug.c | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+)
include/linux/dynamic_debug.h +14 -0
@@ -16,10 +16,17 @@ struct _ddebug {* These fields are used to drive the user interface * for selecting and displaying debug callsites. */ +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +signed int modname_disp; +signed int function_disp; +signed int filename_disp; +signed int format_disp; +#else const char *modname;const char *function;const char *filename;const char *format; +#endif /* * The flags field controls the behaviour at the callsite. * The bits here are changed dynamically when the user
@@ -70,6 +77,12 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,const struct net_device *dev, const char *fmt, ...); +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +#include <asm/dynamic_debug.h> +#ifndef DEFINE_DYNAMIC_DEBUG_METADATA +# error "asm/dynamic_debug.h must provide definition of DEFINE_DYNAMIC_DEBUG_METADATA" +#endif +#else #define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ static struct _ddebug __aligned(8) \ __attribute__((section("__verbose"))) name = { \
@@ -80,6 +93,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .flags_lineno = _DPRINTK_FLAGS_LINENO_INIT, \ _DPRINTK_KEY_INIT \ } +#endif #ifdef HAVE_JUMP_LABEL
lib/Kconfig.debug +3 -0
@@ -146,6 +146,9 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DYNAMIC_DEBUG_RELATIVE_POINTERS + bool + endmenu # "printk and dmesg options" menu "Compile-time checks and compiler options"
lib/dynamic_debug.c +20 -0
@@ -37,6 +37,24 @@#include <linux/device.h> #include <linux/netdevice.h> +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +static inline const char *dd_modname (const struct _ddebug *dd) +{ +return (const char *)dd + dd->modname_disp; +} +static inline const char *dd_function (const struct _ddebug *dd) +{ +return (const char *)dd + dd->function_disp; +} +static inline const char *dd_filename (const struct _ddebug *dd) +{ +return (const char *)dd + dd->filename_disp; +} +static inline const char *dd_format (const struct _ddebug *dd) +{ +return (const char *)dd + dd->format_disp; +} +#else static inline const char *dd_modname (const struct _ddebug *dd) {return dd->modname;
@@ -53,6 +71,8 @@ static inline const char *dd_format(const struct _ddebug *dd) {return dd->format; } +#endif +static inline unsigned dd_lineno (const struct _ddebug *dd) {return dd->flags_lineno >>8 ;
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 21/23 x86: jump_label: introduce ASM_STATIC_KEY_INIT_{TRUE,FALSE}
In reply to Rasmus VillemoesThese will be useful when defining the contents of (a struct containing) a static key in inline assembly.
--- arch/x86/include/asm/jump_label.h | 18 ++++++++++++++++++ include/linux/jump_label.h | 2 ++ 2 files changed, 20 insertions(+)
arch/x86/include/asm/jump_label.h +18 -0
@@ -110,4 +110,22 @@ struct jump_entry {#endif /* __ASSEMBLY__ */ +#ifdef CONFIG_X86_64 +#define ASM_STATIC_KEY_INIT_TRUE \ + "\t.long 1 \t# .enabled\n" \ + "\t.long 0 \t# <padding>\n" \ + "\t.quad "__stringify(__JUMP_TYPE_TRUE)"\t# .type\n" +#define ASM_STATIC_KEY_INIT_FALSE \ + "\t.long 0 \t# .enabled\n" \ + "\t.long 0 \t# <padding>\n" \ + "\t.quad "__stringify(__JUMP_TYPE_FALSE)"\t# .type\n" +#else +#define ASM_STATIC_KEY_INIT_TRUE \ + "\t.long 1 \t# .enabled\n" \ + "\t.long "__stringify(__JUMP_TYPE_TRUE)"\t# .type\n" +#define ASM_STATIC_KEY_INIT_FALSE \ + "\t.long 0 \t# .enabled\n" \ + "\t.long "__stringify(__JUMP_TYPE_FALSE)"\t# .type\n" +#endif +#endif
include/linux/jump_label.h +2 -0
@@ -132,6 +132,8 @@ struct module;#ifdef HAVE_JUMP_LABEL +#define __JUMP_TYPE_FALSE 0 +#define __JUMP_TYPE_TRUE 1#define JUMP_TYPE_FALSE 0UL#define JUMP_TYPE_TRUE 1UL#define JUMP_TYPE_LINKED 2UL
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 22/23 x86_64: use relative pointers with dynamic debug
In reply to Rasmus VillemoesSimilar to how x86_64 uses bug_entry-relative pointers to reduce sizeof(struct bug_entry), the same thing can now be done for struct _ddebug, saving 16 bytes for each of those (i.e., each pr_debug, dev_dbg etc. in a CONFIG_DYNAMIC_DEBUG kernel).
Note the use of .ifndef/.endif in asm to avoid
fs/aio.c:1382: Error: symbol `__UNIQUE_ID_ddebug112' is already defined
This is due to uses of pr_debug et al in functions that get inlined. In such a case, __COUNTER__ is obviously only expanded once, but the asm() is repeated once for every inlined instance. Letting all instances share the same descriptor object is the right thing to do; that is also what happens when it is the compiler that defines a static object inside an inline(d) function.
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/dynamic_debug.h | 35 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 arch/x86/include/asm/dynamic_debug.h
arch/x86/Kconfig +1 -0
@@ -90,6 +90,7 @@ config X86 select CLOCKSOURCE_WATCHDOG select DCACHE_WORD_ACCESS select DMA_DIRECT_OPS + select DYNAMIC_DEBUG_RELATIVE_POINTERS if X86_64 select EDAC_ATOMIC_SCRUB select EDAC_SUPPORT select GENERIC_CLOCKEVENTS
arch/x86/include/asm/dynamic_debug.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_DYNAMIC_DEBUG_H +#define _ASM_X86_DYNAMIC_DEBUG_H + +#ifdef HAVE_JUMP_LABEL +# ifdef DEBUG +# define _DPRINTK_ASM_KEY_INIT ASM_STATIC_KEY_INIT_TRUE +# else +# define _DPRINTK_ASM_KEY_INIT ASM_STATIC_KEY_INIT_FALSE +# endif +#else +# define _DPRINTK_ASM_KEY_INIT "" +#endif + +#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ + extern struct _ddebug name; \ + asm volatile(".ifndef " __stringify(name) "\n" \ + ".pushsection __verbose,\"aw\"\n" \ + "1:\n" \ + __stringify(name) ":\n" \ + "\t.long %c0 - 1b \t# _ddebug::modname_disp\n" \ + "\t.long %c1 - 1b \t# _ddebug::function_disp\n" \ + "\t.long %c2 - 1b \t# _ddebug::filename_disp\n" \ + "\t.long %c3 - 1b \t# _ddebug::format_disp\n" \ + "\t.long %c4 \t# _ddebug::flags_lineno\n" \ + "\t.long 0 \t# <padding>\n" \ + _DPRINTK_ASM_KEY_INIT \ + ".popsection\n" \ + ".endif\n" \ + : : "i" (KBUILD_MODNAME), "i" (__func__), \ + "i" (__FILE__), "i" (fmt), \ + "i" (_DPRINTK_FLAGS_LINENO_INIT)) + +#endif /* _ASM_X86_DYNAMIC_DEBUG_H */ +
Signature · 1 line
2.19.1.3.g1d92a00e68
PATCH v2 23/23 x86: dynamic_debug: protect against dynamic debug identifier reuse
In reply to Rasmus VillemoesMost invocations of DEFINE_DYNAMIC_DEBUG_METADATA happen through "public" macros such as pr_debug or netdev_dbg, which have been updated to ensure they pass a unique identifier to use as the name for the struct _ddebug instance. But it is still possible that someone invokes DEFINE_DYNAMIC_DEBUG_METADATA directly, or creates a new wrapper macro that does not do the extra-level-of-macros-passing-on-a__UNIQUE_ID dance. On x86-64, all subsequent uses of that same identifier would silently reuse the first instance, which is bad.
But we can catch such cases by defining a guard symbol that is unique per expansion of DEFINE_DYNAMIC_DEBUG_METADATA. This still allows gcc to emit multiple copies of some static inline function that has a pr_debug call (because all such copies would pass the same value of %5 to the assembler), but prevents repeated naked DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, "bla") - even with a helpful error message saying that '"descriptor" used as _ddebug identifer more than once'.
--- arch/x86/include/asm/dynamic_debug.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/include/asm/dynamic_debug.h +6 -1
@@ -26,10 +26,15 @@"\t.long 0 \t# <padding>\n" \ _DPRINTK_ASM_KEY_INIT \".popsection\n" \ + ".set "__stringify(name)".ddebug.once, %c5\n" \ + ".elseif "__stringify(name)".ddebug.once - %c5\n" \ + ".line "__stringify(__LINE__) " - 1\n" \ + ".error \"'"__stringify(name)"' used as _ddebug identifier more than once\"\n" \ ".endif\n" \ : : "i" (KBUILD_MODNAME), "i" (__func__), \ "i" (__FILE__), "i" (fmt), \ - "i" (_DPRINTK_FLAGS_LINENO_INIT)) + "i" (_DPRINTK_FLAGS_LINENO_INIT), \ + "i" (__COUNTER__))#endif /* _ASM_X86_DYNAMIC_DEBUG_H */
Signature · 1 line
2.19.1.3.g1d92a00e68
Rafael J. Wysocki
maintainerQuoted 6 lines · Rasmus Villemoes
v2: Added various acks/reviews. I'll follow up with rewriting the x86 part as asm macros once that work is in mainline.
Patches 15, 16 are in next-20181009; in hindsight I should probably have asked Rafael not to pick those.
So I have dropped them (which was easy enough to do).
Thanks,
Rafael
v3 cover various dynamic_debug patches
In reply to Rasmus VillemoesThis started as an experiment to see how hard it would be to change the four pointers in struct _ddebug into relative offsets, a la CONFIG_GENERIC_BUG_RELATIVE_POINTERS, thus saving 16 bytes per pr_debug site (and thus exactly making up for the extra space used by the introduction of jump labels in 9049fc74). I stumbled on a few things that are probably worth fixing regardless of whether that goal is deemed worthwhile.
v2: Added various acks/reviews.
v3: Rebased on top of v4.20-rc1, and (consequently) reimplemented the x86 part using Nadav's asm macro infrastructure. I've taken the liberty of preserving acks/reviews for the first 20, since the rebase was completely clean. OTOH, I've removed any acks/reviews from the last three patches, since they are essentially completely new in this version.
Since there are some interdependencies, it's simplest if these go through the same tree. Andrew, can I get you to pick up patches 1 through 17? They should be ready for some time in -next. If and when the last three (new) patches get ack'ed, I'll ask you to pick up the last 6 (Jason has ack'ed 18-20, but they don't make much sense without at least one arch opting in to use DYNAMIC_DEBUG_RELATIVE_POINTERS).
Rasmus Villemoes (23):
linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited linux/device.h: use unique identifier for each struct _ddebug linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited linux/net.h: use unique identifier for each struct _ddebug linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited linux/printk.h: use unique identifier for each struct _ddebug
dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions
dynamic_debug: don't duplicate modname in ddebug_add_module
dynamic_debug: use pointer comparison in ddebug_remove_module
dynamic_debug: remove unused EXPORT_SYMBOLs
dynamic_debug: move pr_err from module.c to ddebug_add_module
dynamic_debug: add static inline stub for ddebug_add_module
dynamic_debug: refactor dynamic_pr_debug and friends
btrfs: implement btrfs_debug* in terms of helper macro
ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
ACPI: remove unused __acpi_handle_debug macro
ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
dynamic_debug: introduce accessors for string members of struct
_ddebug
dynamic_debug: drop use of bitfields in struct _ddebug
dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS
jump_label: move JUMP_TYPE_* constants to new asm-generic file
x86: jump_label: introduce asm macros STATIC_KEY_INIT{,_TRUE,_FALSE}
x86_64: use relative pointers with dynamic debug
arch/x86/Kconfig | 1 + arch/x86/include/asm/dynamic_debug.h | 58 ++++++++++++ arch/x86/include/asm/jump_label.h | 17 ++++ arch/x86/kernel/macros.S | 1 + fs/btrfs/ctree.h | 34 ++----- include/asm-generic/jump_label.h | 11 +++ include/linux/acpi.h | 11 +-- include/linux/device.h | 6 +- include/linux/dynamic_debug.h | 126 +++++++++++++++---------- include/linux/jump_label.h | 6 +- include/linux/net.h | 6 +- include/linux/printk.h | 6 +- kernel/module.c | 6 +- lib/Kconfig.debug | 3 + lib/dynamic_debug.c | 133 ++++++++++++++++++--------- 15 files changed, 284 insertions(+), 141 deletions(-) create mode 100644 arch/x86/include/asm/dynamic_debug.h create mode 100644 include/asm-generic/jump_label.h
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 1/23 linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited
dev_dbg_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/device.h +1 -1
@@ -1538,7 +1538,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor, fmt); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \__dynamic_dev_dbg (&descriptor, dev,dev_fmt (fmt), \ ##__VA_ARGS__); \
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 2/23 linux/device.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for dev_dbg_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/device.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/device.h +3 -1
@@ -1532,7 +1532,7 @@ do { \ dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)#if defined(CONFIG_DYNAMIC_DEBUG )/* descriptor check is first to prevent flooding with "callbacks suppressed" */ -#define dev_dbg_ratelimited (dev, fmt, ...) \ +#define _dev_dbg_ratelimited (descriptor, dev, fmt, ...) \ do { \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \
@@ -1543,6 +1543,8 @@ do { \__dynamic_dev_dbg (&descriptor, dev,dev_fmt (fmt), \ ##__VA_ARGS__); \ } while (0) +#define dev_dbg_ratelimited (dev, fmt, ...) \ + _dev_dbg_ratelimited(__UNIQUE_ID(ddebug), dev, fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define dev_dbg_ratelimited (dev, fmt, ...) \ do { \
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 3/23 linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited
In reply to Rasmus Villemoesnet_dbg_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/net.h +1 -1
@@ -263,7 +263,7 @@ do { \#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ + if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ net_ratelimit()) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ ##__VA_ARGS__); \
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 4/23 linux/net.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for net_dbg_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/net.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/net.h +3 -1
@@ -260,7 +260,7 @@ do { \#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)#if defined(CONFIG_DYNAMIC_DEBUG ) -#define net_dbg_ratelimited (fmt, ...) \ +#define _net_dbg_ratelimited (descriptor, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \
@@ -268,6 +268,8 @@ do { \__dynamic_pr_debug (&descriptor,pr_fmt (fmt), \ ##__VA_ARGS__); \ } while (0) +#define net_dbg_ratelimited (fmt, ...) \ + _net_dbg_ratelimited(__UNIQUE_ID(ddebug), fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define net_dbg_ratelimited (fmt, ...) \ net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
Signature · 1 line
2.19.1.6.gbde171bbf5
Re: [PATCH v3 04/23] linux/net.h: use unique identifier for each struct _ddebug
Quoted 6 lines · Rasmus Villemoes
Changes on x86-64 later in this series require that all struct
_ddebugdescriptors in a translation unit uses distinct identifiers. Realize that fornet_dbg_ratelimitedby generating such an identifier via__UNIQUE_IDand pass that to an extra level of macros.No functional change.
Why does this require an extra indirection _<macro>?
Quoted 29 lines
Acked-by Jason Baron <[email protected]>Signed-off-by Rasmus Villemoes <[email protected]>--- include/linux/net.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)include/linux/net.h +3
-1@@ -260,7 +260,7 @@ do { \#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__)#if defined(CONFIG_DYNAMIC_DEBUG ) -#define net_dbg_ratelimited (fmt, ...) \ +#define _net_dbg_ratelimited (descriptor, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ if (DYNAMIC_DEBUG_BRANCH(descriptor) && \@@ -268,6 +268,8 @@ do { \__dynamic_pr_debug (&descriptor,pr_fmt (fmt), \ ##__VA_ARGS__); \ } while (0) +#define net_dbg_ratelimited (fmt, ...) \ + _net_dbg_ratelimited(__UNIQUE_ID(ddebug), fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define net_dbg_ratelimited (fmt, ...) \ net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__)
Re: [PATCH v3 04/23] linux/net.h: use unique identifier for each struct _ddebug
Quoted 10 lines · Joe Perches
Quoted 6 lines · Rasmus Villemoes
Changes on x86-64 later in this series require that all struct
_ddebugdescriptors in a translation unit uses distinct identifiers. Realize that fornet_dbg_ratelimitedby generating such an identifier via__UNIQUE_IDand pass that to an extra level of macros.No functional change.
Why does this require an extra indirection _<macro>?
Because the identifier used in the
Quoted 1 line
Quoted 1 line
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);
line must be the same as the one in the
Quoted 1 line
Quoted 1 line
if (
DYNAMIC_DEBUG_BRANCH(descriptor)&&
line. That identifier used to be simply "descriptor", with C scope rules making that ok. But because of the asm games I'm playing later, I need to generate a fresh identifier for each instance. That identifier must be referenced in two places in the C source - hence the need to use an extra level of macros to have the __UNIQUE_ID() expanded before _net_dbg_ratelimited gets expanded.
More or less every use of __UNIQUE_ID requires such an extra level (because one very rarely needs to use an identifier exactly once - the point of giving stuff a name is to refer to it again.)
Rasmus
PATCH v3 5/23 linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited
In reply to Rasmus Villemoespr_debug_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation on architectures that HAVE_JUMP_LABEL. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/printk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/printk.h +1 -1
@@ -466,7 +466,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor,pr_fmt (fmt)); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ }while (0 )
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 6/23 linux/printk.h: use unique identifier for each struct _ddebug
In reply to Rasmus VillemoesChanges on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit uses distinct identifiers. Realize that for pr_debug_ratelimited by generating such an identifier via __UNIQUE_ID and pass that to an extra level of macros.
No functional change.
--- include/linux/printk.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/printk.h +3 -1
@@ -460,7 +460,7 @@ extern int kptr_restrict;/* If you are writing a driver, please use dev_dbg instead */ #if defined(CONFIG_DYNAMIC_DEBUG )/* descriptor check is first to prevent flooding with "callbacks suppressed" */ -#define pr_debug_ratelimited (fmt, ...) \ +#define _pr_debug_ratelimited (descriptor, fmt, ...) \ do { \ static DEFINE_RATELIMIT_STATE(_rs, \ DEFAULT_RATELIMIT_INTERVAL, \
@@ -470,6 +470,8 @@ do { \ __ratelimit(&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ } while (0) +#define pr_debug_ratelimited (fmt, ...) \ + _pr_debug_ratelimited(__UNIQUE_ID(ddebug), fmt, ##__VA_ARGS__)#elif defined(DEBUG )#define pr_debug_ratelimited (fmt, ...) \ printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 7/23 dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions
In reply to Rasmus VillemoesInstead of defining DEFINE_DYNAMIC_DEBUG_METADATA in terms of a helper DEFINE_DYNAMIC_DEBUG_METADATA_KEY, that needs another helper dd_key_init to be properly defined, just make the various #ifdef branches define a _DPRINTK_KEY_INIT that can be used directly, similar to _DPRINTK_FLAGS_DEFAULT.
--- include/linux/dynamic_debug.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
include/linux/dynamic_debug.h +7 -15
@@ -71,7 +71,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,const struct net_device *dev, const char *fmt, ...); -#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY (name, fmt, key, init) \ +#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ static struct _ddebug __aligned(8) \ __attribute__((section("__verbose"))) name = { \ .modname = KBUILD_MODNAME, \
@@ -80,35 +80,27 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .format = (fmt), \ .lineno = __LINE__, \ .flags = _DPRINTK_FLAGS_DEFAULT, \ - dd_key_init(key, init) \ + _DPRINTK_KEY_INIT \ }#ifdef HAVE_JUMP_LABEL -#define dd_key_init (key, init) key = (init) -#ifdef DEBUG -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_true, \ - (STATIC_KEY_TRUE_INIT)) + +#define _DPRINTK_KEY_INIT .key.dd_key_true = (STATIC_KEY_TRUE_INIT)#define DYNAMIC_DEBUG_BRANCH (descriptor) \ static_branch_likely(&descriptor.key.dd_key_true)#else -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_false, \ - (STATIC_KEY_FALSE_INIT)) +#define _DPRINTK_KEY_INIT .key.dd_key_false = (STATIC_KEY_FALSE_INIT)#define DYNAMIC_DEBUG_BRANCH (descriptor) \ static_branch_unlikely(&descriptor.key.dd_key_false)#endif -#else - -#define dd_key_init (key, init) +#else /* !HAVE_JUMP_LABEL */ -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, 0, 0) +#define _DPRINTK_KEY_INIT#ifdef DEBUG #define DYNAMIC_DEBUG_BRANCH (descriptor) \
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 8/23 dynamic_debug: don't duplicate modname in ddebug_add_module
In reply to Rasmus VillemoesFor built-in modules, we're already reusing the passed-in string via kstrdup_const(). But for actual modules (i.e. when we're called from dynamic_debug_setup in module.c), the passed-in string (which points at the name[] array inside struct module) is also guaranteed to live at least as long as the struct ddebug_table, since free_module() calls ddebug_remove_module().
--- lib/dynamic_debug.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
lib/dynamic_debug.c +7 -8
@@ -847,17 +847,17 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *name) {struct ddebug_table *dt; -const char *new_name; dt =kzalloc (sizeof (*dt),GFP_KERNEL );if (dt ==NULL )return -ENOMEM ; - new_name =kstrdup_const (name,GFP_KERNEL ); -if (new_name ==NULL ) { -kfree (dt); -return -ENOMEM ; - } - dt->mod_name = new_name; +/* +* For built-in modules, name lives in .rodata and is +* immortal. For loaded modules, name points at the name[] +* member of struct module, which lives at least as long as +* this struct ddebug_table. +*/ + dt->mod_name = name; dt->num_ddebugs = n; dt->ddebugs = tab;
@@ -913,7 +913,6 @@ int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)static void ddebug_table_free (struct ddebug_table *dt) {list_del_init (&dt->link); -kfree_const (dt->mod_name);kfree (dt); }
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 9/23 dynamic_debug: use pointer comparison in ddebug_remove_module
In reply to Rasmus VillemoesNow that we store the passed-in string directly in ddebug_add_module, we can use pointer equality instead of strcmp. This is a little more efficient, but more importantly, this also makes the code somewhat more correct:
Currently, if one loads and then unloads a module whose name happens to match the KBUILD_MODNAME of some built-in functionality (which need not even be modular at all), all of their dynamic debug entries vanish along with those of the actual module. For example, loading and unloading a core.ko hides all pr_debugs from drivers/base/core.c and other built-in files called core.c (incidentally, there is an in-tree module whose name is core, but I just tested this with an out-of-tree trivial one).
--- lib/dynamic_debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/dynamic_debug.c +2 -1
@@ -929,9 +929,10 @@ int ddebug_remove_module(const char *mod_name)mutex_lock (&ddebug_lock);list_for_each_entry_safe (dt, nextdt, &ddebug_tables, link) { -if (!strcmp (dt->mod_name, mod_name)) { +if (dt->mod_name == mod_name) {ddebug_table_free (dt); ret =0 ; +break ; } }mutex_unlock (&ddebug_lock);
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 10/23 dynamic_debug: remove unused EXPORT_SYMBOLs
In reply to Rasmus VillemoesThe only caller of ddebug_{add,remove}_module outside dynamic_debug.c is kernel/module.c, which is obviously not itself modular (though it would be an interesting exercise to make that happen...). I also fail to see how these interfaces can be used by modules, in-tree or not.
--- lib/dynamic_debug.c | 2 -- 1 file changed, 2 deletions(-)
lib/dynamic_debug.c +0 -2
@@ -868,7 +868,6 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,vpr_info ("%u debug prints in module %s\n" , n, dt->mod_name);return 0 ; } -EXPORT_SYMBOL_GPL (ddebug_add_module);/* helper for ddebug_dyndbg_(boot|module)_param_cb */ static int ddebug_dyndbg_param_cb(char *param, char *val,
@@ -938,7 +937,6 @@ int ddebug_remove_module(const char *mod_name)mutex_unlock (&ddebug_lock);return ret; } -EXPORT_SYMBOL_GPL (ddebug_remove_module);static void ddebug_remove_all_tables (void ) {
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 11/23 dynamic_debug: move pr_err from module.c to ddebug_add_module
In reply to Rasmus VillemoesThis serves two purposes: First, we get a diagnostic if (though extremely unlikely), any of the calls of ddebug_add_module for built-in code fails, effectively disabling dynamic_debug. Second, I want to make struct _ddebug opaque, and avoid accessing any of its members outside dynamic_debug.[ch].
--- kernel/module.c | 4 +--- lib/dynamic_debug.c | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/module.c +1 -3
@@ -2716,9 +2716,7 @@ static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigif (!debug)return ;#ifdef CONFIG_DYNAMIC_DEBUG -if (ddebug_add_module (debug, num, mod->name)) -pr_err ("dynamic debug error adding module: %s\n" , - debug->modname); +ddebug_add_module (debug, num, mod->name);#endif }
lib/dynamic_debug.c +3 -1
@@ -849,8 +849,10 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,struct ddebug_table *dt; dt =kzalloc (sizeof (*dt),GFP_KERNEL ); -if (dt ==NULL ) +if (dt ==NULL ) { +pr_err ("error adding module: %s\n" , name);return -ENOMEM ; + }/* * For built-in modules, name lives in .rodata and is * immortal. For loaded modules, name points at the name[]
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 12/23 dynamic_debug: add static inline stub for ddebug_add_module
In reply to Rasmus VillemoesFor symmetry with ddebug_remove_module, and to avoid a bit of ifdeffery in module.c, move the declaration of ddebug_add_module inside #if defined(CONFIG_DYNAMIC_DEBUG) and add a corresponding no-op stub in the #else branch.
--- include/linux/dynamic_debug.h | 10 ++++++++-- kernel/module.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)
include/linux/dynamic_debug.h +8 -2
@@ -47,10 +47,10 @@ struct _ddebug { } __attribute__((aligned(8))); -int ddebug_add_module (struct _ddebug *tab,unsigned int n, -const char *modname);#if defined(CONFIG_DYNAMIC_DEBUG ) +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, ...);
@@ -152,6 +152,12 @@ do { \#include <linux/string.h> #include <linux/errno.h> +static inline int ddebug_add_module (struct _ddebug *tab,unsigned int n, +const char *modname) +{ +return 0 ; +} +static inline int ddebug_remove_module (const char *mod) {return 0 ;
kernel/module.c +0 -2
@@ -2715,9 +2715,7 @@ static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsig {if (!debug)return ; -#ifdef CONFIG_DYNAMIC_DEBUG ddebug_add_module (debug, num, mod->name); -#endif }static void dynamic_debug_remove (struct module *mod,struct _ddebug *debug)
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 13/23 dynamic_debug: refactor dynamic_pr_debug and friends
In reply to Rasmus VillemoesFor the upcoming 'define the _ddebug descriptor in assembly', we need all the descriptors in a translation unit to have distinct names (because asm does not understand C scope). The easiest way to achieve that is as usual with an extra level of macros, passing the identifier to use to the innermost macro, generating it via __UNIQUE_ID or something.
However, instead of repeating that exercise for dynamic_pr_debug, dynamic_dev_dbg, dynamic_netdev_dbg and dynamic_hex_dump separately, we can use the similarity between their bodies to implement them via a common macro, _dynamic_func_call - though the hex_dump case requires a slight variant, since print_hex_dump does not take the _ddebug descriptor. We'll also get to use that variant elsewhere (btrfs).
--- include/linux/dynamic_debug.h | 72 +++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 29 deletions(-)
include/linux/dynamic_debug.h +43 -29
@@ -112,40 +112,54 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,#endif -#define dynamic_pr_debug (fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ - ##__VA_ARGS__); \ +#define __dynamic_func_call (id, fmt, func, ...) do { \ + DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ + if (DYNAMIC_DEBUG_BRANCH(id)) \ + func(&id, ##__VA_ARGS__); \ } while (0) -#define dynamic_dev_dbg (dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_dev_dbg(&descriptor, dev, fmt, \ - ##__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__); \ } while (0) -#define dynamic_netdev_dbg (dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_netdev_dbg(&descriptor, dev, fmt, \ - ##__VA_ARGS__); \ -} while (0) +/* +* "Factory macro" for generating a call to func, guarded by a +* DYNAMIC_DEBUG_BRANCH. The dynamic debug decriptor will be +* initialized using the fmt argument. The function will be called with +* the address of the descriptor as first argument, followed by all +* the varargs. Note that fmt is repeated in invocations of this +* macro. +*/ +#define _dynamic_func_call (fmt, func, ...) \ + __dynamic_func_call(__UNIQUE_ID(ddebug), 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_hex_dump (prefix_str, prefix_type, rowsize, \ - groupsize, buf, len, ascii) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \ - __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - print_hex_dump(KERN_DEBUG, prefix_str, \ - prefix_type, rowsize, groupsize, \ - buf, len, ascii); \ -} while (0) +#define dynamic_pr_debug (fmt, ...) \ + _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, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_netdev_dbg (dev, fmt, ...) \ + _dynamic_func_call(fmt, __dynamic_netdev_dbg, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_hex_dump (prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \ + print_hex_dump, \ + KERN_DEBUG, prefix_str, prefix_type, \ + rowsize, groupsize, buf, len, ascii)#else
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 14/23 btrfs: implement btrfs_debug* in terms of helper macro
In reply to Rasmus VillemoesFirst, the btrfs_debug macros open-code (one possible definition of) DYNAMIC_DEBUG_BRANCH, so they don't benefit from the HAVE_JUMP_LABEL optimization.
Second, changes on x86-64 later in this series require that all struct _ddebug descriptors in a translation unit use distinct identifiers.
Using the new _dynamic_func_call_no_desc helper macro from dynamic_debug.h takes care of both of these.
--- fs/btrfs/ctree.h | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-)
fs/btrfs/ctree.h +10 -24
@@ -3334,31 +3334,17 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);#if defined(CONFIG_DYNAMIC_DEBUG ) #define btrfs_debug(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk(fs_info, KERN_DEBUG fmt, ##args); \ -} while (0) -#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args); \ -} while (0) + _dynamic_func_call_no_desc(fmt, btrfs_printk, \ + fs_info, KERN_DEBUG fmt, ##args) +#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ + _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \ + fs_info, KERN_DEBUG fmt, ##args) #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, \ - ##args);\ -} while (0) -#define btrfs_debug_rl(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, \ - ##args); \ -} while (0) + _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \ + fs_info, KERN_DEBUG fmt, ##args) +#define btrfs_debug_rl(fs_info, fmt, args...) \ + _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \ + fs_info, KERN_DEBUG fmt, ##args)#elif defined(DEBUG ) #define btrfs_debug(fs_info, fmt, args...) \ btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 15/23 ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
In reply to Rasmus Villemoesdynamic debug may be implemented via static keys, but ACPI is missing out on that runtime benefit since it open-codes one possible definition of DYNAMIC_DEBUG_BRANCH.
--- include/linux/acpi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/acpi.h +1 -1
@@ -980,7 +980,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#define acpi_handle_debug (handle, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ + if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ ##__VA_ARGS__); \ } while (0)
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 16/23 ACPI: remove unused __acpi_handle_debug macro
In reply to Rasmus VillemoesIf CONFIG_DYNAMIC_DEBUG is not set, acpi_handle_debug directly invokes acpi_handle_printk (if DEBUG) or does a no-printk (if !DEBUG). So this macro is never used.
--- include/linux/acpi.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/acpi.h +0 -3
@@ -946,9 +946,6 @@ acpi_handle_printk(const char *level, void *handle, const char *fmt, ...) {}#if defined(CONFIG_ACPI ) && defined(CONFIG_DYNAMIC_DEBUG ) __printf(3, 4)void __acpi_handle_debug (struct _ddebug *descriptor,acpi_handle handle,const char *fmt, ...); -#else -#define __acpi_handle_debug (descriptor, handle, fmt, ...) \ - acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__);#endif /*
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 17/23 ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
In reply to Rasmus VillemoesWith coming changes on x86-64, all dynamic debug descriptors in a translation unit must have distinct names. The macro _dynamic_func_call takes care of that. No functional change.
--- include/linux/acpi.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
include/linux/acpi.h +2 -6
@@ -975,12 +975,8 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#else #if defined(CONFIG_DYNAMIC_DEBUG )#define acpi_handle_debug (handle, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ - ##__VA_ARGS__); \ -} while (0) + _dynamic_func_call(fmt, __acpi_handle_debug, \ + handle, pr_fmt(fmt), ##__VA_ARGS__)#else #define acpi_handle_debug (handle, fmt, ...) \ ({ \
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 18/23 dynamic_debug: introduce accessors for string members of struct _ddebug
In reply to Rasmus VillemoesWhen we introduce compact versions of these pointers (a la CONFIG_GENERIC_BUG_RELATIVE_POINTERS), all access to these members must go via appropriate accessors. This just mass-converts dynamic_debug.c to use the new accessors.
--- lib/dynamic_debug.c | 51 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-)
lib/dynamic_debug.c +34 -17
@@ -37,6 +37,23 @@#include <linux/device.h> #include <linux/netdevice.h> +static inline const char *dd_modname (const struct _ddebug *dd) +{ +return dd->modname; +} +static inline const char *dd_function (const struct _ddebug *dd) +{ +return dd->function; +} +static inline const char *dd_filename (const struct _ddebug *dd) +{ +return dd->filename; +} +static inline const char *dd_format (const struct _ddebug *dd) +{ +return dd->format; +} +extern struct _ddebug __start___verbose[];extern struct _ddebug __stop___verbose[];
@@ -158,21 +175,21 @@ static int ddebug_change(const struct ddebug_query *query,/* match against the source filename */ if (query->filename && - !match_wildcard (query->filename, dp->filename) && + !match_wildcard (query->filename,dd_filename (dp)) && !match_wildcard (query->filename, -kbasename (dp->filename)) && +kbasename (dd_filename (dp))) && !match_wildcard (query->filename, -trim_prefix (dp->filename))) +trim_prefix (dd_filename (dp))))continue ;/* match against the function */ if (query->function && - !match_wildcard (query->function, dp->function)) + !match_wildcard (query->function,dd_function (dp)))continue ;/* match against the format */ if (query->format && - !strstr (dp->format, query->format)) + !strstr (dd_format (dp), query->format))continue ;/* match against the line number range */
@@ -197,8 +214,8 @@ static int ddebug_change(const struct ddebug_query *query,#endif dp->flags = newflags;vpr_info ("changed %s:%d [%s]%s =%s\n" , -trim_prefix (dp->filename), dp->lineno, - dt->mod_name, dp->function, +trim_prefix (dd_filename (dp)), dp->lineno, + dt->mod_name,dd_function (dp),ddebug_describe_flags (dp, flagbuf,sizeof (flagbuf))); }
@@ -533,10 +550,10 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf) pos_after_tid = pos;if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME) pos +=snprintf (buf + pos,remaining (pos),"%s:" , - desc->modname); +dd_modname (desc));if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) pos +=snprintf (buf + pos,remaining (pos),"%s:" , - desc->function); +dd_function (desc));if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) pos +=snprintf (buf + pos,remaining (pos),"%d:" , desc->lineno);
@@ -790,10 +807,10 @@ static int ddebug_proc_show(struct seq_file *m, void *p) }seq_printf (m,"%s:%u [%s]%s =%s \"" , -trim_prefix (dp->filename), dp->lineno, - iter->table->mod_name, dp->function, +trim_prefix (dd_filename (dp)), dp->lineno, + iter->table->mod_name,dd_function (dp),ddebug_describe_flags (dp, flagsbuf,sizeof (flagsbuf))); -seq_escape (m, dp->format,"\t\r\n\"" ); +seq_escape (m,dd_format (dp),"\t\r\n\"" );seq_puts (m,"\"\n" );return 0 ;
@@ -987,20 +1004,20 @@ static int __init dynamic_debug_init(void)return 1 ; } iter = __start___verbose; - modname = iter->modname; + modname =dd_modname (iter); iter_start = iter;for (; iter < __stop___verbose; iter++) { entries++; - verbose_bytes +=strlen (iter->modname) +strlen (iter->function) - +strlen (iter->filename) +strlen (iter->format); + verbose_bytes +=strlen (dd_modname (iter)) +strlen (dd_function (iter)) + +strlen (dd_filename (iter)) +strlen (dd_format (iter)); -if (strcmp (modname, iter->modname)) { +if (strcmp (modname,dd_modname (iter))) { modct++; ret =ddebug_add_module (iter_start, n, modname);if (ret) goto out_err; n =0 ; - modname = iter->modname; + modname =dd_modname (iter); iter_start = iter; } n++;
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 19/23 dynamic_debug: drop use of bitfields in struct _ddebug
In reply to Rasmus VillemoesProperly initializing a struct containing bitfields in assembly is hard. Instead, merge lineno and flags to a single unsigned int, which we mask manually. This should not cause any worse code than what gcc would need to generate for accessing the bitfields anyway.
Actually, on 64 bit, there is a four byte hole after these fields, so we could just give flags and lineno each their own u32. But I don't think that's worth the ifdeffery.
--- include/linux/dynamic_debug.h | 12 ++++------ lib/dynamic_debug.c | 44 +++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 22 deletions(-)
include/linux/dynamic_debug.h +5 -7
@@ -20,7 +20,6 @@ struct _ddebug {const char *function;const char *filename;const char *format; - unsigned int lineno:18;/* * The flags field controls the behaviour at the callsite. * The bits here are changed dynamically when the user
@@ -37,7 +36,7 @@ struct _ddebug {#else #define _DPRINTK_FLAGS_DEFAULT 0#endif - unsigned int flags:8; +unsigned int flags_lineno;/* flags in lower 8 bits, lineno in upper 24 */ #ifdef HAVE_JUMP_LABEL union { struct static_key_true dd_key_true;
@@ -46,7 +45,7 @@ struct _ddebug {#endif } __attribute__((aligned(8))); - +#define _DPRINTK_FLAGS_LINENO_INIT (((unsigned)__LINE__ << 8) | _DPRINTK_FLAGS_DEFAULT)#if defined(CONFIG_DYNAMIC_DEBUG ) int ddebug_add_module(struct _ddebug *tab, unsigned int n,
@@ -78,8 +77,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .function = __func__, \ .filename = __FILE__, \ .format = (fmt), \ - .lineno = __LINE__, \ - .flags = _DPRINTK_FLAGS_DEFAULT, \ + .flags_lineno = _DPRINTK_FLAGS_LINENO_INIT, \ _DPRINTK_KEY_INIT \ }
@@ -104,10 +102,10 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,#ifdef DEBUG #define DYNAMIC_DEBUG_BRANCH (descriptor) \ - likely(descriptor.flags & _DPRINTK_FLAGS_PRINT) + likely(descriptor.flags_lineno & _DPRINTK_FLAGS_PRINT)#else #define DYNAMIC_DEBUG_BRANCH (descriptor) \ - unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) + unlikely(descriptor.flags_lineno & _DPRINTK_FLAGS_PRINT)#endif #endif
lib/dynamic_debug.c +29 -15
108 lines not on this page · raw message
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 20/23 dynamic_debug: introduce CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS
In reply to Rasmus VillemoesBased on the same idea for struct bug_entry, an architecture can opt-in to use relative pointers in struct _ddebug. It only makes sense for 64 bit architectures, where one saves 16 bytes per entry (out of 40 or 56, depending on CONFIG_JUMP_LABEL). The architecture is responsible for providing a suitable DEFINE_DYNAMIC_DEBUG_METADATA macro in <asm/dynamic_debug.h>.
--- include/linux/dynamic_debug.h | 14 ++++++++++++++ lib/Kconfig.debug | 3 +++ lib/dynamic_debug.c | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+)
include/linux/dynamic_debug.h +14 -0
@@ -16,10 +16,17 @@ struct _ddebug {* These fields are used to drive the user interface * for selecting and displaying debug callsites. */ +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +signed int modname_disp; +signed int function_disp; +signed int filename_disp; +signed int format_disp; +#else const char *modname;const char *function;const char *filename;const char *format; +#endif /* * The flags field controls the behaviour at the callsite. * The bits here are changed dynamically when the user
@@ -70,6 +77,12 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,const struct net_device *dev, const char *fmt, ...); +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +#include <asm/dynamic_debug.h> +#ifndef DEFINE_DYNAMIC_DEBUG_METADATA +# error "asm/dynamic_debug.h must provide definition of DEFINE_DYNAMIC_DEBUG_METADATA" +#endif +#else #define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ static struct _ddebug __aligned(8) \ __attribute__((section("__verbose"))) name = { \
@@ -80,6 +93,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .flags_lineno = _DPRINTK_FLAGS_LINENO_INIT, \ _DPRINTK_KEY_INIT \ } +#endif #ifdef HAVE_JUMP_LABEL
lib/Kconfig.debug +3 -0
@@ -146,6 +146,9 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DYNAMIC_DEBUG_RELATIVE_POINTERS + bool + endmenu # "printk and dmesg options" menu "Compile-time checks and compiler options"
lib/dynamic_debug.c +20 -0
@@ -37,6 +37,24 @@#include <linux/device.h> #include <linux/netdevice.h> +#ifdef CONFIG_DYNAMIC_DEBUG_RELATIVE_POINTERS +static inline const char *dd_modname (const struct _ddebug *dd) +{ +return (const char *)dd + dd->modname_disp; +} +static inline const char *dd_function (const struct _ddebug *dd) +{ +return (const char *)dd + dd->function_disp; +} +static inline const char *dd_filename (const struct _ddebug *dd) +{ +return (const char *)dd + dd->filename_disp; +} +static inline const char *dd_format (const struct _ddebug *dd) +{ +return (const char *)dd + dd->format_disp; +} +#else static inline const char *dd_modname (const struct _ddebug *dd) {return dd->modname;
@@ -53,6 +71,8 @@ static inline const char *dd_format(const struct _ddebug *dd) {return dd->format; } +#endif +static inline unsigned dd_lineno (const struct _ddebug *dd) {return dd->flags_lineno >>8 ;
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 21/23 jump_label: move JUMP_TYPE_* constants to new asm-generic file
In reply to Rasmus VillemoesI'm going to need to refer to the JUMP_TYPE_FALSE and JUMP_TYPE_TRUE constants from asm code. In order to do that, move them to an asm-generic header and define them using the UL() helper macro.
--- include/asm-generic/jump_label.h | 11 +++++++++++ include/linux/jump_label.h | 6 +----- 2 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 include/asm-generic/jump_label.h
include/asm-generic/jump_label.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef __ASM_GENERIC_JUMP_LABEL_H +#define __ASM_GENERIC_JUMP_LABEL_H + +#include <linux/const.h> + +#define JUMP_TYPE_FALSE UL(0) +#define JUMP_TYPE_TRUE UL(1) +#define JUMP_TYPE_LINKED UL(2) +#define JUMP_TYPE_MASK UL(3) + +#endif /* __ASM_GENERIC_JUMP_LABEL_H */
include/linux/jump_label.h +1 -5
@@ -119,6 +119,7 @@ struct static_key {#ifdef HAVE_JUMP_LABEL #include <asm/jump_label.h> +#include <asm-generic/jump_label.h> #ifndef __ASSEMBLY__#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE
@@ -194,11 +195,6 @@ struct module;#ifdef HAVE_JUMP_LABEL -#define JUMP_TYPE_FALSE 0UL -#define JUMP_TYPE_TRUE 1UL -#define JUMP_TYPE_LINKED 2UL -#define JUMP_TYPE_MASK 3UL - static __always_inline bool static_key_false(struct static_key *key) {return arch_static_branch (key, false);
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 22/23 x86: jump_label: introduce asm macros STATIC_KEY_INIT{,_TRUE,_FALSE}
In reply to Rasmus VillemoesThese will be useful when defining the contents of (a struct containing) a static key in assembly.
--- arch/x86/include/asm/jump_label.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
arch/x86/include/asm/jump_label.h +17 -0
@@ -12,6 +12,7 @@#include <asm/asm.h> #include <asm/nops.h> +#include <asm-generic/jump_label.h> #ifndef __ASSEMBLY__
@@ -64,6 +65,22 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool .popsection .endm +.macro STATIC_KEY_INIT enabled:req type:req + .long \enabled # .enabled +#ifdef CONFIG_X86_64 + .long 0 # <padding> +#endif + _ASM_PTR \type # .type +.endm + +.macro STATIC_KEY_INIT_TRUE + STATIC_KEY_INIT 1 JUMP_TYPE_TRUE +.endm + +.macro STATIC_KEY_INIT_FALSE + STATIC_KEY_INIT 0 JUMP_TYPE_FALSE +.endm +#endif /* __ASSEMBLY__ */ #endif
Signature · 1 line
2.19.1.6.gbde171bbf5
PATCH v3 23/23 x86_64: use relative pointers with dynamic debug
In reply to Rasmus VillemoesSimilar to how x86_64 uses bug_entry-relative pointers to reduce sizeof(struct bug_entry), the same thing can now be done for struct _ddebug, saving 16 bytes for each of those (i.e., each pr_debug, dev_dbg etc. in a CONFIG_DYNAMIC_DEBUG kernel).
Note the use of .ifndef/.endif in asm to avoid
fs/aio.c:1382: Error: symbol `__UNIQUE_ID_ddebug112' is already defined
This is due to uses of pr_debug et al in functions that get inlined. In such a case, __COUNTER__ is obviously only expanded once, but the asm() is repeated once for every inlined instance. Letting all instances share the same descriptor object is the right thing to do; that is also what happens when it is the compiler that defines a static object inside an inline(d) function.
That, however, leads to another problem if the same identifier is used in two different DEFINE_DYNAMIC_DEBUG_METADATA() in the same translation
unit: They would both end up referring to the same (first occuring) instance. So the second one would end up using the wrong file, line, function etc. information. All current in-tree macro users of DEFINE_DYNAMIC_DEBUG_METADATA() have been updated to ensure they use UNIQUE_ID to generate the identifier.
To prevent such a problem from going unnoticed, we use a guard symbol in assembly whose value is unique per DEFINE_DYNAMIC_DEBUG_METADATA invocation.
--- arch/x86/Kconfig | 1 + arch/x86/include/asm/dynamic_debug.h | 58 ++++++++++++++++++++++++++++ arch/x86/kernel/macros.S | 1 + 3 files changed, 60 insertions(+) create mode 100644 arch/x86/include/asm/dynamic_debug.h
arch/x86/Kconfig +1 -0
@@ -91,6 +91,7 @@ config X86 select CLOCKSOURCE_WATCHDOG select DCACHE_WORD_ACCESS select DMA_DIRECT_OPS + select DYNAMIC_DEBUG_RELATIVE_POINTERS if X86_64 select EDAC_ATOMIC_SCRUB select EDAC_SUPPORT select GENERIC_CLOCKEVENTS
arch/x86/include/asm/dynamic_debug.h new file +58 -0
58 lines not on this page · raw message
arch/x86/kernel/macros.S +1 -0
@@ -14,3 +14,4 @@ #include <asm/asm.h> #include <asm/cpufeature.h> #include <asm/jump_label.h> +#include <asm/dynamic_debug.h>
Signature · 1 line
2.19.1.6.gbde171bbf5
v4 cover various dynamic_debug patches
In reply to Rasmus VillemoesThis started as an experiment to see how hard it would be to change the four pointers in struct _ddebug into relative offsets, a la CONFIG_GENERIC_BUG_RELATIVE_POINTERS, thus saving 16 bytes per pr_debug site (and thus exactly making up for the extra space used by the introduction of jump labels in 9049fc74). I stumbled on a few things that are probably worth fixing regardless of whether that goal is deemed worthwhile.
Back at v3 (in November), I redid the implementation on top of the fancy new asm-macros stuff. Luckily enough, v3 didn't get picked up, since the asm-macros were backed out again. I still want to do the relative-pointers thing eventually, but we're close to the merge window opening, so here's just most of the "incidental" patches, some of which also serve as preparation for the relative pointers.
I'm not sure how long an Ack/Reviewed-by is good for, but OTOH it also feels rude to just drop them on the floor. I've kept those tags since the rebasing to current master went completely smooth.
Andrew, please pick these up for soaking in -next.
v3 series: lkml.kernel.org/r/[email protected] v2 series: lkml.kernel.org/r/[email protected]
Rasmus Villemoes (14):
linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited
dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions
dynamic_debug: don't duplicate modname in ddebug_add_module
dynamic_debug: use pointer comparison in ddebug_remove_module
dynamic_debug: remove unused EXPORT_SYMBOLs
dynamic_debug: move pr_err from module.c to ddebug_add_module
dynamic_debug: add static inline stub for ddebug_add_module
dynamic_debug: refactor dynamic_pr_debug and friends
btrfs: implement btrfs_debug* in terms of helper macro
ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
ACPI: remove unused __acpi_handle_debug macro
ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
fs/btrfs/ctree.h | 34 ++++-------- include/linux/acpi.h | 11 +--- include/linux/device.h | 2 +- include/linux/dynamic_debug.h | 102 +++++++++++++++++++--------------- include/linux/net.h | 2 +- include/linux/printk.h | 2 +- kernel/module.c | 6 +- lib/dynamic_debug.c | 22 ++++---- 8 files changed, 84 insertions(+), 97 deletions(-)
Signature · 1 line
2.20.1
PATCH v4 1/14 linux/device.h: use DYNAMIC_DEBUG_BRANCH in dev_dbg_ratelimited
dev_dbg_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation when CONFIG_JUMP_LABEL is set. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/device.h +1 -1
@@ -1548,7 +1548,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor, fmt); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \__dynamic_dev_dbg (&descriptor, dev,dev_fmt (fmt), \ ##__VA_ARGS__); \
Signature · 1 line
2.20.1
PATCH v4 2/14 linux/net.h: use DYNAMIC_DEBUG_BRANCH in net_dbg_ratelimited
In reply to Rasmus Villemoesnet_dbg_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation when CONFIG_JUMP_LABEL is set. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/net.h +1 -1
@@ -263,7 +263,7 @@ do { \#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ + if (DYNAMIC_DEBUG_BRANCH(descriptor) && \ net_ratelimit()) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ ##__VA_ARGS__); \
Signature · 1 line
2.20.1
PATCH v4 3/14 linux/printk.h: use DYNAMIC_DEBUG_BRANCH in pr_debug_ratelimited
In reply to Rasmus Villemoespr_debug_ratelimited tests the dynamic debug descriptor the old-fashioned way, and doesn't utilize the static key/jump label implementation when CONFIG_JUMP_LABEL is set. Use the DYNAMIC_DEBUG_BRANCH which is defined appropriately.
--- include/linux/printk.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/printk.h +1 -1
@@ -461,7 +461,7 @@ do { \DEFAULT_RATELIMIT_INTERVAL , \ DEFAULT_RATELIMIT_BURST); \DEFINE_DYNAMIC_DEBUG_METADATA (descriptor,pr_fmt (fmt)); \ -if (unlikely (descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ +if (DYNAMIC_DEBUG_BRANCH (descriptor) && \__ratelimit (&_rs)) \ __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ }while (0 )
Signature · 1 line
2.20.1
PATCH v4 4/14 dynamic_debug: consolidate DEFINE_DYNAMIC_DEBUG_METADATA definitions
In reply to Rasmus VillemoesInstead of defining DEFINE_DYNAMIC_DEBUG_METADATA in terms of a helper DEFINE_DYNAMIC_DEBUG_METADATA_KEY, that needs another helper dd_key_init to be properly defined, just make the various #ifdef branches define a _DPRINTK_KEY_INIT that can be used directly, similar to _DPRINTK_FLAGS_DEFAULT.
--- include/linux/dynamic_debug.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
include/linux/dynamic_debug.h +7 -15
@@ -71,7 +71,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,const struct net_device *dev, const char *fmt, ...); -#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY (name, fmt, key, init) \ +#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ static struct _ddebug __aligned(8) \ __attribute__((section("__verbose"))) name = { \ .modname = KBUILD_MODNAME, \
@@ -80,35 +80,27 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, .format = (fmt), \ .lineno = __LINE__, \ .flags = _DPRINTK_FLAGS_DEFAULT, \ - dd_key_init(key, init) \ + _DPRINTK_KEY_INIT \ }#ifdef CONFIG_JUMP_LABEL -#define dd_key_init (key, init) key = (init) -#ifdef DEBUG -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_true, \ - (STATIC_KEY_TRUE_INIT)) + +#define _DPRINTK_KEY_INIT .key.dd_key_true = (STATIC_KEY_TRUE_INIT)#define DYNAMIC_DEBUG_BRANCH (descriptor) \ static_branch_likely(&descriptor.key.dd_key_true)#else -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_false, \ - (STATIC_KEY_FALSE_INIT)) +#define _DPRINTK_KEY_INIT .key.dd_key_false = (STATIC_KEY_FALSE_INIT)#define DYNAMIC_DEBUG_BRANCH (descriptor) \ static_branch_unlikely(&descriptor.key.dd_key_false)#endif -#else - -#define dd_key_init (key, init) +#else /* !HAVE_JUMP_LABEL */ -#define DEFINE_DYNAMIC_DEBUG_METADATA (name, fmt) \ - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, 0, 0) +#define _DPRINTK_KEY_INIT#ifdef DEBUG #define DYNAMIC_DEBUG_BRANCH (descriptor) \
Signature · 1 line
2.20.1
PATCH v4 5/14 dynamic_debug: don't duplicate modname in ddebug_add_module
In reply to Rasmus VillemoesFor built-in modules, we're already reusing the passed-in string via kstrdup_const(). But for actual modules (i.e. when we're called from dynamic_debug_setup in module.c), the passed-in string (which points at the name[] array inside struct module) is also guaranteed to live at least as long as the struct ddebug_table, since free_module() calls ddebug_remove_module().
--- lib/dynamic_debug.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
lib/dynamic_debug.c +7 -8
@@ -847,17 +847,17 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *name) {struct ddebug_table *dt; -const char *new_name; dt =kzalloc (sizeof (*dt),GFP_KERNEL );if (dt ==NULL )return -ENOMEM ; - new_name =kstrdup_const (name,GFP_KERNEL ); -if (new_name ==NULL ) { -kfree (dt); -return -ENOMEM ; - } - dt->mod_name = new_name; +/* +* For built-in modules, name lives in .rodata and is +* immortal. For loaded modules, name points at the name[] +* member of struct module, which lives at least as long as +* this struct ddebug_table. +*/ + dt->mod_name = name; dt->num_ddebugs = n; dt->ddebugs = tab;
@@ -913,7 +913,6 @@ int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)static void ddebug_table_free (struct ddebug_table *dt) {list_del_init (&dt->link); -kfree_const (dt->mod_name);kfree (dt); }
Signature · 1 line
2.20.1
PATCH v4 6/14 dynamic_debug: use pointer comparison in ddebug_remove_module
In reply to Rasmus VillemoesNow that we store the passed-in string directly in ddebug_add_module, we can use pointer equality instead of strcmp. This is a little more efficient, but more importantly, this also makes the code somewhat more correct:
Currently, if one loads and then unloads a module whose name happens to match the KBUILD_MODNAME of some built-in functionality (which need not even be modular at all), all of their dynamic debug entries vanish along with those of the actual module. For example, loading and unloading a core.ko hides all pr_debugs from drivers/base/core.c and other built-in files called core.c (incidentally, there is an in-tree module whose name is core, but I just tested this with an out-of-tree trivial one).
--- lib/dynamic_debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/dynamic_debug.c +2 -1
@@ -929,9 +929,10 @@ int ddebug_remove_module(const char *mod_name)mutex_lock (&ddebug_lock);list_for_each_entry_safe (dt, nextdt, &ddebug_tables, link) { -if (!strcmp (dt->mod_name, mod_name)) { +if (dt->mod_name == mod_name) {ddebug_table_free (dt); ret =0 ; +break ; } }mutex_unlock (&ddebug_lock);
Signature · 1 line
2.20.1
PATCH v4 7/14 dynamic_debug: remove unused EXPORT_SYMBOLs
In reply to Rasmus VillemoesThe only caller of ddebug_{add,remove}_module outside dynamic_debug.c is kernel/module.c, which is obviously not itself modular (though it would be an interesting exercise to make that happen...). I also fail to see how these interfaces can be used by modules, in-tree or not.
--- lib/dynamic_debug.c | 2 -- 1 file changed, 2 deletions(-)
lib/dynamic_debug.c +0 -2
@@ -868,7 +868,6 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,vpr_info ("%u debug prints in module %s\n" , n, dt->mod_name);return 0 ; } -EXPORT_SYMBOL_GPL (ddebug_add_module);/* helper for ddebug_dyndbg_(boot|module)_param_cb */ static int ddebug_dyndbg_param_cb(char *param, char *val,
@@ -938,7 +937,6 @@ int ddebug_remove_module(const char *mod_name)mutex_unlock (&ddebug_lock);return ret; } -EXPORT_SYMBOL_GPL (ddebug_remove_module);static void ddebug_remove_all_tables (void ) {
Signature · 1 line
2.20.1
PATCH v4 8/14 dynamic_debug: move pr_err from module.c to ddebug_add_module
In reply to Rasmus VillemoesThis serves two purposes: First, we get a diagnostic if (though extremely unlikely), any of the calls of ddebug_add_module for built-in code fails, effectively disabling dynamic_debug. Second, I want to make struct _ddebug opaque, and avoid accessing any of its members outside dynamic_debug.[ch].
--- kernel/module.c | 4 +--- lib/dynamic_debug.c | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-)
kernel/module.c +1 -3
@@ -2720,9 +2720,7 @@ static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsigif (!debug)return ;#ifdef CONFIG_DYNAMIC_DEBUG -if (ddebug_add_module (debug, num, mod->name)) -pr_err ("dynamic debug error adding module: %s\n" , - debug->modname); +ddebug_add_module (debug, num, mod->name);#endif }
lib/dynamic_debug.c +3 -1
@@ -849,8 +849,10 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,struct ddebug_table *dt; dt =kzalloc (sizeof (*dt),GFP_KERNEL ); -if (dt ==NULL ) +if (dt ==NULL ) { +pr_err ("error adding module: %s\n" , name);return -ENOMEM ; + }/* * For built-in modules, name lives in .rodata and is * immortal. For loaded modules, name points at the name[]
Signature · 1 line
2.20.1
PATCH v4 9/14 dynamic_debug: add static inline stub for ddebug_add_module
In reply to Rasmus VillemoesFor symmetry with ddebug_remove_module, and to avoid a bit of ifdeffery in module.c, move the declaration of ddebug_add_module inside #if defined(CONFIG_DYNAMIC_DEBUG) and add a corresponding no-op stub in the #else branch.
--- include/linux/dynamic_debug.h | 10 ++++++++-- kernel/module.c | 2 -- 2 files changed, 8 insertions(+), 4 deletions(-)
include/linux/dynamic_debug.h +8 -2
@@ -47,10 +47,10 @@ struct _ddebug { } __attribute__((aligned(8))); -int ddebug_add_module (struct _ddebug *tab,unsigned int n, -const char *modname);#if defined(CONFIG_DYNAMIC_DEBUG ) +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, ...);
@@ -152,6 +152,12 @@ do { \#include <linux/string.h> #include <linux/errno.h> +static inline int ddebug_add_module (struct _ddebug *tab,unsigned int n, +const char *modname) +{ +return 0 ; +} +static inline int ddebug_remove_module (const char *mod) {return 0 ;
kernel/module.c +0 -2
@@ -2719,9 +2719,7 @@ static void dynamic_debug_setup(struct module *mod, struct _ddebug *debug, unsig {if (!debug)return ; -#ifdef CONFIG_DYNAMIC_DEBUG ddebug_add_module (debug, num, mod->name); -#endif }static void dynamic_debug_remove (struct module *mod,struct _ddebug *debug)
Signature · 1 line
2.20.1
PATCH v4 10/14 dynamic_debug: refactor dynamic_pr_debug and friends
In reply to Rasmus VillemoesFor the upcoming 'define the _ddebug descriptor in assembly', we need all the descriptors in a translation unit to have distinct names (because asm does not understand C scope). The easiest way to achieve that is as usual with an extra level of macros, passing the identifier to use to the innermost macro, generating it via __UNIQUE_ID or something.
However, instead of repeating that exercise for dynamic_pr_debug, dynamic_dev_dbg, dynamic_netdev_dbg and dynamic_hex_dump separately, we can use the similarity between their bodies to implement them via a common macro, _dynamic_func_call - though the hex_dump case requires a slight variant, since print_hex_dump does not take the _ddebug descriptor. We'll also get to use that variant elsewhere (btrfs).
--- include/linux/dynamic_debug.h | 72 +++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 29 deletions(-)
include/linux/dynamic_debug.h +43 -29
@@ -112,40 +112,54 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,#endif -#define dynamic_pr_debug (fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ - ##__VA_ARGS__); \ +#define __dynamic_func_call (id, fmt, func, ...) do { \ + DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ + if (DYNAMIC_DEBUG_BRANCH(id)) \ + func(&id, ##__VA_ARGS__); \ } while (0) -#define dynamic_dev_dbg (dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_dev_dbg(&descriptor, dev, fmt, \ - ##__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__); \ } while (0) -#define dynamic_netdev_dbg (dev, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __dynamic_netdev_dbg(&descriptor, dev, fmt, \ - ##__VA_ARGS__); \ -} while (0) +/* +* "Factory macro" for generating a call to func, guarded by a +* DYNAMIC_DEBUG_BRANCH. The dynamic debug decriptor will be +* initialized using the fmt argument. The function will be called with +* the address of the descriptor as first argument, followed by all +* the varargs. Note that fmt is repeated in invocations of this +* macro. +*/ +#define _dynamic_func_call (fmt, func, ...) \ + __dynamic_func_call(__UNIQUE_ID(ddebug), 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_hex_dump (prefix_str, prefix_type, rowsize, \ - groupsize, buf, len, ascii) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \ - __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - print_hex_dump(KERN_DEBUG, prefix_str, \ - prefix_type, rowsize, groupsize, \ - buf, len, ascii); \ -} while (0) +#define dynamic_pr_debug (fmt, ...) \ + _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, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_netdev_dbg (dev, fmt, ...) \ + _dynamic_func_call(fmt, __dynamic_netdev_dbg, \ + dev, fmt, ##__VA_ARGS__) + +#define dynamic_hex_dump (prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \ + print_hex_dump, \ + KERN_DEBUG, prefix_str, prefix_type, \ + rowsize, groupsize, buf, len, ascii)#else
Signature · 1 line
2.20.1
PATCH v4 11/14 btrfs: implement btrfs_debug* in terms of helper macro
In reply to Rasmus VillemoesFirst, the btrfs_debug macros open-code (one possible definition of) DYNAMIC_DEBUG_BRANCH, so they don't benefit from the CONFIG_JUMP_LABEL optimization.
Second, a planned change of struct _ddebug (to reduce its size on 64 bit machines) requires that all descriptors in a translation unit use distinct identifiers.
Using the new _dynamic_func_call_no_desc helper macro from dynamic_debug.h takes care of both of these. No functional change.
--- fs/btrfs/ctree.h | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-)
fs/btrfs/ctree.h +10 -24
@@ -3415,31 +3415,17 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);#if defined(CONFIG_DYNAMIC_DEBUG ) #define btrfs_debug(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk(fs_info, KERN_DEBUG fmt, ##args); \ -} while (0) -#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args); \ -} while (0) + _dynamic_func_call_no_desc(fmt, btrfs_printk, \ + fs_info, KERN_DEBUG fmt, ##args) +#define btrfs_debug_in_rcu(fs_info, fmt, args...) \ + _dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu, \ + fs_info, KERN_DEBUG fmt, ##args) #define btrfs_debug_rl_in_rcu(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, \ - ##args);\ -} while (0) -#define btrfs_debug_rl(fs_info, fmt, args...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ - btrfs_printk_ratelimited(fs_info, KERN_DEBUG fmt, \ - ##args); \ -} while (0) + _dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu, \ + fs_info, KERN_DEBUG fmt, ##args) +#define btrfs_debug_rl(fs_info, fmt, args...) \ + _dynamic_func_call_no_desc(fmt, btrfs_printk_ratelimited, \ + fs_info, KERN_DEBUG fmt, ##args)#elif defined(DEBUG ) #define btrfs_debug(fs_info, fmt, args...) \ btrfs_printk(fs_info, KERN_DEBUG fmt, ##args)
Signature · 1 line
2.20.1
PATCH v4 12/14 ACPI: use proper DYNAMIC_DEBUG_BRANCH macro
In reply to Rasmus Villemoesdynamic debug may be implemented via static keys, but ACPI is missing out on that runtime benefit since it open-codes one possible definition of DYNAMIC_DEBUG_BRANCH.
--- include/linux/acpi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/acpi.h +1 -1
@@ -987,7 +987,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#define acpi_handle_debug (handle, fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ + if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ ##__VA_ARGS__); \ } while (0)
Signature · 1 line
2.20.1
PATCH v4 13/14 ACPI: remove unused __acpi_handle_debug macro
In reply to Rasmus VillemoesIf CONFIG_DYNAMIC_DEBUG is not set, acpi_handle_debug directly invokes acpi_handle_printk (if DEBUG) or does a no-printk (if !DEBUG). So this macro is never used.
--- include/linux/acpi.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/acpi.h +0 -3
@@ -953,9 +953,6 @@ acpi_handle_printk(const char *level, void *handle, const char *fmt, ...) {}#if defined(CONFIG_ACPI ) && defined(CONFIG_DYNAMIC_DEBUG ) __printf(3, 4)void __acpi_handle_debug (struct _ddebug *descriptor,acpi_handle handle,const char *fmt, ...); -#else -#define __acpi_handle_debug (descriptor, handle, fmt, ...) \ - acpi_handle_printk(KERN_DEBUG, handle, fmt, ##__VA_ARGS__);#endif /*
Signature · 1 line
2.20.1
PATCH v4 14/14 ACPI: implement acpi_handle_debug in terms of _dynamic_func_call
In reply to Rasmus VillemoesWith coming changes on x86-64, all dynamic debug descriptors in a translation unit must have distinct names. The macro _dynamic_func_call takes care of that. No functional change.
--- include/linux/acpi.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
include/linux/acpi.h +2 -6
@@ -982,12 +982,8 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c#else #if defined(CONFIG_DYNAMIC_DEBUG )#define acpi_handle_debug (handle, fmt, ...) \ -do { \ - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ - __acpi_handle_debug(&descriptor, handle, pr_fmt(fmt), \ - ##__VA_ARGS__); \ -} while (0) + _dynamic_func_call(fmt, __acpi_handle_debug, \ + handle, pr_fmt(fmt), ##__VA_ARGS__)#else #define acpi_handle_debug (handle, fmt, ...) \ ({ \
Signature · 1 line
2.20.1