在阅读高通Display驱动代码的时候,几乎每个文件都在第一行定义pr_fmt,如
kernel/msm-4.14/drivers/gpu/drm/msm/dsi-staging/dsi_diplay.c
#define pr_fmt(fmt) "msm-dsi-display:[%s] " fmt, __func__
kernel/msm-4.14/drivers/gpu/drm/msm/dsi-staging/dsi_panel.c
#define pr_fmt(fmt) "msm-dsi-panel:[%s:%d] " fmt, __func__, __LINE__
于是,跟了一下代码,看看pr_fmt有什么作用,下面直接粘贴printk.h的定义
#ifndef pr_fmt
#define pr_fmt(fmt) fmt
#endif
/*
* 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.
*/
#define pr_emerg(fmt, ...) \
printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
#define pr_alert(fmt, ...) \
printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
#define pr_crit(fmt, ...) \
printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
#define pr_err(fmt, ...) \
printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
#define pr_warning(fmt, ...) \
printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
#define pr_warn pr_warning
#define pr_notice(fmt, ...) \
printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
#define pr_info(fmt, ...) \
printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
/*
* Like KERN_CONT, pr_cont() should only be used when continuing
* a line with no newline ('\n') enclosed. Otherwise it defaults
* back to KERN_DEFAULT.
*/
#define pr_cont(fmt, ...) \
printk(KERN_CONT fmt, ##__VA_ARGS__)
如果驱动中没有定义pr_fmt(fmt),那么,pr_fmt(fmt)就是fmt。
从printk.h可以发现定义的log输出函数基本上都会用pr_fmt这个宏,这样的话,只要在驱动文件定义pr_fmt,如上述"msm-dsi-display",调试log就会附加定义的信息,这样在分析log时,通过关键字可以很方便提取到整个文件输出的log。
[ 23.665345] [<7>][1, swapper/0]msm-dsi-display soc:qcom,dsi-display-primary: soc:qcom,dsi-display-primary supply vdd not found, using dummy regulator
[ 23.679722] [<7>][1, swapper/0]msm-dsi-display:[dsi_display_bind] Successfully bind display panel 'dsi_s6e3fc2x01_sumsung_amoled_cmd_display'
[ 23.932055] [<4>][1, swapper/0]msm-dsi-panel:[dsi_panel_parse_topology:2636] default topology: lm: 1 comp_enc:0 intf: 1
[ 23.943331] [<7>][1, swapper/0]msm-dsi-panel:[dsi_panel_parse_partial_update_caps:2726] partial update disabled as the property is not set