在我们的长连接网关中使用了syslog作为日志收集的工具,又因为引入dpdk作为用户态协议栈,调用ff_init后,发现日志输出不到syslog了,经过研究dpdk的文档后,发现dpdk支持syslog的配置,祥见rte_eal_init函数的实现,我们只需要添加“--syslog=local6”参数就行,“local6”就是syslog的facility,它的取值参考syslog的定义,实际上当然我们还可以调用rte_eal_log_init去设置syslog输出。在f-stack中可以修改如下代码实现:
/lib/ff_config.c 文件
static int
dpdk_args_setup(struct ff_config *cfg)
{
int n = 0, i;
dpdk_argv[n++] = strdup("f-stack");
char temp[DPDK_CONFIG_MAXLEN] = {0}, temp2[DPDK_CONFIG_MAXLEN] = {0};
if (cfg->dpdk.no_huge) {
dpdk_argv[n++] = strdup("--no-huge");
}
if (cfg->dpdk.proc_mask) {
sprintf(temp, "-c%s", cfg->dpdk.proc_mask);
dpdk_argv[n++] = strdup(temp);
}
if (cfg->dpdk.nb_channel) {
sprintf(temp, "-n%d", cfg->dpdk.nb_channel);
dpdk_argv[n++] = strdup(temp);
}
if (cfg->dpdk.memory) {
sprintf(temp, "-m%d", cfg->dpdk.memory);
dpdk_argv[n++] = strdup(temp);
}
if (cfg->dpdk.proc_type) {
sprintf(temp, "--proc-type=%s", cfg->dpdk.proc_type);
dpdk_argv[n++] = strdup(temp);
}
if (cfg->dpdk.base_virtaddr) {
sprintf(temp, "--base-virtaddr=%s", cfg->dpdk.base_virtaddr);
dpdk_argv[n++] = strdup(temp);
}
sprintf(temp, "--syslog=%s", "local6");
dpdk_argv[n++] = strdup(temp);
if (cfg->dpdk.nb_vdev) {
for (i=0; i<cfg->dpdk.nb_vdev; i++) {
sprintf(temp, "--vdev=virtio_user%d,path=%s",
cfg->dpdk.vdev_cfgs[i].vdev_id,
cfg->dpdk.vdev_cfgs[i].path);
if (cfg->dpdk.vdev_cfgs[i].nb_queues) {
sprintf(temp2, ",queues=%u",
cfg->dpdk.vdev_cfgs[i].nb_queues);
strcat(temp, temp2);
}
if (cfg->dpdk.vdev_cfgs[i].nb_cq) {
sprintf(temp2, ",cq=%u",
cfg->dpdk.vdev_cfgs[i].nb_cq);
strcat(temp, temp2);
}
if (cfg->dpdk.vdev_cfgs[i].queue_size) {
sprintf(temp2, ",queue_size=%u",
cfg->dpdk.vdev_cfgs[i].queue_size);
strcat(temp, temp2);
}
if (cfg->dpdk.vdev_cfgs[i].mac) {
sprintf(temp2, ",mac=%s",
cfg->dpdk.vdev_cfgs[i].mac);
strcat(temp, temp2);
}
dpdk_argv[n++] = strdup(temp);
...... // 此处代码省略
}
以上仅是测试代码,实际工程不能如此草率。
参考文档:https://programming.vip/docs/dpdk-rte_log-log-module.html
https://dpdk.readthedocs.io/en/v16.04/testpmd_app_ug/run_app.html