Bluetooth: Add debugfs option to enable runtime debug statements
Subsystems (2)
Marcel Holtmann
maintainerRFC v2 1/1 Bluetooth: Add debugfs option to enable runtime debug statements
--- include/net/bluetooth/bluetooth.h | 8 ++++ net/bluetooth/Kconfig | 7 +++ net/bluetooth/af_bluetooth.c | 2 + net/bluetooth/lib.c | 71 +++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+)
include/net/bluetooth/bluetooth.h +8 -0
@@ -129,6 +129,8 @@ void bt_warn(const char *fmt, ...); __printf(1, 2)void bt_err (const char *fmt, ...); __printf(1, 2) +void bt_dbg (const char *fmt, ...); +__printf(1, 2)void bt_warn_ratelimited (const char *fmt, ...); __printf(1, 2)void bt_err_ratelimited (const char *fmt, ...);
@@ -136,7 +138,11 @@ void bt_err_ratelimited(const char *fmt, ...);#define BT_INFO (fmt, ...) bt_info(fmt "\n", ##__VA_ARGS__)#define BT_WARN (fmt, ...) bt_warn(fmt "\n", ##__VA_ARGS__)#define BT_ERR (fmt, ...) bt_err(fmt "\n", ##__VA_ARGS__) +#if IS_ENABLED (CONFIG_BT_DEBUGFS_OPTION ) +#define BT_DBG (fmt, ...) bt_dbg(fmt "\n", ##__VA_ARGS__) +#else #define BT_DBG (fmt, ...) pr_debug(fmt "\n", ##__VA_ARGS__) +#endif #define bt_dev_info (hdev, fmt, ...) \ BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
@@ -393,6 +399,8 @@ void bt_procfs_cleanup(struct net *net, const char *name);extern struct dentry *bt_debugfs; +void bt_lib_debugfs_init (void ); +int l2cap_init (void );void l2cap_exit (void );
net/bluetooth/Kconfig +7 -0
@@ -128,4 +128,11 @@ config BT_DEBUGFS Provide extensive information about internal Bluetooth states in debugfs. + When dynamic debug is not used, then this option also includes + a switch to enable/disable internal debug statements. + +config BT_DEBUGFS_OPTION + bool + default y if BT_DEBUGFS && !DYNAMIC_DEBUG + source "drivers/bluetooth/Kconfig"
net/bluetooth/af_bluetooth.c +2 -0
@@ -731,6 +731,8 @@ static int __init bt_init(void) bt_debugfs =debugfs_create_dir ("bluetooth" ,NULL ); +bt_lib_debugfs_init (); +bt_leds_init (); err =bt_sysfs_init ();
net/bluetooth/lib.c +71 -0
89 lines not on this page · raw message
Signature · 1 line
2.24.1
Hi Marcel, Alain,
Looks wonderful to me.
Quoted 171 lines · Marcel Holtmann
Signed-off-by Marcel Holtmann <[email protected]>--- include/net/bluetooth/bluetooth.h | 8 ++++ net/bluetooth/Kconfig | 7 +++ net/bluetooth/af_bluetooth.c | 2 + net/bluetooth/lib.c | 71 +++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+)include/net/bluetooth/bluetooth.h +8
-0@@ -129,6 +129,8 @@ void bt_warn(const char *fmt, ...); __printf(1, 2)void bt_err (const char *fmt, ...); __printf(1, 2) +void bt_dbg (const char *fmt, ...); +__printf(1, 2)void bt_warn_ratelimited (const char *fmt, ...); __printf(1, 2)void bt_err_ratelimited (const char *fmt, ...);@@ -136,7 +138,11 @@ void bt_err_ratelimited(const char *fmt, ...);#define BT_INFO (fmt, ...) bt_info(fmt "\n", ##__VA_ARGS__)#define BT_WARN (fmt, ...) bt_warn(fmt "\n", ##__VA_ARGS__)#define BT_ERR (fmt, ...) bt_err(fmt "\n", ##__VA_ARGS__) +#if IS_ENABLED (CONFIG_BT_DEBUGFS_OPTION ) +#define BT_DBG (fmt, ...) bt_dbg(fmt "\n", ##__VA_ARGS__) +#else #define BT_DBG (fmt, ...) pr_debug(fmt "\n", ##__VA_ARGS__) +#endif #define bt_dev_info (hdev, fmt, ...) \ BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)@@ -393,6 +399,8 @@ void bt_procfs_cleanup(struct net *net, const char *name);extern struct dentry *bt_debugfs; +void bt_lib_debugfs_init (void ); +int l2cap_init (void );void l2cap_exit (void );net/bluetooth/Kconfig +7
-0@@ -128,4 +128,11 @@ config BT_DEBUGFS Provide extensive information about internal Bluetooth states in debugfs. + When dynamic debug is not used, then this option also includes + a switch to enable/disable internal debug statements. + +config BT_DEBUGFS_OPTION + bool + default y if BT_DEBUGFS && !DYNAMIC_DEBUG + source "drivers/bluetooth/Kconfig"net/bluetooth/af_bluetooth.c +2
-0@@ -731,6 +731,8 @@ static int __init bt_init(void) bt_debugfs =debugfs_create_dir ("bluetooth" ,NULL ); +bt_lib_debugfs_init (); +bt_leds_init (); err =bt_sysfs_init ();net/bluetooth/lib.c +71
-1@@ -27,6 +27,7 @@#define pr_fmt (fmt) "Bluetooth: " fmt#include <linux/export.h> +#include <linux/debugfs.h> #include <net/bluetooth/bluetooth.h> @@ -135,6 +136,57 @@ int bt_to_errno(__u16 code) }EXPORT_SYMBOL (bt_to_errno); +#ifdef CONFIG_BT_DEBUGFS_OPTION +static bool debug_enable; + +static ssize_t debug_enable_read (struct file *file,char __user *user_buf, +size_t count,loff_t *ppos) +{ +char buf[3 ]; + + buf[0 ] = debug_enable ?'Y' :'N' ; + buf[1 ] ='\n' ; + buf[2 ] ='\0' ; +return simple_read_from_buffer (user_buf, count, ppos, buf,2 ); +} + +static ssize_t debug_enable_write (struct file *file, +const char __user *user_buf, +size_t count,loff_t *ppos) +{ +bool enable; +int err; + + err =kstrtobool_from_user (user_buf, count, &enable); +if (err) +return err; + +if (enable == debug_enable) +return -EALREADY ; + + debug_enable = enable; + +return count; +} + +static const struct file_operations debug_enable_fops = { + .open = simple_open, + .read = debug_enable_read, + .write = debug_enable_write, + .llseek = default_llseek, +}; + +void bt_lib_debugfs_init (void ) +{ +debugfs_create_file ("debug_enable" ,0644 , bt_debugfs,NULL , + &debug_enable_fops); +} +#else +void bt_lib_debugfs_init (void ) +{ +} +#endif +void bt_info (const char *format, ...) {struct va_format vaf;@@ -183,6 +235,25 @@ void bt_err(const char *format, ...) }EXPORT_SYMBOL (bt_err); +void bt_dbg (const char *format, ...) +{ +struct va_format vaf; +va_list args; + +if (likely (!debug_enable)) +return ; + +va_start (args, format); + + vaf.fmt = format; + vaf.va = &args; + + printk(KERN_DEBUG pr_fmt("%pV"), &vaf); + + va_end(args); +} +EXPORT_SYMBOL (bt_dbg); +void bt_warn_ratelimited (const char *format, ...) {struct va_format vaf; --2.24.1
kbuild test robot
build bot[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi Marcel,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on bluetooth-next/master]
[also build test ERROR on next-20200131]
[cannot apply to bluetooth/master v5.5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Marcel-Holtmann/Bluetooth-Add-debugfs-option-to-enable-runtime-debug-statements/20200203-081756 base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master config: openrisc-randconfig-a001-20200202 (attached as .config) compiler: or1k-linux-gcc (GCC) 9.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=9.2.0 make.cross ARCH=openrisc
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
In file included from include/linux/kernel.h:11,
from include/linux/list.h:9, from include/linux/wait.h:7, from include/linux/wait_bit.h:8, from include/linux/fs.h:6, from include/linux/debugfs.h:15, from net/bluetooth/lib.c:30:
net/bluetooth/lib.c: In function 'bt_dbg':
>> net/bluetooth/lib.c:243:14: error: 'debug_enable' undeclared (first use in this function)
243 | if (likely(!debug_enable))
| ^~~~~~~~~~~~
include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
58 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
| ^~~~
net/bluetooth/lib.c:243:2: note: in expansion of macro 'if'
243 | if (likely(!debug_enable))
| ^~
include/linux/compiler.h:45:22: note: in expansion of macro '__branch_check__'
45 | # define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x)))
| ^~~~~~~~~~~~~~~~
net/bluetooth/lib.c:243:6: note: in expansion of macro 'likely'
243 | if (likely(!debug_enable))
| ^~~~~~
net/bluetooth/lib.c:243:14: note: each undeclared identifier is reported only once for each function it appears in
243 | if (likely(!debug_enable))
| ^~~~~~~~~~~~
include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
58 | #define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
| ^~~~
net/bluetooth/lib.c:243:2: note: in expansion of macro 'if'
243 | if (likely(!debug_enable))
| ^~
include/linux/compiler.h:45:22: note: in expansion of macro '__branch_check__'
45 | # define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x)))
| ^~~~~~~~~~~~~~~~
net/bluetooth/lib.c:243:6: note: in expansion of macro 'likely'
243 | if (likely(!debug_enable))
| ^~~~~~vim +/debug_enable +243 net/bluetooth/lib.c
237
238 void bt_dbg(const char *format, ...)
239 {
240 struct va_format vaf;
241 va_list args;
242
> 243 if (likely(!debug_enable))
244 return;
245
246 va_start(args, format);
247
248 vaf.fmt = format;
249 vaf.va = &args;
250
251 printk(KERN_DEBUG pr_fmt("%pV"), &vaf);
252
253 va_end(args);
254 }
255 EXPORT_SYMBOL(bt_dbg);
256
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation
kbuild test robot
build bot[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi Marcel,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on next-20200203]
[cannot apply to bluetooth/master v5.5]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Marcel-Holtmann/Bluetooth-Add-debugfs-option-to-enable-runtime-debug-statements/20200203-081756 base: https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master config: microblaze-randconfig-a001-20200203 (attached as .config) compiler: microblaze-linux-gcc (GCC) 7.5.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.5.0 make.cross ARCH=microblaze
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
In file included from include/linux/kernel.h:11:0,
from include/linux/list.h:9,
from include/linux/wait.h:7,
from include/linux/wait_bit.h:8,
from include/linux/fs.h:6,
from include/linux/debugfs.h:15,
from net/bluetooth/lib.c:30:
net/bluetooth/lib.c: In function 'bt_dbg':
net/bluetooth/lib.c:243:14: error: 'debug_enable' undeclared (first use in this function); did you mean 'napi_enable'?
if (likely(!debug_enable))
^
include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> net/bluetooth/lib.c:243:2: note: in expansion of macro 'if'
if (likely(!debug_enable))
^~
include/linux/compiler.h:45:22: note: in expansion of macro '__branch_check__'
# define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x)))
^~~~~~~~~~~~~~~~
>> net/bluetooth/lib.c:243:6: note: in expansion of macro 'likely'
if (likely(!debug_enable))
^~~~~~
net/bluetooth/lib.c:243:14: note: each undeclared identifier is reported only once for each function it appears in
if (likely(!debug_enable))
^
include/linux/compiler.h:58:52: note: in definition of macro '__trace_if_var'
#define __trace_if_var(cond) (__builtin_constant_p(cond) ? (cond) : __trace_if_value(cond))
^~~~
>> net/bluetooth/lib.c:243:2: note: in expansion of macro 'if'
if (likely(!debug_enable))
^~
include/linux/compiler.h:45:22: note: in expansion of macro '__branch_check__'
# define likely(x) (__branch_check__(x, 1, __builtin_constant_p(x)))
^~~~~~~~~~~~~~~~
>> net/bluetooth/lib.c:243:6: note: in expansion of macro 'likely'
if (likely(!debug_enable))
^~~~~~vim +/if +243 net/bluetooth/lib.c
237
238 void bt_dbg(const char *format, ...)
239 {
240 struct va_format vaf;
241 va_list args;
242
> 243 if (likely(!debug_enable))
244 return;
245
246 va_start(args, format);
247
248 vaf.fmt = format;
249 vaf.va = &args;
250
251 printk(KERN_DEBUG pr_fmt("%pV"), &vaf);
252
253 va_end(args);
254 }
255 EXPORT_SYMBOL(bt_dbg);
256
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation