Skip to content

Commit ad7d61f

Browse files
cdownpmladek
authored andcommitted
printk: index: Add indexing support to dev_printk
While for most kinds of issues we have counters, tracepoints, or metrics with a stable interface which can reliably be used to indicate issues, in order to react to production issues quickly we sometimes need to work with the interface which most kernel developers naturally use when developing: printk, and printk-esques like dev_printk. dev_printk is by far the most likely custom subsystem printk to benefit from the printk indexing infrastructure, since niche device issues brought about by production changes, firmware upgrades, and the like are one of the most common things that we need printk infrastructure's assistance to monitor. Often these errors were never expected to practically manifest in reality, and exhibit in code without extensive (or any) metrics present. As such, there are typically very few options for issue detection available to those with large fleets at the time the incident happens, and we thus benefit strongly from monitoring netconsole in these instances. As such, add the infrastructure for dev_printk to be indexed in the printk index. Even on a minimal kernel config, the coverage of the base kernel's printk index is significantly improved: Before: [root@ktst ~]# wc -l /sys/kernel/debug/printk/index/vmlinux 4497 /sys/kernel/debug/printk/index/vmlinux After: [root@ktst ~]# wc -l /sys/kernel/debug/printk/index/vmlinux 5573 /sys/kernel/debug/printk/index/vmlinux In terms of implementation, in order to trivially disambiguate them, dev_printk is now a macro which wraps _dev_printk. Signed-off-by: Chris Down <[email protected]> Cc: Petr Mladek <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Rasmus Villemoes <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Tested-by: Petr Mladek <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/959c7aed1017cb2c9de922e0a820d397e29c6a5a.1623775748.git.chris@chrisdown.name
1 parent 3370155 commit ad7d61f

File tree

2 files changed

+52
-20
lines changed

2 files changed

+52
-20
lines changed

drivers/base/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4579,8 +4579,8 @@ static void __dev_printk(const char *level, const struct device *dev,
45794579
printk("%s(NULL device *): %pV", level, vaf);
45804580
}
45814581

4582-
void dev_printk(const char *level, const struct device *dev,
4583-
const char *fmt, ...)
4582+
void _dev_printk(const char *level, const struct device *dev,
4583+
const char *fmt, ...)
45844584
{
45854585
struct va_format vaf;
45864586
va_list args;
@@ -4594,7 +4594,7 @@ void dev_printk(const char *level, const struct device *dev,
45944594

45954595
va_end(args);
45964596
}
4597-
EXPORT_SYMBOL(dev_printk);
4597+
EXPORT_SYMBOL(_dev_printk);
45984598

45994599
#define define_dev_printk_level(func, kern_level) \
46004600
void func(const struct device *dev, const char *fmt, ...) \

include/linux/dev_printk.h

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ __printf(3, 4) __cold
3838
int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...);
3939

4040
__printf(3, 4) __cold
41-
void dev_printk(const char *level, const struct device *dev,
42-
const char *fmt, ...);
41+
void _dev_printk(const char *level, const struct device *dev,
42+
const char *fmt, ...);
4343
__printf(2, 3) __cold
4444
void _dev_emerg(const struct device *dev, const char *fmt, ...);
4545
__printf(2, 3) __cold
@@ -69,7 +69,7 @@ static inline void __dev_printk(const char *level, const struct device *dev,
6969
struct va_format *vaf)
7070
{}
7171
static inline __printf(3, 4)
72-
void dev_printk(const char *level, const struct device *dev,
72+
void _dev_printk(const char *level, const struct device *dev,
7373
const char *fmt, ...)
7474
{}
7575

@@ -97,25 +97,57 @@ void _dev_info(const struct device *dev, const char *fmt, ...)
9797

9898
#endif
9999

100+
/*
101+
* Need to take variadic arguments even though we don't use them, as dev_fmt()
102+
* may only just have been expanded and may result in multiple arguments.
103+
*/
104+
#define dev_printk_index_emit(level, fmt, ...) \
105+
printk_index_subsys_emit("%s %s: ", level, fmt)
106+
107+
#define dev_printk_index_wrap(_p_func, level, dev, fmt, ...) \
108+
({ \
109+
dev_printk_index_emit(level, fmt); \
110+
_p_func(dev, fmt, ##__VA_ARGS__); \
111+
})
112+
113+
/*
114+
* Some callsites directly call dev_printk rather than going through the
115+
* dev_<level> infrastructure, so we need to emit here as well as inside those
116+
* level-specific macros. Only one index entry will be produced, either way,
117+
* since dev_printk's `fmt` isn't known at compile time if going through the
118+
* dev_<level> macros.
119+
*
120+
* dev_fmt() isn't called for dev_printk when used directly, as it's used by
121+
* the dev_<level> macros internally which already have dev_fmt() processed.
122+
*
123+
* We also can't use dev_printk_index_wrap directly, because we have a separate
124+
* level to process.
125+
*/
126+
#define dev_printk(level, dev, fmt, ...) \
127+
({ \
128+
dev_printk_index_emit(level, fmt); \
129+
_dev_printk(level, dev, fmt, ##__VA_ARGS__); \
130+
})
131+
100132
/*
101133
* #defines for all the dev_<level> macros to prefix with whatever
102134
* possible use of #define dev_fmt(fmt) ...
103135
*/
104136

105-
#define dev_emerg(dev, fmt, ...) \
106-
_dev_emerg(dev, dev_fmt(fmt), ##__VA_ARGS__)
107-
#define dev_crit(dev, fmt, ...) \
108-
_dev_crit(dev, dev_fmt(fmt), ##__VA_ARGS__)
109-
#define dev_alert(dev, fmt, ...) \
110-
_dev_alert(dev, dev_fmt(fmt), ##__VA_ARGS__)
111-
#define dev_err(dev, fmt, ...) \
112-
_dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__)
113-
#define dev_warn(dev, fmt, ...) \
114-
_dev_warn(dev, dev_fmt(fmt), ##__VA_ARGS__)
115-
#define dev_notice(dev, fmt, ...) \
116-
_dev_notice(dev, dev_fmt(fmt), ##__VA_ARGS__)
117-
#define dev_info(dev, fmt, ...) \
118-
_dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__)
137+
#define dev_emerg(dev, fmt, ...) \
138+
dev_printk_index_wrap(_dev_emerg, KERN_EMERG, dev, dev_fmt(fmt), ##__VA_ARGS__)
139+
#define dev_crit(dev, fmt, ...) \
140+
dev_printk_index_wrap(_dev_crit, KERN_CRIT, dev, dev_fmt(fmt), ##__VA_ARGS__)
141+
#define dev_alert(dev, fmt, ...) \
142+
dev_printk_index_wrap(_dev_alert, KERN_ALERT, dev, dev_fmt(fmt), ##__VA_ARGS__)
143+
#define dev_err(dev, fmt, ...) \
144+
dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
145+
#define dev_warn(dev, fmt, ...) \
146+
dev_printk_index_wrap(_dev_warn, KERN_WARNING, dev, dev_fmt(fmt), ##__VA_ARGS__)
147+
#define dev_notice(dev, fmt, ...) \
148+
dev_printk_index_wrap(_dev_notice, KERN_NOTICE, dev, dev_fmt(fmt), ##__VA_ARGS__)
149+
#define dev_info(dev, fmt, ...) \
150+
dev_printk_index_wrap(_dev_info, KERN_INFO, dev, dev_fmt(fmt), ##__VA_ARGS__)
119151

120152
#if defined(CONFIG_DYNAMIC_DEBUG) || \
121153
(defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))

0 commit comments

Comments
 (0)