概述:
DPDK 日志系统分为1-8个等级,在lib/librte_eal/common/include/rte_log.h文件中定义,每个DPDK模块都可以定义一个预设日志输出等级,只有日志输出语句的等级小于等于预设输出等级才能被输出。
以下为dpdk对日志的分级:
/* Can't use 0, as it gives compiler warnings */
#define RTE_LOG_EMERG 1U /**< System is unusable. */
#define RTE_LOG_ALERT 2U /**< Action must be taken immediately. */
#define RTE_LOG_CRIT 3U /**< Critical conditions. */
#define RTE_LOG_ERR 4U /**< Error conditions. */
#define RTE_LOG_WARNING 5U /**< Warning conditions. */
#define RTE_LOG_NOTICE 6U /**< Normal but significant condition. */
#define RTE_LOG_INFO 7U /**< Informational. */
#define RTE_LOG_DEBUG 8U /**< Debug-level messages. */
Dpdk 使用int rte_log(uint32_t level, uint32_t logtype, const char *format, …); 函数打印日志,传入参数为:
-
此条日志输出等级,
-
日志type,
-
输出log信息,
但在dpdk中并不会直接使用rte_log,而是不同模块对它进行二次封装后使用
日志输出分析
例如在drivers/net/ixgbe/ixgbe_ethdev.c + 1038 ,此条log默认不会被输出,分析见后文
PMD_DRV_LOG(DEBUG, "SWFW phy%d lock released", hw->bus.func);
PMD_DRV_LOG的宏定义在ixgbe_log.h (通过ixgbe_ethdev.c对头文件的include可以看出,每个使用了LOG的地方,都会include一个xxx_log.h的文件),它的定义为:
extern int ixgbe_logtype_driver;
#define PMD_DRV_LOG_RAW(level, fmt, args...) \rte_log(RTE_LOG_ ## level, ixgbe_logtype_driver, "%s(): " fmt, \__func__, ## args)
传入的DEBUG被拼接为了RTE_LOG_DEBUG
对于宏中的ixgbe_logtype_driver 变量的定义和初始化:
//drivers/net/ixgbe/ixgbe_ethdev.c +8916 RTE_INIT(ixgbe_init_log){ixgbe_logtype_init = rte_log_register("pmd.net.ixgbe.init");if (ixgbe_logtype_init >= 0)rte_log_set_level(ixgbe_logtype_init, RTE_LOG_NOTICE);ixgbe_logtype_driver = rte_log_register("pmd.net.ixgbe.driver");if (ixgbe_logtype_driver >= 0)rte_log_set_level(ixgbe_logtype_driver, RTE_LOG_NOTICE);}
- 调用rte_log_register函数为ixgbe注册了名为”pmd.net.ixgbe.init”的日志type
返回一个int作为此日志的type( ixgbe_logtype_driver是为了方便代码编写,”pmd.net.ixgbe.init”是为了方便用户,他们是一一映射的)。 - 随后使用rte_log_set_level设置了默认日志输出等级为RTE_LOG_NOTICE
RTE_LOG_NOTICE<RTE_LOG_DEBUG,因此pmd.net.ixgbe.init日志 的DEBUG信息默认将不会输出。
log的使用
想要看到上文中ixgbe_logtype_driver 的debug级别日志需要在启动时传入–log-level参数,指定ixgbe_logtype_driver的debug开启。
以testpmd为例子:
./mips-loongson3a-linuxapp-gcc/app/testpmd --log-level=pmd.net.ixgbe.driver:8
则可以看见很多的debug信息被输出。这里的pmd.net.ixgbe.driver就是rte_log_register时传入的名字。
因此,想要看到对应的log,只需要展开二次封装的宏(如上文的PMD_DRV_LOG)找到此条log对应的type名字,在–log-level中传入设置即可