dev_dbg/dynamic_debug: Update to use printk_emit, optimize stack
commitc4e00daaa9
("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,..). commitaf7f2158fd
("drivers-core: make structured logging play nice with dynamic-debug") made a minimal correction. 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: dev_dbg: 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 Make __dev_printk static not global o Remove include header declaration of __dev_printk o Remove now unused EXPORT_SYMBOL() of __dev_printk o Whitespace neatening dynamic_dev_dbg: o Remove KERN_DEBUG from dynamic_emit_prefix o Call create_syslog_header and printk_emit o Whitespace neatening Signed-off-by: Joe Perches <joe@perches.com> Acked-by: David S. Miller <davem@davemloft.net> Tested-by: Jim Cromie <jim.cromie@gmail.com> Acked-by: Jason Baron <jbaron@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
8f949b9a7e
commit
798efc60e4
|
@ -1865,26 +1865,19 @@ void device_shutdown(void)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef CONFIG_PRINTK
|
#ifdef CONFIG_PRINTK
|
||||||
int __dev_printk(const char *level, const struct device *dev,
|
int create_syslog_header(const struct device *dev, char *hdr, size_t hdrlen)
|
||||||
struct va_format *vaf)
|
|
||||||
{
|
{
|
||||||
char dict[128];
|
|
||||||
const char *level_extra = "";
|
|
||||||
size_t dictlen = 0;
|
|
||||||
const char *subsys;
|
const char *subsys;
|
||||||
|
size_t pos = 0;
|
||||||
if (!dev)
|
|
||||||
return printk("%s(NULL device *): %pV", level, vaf);
|
|
||||||
|
|
||||||
if (dev->class)
|
if (dev->class)
|
||||||
subsys = dev->class->name;
|
subsys = dev->class->name;
|
||||||
else if (dev->bus)
|
else if (dev->bus)
|
||||||
subsys = dev->bus->name;
|
subsys = dev->bus->name;
|
||||||
else
|
else
|
||||||
goto skip;
|
return 0;
|
||||||
|
|
||||||
dictlen += snprintf(dict + dictlen, sizeof(dict) - dictlen,
|
pos += snprintf(hdr + pos, hdrlen - pos, "SUBSYSTEM=%s", subsys);
|
||||||
"SUBSYSTEM=%s", subsys);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add device identifier DEVICE=:
|
* Add device identifier DEVICE=:
|
||||||
|
@ -1900,32 +1893,41 @@ int __dev_printk(const char *level, const struct device *dev,
|
||||||
c = 'b';
|
c = 'b';
|
||||||
else
|
else
|
||||||
c = 'c';
|
c = 'c';
|
||||||
dictlen++;
|
pos++;
|
||||||
dictlen += snprintf(dict + dictlen, sizeof(dict) - dictlen,
|
pos += snprintf(hdr + pos, hdrlen - pos,
|
||||||
"DEVICE=%c%u:%u",
|
"DEVICE=%c%u:%u",
|
||||||
c, MAJOR(dev->devt), MINOR(dev->devt));
|
c, MAJOR(dev->devt), MINOR(dev->devt));
|
||||||
} else if (strcmp(subsys, "net") == 0) {
|
} else if (strcmp(subsys, "net") == 0) {
|
||||||
struct net_device *net = to_net_dev(dev);
|
struct net_device *net = to_net_dev(dev);
|
||||||
|
|
||||||
dictlen++;
|
pos++;
|
||||||
dictlen += snprintf(dict + dictlen, sizeof(dict) - dictlen,
|
pos += snprintf(hdr + pos, hdrlen - pos,
|
||||||
"DEVICE=n%u", net->ifindex);
|
"DEVICE=n%u", net->ifindex);
|
||||||
} else {
|
} else {
|
||||||
dictlen++;
|
pos++;
|
||||||
dictlen += snprintf(dict + dictlen, sizeof(dict) - dictlen,
|
pos += snprintf(hdr + pos, hdrlen - pos,
|
||||||
"DEVICE=+%s:%s", subsys, dev_name(dev));
|
"DEVICE=+%s:%s", subsys, dev_name(dev));
|
||||||
}
|
}
|
||||||
skip:
|
|
||||||
if (level[2])
|
|
||||||
level_extra = &level[2]; /* skip past KERN_SOH "L" */
|
|
||||||
|
|
||||||
return printk_emit(0, level[1] - '0',
|
return pos;
|
||||||
dictlen ? dict : NULL, dictlen,
|
}
|
||||||
"%s %s: %s%pV",
|
EXPORT_SYMBOL(create_syslog_header);
|
||||||
dev_driver_string(dev), dev_name(dev),
|
|
||||||
level_extra, vaf);
|
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,
|
int dev_printk(const char *level, const struct device *dev,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
|
@ -1940,6 +1942,7 @@ int dev_printk(const char *level, const struct device *dev,
|
||||||
vaf.va = &args;
|
vaf.va = &args;
|
||||||
|
|
||||||
r = __dev_printk(level, dev, &vaf);
|
r = __dev_printk(level, dev, &vaf);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
@ -1959,6 +1962,7 @@ int func(const struct device *dev, const char *fmt, ...) \
|
||||||
vaf.va = &args; \
|
vaf.va = &args; \
|
||||||
\
|
\
|
||||||
r = __dev_printk(kern_level, dev, &vaf); \
|
r = __dev_printk(kern_level, dev, &vaf); \
|
||||||
|
\
|
||||||
va_end(args); \
|
va_end(args); \
|
||||||
\
|
\
|
||||||
return r; \
|
return r; \
|
||||||
|
|
|
@ -895,12 +895,12 @@ extern const char *dev_driver_string(const struct device *dev);
|
||||||
|
|
||||||
#ifdef CONFIG_PRINTK
|
#ifdef CONFIG_PRINTK
|
||||||
|
|
||||||
extern int __dev_printk(const char *level, const struct device *dev,
|
extern int create_syslog_header(const struct device *dev,
|
||||||
struct va_format *vaf);
|
char *hdr, size_t hdrlen);
|
||||||
|
|
||||||
extern __printf(3, 4)
|
extern __printf(3, 4)
|
||||||
int dev_printk(const char *level, const struct device *dev,
|
int dev_printk(const char *level, const struct device *dev,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...);
|
||||||
;
|
|
||||||
extern __printf(2, 3)
|
extern __printf(2, 3)
|
||||||
int dev_emerg(const struct device *dev, const char *fmt, ...);
|
int dev_emerg(const struct device *dev, const char *fmt, ...);
|
||||||
extern __printf(2, 3)
|
extern __printf(2, 3)
|
||||||
|
|
|
@ -521,25 +521,25 @@ static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf)
|
||||||
int pos_after_tid;
|
int pos_after_tid;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
pos += snprintf(buf + pos, remaining(pos), "%s", KERN_DEBUG);
|
*buf = '\0';
|
||||||
|
|
||||||
if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
|
if (desc->flags & _DPRINTK_FLAGS_INCL_TID) {
|
||||||
if (in_interrupt())
|
if (in_interrupt())
|
||||||
pos += snprintf(buf + pos, remaining(pos), "%s ",
|
pos += snprintf(buf + pos, remaining(pos), "<intr> ");
|
||||||
"<intr>");
|
|
||||||
else
|
else
|
||||||
pos += snprintf(buf + pos, remaining(pos), "[%d] ",
|
pos += snprintf(buf + pos, remaining(pos), "[%d] ",
|
||||||
task_pid_vnr(current));
|
task_pid_vnr(current));
|
||||||
}
|
}
|
||||||
pos_after_tid = pos;
|
pos_after_tid = pos;
|
||||||
if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
|
if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME)
|
||||||
pos += snprintf(buf + pos, remaining(pos), "%s:",
|
pos += snprintf(buf + pos, remaining(pos), "%s:",
|
||||||
desc->modname);
|
desc->modname);
|
||||||
if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
|
if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
|
||||||
pos += snprintf(buf + pos, remaining(pos), "%s:",
|
pos += snprintf(buf + pos, remaining(pos), "%s:",
|
||||||
desc->function);
|
desc->function);
|
||||||
if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
|
if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO)
|
||||||
pos += snprintf(buf + pos, remaining(pos), "%d:",
|
pos += snprintf(buf + pos, remaining(pos), "%d:",
|
||||||
desc->lineno);
|
desc->lineno);
|
||||||
if (pos - pos_after_tid)
|
if (pos - pos_after_tid)
|
||||||
pos += snprintf(buf + pos, remaining(pos), " ");
|
pos += snprintf(buf + pos, remaining(pos), " ");
|
||||||
if (pos >= PREFIX_SIZE)
|
if (pos >= PREFIX_SIZE)
|
||||||
|
@ -559,9 +559,13 @@ int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
|
||||||
BUG_ON(!fmt);
|
BUG_ON(!fmt);
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
||||||
vaf.fmt = fmt;
|
vaf.fmt = fmt;
|
||||||
vaf.va = &args;
|
vaf.va = &args;
|
||||||
res = printk("%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf);
|
|
||||||
|
res = printk(KERN_DEBUG "%s%pV",
|
||||||
|
dynamic_emit_prefix(descriptor, buf), &vaf);
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@ -574,15 +578,30 @@ int __dynamic_dev_dbg(struct _ddebug *descriptor,
|
||||||
struct va_format vaf;
|
struct va_format vaf;
|
||||||
va_list args;
|
va_list args;
|
||||||
int res;
|
int res;
|
||||||
char buf[PREFIX_SIZE];
|
|
||||||
|
|
||||||
BUG_ON(!descriptor);
|
BUG_ON(!descriptor);
|
||||||
BUG_ON(!fmt);
|
BUG_ON(!fmt);
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
||||||
vaf.fmt = fmt;
|
vaf.fmt = fmt;
|
||||||
vaf.va = &args;
|
vaf.va = &args;
|
||||||
res = __dev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf);
|
|
||||||
|
if (!dev) {
|
||||||
|
res = printk(KERN_DEBUG "(NULL device *): %pV", &vaf);
|
||||||
|
} else {
|
||||||
|
char buf[PREFIX_SIZE];
|
||||||
|
char dict[128];
|
||||||
|
size_t dictlen;
|
||||||
|
|
||||||
|
dictlen = create_syslog_header(dev, dict, sizeof(dict));
|
||||||
|
|
||||||
|
res = printk_emit(0, 7, dictlen ? dict : NULL, dictlen,
|
||||||
|
"%s%s %s: %pV",
|
||||||
|
dynamic_emit_prefix(descriptor, buf),
|
||||||
|
dev_driver_string(dev), dev_name(dev), &vaf);
|
||||||
|
}
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in New Issue