dynamic_debug: Restore dev_dbg functionality, optimize stack
Subsystems (5)
PATCH v2 1/1 dynamic_debug: Restore dev_dbg functionality, optimize stack
In reply to a message not in the archivecommit c4e00daaa9 ("driver-core: extend dev_printk() to pass structured data") changed __dev_printk and broke dynamic-debug's ability to control the dynamic prefix of dev_dbg(dev,..).
dynamic_emit_prefix() adds "[tid] module:func:line:" to the output and those additions got lost.
In addition, the current dynamic debug code uses up to 3 recursion levels via %pV. This can consume quite a bit of stack. Directly call printk_emit to reduce the recursion depth.
These changes include:
o Remove KERN_DEBUG from dynamic_emit_prefix
o Create and use function create_syslog_header to format the syslog header for printk_emit uses.
o Call create_syslog_header and neaten __dev_printk
o Call create_syslog_header and printk_emit from dynamic_dev_dbg
o Call create_syslog_header and printk_emit from dynamic_netdev_dbg
o Make __dev_printk and __netdev_printk static not global
o Remove include header declarations of __dev_printk and __netdev_printk
o Remove now unused EXPORT_SYMBOL()s of __dev_printk and __netdev_printk
o Whitespace neatening
Changes in v2:
o Fix dynamic_emit_prefix to always initialize output
o Call create_syslog_header and emit_printk from__netdev_printk and eliminate call to dev_printk to remove another recursion via %pV
--- drivers/base/core.c | 57 +++++++++++++++++++++++---------------- include/linux/device.h | 11 +++----- include/linux/netdevice.h | 3 -- lib/dynamic_debug.c | 65 ++++++++++++++++++++++++++++++++++++--------- net/core/dev.c | 24 ++++++++++++----- 5 files changed, 106 insertions(+), 54 deletions(-)
drivers/base/core.c +33 -24
@@ -1861,25 +1861,19 @@ void device_shutdown(void)*/ #ifdef CONFIG_PRINTK -int __dev_printk (const char *level,const struct device *dev, -struct va_format *vaf) +int create_syslog_header (const struct device *dev,char *hdr,size_t hdrlen) { -char dict[128 ]; -size_t dictlen =0 ;const char *subsys; - -if (!dev) -return printk ("%s(NULL device *): %pV" , level, vaf); +size_t pos =0 ;if (dev->class) subsys = dev->class->name;else if (dev->bus) subsys = dev->bus->name;else - goto skip; +return 0 ; - dictlen +=snprintf (dict + dictlen,sizeof (dict) - dictlen, -"SUBSYSTEM=%s" , subsys); + pos +=snprintf (hdr + pos, hdrlen - pos,"SUBSYSTEM=%s" , subsys);/* * Add device identifier DEVICE=:
@@ -1895,28 +1889,41 @@ int __dev_printk(const char *level, const struct device *dev, c ='b' ; else c ='c' ; - dictlen++; - dictlen +=snprintf (dict + dictlen,sizeof (dict) - dictlen, -"DEVICE=%c%u:%u" , - c,MAJOR (dev->devt),MINOR (dev->devt)); + pos++; + pos +=snprintf (hdr + pos, hdrlen - pos, +"DEVICE=%c%u:%u" , + c,MAJOR (dev->devt),MINOR (dev->devt)); }else if (strcmp (subsys,"net" ) ==0 ) {struct net_device *net =to_net_dev (dev); - dictlen++; - dictlen +=snprintf (dict + dictlen,sizeof (dict) - dictlen, -"DEVICE=n%u" , net->ifindex); + pos++; + pos +=snprintf (hdr + pos, hdrlen - pos, +"DEVICE=n%u" , net->ifindex); }else { - dictlen++; - dictlen +=snprintf (dict + dictlen,sizeof (dict) - dictlen, -"DEVICE=+%s:%s" , subsys,dev_name (dev)); + pos++; + pos +=snprintf (hdr + pos, hdrlen - pos, +"DEVICE=+%s:%s" , subsys,dev_name (dev)); } -skip: -return printk_emit (0 , level[1 ] -'0' , - dictlen ? dict :NULL , dictlen, + +return pos; +} +EXPORT_SYMBOL (create_syslog_header); + +static int __dev_printk (const char *level,const struct device *dev, +struct va_format *vaf) +{ +char hdr[128 ]; +size_t hdrlen; + +if (!dev) +return printk ("%s(NULL device *): %pV" , level, vaf); + + hdrlen =create_syslog_header (dev, hdr,sizeof (hdr)); + +return printk_emit (0 , level[1 ] -'0' , hdrlen ? hdr :NULL , hdrlen,"%s %s: %pV" ,dev_driver_string (dev),dev_name (dev), vaf); } -EXPORT_SYMBOL (__dev_printk);int dev_printk (const char *level,const struct device *dev,const char *fmt, ...)
@@ -1931,6 +1938,7 @@ int dev_printk(const char *level, const struct device *dev, vaf.va = &args; r =__dev_printk (level, dev, &vaf); +va_end (args);return r;
@@ -1950,6 +1958,7 @@ int func(const struct device *dev, const char *fmt, ...) \ vaf.va = &args; \ \ r =__dev_printk (kern_level, dev, &vaf); \ + \va_end (args); \ \return r; \
include/linux/device.h +4 -7
@@ -891,12 +891,12 @@ extern const char *dev_driver_string(const struct device *dev);#ifdef CONFIG_PRINTK -extern int __dev_printk (const char *level,const struct device *dev, -struct va_format *vaf); +extern int create_syslog_header (const struct device *dev, +char *hdr,size_t hdrlen); + extern __printf(3, 4) int dev_printk(const char *level, const struct device *dev, - const char *fmt, ...) - ; + const char *fmt, ...); extern __printf(2, 3) int dev_emerg(const struct device *dev, const char *fmt, ...); extern __printf(2, 3)
@@ -914,9 +914,6 @@ int _dev_info(const struct device *dev, const char *fmt, ...);#else -static inline int __dev_printk (const char *level,const struct device *dev, -struct va_format *vaf) -{return 0 ; } static inline __printf(3, 4) int dev_printk(const char *level, const struct device *dev, const char *fmt, ...)
include/linux/netdevice.h +0 -3
@@ -2715,9 +2715,6 @@ static inline const char *netdev_name(const struct net_device *dev)return dev->name; } -extern int __netdev_printk (const char *level,const struct net_device *dev, -struct va_format *vaf); - extern __printf(3, 4) int netdev_printk(const char *level, const struct net_device *dev, const char *format, ...);
lib/dynamic_debug.c +52 -13
121 lines not on this page · raw message
net/core/dev.c +17 -7
@@ -6358,22 +6358,30 @@ const char *netdev_drivername(const struct net_device *dev)return empty; } -int __netdev_printk (const char *level,const struct net_device *dev, +static int __netdev_printk (const char *level,const struct net_device *dev,struct va_format *vaf) {int r; -if (dev && dev->dev.parent) - r =dev_printk (level, dev->dev.parent,"%s: %pV" , -netdev_name (dev), vaf); -else if (dev) +if (dev && dev->dev.parent) { +char dict[128 ]; +size_t dictlen =create_syslog_header (dev->dev.parent, + dict,sizeof (dict)); + + r =printk_emit (0 , level[1 ] -'0' , + dictlen ? dict :NULL , dictlen, +"%s %s %s: %pV" , +dev_driver_string (dev->dev.parent), +dev_name (dev->dev.parent), +netdev_name (dev), &vaf); + }else if (dev) { r =printk ("%s%s: %pV" , level,netdev_name (dev), vaf); -else + }else { r =printk ("%s(NULL net_device): %pV" , level, vaf); + }return r; } -EXPORT_SYMBOL (__netdev_printk);int netdev_printk (const char *level,const struct net_device *dev,const char *format, ...)
@@ -6388,6 +6396,7 @@ int netdev_printk(const char *level, const struct net_device *dev, vaf.va = &args; r =__netdev_printk (level, dev, &vaf); +va_end (args);return r;
@@ -6407,6 +6416,7 @@ int func(const struct net_device *dev, const char *fmt, ...) \ vaf.va = &args; \ \ r =__netdev_printk (level, dev, &vaf); \ + \va_end (args); \ \return r; \
Signature · 1 line
1.7.8.111.gad25c.dirty
Andrew Morton
maintainerQuoted 24 lines · On Sat, 28 Jul 2012 00:55:07 -0700 Joe Perches <[email protected]> wrote:
commit
c4e00daaa9("driver-core: extenddev_printk()to pass structured data") changed__dev_printkand broke dynamic-debug's ability to control the dynamic prefix ofdev_dbg(dev,..).
dynamic_emit_prefix()adds "[tid] module:func:line:" to the output and those additions got lost.In addition, the current dynamic debug code uses up to 3 recursion levels via %pV. This can consume quite a bit of stack. Directly call
printk_emitto reduce the recursion depth.These changes include:
o Remove
KERN_DEBUGfromdynamic_emit_prefix
o Create and use functioncreate_syslog_headerto format the syslog header forprintk_emituses.
o Callcreate_syslog_headerand neaten__dev_printk
o Callcreate_syslog_headerandprintk_emitfromdynamic_dev_dbg
o Callcreate_syslog_headerandprintk_emitfromdynamic_netdev_dbg
o Make__dev_printkand__netdev_printkstatic not global
o Remove include header declarations of__dev_printkand__netdev_printk
o Remove now unused EXPORT_SYMBOL()s of__dev_printkand__netdev_printk
o Whitespace neatening
Quoted 5 lines
Changes in v2:
o Fix
dynamic_emit_prefixto always initialize output
o Callcreate_syslog_headerandemit_printkfrom__netdev_printkand eliminate call todev_printkto remove another recursion via %pV
This one causes an oops-on-boot
(http://ozlabs.org/~akpm/stuff/IMG_20120731_144047.jpg). v1 didn't do that.
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Sat, 28 Jul 2012 00:55:07 -0700 Joe Perches <[email protected]> wrote:
commit
c4e00daaa9("driver-core: extenddev_printk()to pass structured data") changed__dev_printkand broke dynamic-debug's ability to control the dynamic prefix ofdev_dbg(dev,..).
Quoted 6 lines
Quoted 6 lines
dynamic_emit_prefix()adds "[tid] module:func:line:" to the output and those additions got lost.In addition, the current dynamic debug code uses up to 3 recursion levels via %pV. This can consume quite a bit of stack. Directly call
printk_emitto reduce the recursion depth.
[]
Quoted 6 lines
Quoted 5 lines
Changes in v2:
o Fix
dynamic_emit_prefixto always initialize output
o Callcreate_syslog_headerandemit_printkfrom__netdev_printkand eliminate call todev_printkto remove another recursion via %pV
Quoted 6 lines
This one causes an oops-on-boot
(http://ozlabs.org/~akpm/stuff/IMG_20120731_144047.jpg). v1 didn't do that.
Thanks. I'll fix it when I can.
Expect a week or so delay though.
I'm a bit busy on other projects and this one seems to require additional testing.
cheers, Joe