dynamic_debug: Add an option to enable dynamic debug for modules only
Subsystems (7)
PATCH v2 1/1 dynamic_debug: Add an option to enable dynamic debug for modules only
From: Orson Zhai <[email protected]>
Instead of enabling dynamic debug globally with CONFIG_DYNAMIC_DEBUG, CONFIG_DYNAMIC_DEBUG_CORE will only enable core function of dynamic debug. With the DYNAMIC_DEBUG_MODULE defined for any modules, dynamic debug will be tied to them.
This is useful for people who only want to enable dynamic debug for kernel modules without worrying about kernel image size and memory consumption is increasing too much.
---
Changes to V2:
1) Change DEBUG_MODULE to DYNAMIC_DEBUG_MODULE.
2) Change more #if defined(DYNAMIC_DEBUG) condition (in net.h, netdevice.h and ib_verbs.h).
3) Rewrite description in howto document.
4) Add acked-by from Greg.
Documentation/admin-guide/dynamic-debug-howto.rst | 5 +++++ include/linux/dev_printk.h | 6 ++++-- include/linux/dynamic_debug.h | 2 +- include/linux/net.h | 3 ++- include/linux/netdevice.h | 6 ++++-- include/linux/printk.h | 14 +++++++++----- include/rdma/ib_verbs.h | 6 ++++-- lib/Kconfig.debug | 12 ++++++++++++ lib/Makefile | 2 +- lib/dynamic_debug.c | 9 +++++++-- 10 files changed, 49 insertions(+), 16 deletions(-)
Documentation/admin-guide/dynamic-debug-howto.rst +5 -0
@@ -13,6 +13,11 @@ kernel code to obtain additional kernel information. Currently, if ``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically enabled per-callsite. +If you do not want to enable dynamic debug globally (i.e. in some embedded +system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic +debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any +modules which you'd like to dynamically debug later. + If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just shortcut for ``print_hex_dump(KERN_DEBUG)``.
include/linux/dev_printk.h +4 -2
@@ -109,7 +109,8 @@ void _dev_info(const struct device *dev, const char *fmt, ...)#define dev_info (dev, fmt, ...) \ _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define dev_dbg (dev, fmt, ...) \ dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)#elif defined(DEBUG )
@@ -181,7 +182,8 @@ do { \ dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)#define dev_info_ratelimited (dev, fmt, ...) \ dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define dev_dbg_ratelimited (dev, fmt, ...) \ do { \
include/linux/dynamic_debug.h +1 -1
@@ -48,7 +48,7 @@ struct _ddebug { -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG_CORE )int ddebug_add_module (struct _ddebug *tab,unsigned int n,const char *modname);extern int ddebug_remove_module (const char *mod_name);
include/linux/net.h +2 -1
@@ -264,7 +264,8 @@ do { \ net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
include/linux/netdevice.h +4 -2
@@ -4868,7 +4868,8 @@ do { \#define MODULE_ALIAS_NETDEV (device) \ MODULE_ALIAS("netdev-" device) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netdev_dbg(__dev, format, args...) \ do { \ dynamic_netdev_dbg(__dev, format, ##args); \
@@ -4938,7 +4939,8 @@ do { \ #define netif_info(priv, type, dev, fmt, args...) \ netif_level(info, priv, type, dev, fmt, ##args) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netif_dbg(priv, type, netdev, format, args...) \ do { \ if (netif_msg_##type(priv)) \
include/linux/printk.h +9 -5
@@ -286,8 +286,9 @@ extern int kptr_restrict;/* * These can be used to print at the various log levels. * All of these will print unconditionally, although note that pr_debug() -* and other debug macros are compiled out unless either DEBUG is defined -* or CONFIG_DYNAMIC_DEBUG is set. +* and other debug macros are compiled out unless either DEBUG is defined, +* CONFIG_DYNAMIC_DEBUG is set, or CONFIG_DYNAMIC_DEBUG_CORE is set when +* DYNAMIC_DEBUG_MODULE being defined for any modules. */ #define pr_emerg (fmt, ...) \ printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
@@ -322,7 +323,8 @@ extern int kptr_restrict;/* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#include <linux/dynamic_debug.h> /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
@@ -448,7 +450,8 @@ extern int kptr_restrict;#endif /* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define pr_debug_ratelimited (fmt, ...) \ do { \
@@ -495,7 +498,8 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,#endif -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define print_hex_dump_debug (prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ dynamic_hex_dump(prefix_str, prefix_type, rowsize, \
include/rdma/ib_verbs.h +4 -2
@@ -100,7 +100,8 @@ void ibdev_notice(const struct ib_device *ibdev, const char *format, ...); __printf(2, 3) __coldvoid ibdev_info (const struct ib_device *ibdev,const char *format, ...); -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define ibdev_dbg(__dev, format, args...) \ dynamic_ibdev_dbg(__dev, format, ##args)#else
@@ -133,7 +134,8 @@ do { \#define ibdev_info_ratelimited (ibdev, fmt, ...) \ ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define ibdev_dbg_ratelimited (ibdev, fmt, ...) \ do { \
lib/Kconfig.debug +12 -0
@@ -99,6 +99,7 @@ config DYNAMIC_DEBUG default n depends on PRINTK depends on (DEBUG_FS || PROC_FS) + select DYNAMIC_DEBUG_CORE help Compiles debug level messages into the kernel, which would not
@@ -165,6 +166,17 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DYNAMIC_DEBUG_CORE + bool "Enable core function of dynamic debug support" + depends on PRINTK + depends on (DEBUG_FS || PROC_FS) + help + Enable core functional support of dynamic debug. It is useful + when you want to tie dynamic debug to your kernel modules with + DYNAMIC_DEBUG_MODULE defined for each of them, especially for + the case of embedded system where the kernel image size is + sensitive for people. + config SYMBOLIC_ERRNAME bool "Support symbolic error names in printf" default y if PRINTK
lib/Makefile +1 -1
@@ -186,7 +186,7 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o -obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o +obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o obj-$(CONFIG_NLATTR) += nlattr.o
lib/dynamic_debug.c +7 -2
@@ -1032,8 +1032,13 @@ static int __init dynamic_debug_init(void)int verbose_bytes =0 ;if (&__start___verbose == &__stop___verbose) { -pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); -return 1 ; +if (IS_ENABLED (CONFIG_DYNAMIC_DEBUG )) { +pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); +return 1 ; + } +pr_info ("Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build\n" ); + ddebug_init_success =1 ; +return 0 ; } iter = __start___verbose; modname = iter->modname;
Signature · 1 line
2.7.4
Quoted 10 lines · Orson Zhai
From: Orson Zhai <[email protected]>
Instead of enabling dynamic debug globally with
CONFIG_DYNAMIC_DEBUG,CONFIG_DYNAMIC_DEBUG_COREwill only enable core function of dynamic debug. With theDYNAMIC_DEBUG_MODULEdefined for any modules, dynamic debug will be tied to them.This is useful for people who only want to enable dynamic debug for kernel modules without worrying about kernel image size and memory consumption is increasing too much.
Let's talk about extreme case, what is the output of bloat-o-meter for allyesconfig build with and without dynamic debug?
I imagine that people who are interested in decreasing memory footprint will use minimal config anyway, so it is very interesting to see who is the target audience for this change?
Thanks
Quoted 251 lines
Signed-off-by Orson Zhai <[email protected]>---
Changes to V2:
1) ChangeDEBUG_MODULEtoDYNAMIC_DEBUG_MODULE.
2) Change more #ifdefined(DYNAMIC_DEBUG)condition (innet.h,netdevice.handib_verbs.h).
3) Rewrite description in howto document.
4) Add acked-by from Greg.Documentation/admin-guide/dynamic-debug-howto.rst | 5 +++++ include/linux/dev_printk.h | 6 ++++-- include/linux/dynamic_debug.h | 2 +- include/linux/net.h | 3 ++- include/linux/netdevice.h | 6 ++++-- include/linux/printk.h | 14 +++++++++----- include/rdma/ib_verbs.h | 6 ++++-- lib/Kconfig.debug | 12 ++++++++++++ lib/Makefile | 2 +- lib/dynamic_debug.c | 9 +++++++-- 10 files changed, 49 insertions(+), 16 deletions(-)Documentation/admin-guide/dynamic-debug-howto.rst +5
-0@@ -13,6 +13,11 @@ kernel code to obtain additional kernel information. Currently, if ``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically enabled per-callsite. +If you do not want to enable dynamic debug globally (i.e. in some embedded +system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic +debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any +modules which you'd like to dynamically debug later. + If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just shortcut for ``print_hex_dump(KERN_DEBUG)``.include/linux/dev_printk.h +4
-2@@ -109,7 +109,8 @@ void _dev_info(const struct device *dev, const char *fmt, ...)#define dev_info (dev, fmt, ...) \ _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define dev_dbg (dev, fmt, ...) \ dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)#elif defined(DEBUG )@@ -181,7 +182,8 @@ do { \ dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)#define dev_info_ratelimited (dev, fmt, ...) \ dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define dev_dbg_ratelimited (dev, fmt, ...) \ do { \include/linux/dynamic_debug.h +1
-1@@ -48,7 +48,7 @@ struct _ddebug { -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG_CORE )int ddebug_add_module (struct _ddebug *tab,unsigned int n,const char *modname);extern int ddebug_remove_module (const char *mod_name);include/linux/net.h +2
-1@@ -264,7 +264,8 @@ do { \ net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \include/linux/netdevice.h +4
-2@@ -4868,7 +4868,8 @@ do { \#define MODULE_ALIAS_NETDEV (device) \ MODULE_ALIAS("netdev-" device) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netdev_dbg(__dev, format, args...) \ do { \ dynamic_netdev_dbg(__dev, format, ##args); \@@ -4938,7 +4939,8 @@ do { \ #define netif_info(priv, type, dev, fmt, args...) \ netif_level(info, priv, type, dev, fmt, ##args) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netif_dbg(priv, type, netdev, format, args...) \ do { \ if (netif_msg_##type(priv)) \include/linux/printk.h +9
-5@@ -286,8 +286,9 @@ extern int kptr_restrict;/* * These can be used to print at the various log levels. * All of these will print unconditionally, although note that pr_debug() -* and other debug macros are compiled out unless either DEBUG is defined -* or CONFIG_DYNAMIC_DEBUG is set. +* and other debug macros are compiled out unless either DEBUG is defined, +* CONFIG_DYNAMIC_DEBUG is set, or CONFIG_DYNAMIC_DEBUG_CORE is set when +* DYNAMIC_DEBUG_MODULE being defined for any modules. */ #define pr_emerg (fmt, ...) \ printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)@@ -322,7 +323,8 @@ extern int kptr_restrict;/* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#include <linux/dynamic_debug.h> /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ @@ -448,7 +450,8 @@ extern int kptr_restrict;#endif /* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define pr_debug_ratelimited (fmt, ...) \ do { \@@ -495,7 +498,8 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,#endif -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define print_hex_dump_debug (prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ dynamic_hex_dump(prefix_str, prefix_type, rowsize, \include/rdma/ib_verbs.h +4
-2@@ -100,7 +100,8 @@ void ibdev_notice(const struct ib_device *ibdev, const char *format, ...); __printf(2, 3) __coldvoid ibdev_info (const struct ib_device *ibdev,const char *format, ...); -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define ibdev_dbg(__dev, format, args...) \ dynamic_ibdev_dbg(__dev, format, ##args)#else @@ -133,7 +134,8 @@ do { \#define ibdev_info_ratelimited (ibdev, fmt, ...) \ ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define ibdev_dbg_ratelimited (ibdev, fmt, ...) \ do { \lib/Kconfig.debug +12
-0@@ -99,6 +99,7 @@ config DYNAMIC_DEBUG default n depends on PRINTK depends on (DEBUG_FS || PROC_FS) + select DYNAMIC_DEBUG_CORE help Compiles debug level messages into the kernel, which would not@@ -165,6 +166,17 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DYNAMIC_DEBUG_CORE + bool "Enable core function of dynamic debug support" + depends on PRINTK + depends on (DEBUG_FS || PROC_FS) + help + Enable core functional support of dynamic debug. It is useful + when you want to tie dynamic debug to your kernel modules with + DYNAMIC_DEBUG_MODULE defined for each of them, especially for + the case of embedded system where the kernel image size is + sensitive for people. + config SYMBOLIC_ERRNAME bool "Support symbolic error names in printf" default y if PRINTKlib/Makefile +1
-1@@ -186,7 +186,7 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o -obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o +obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o obj-$(CONFIG_NLATTR) += nlattr.olib/dynamic_debug.c +7
-3@@ -1032,8 +1032,13 @@ static int __init dynamic_debug_init(void)int verbose_bytes =0 ;if (&__start___verbose == &__stop___verbose) { -pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); -return 1 ; +if (IS_ENABLED (CONFIG_DYNAMIC_DEBUG )) { +pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); +return 1 ; + } +pr_info ("Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build\n" ); + ddebug_init_success =1 ; +return 0 ; } iter = __start___verbose; modname = iter->modname; --2.7.4
Quoted 9 lines · Leon Romanovsky
Quoted 7 lines · Orson Zhai
From: Orson Zhai <[email protected]>
Instead of enabling dynamic debug globally with
CONFIG_DYNAMIC_DEBUG,CONFIG_DYNAMIC_DEBUG_COREwill only enable core function of dynamic debug. With theDYNAMIC_DEBUG_MODULEdefined for any modules, dynamic debug will be tied to them.
Quoted 6 lines
Quoted 3 lines
This is useful for people who only want to enable dynamic debug for kernel modules without worrying about kernel image size and memory consumption is increasing too much.
Let's talk about extreme case, what is the output of bloat-o-meter for allyesconfig build with and without dynamic debug?
It is a good question.
I have done exactly what you ask for x86 build yesterday. Here is the result:
Total: Before=306735842, After=312600260, chg +1.91%
In my case of a mobile phone, the difference is about 2MiB on 14MiB kernel image (not compressed).
The reduced size is often critical sometimes, especially for low-end phones, say a system with 512MB DDR memory.
Another smaller arm system in my hand, kernel size reduced about 600KiB to the zImage
of 4.2MiB.
Quoted 4 lines
I imagine that people who are interested in decreasing memory footprint will use minimal config anyway, so it is very interesting to see who is the target audience for this change?
My motivation came from the concept of GKI (Generic Kernel Image) in Android. Google will release a common kernel image (binary) to all of the Android system vendors in the world instead of letting them to build their owns as before. Every SoC vendor's device drivers will be provided in kernel modules only. By my patch, the driver owners could debug their modules in field (say production releases)
without having to enable dynamic debug for the whole GKI.
-Orson
Quoted 254 lines
Thanks
Quoted 251 lines
Signed-off-by Orson Zhai <[email protected]>---
Changes to V2:
1) ChangeDEBUG_MODULEtoDYNAMIC_DEBUG_MODULE.
2) Change more #ifdefined(DYNAMIC_DEBUG)condition (innet.h,netdevice.handib_verbs.h).
3) Rewrite description in howto document.
4) Add acked-by from Greg.Documentation/admin-guide/dynamic-debug-howto.rst | 5 +++++ include/linux/dev_printk.h | 6 ++++-- include/linux/dynamic_debug.h | 2 +- include/linux/net.h | 3 ++- include/linux/netdevice.h | 6 ++++-- include/linux/printk.h | 14 +++++++++----- include/rdma/ib_verbs.h | 6 ++++-- lib/Kconfig.debug | 12 ++++++++++++ lib/Makefile | 2 +- lib/dynamic_debug.c | 9 +++++++-- 10 files changed, 49 insertions(+), 16 deletions(-)Documentation/admin-guide/dynamic-debug-howto.rst +5
-0@@ -13,6 +13,11 @@ kernel code to obtain additional kernel information. Currently, if ``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically enabled per-callsite. +If you do not want to enable dynamic debug globally (i.e. in some embedded +system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic +debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any +modules which you'd like to dynamically debug later. + If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just shortcut for ``print_hex_dump(KERN_DEBUG)``.include/linux/dev_printk.h +4
-2@@ -109,7 +109,8 @@ void _dev_info(const struct device *dev, const char *fmt, ...)#define dev_info (dev, fmt, ...) \ _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define dev_dbg (dev, fmt, ...) \ dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)#elif defined(DEBUG )@@ -181,7 +182,8 @@ do { \ dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)#define dev_info_ratelimited (dev, fmt, ...) \ dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define dev_dbg_ratelimited (dev, fmt, ...) \ do { \include/linux/dynamic_debug.h +1
-1@@ -48,7 +48,7 @@ struct _ddebug { -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG_CORE )int ddebug_add_module (struct _ddebug *tab,unsigned int n,const char *modname);extern int ddebug_remove_module (const char *mod_name);include/linux/net.h +2
-1@@ -264,7 +264,8 @@ do { \ net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \include/linux/netdevice.h +4
-2@@ -4868,7 +4868,8 @@ do { \#define MODULE_ALIAS_NETDEV (device) \ MODULE_ALIAS("netdev-" device) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netdev_dbg(__dev, format, args...) \ do { \ dynamic_netdev_dbg(__dev, format, ##args); \@@ -4938,7 +4939,8 @@ do { \ #define netif_info(priv, type, dev, fmt, args...) \ netif_level(info, priv, type, dev, fmt, ##args) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netif_dbg(priv, type, netdev, format, args...) \ do { \ if (netif_msg_##type(priv)) \include/linux/printk.h +9
-5@@ -286,8 +286,9 @@ extern int kptr_restrict;/* * These can be used to print at the various log levels. * All of these will print unconditionally, although note that pr_debug() -* and other debug macros are compiled out unless either DEBUG is defined -* or CONFIG_DYNAMIC_DEBUG is set. +* and other debug macros are compiled out unless either DEBUG is defined, +* CONFIG_DYNAMIC_DEBUG is set, or CONFIG_DYNAMIC_DEBUG_CORE is set when +* DYNAMIC_DEBUG_MODULE being defined for any modules. */ #define pr_emerg (fmt, ...) \ printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)@@ -322,7 +323,8 @@ extern int kptr_restrict;/* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#include <linux/dynamic_debug.h> /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ @@ -448,7 +450,8 @@ extern int kptr_restrict;#endif /* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define pr_debug_ratelimited (fmt, ...) \ do { \@@ -495,7 +498,8 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,#endif -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define print_hex_dump_debug (prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ dynamic_hex_dump(prefix_str, prefix_type, rowsize, \include/rdma/ib_verbs.h +4
-2@@ -100,7 +100,8 @@ void ibdev_notice(const struct ib_device *ibdev, const char *format, ...); __printf(2, 3) __coldvoid ibdev_info (const struct ib_device *ibdev,const char *format, ...); -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define ibdev_dbg(__dev, format, args...) \ dynamic_ibdev_dbg(__dev, format, ##args)#else @@ -133,7 +134,8 @@ do { \#define ibdev_info_ratelimited (ibdev, fmt, ...) \ ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define ibdev_dbg_ratelimited (ibdev, fmt, ...) \ do { \lib/Kconfig.debug +12
-0@@ -99,6 +99,7 @@ config DYNAMIC_DEBUG default n depends on PRINTK depends on (DEBUG_FS || PROC_FS) + select DYNAMIC_DEBUG_CORE help Compiles debug level messages into the kernel, which would not@@ -165,6 +166,17 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DYNAMIC_DEBUG_CORE + bool "Enable core function of dynamic debug support" + depends on PRINTK + depends on (DEBUG_FS || PROC_FS) + help + Enable core functional support of dynamic debug. It is useful + when you want to tie dynamic debug to your kernel modules with + DYNAMIC_DEBUG_MODULE defined for each of them, especially for + the case of embedded system where the kernel image size is + sensitive for people. + config SYMBOLIC_ERRNAME bool "Support symbolic error names in printf" default y if PRINTKlib/Makefile +1
-1@@ -186,7 +186,7 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o -obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o +obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o obj-$(CONFIG_NLATTR) += nlattr.olib/dynamic_debug.c +7
-3@@ -1032,8 +1032,13 @@ static int __init dynamic_debug_init(void)int verbose_bytes =0 ;if (&__start___verbose == &__stop___verbose) { -pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); -return 1 ; +if (IS_ENABLED (CONFIG_DYNAMIC_DEBUG )) { +pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); +return 1 ; + } +pr_info ("Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build\n" ); + ddebug_init_success =1 ; +return 0 ; } iter = __start___verbose; modname = iter->modname; --2.7.4
Quoted 21 lines · Orson Zhai
Quoted 9 lines · Leon Romanovsky
Quoted 7 lines · Orson Zhai
From: Orson Zhai <[email protected]>
Instead of enabling dynamic debug globally with
CONFIG_DYNAMIC_DEBUG,CONFIG_DYNAMIC_DEBUG_COREwill only enable core function of dynamic debug. With theDYNAMIC_DEBUG_MODULEdefined for any modules, dynamic debug will be tied to them.Quoted 6 lines
Quoted 3 lines
This is useful for people who only want to enable dynamic debug for kernel modules without worrying about kernel image size and memory consumption is increasing too much.
Let's talk about extreme case, what is the output of bloat-o-meter for allyesconfig build with and without dynamic debug?
It is a good question.
I have done exactly what you ask for x86 build yesterday. Here is the result:
Total: Before=306735842, After=312600260, chg +1.91%
Quoted 8 lines
In my case of a mobile phone, the difference is about 2MiB on 14MiB kernel image (not compressed).
The reduced size is often critical sometimes, especially for low-end phones, say a system with 512MB DDR memory.Another smaller arm system in my hand, kernel size reduced about 600KiB to the zImage
of 4.2MiB.
The numbers support the assumption that "memory consumption is increasing too much" sentence is not fully accurate. According to the result of compilation for mobile phone, it looks like the problem with explode of prints, which is better to clean, before introducing extra config.
Quoted 6 lines
Quoted 5 lines
I imagine that people who are interested in decreasing memory footprint will use minimal config anyway, so it is very interesting to see who is the target audience for this change?
Quoted 7 lines
My motivation came from the concept of GKI (Generic Kernel Image) in Android. Google will release a common kernel image (binary) to all of the Android system vendors in the world instead of letting them to build their owns as before. Every SoC vendor's device drivers will be provided in kernel modules only. By my patch, the driver owners could debug their modules in field (say production releases)
without having to enable dynamic debug for the whole GKI.
Will Google release that binary with CONFIG_DYNAMIC_DEBUG_CORE disabled?
If yes, by introducing you kernel config, these driver authors won't be able to enable debug on GKI (at least for production) at all. If no, what is the point of this change?
Quoted 257 lines
-Orson
Quoted 254 lines
Thanks
Quoted 251 lines
Signed-off-by Orson Zhai <[email protected]>---
Changes to V2:
1) ChangeDEBUG_MODULEtoDYNAMIC_DEBUG_MODULE.
2) Change more #ifdefined(DYNAMIC_DEBUG)condition (innet.h,netdevice.handib_verbs.h).
3) Rewrite description in howto document.
4) Add acked-by from Greg.Documentation/admin-guide/dynamic-debug-howto.rst | 5 +++++ include/linux/dev_printk.h | 6 ++++-- include/linux/dynamic_debug.h | 2 +- include/linux/net.h | 3 ++- include/linux/netdevice.h | 6 ++++-- include/linux/printk.h | 14 +++++++++----- include/rdma/ib_verbs.h | 6 ++++-- lib/Kconfig.debug | 12 ++++++++++++ lib/Makefile | 2 +- lib/dynamic_debug.c | 9 +++++++-- 10 files changed, 49 insertions(+), 16 deletions(-)Documentation/admin-guide/dynamic-debug-howto.rst +5
-0@@ -13,6 +13,11 @@ kernel code to obtain additional kernel information. Currently, if ``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically enabled per-callsite. +If you do not want to enable dynamic debug globally (i.e. in some embedded +system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic +debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any +modules which you'd like to dynamically debug later. + If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just shortcut for ``print_hex_dump(KERN_DEBUG)``.include/linux/dev_printk.h +4
-2@@ -109,7 +109,8 @@ void _dev_info(const struct device *dev, const char *fmt, ...)#define dev_info (dev, fmt, ...) \ _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define dev_dbg (dev, fmt, ...) \ dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)#elif defined(DEBUG )@@ -181,7 +182,8 @@ do { \ dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)#define dev_info_ratelimited (dev, fmt, ...) \ dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define dev_dbg_ratelimited (dev, fmt, ...) \ do { \include/linux/dynamic_debug.h +1
-1@@ -48,7 +48,7 @@ struct _ddebug { -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG_CORE )int ddebug_add_module (struct _ddebug *tab,unsigned int n,const char *modname);extern int ddebug_remove_module (const char *mod_name);include/linux/net.h +2
-1@@ -264,7 +264,8 @@ do { \ net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \include/linux/netdevice.h +4
-2@@ -4868,7 +4868,8 @@ do { \#define MODULE_ALIAS_NETDEV (device) \ MODULE_ALIAS("netdev-" device) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netdev_dbg(__dev, format, args...) \ do { \ dynamic_netdev_dbg(__dev, format, ##args); \@@ -4938,7 +4939,8 @@ do { \ #define netif_info(priv, type, dev, fmt, args...) \ netif_level(info, priv, type, dev, fmt, ##args) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netif_dbg(priv, type, netdev, format, args...) \ do { \ if (netif_msg_##type(priv)) \include/linux/printk.h +9
-5@@ -286,8 +286,9 @@ extern int kptr_restrict;/* * These can be used to print at the various log levels. * All of these will print unconditionally, although note that pr_debug() -* and other debug macros are compiled out unless either DEBUG is defined -* or CONFIG_DYNAMIC_DEBUG is set. +* and other debug macros are compiled out unless either DEBUG is defined, +* CONFIG_DYNAMIC_DEBUG is set, or CONFIG_DYNAMIC_DEBUG_CORE is set when +* DYNAMIC_DEBUG_MODULE being defined for any modules. */ #define pr_emerg (fmt, ...) \ printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)@@ -322,7 +323,8 @@ extern int kptr_restrict;/* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#include <linux/dynamic_debug.h> /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ @@ -448,7 +450,8 @@ extern int kptr_restrict;#endif /* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define pr_debug_ratelimited (fmt, ...) \ do { \@@ -495,7 +498,8 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,#endif -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define print_hex_dump_debug (prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ dynamic_hex_dump(prefix_str, prefix_type, rowsize, \include/rdma/ib_verbs.h +4
-2@@ -100,7 +100,8 @@ void ibdev_notice(const struct ib_device *ibdev, const char *format, ...); __printf(2, 3) __coldvoid ibdev_info (const struct ib_device *ibdev,const char *format, ...); -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define ibdev_dbg(__dev, format, args...) \ dynamic_ibdev_dbg(__dev, format, ##args)#else @@ -133,7 +134,8 @@ do { \#define ibdev_info_ratelimited (ibdev, fmt, ...) \ ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define ibdev_dbg_ratelimited (ibdev, fmt, ...) \ do { \lib/Kconfig.debug +12
-0@@ -99,6 +99,7 @@ config DYNAMIC_DEBUG default n depends on PRINTK depends on (DEBUG_FS || PROC_FS) + select DYNAMIC_DEBUG_CORE help Compiles debug level messages into the kernel, which would not@@ -165,6 +166,17 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DYNAMIC_DEBUG_CORE + bool "Enable core function of dynamic debug support" + depends on PRINTK + depends on (DEBUG_FS || PROC_FS) + help + Enable core functional support of dynamic debug. It is useful + when you want to tie dynamic debug to your kernel modules with + DYNAMIC_DEBUG_MODULE defined for each of them, especially for + the case of embedded system where the kernel image size is + sensitive for people. + config SYMBOLIC_ERRNAME bool "Support symbolic error names in printf" default y if PRINTKlib/Makefile +1
-1@@ -186,7 +186,7 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o -obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o +obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o obj-$(CONFIG_NLATTR) += nlattr.olib/dynamic_debug.c +7
-3@@ -1032,8 +1032,13 @@ static int __init dynamic_debug_init(void)int verbose_bytes =0 ;if (&__start___verbose == &__stop___verbose) { -pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); -return 1 ; +if (IS_ENABLED (CONFIG_DYNAMIC_DEBUG )) { +pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); +return 1 ; + } +pr_info ("Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build\n" ); + ddebug_init_success =1 ; +return 0 ; } iter = __start___verbose; modname = iter->modname; --2.7.4
Quoted 28 lines · Leon Romanovsky
Quoted 26 lines · Orson Zhai
Quoted 9 lines · Leon Romanovsky
Quoted 7 lines · Orson Zhai
From: Orson Zhai <[email protected]>
Instead of enabling dynamic debug globally with
CONFIG_DYNAMIC_DEBUG,CONFIG_DYNAMIC_DEBUG_COREwill only enable core function of dynamic debug. With theDYNAMIC_DEBUG_MODULEdefined for any modules, dynamic debug will be tied to them.Quoted 6 lines
Quoted 3 lines
This is useful for people who only want to enable dynamic debug for kernel modules without worrying about kernel image size and memory consumption is increasing too much.
Let's talk about extreme case, what is the output of bloat-o-meter for allyesconfig build with and without dynamic debug?
It is a good question.
I have done exactly what you ask for x86 build yesterday. Here is the result:
Total: Before=306735842, After=312600260, chg +1.91%In my case of a mobile phone, the difference is about 2MiB on 14MiB kernel image (not compressed).
The reduced size is often critical sometimes, especially for low-end phones, say a system with 512MB DDR memory.
Quoted 6 lines
Quoted 3 lines
Another smaller arm system in my hand, kernel size reduced about 600KiB to the zImage
of 4.2MiB.The numbers support the assumption that "memory consumption is increasing too much" sentence is not fully accurate.
OK, I may change the description more accurate. I was thinking about only embedded
environment for this patch. But it really should be accurate for all kinds users to learn
about it.
.
Quoted 3 lines
According to the result of
compilation for mobile phone, it looks like the problem with explode of prints, which is better to clean, before introducing extra config.
I don't think the debug log print is too much in my kernel. I didn't add extra debug print other than its original code.
In fact it is very close to one of GKI kernels which could be found at AOSP kernel/common branch: android-5.4.
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines
I imagine that people who are interested in decreasing memory footprint will use minimal config anyway, so it is very interesting to see who is the target audience for this change?
Quoted 7 lines
My motivation came from the concept of GKI (Generic Kernel Image) in Android. Google will release a common kernel image (binary) to all of the Android system vendors in the world instead of letting them to build their owns as before. Every SoC vendor's device drivers will be provided in kernel modules only. By my patch, the driver owners could debug their modules in field (say production releases)
without having to enable dynamic debug for the whole GKI.
Quoted 2 lines
Will Google release that binary with
CONFIG_DYNAMIC_DEBUG_COREdisabled?
In Google's plan, there will be only one GKI (no debug version) for one Android version per kernel version per year.
So if I request to enable it and they accept my request (actually they did), the config will be opened in that
GKI release for this year.
Quoted 3 lines
If yes, by introducing you kernel config, these driver authors won't be able to enable debug on GKI (at least for production) at all. If no, what is the point of this change?
I am sorry to make you feel confused.
One of the main purpose of this change is to export the core functions of dynamic debug to kernel modules.
These functions are defined in lib/dynamic_debug.c. EXPORT_SYMBOL(__dynamic_pr_debug); EXPORT_SYMBOL(__dynamic_dev_dbg); EXPORT_SYMBOL(__dynamic_netdev_dbg); EXPORT_SYMBOL(__dynamic_ibdev_dbg);
These are only being built when CONFIG_DYNAMIC_DEBUG is set. But all pr_debug in GKI will be built-in as well.
It will increase not very much size as you pointed out but might worth to be considerred for some cases.
To eliminate this "side-effect", my change will give an option to people like Google guys to export these symbols
without the burden of size it adds before.
-Orson
Quoted 258 lines
Quoted 258 lines
-Orson
Quoted 254 lines
Thanks
Quoted 251 lines
Signed-off-by Orson Zhai <[email protected]>---
Changes to V2:
1) ChangeDEBUG_MODULEtoDYNAMIC_DEBUG_MODULE.
2) Change more #ifdefined(DYNAMIC_DEBUG)condition (innet.h,netdevice.handib_verbs.h).
3) Rewrite description in howto document.
4) Add acked-by from Greg.Documentation/admin-guide/dynamic-debug-howto.rst | 5 +++++ include/linux/dev_printk.h | 6 ++++-- include/linux/dynamic_debug.h | 2 +- include/linux/net.h | 3 ++- include/linux/netdevice.h | 6 ++++-- include/linux/printk.h | 14 +++++++++----- include/rdma/ib_verbs.h | 6 ++++-- lib/Kconfig.debug | 12 ++++++++++++ lib/Makefile | 2 +- lib/dynamic_debug.c | 9 +++++++-- 10 files changed, 49 insertions(+), 16 deletions(-)Documentation/admin-guide/dynamic-debug-howto.rst +5
-0@@ -13,6 +13,11 @@ kernel code to obtain additional kernel information. Currently, if ``print_hex_dump_debug()``/``print_hex_dump_bytes()`` calls can be dynamically enabled per-callsite. +If you do not want to enable dynamic debug globally (i.e. in some embedded +system), you may set ``CONFIG_DYNAMIC_DEBUG_CORE`` as basic support of dynamic +debug and add ``ccflags := -DDYNAMIC_DEBUG_MODULE`` into the Makefile of any +modules which you'd like to dynamically debug later. + If ``CONFIG_DYNAMIC_DEBUG`` is not set, ``print_hex_dump_debug()`` is just shortcut for ``print_hex_dump(KERN_DEBUG)``.include/linux/dev_printk.h +4
-2@@ -109,7 +109,8 @@ void _dev_info(const struct device *dev, const char *fmt, ...)#define dev_info (dev, fmt, ...) \ _dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define dev_dbg (dev, fmt, ...) \ dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)#elif defined(DEBUG )@@ -181,7 +182,8 @@ do { \ dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)#define dev_info_ratelimited (dev, fmt, ...) \ dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define dev_dbg_ratelimited (dev, fmt, ...) \ do { \include/linux/dynamic_debug.h +1
-1@@ -48,7 +48,7 @@ struct _ddebug { -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG_CORE )int ddebug_add_module (struct _ddebug *tab,unsigned int n,const char *modname);extern int ddebug_remove_module (const char *mod_name);include/linux/net.h +2
-1@@ -264,7 +264,8 @@ do { \ net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__)#define net_info_ratelimited (fmt, ...) \ net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define net_dbg_ratelimited (fmt, ...) \ do { \ DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \include/linux/netdevice.h +4
-2@@ -4868,7 +4868,8 @@ do { \#define MODULE_ALIAS_NETDEV (device) \ MODULE_ALIAS("netdev-" device) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netdev_dbg(__dev, format, args...) \ do { \ dynamic_netdev_dbg(__dev, format, ##args); \@@ -4938,7 +4939,8 @@ do { \ #define netif_info(priv, type, dev, fmt, args...) \ netif_level(info, priv, type, dev, fmt, ##args) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define netif_dbg(priv, type, netdev, format, args...) \ do { \ if (netif_msg_##type(priv)) \include/linux/printk.h +9
-5@@ -286,8 +286,9 @@ extern int kptr_restrict;/* * These can be used to print at the various log levels. * All of these will print unconditionally, although note that pr_debug() -* and other debug macros are compiled out unless either DEBUG is defined -* or CONFIG_DYNAMIC_DEBUG is set. +* and other debug macros are compiled out unless either DEBUG is defined, +* CONFIG_DYNAMIC_DEBUG is set, or CONFIG_DYNAMIC_DEBUG_CORE is set when +* DYNAMIC_DEBUG_MODULE being defined for any modules. */ #define pr_emerg (fmt, ...) \ printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)@@ -322,7 +323,8 @@ extern int kptr_restrict;/* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#include <linux/dynamic_debug.h> /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */ @@ -448,7 +450,8 @@ extern int kptr_restrict;#endif /* If you are writing a driver, please use dev_dbg instead */ -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define pr_debug_ratelimited (fmt, ...) \ do { \@@ -495,7 +498,8 @@ static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,#endif -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))#define print_hex_dump_debug (prefix_str, prefix_type, rowsize, \ groupsize, buf, len, ascii) \ dynamic_hex_dump(prefix_str, prefix_type, rowsize, \include/rdma/ib_verbs.h +4
-2@@ -100,7 +100,8 @@ void ibdev_notice(const struct ib_device *ibdev, const char *format, ...); __printf(2, 3) __coldvoid ibdev_info (const struct ib_device *ibdev,const char *format, ...); -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE )) #define ibdev_dbg(__dev, format, args...) \ dynamic_ibdev_dbg(__dev, format, ##args)#else @@ -133,7 +134,8 @@ do { \#define ibdev_info_ratelimited (ibdev, fmt, ...) \ ibdev_level_ratelimited(ibdev_info, ibdev, fmt, ##__VA_ARGS__) -#if defined(CONFIG_DYNAMIC_DEBUG ) +#if defined(CONFIG_DYNAMIC_DEBUG ) || \ + (defined(CONFIG_DYNAMIC_DEBUG_CORE ) && defined(DYNAMIC_DEBUG_MODULE ))/* descriptor check is first to prevent flooding with "callbacks suppressed" */ #define ibdev_dbg_ratelimited (ibdev, fmt, ...) \ do { \lib/Kconfig.debug +12
-0@@ -99,6 +99,7 @@ config DYNAMIC_DEBUG default n depends on PRINTK depends on (DEBUG_FS || PROC_FS) + select DYNAMIC_DEBUG_CORE help Compiles debug level messages into the kernel, which would not@@ -165,6 +166,17 @@ config DYNAMIC_DEBUG See Documentation/admin-guide/dynamic-debug-howto.rst for additional information. +config DYNAMIC_DEBUG_CORE + bool "Enable core function of dynamic debug support" + depends on PRINTK + depends on (DEBUG_FS || PROC_FS) + help + Enable core functional support of dynamic debug. It is useful + when you want to tie dynamic debug to your kernel modules with + DYNAMIC_DEBUG_MODULE defined for each of them, especially for + the case of embedded system where the kernel image size is + sensitive for people. + config SYMBOLIC_ERRNAME bool "Support symbolic error names in printf" default y if PRINTKlib/Makefile +1
-1@@ -186,7 +186,7 @@ lib-$(CONFIG_GENERIC_BUG) += bug.o obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o -obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o +obj-$(CONFIG_DYNAMIC_DEBUG_CORE) += dynamic_debug.o obj-$(CONFIG_SYMBOLIC_ERRNAME) += errname.o obj-$(CONFIG_NLATTR) += nlattr.olib/dynamic_debug.c +7
-3@@ -1032,8 +1032,13 @@ static int __init dynamic_debug_init(void)int verbose_bytes =0 ;if (&__start___verbose == &__stop___verbose) { -pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); -return 1 ; +if (IS_ENABLED (CONFIG_DYNAMIC_DEBUG )) { +pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); +return 1 ; + } +pr_info ("Ignore empty _ddebug table in a CONFIG_DYNAMIC_DEBUG_CORE build\n" ); + ddebug_init_success =1 ; +return 0 ; } iter = __start___verbose; modname = iter->modname; --2.7.4
Petr Mladek
maintainerQuoted 12 lines · Orson Zhai
Quoted 11 lines · Leon Romanovsky
Quoted 8 lines · Orson Zhai
On Tue, Apr 21, 2020 at 3:10 AM Leon Romanovsky <[email protected]> wrote:
My motivation came from the concept of GKI (Generic Kernel Image) in Android. Google will release a common kernel image (binary) to all of the Android system vendors in the world instead of letting them to build their owns as before. Every SoC vendor's device drivers will be provided in kernel modules only. By my patch, the driver owners could debug their modules in field (say production releases)
without having to enable dynamic debug for the whole GKI.
Quoted 4 lines
Quoted 2 lines
Will Google release that binary with
CONFIG_DYNAMIC_DEBUG_COREdisabled?In Google's plan, there will be only one GKI (no debug version) for one Android version per kernel version per year.
Are there plans to use modules with debug messages enabled on production systems?
IMHO, the debug messages are primary needed during development and when fixing bugs. I am sure that developers will want to enable many more features that will help with debugging and which will be disabled on production systems.
I expect that Google will not release only the single binary. They should release also the sources and build configuration. Then developers might build their own versions with the needed debugging features enabled.
Best Regards,
Petr
Quoted 14 lines · Petr Mladek
Quoted 12 lines · Orson Zhai
Quoted 11 lines · Leon Romanovsky
Quoted 8 lines · Orson Zhai
On Tue, Apr 21, 2020 at 3:10 AM Leon Romanovsky <[email protected]> wrote:
My motivation came from the concept of GKI (Generic Kernel Image) in Android. Google will release a common kernel image (binary) to all of the Android system vendors in the world instead of letting them to build their owns as before. Every SoC vendor's device drivers will be provided in kernel modules only. By my patch, the driver owners could debug their modules in field (say production releases)
without having to enable dynamic debug for the whole GKI.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Will Google release that binary with
CONFIG_DYNAMIC_DEBUG_COREdisabled?In Google's plan, there will be only one GKI (no debug version) for one Android version per kernel version per year.
Are there plans to use modules with debug messages enabled on production systems?
Yes, but in a managed way. They are not being enabled directly to log buffer. Users / FAEs (Field Application Engineer) might control to open or close every single one on-the-fly.
Quoted 5 lines
IMHO, the debug messages are primary needed during development and when fixing bugs. I am sure that developers will want to enable many more features that will help with debugging and which will be disabled on production systems.
I agree with you in general speaking.
For real production build we usually keep a few critical debugging methods in case of some
potential bugs which are extremely hard to be found in production test. Dynamic debug is one of these methods.
I assume it is widely used for maintenance to PC or server because I can find it is enabled in some
popular Linux distribution configs.
Here is the search result from my PC with Ubuntu default installation.
zhai@ThinkPad:/boot$ cat config-4.15.0-99-generic | grep DYNAMIC_DEBUG CONFIG_DYNAMIC_DEBUG=y
Quoted 3 lines
I expect that Google will not release only the single binary. They should release also the sources and build configuration. Then
Yes, they have released the source and configuration which could be freely downloaded from Google's website.
Quoted 2 lines
developers might build their own versions with the needed debugging features enabled.
Yes, we do have the debug build for this.
But as I mentioned above, it is a little bit different for my requirement. Actually my patch is to address the problem for embedded system where image size is needed to be
considered when CONFIG_DYNAMIC_DEBUG is being enable globally.
For a "make allyesconfig" build, 2,335,704 bytes will be increased by enabling CONFIG_DYNAMIC_DEBUG.
It is trivial for PC or server but might matter for embedded product. So my patch is to give user an option to
only enable dynamic debug for modules especially in this GKI case.
Thanks
Orson
Quoted 3 lines
Best Regards,
Petr
Quoted 20 lines · Orson Zhai
Quoted 19 lines · Petr Mladek
Quoted 16 lines · Orson Zhai
Quoted 11 lines · Leon Romanovsky
Quoted 8 lines · Orson Zhai
On Tue, Apr 21, 2020 at 3:10 AM Leon Romanovsky <[email protected]> wrote:
My motivation came from the concept of GKI (Generic Kernel Image) in Android. Google will release a common kernel image (binary) to all of the Android system vendors in the world instead of letting them to build their owns as before. Every SoC vendor's device drivers will be provided in kernel modules only. By my patch, the driver owners could debug their modules in field (say production releases)
without having to enable dynamic debug for the whole GKI.Quoted 2 lines
Will Google release that binary with
CONFIG_DYNAMIC_DEBUG_COREdisabled?In Google's plan, there will be only one GKI (no debug version) for one Android version per kernel version per year.
Quoted 6 lines
Quoted 2 lines
Are there plans to use modules with debug messages enabled on production systems?
Yes, but in a managed way. They are not being enabled directly to log buffer. Users / FAEs (Field Application Engineer) might control to open or close every single one on-the-fly.
I see.
Quoted 5 lines
Quoted 4 lines
IMHO, the debug messages are primary needed during development and when fixing bugs. I am sure that developers will want to enable many more features that will help with debugging and which will be disabled on production systems.
Quoted 8 lines
I agree with you in general speaking.
For real production build we usually keep a few critical debugging methods in case of some
potential bugs which are extremely hard to be found in production test. Dynamic debug is one of these methods.
I assume it is widely used for maintenance to PC or server because I can find it is enabled in some
popular Linux distribution configs.
Fair enough.
Feel free to add:
Best Regards,
Petr