提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
前言
本人负责的数据处理引擎一直是在centos系统中运行,近期在适配ubuntu系统时, dpdk模块出现了一些问题,主要是dpdk动态库在ubuntu系统中使用的问题,现将适配过程中遇到的坑和解决方法记录一下。
一、问题一: 内核版本高,dpdk版本低,编译失败
1.问题现象
a) 数据处理引擎一直运行在centos7.6系统下,内核版本为3.10.0-957.el7.x86_64,dpdk版本为16.07,编译正常。
b) 待适配系统为ubuntu16.04.7,内核版本为4.15.0-112-generic,同样使用dpdk16.07,编译igb_uio.c时报错,如下:
/root/dpdk/x86_64-native-linuxapp-gcc/build/lib/librte_eal/linuxapp/igb_uio/igb_uio.c:383:7: error: implicit declaration of function ‘pci_enable_msix’ [-Werror=implicit-function-declaration]
if (pci_enable_msix(dev, &msix_entry, 1) == 0) {
^
cc1: all warnings being treated as errors
上述错误是由于内核文件中没有pci_enable_msix定义。根本原因时dpdk16.07版本太老,内核版本比较新。
2.解决方法
使用较新的dpdk版本。在这里选择了dpdk17.11.10, 编译顺利通过。
二、问题二:程序启动时无法加载网卡驱动动态库,导致无法识别到可用的端口
1.问题现象
a) 在centos7.6系统下,使用dpdk动态库编译第三方程序(test),可以正常运行。
b) 在ubuntu16.04系统下,使用同样dpdk版本编译第三方程序tset,并配置好dpdk环境后(加载igb_uio, 分配大页,绑定网卡)后,test运行失败,dpdk初始化时发现不了网卡设备,如下:
EAL: Detected 32 lcore(s)
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
skip pci addr: 0000:01:00.1
skip pci addr: 0000:02:00.0
skip pci addr: 0000:02:00.1
EAL: Error - exiting with code: 1
Cause: can not find port
cmake脚本中明确链接了librte_pmd_ixgbe.so库,但是ldd test的结果中,却没有librte_pmd_ixgbe.so。初步判定是由于tset运行时没有加载librte_pmd_ixgbe.so所致。
c) 为确认ubuntu中test启动失败的问题是由于未加载网卡驱动动态库所致。 在ubuntu16.04系统下,使用同样dpdk版本静态库编译第三方程序tset,test也可以运行。此处可以说明ubuntu系统下使用动态库时,未加载网卡驱动库所致。
2.问题分析
通过ubuntu系统下使用静态库和动态库时,test的运行情况对比可以发现:
使用静态库时, rte_eal_init可以扫描到网卡设备,找到所有可用的端口;但是使用动态库时,rte_eal_init可以扫描不到网卡设备,找不到所有可用的端口,并且ldd tset的结果中没有librte_pmd_ixgbe.so等类似得到网卡驱动动态库。
因此只要tset可以正常加载到网卡驱动动态库,test就可以扫描到网卡设备。
3.解决方法
- 方法一
****启动程序时,使用-d选项指定要加载的driver(EAL的“-d”选项可以指定需要载入的动态链接库)**,如下:
root@ubuntu1604:~# ./testp -c 0xff -n 2 -d ../lib/librte_pmd_e1000.so -d ../lib/librte_pmd_ixgbe.so
源码中对应的说明如下:
void
eal_common_usage(void)
{
printf("[options]\n\n"
"EAL common options:\n"
" -c COREMASK Hexadecimal bitmask of cores to run on\n"
" -l CORELIST List of cores to run on\n"
" The argument format is <c1>[-c2][,c3[-c4],...]\n"
" where c1, c2, etc are core indexes between 0 and %d\n"
" --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
" The argument format is\n"
" '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
" lcores and cpus list are grouped by '(' and ')'\n"
" Within the group, '-' is used for range separator,\n"
" ',' is used for single number separator.\n"
" '( )' can be omitted for single element group,\n"
" '@' can be omitted if cpus and lcores have the same value\n"
" -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
" --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
" --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
" -n CHANNELS Number of memory channels\n"
" -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
" -r RANKS Force number of memory ranks (don't detect)\n"
" -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
" Prevent EAL from using this PCI device. The argument\n"
" format is <domain:bus:devid.func>.\n"
" -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
" Only use the specified PCI devices. The argument format\n"
" is <[domain:]bus:devid.func>. This option can be present\n"
" several times (once per device).\n"
" [NOTE: PCI whitelist cannot be used with -b option]\n"
" --"OPT_VDEV" Add a virtual device.\n"
" The argument format is <driver><id>[,key=val,...]\n"
" (ex: --vdev=net_pcap0,iface=eth2).\n"
" -d LIB.so|DIR Add a driver or driver directory\n"
" (can be used multiple times)\n"
" --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
" --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
" --"OPT_SYSLOG" Set syslog facility\n"
" --"OPT_LOG_LEVEL"=<int> Set global log level\n"
" --"OPT_LOG_LEVEL"=<type-regexp>,<int>\n"
" Set specific log level\n"
" -v Display version information on startup\n"
" -h, --help This help\n"
"\nEAL options for DEBUG use only:\n"
" --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
" --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
" --"OPT_NO_PCI" Disable PCI\n"
" --"OPT_NO_HPET" Disable HPET\n"
" --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
"\n", RTE_MAX_LCORE);
}
2.方法二
在编译dpdk前,修改common_base中的CONFIG_RTE_EAL_PMD_PATH变量(默认为""),设置driver的路径,如下:
# Default driver path (or "" to disable)
CONFIG_RTE_EAL_PMD_PATH="/lib64/dpdk_driver_lib"
编译完成后,将网卡驱动动态库放到设置CONFIG_RTE_EAL_PMD_PATH的路径下即可。这样使用dpdk动态库编译出来的第三方程序就可以正常加载网卡驱动,rte_eal_init时就可以扫描到网卡设备了。
3、源码加载流程
rte_eal_init
│
├──eal_plugins_init (EAL的“-d”选项可以指定需要载入的动态链接库)
│ │
│ ├──如果全局变量 default_solib_dir 所指的Default path of external loadable drivers有效
│ │ │
│ │ └──eal_plugin_add
│ │ │
│ │ ├──malloc一个struct shared_driver结构,拷贝路径名称
│ │ │
│ │ └──将此struct shared_driver结构挂载到List of external loadable drivers中 solib_list
│ │
│ └──遍历solib_list上挂载的所有struct shared_driver结构
│ │
│ ├──如果当前struct shared_driver结构所保存的路径是目录
│ │ │
│ │ └──eal_plugindir_init
│ │ │
│ │ └──对目录中的每个普通文件,执行eal_plugin_add
│ │ (将文件挂载到Listof external loadable drivers的尾部,待接下来的遍历循环进行处理)
│ │
│ └──否则,是共享库的情况
│ │
│ └──调用dlopen打开指定的动态链接库
————————————————
int
eal_plugins_init(void)
{
struct shared_driver *solib = NULL;
struct stat sb;
//此处的default_solib_dir的值为宏定义RTE_EAL_PMD_PATH的值,通过在common_base设置CONFIG_RTE_EAL_PMD_PATH,在编译dpdk时会生成rte_config.h头文件,该文件中RTE_EAL_PMD_PATH宏定义的值为common_base中设置CONFIG_RTE_EAL_PMD_PATH的值
if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
S_ISDIR(sb.st_mode))
eal_plugin_add(default_solib_dir);
TAILQ_FOREACH(solib, &solib_list, next) {
if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
if (eal_plugindir_init(solib->name) == -1) {
RTE_LOG(ERR, EAL,
"Cannot init plugin directory %s\n",
solib->name);
return -1;
}
} else {
RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
solib->name);
solib->lib_handle = dlopen(solib->name, RTLD_NOW);
if (solib->lib_handle == NULL) {
RTE_LOG(ERR, EAL, "%s\n", dlerror());
return -1;
}
}
}
return 0;
}
三、问题三: 创建内存池失败
1. 问题现象
使用rte_mempool_create或rte_pktmbuf_pool_create创建内存时失败,报错信息如下
EAL: Detected 32 lcore(s)
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: PCI device 0000:04:00.0 on NUMA socket 0
EAL: probe driver: 8086:105e net_e1000_em
EAL: PCI device 0000:04:00.1 on NUMA socket 0
EAL: probe driver: 8086:105e net_e1000_em
EAL: PCI device 0000:44:00.0 on NUMA socket 1
EAL: probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:44:00.1 on NUMA socket 1
EAL: probe driver: 8086:10fb net_ixgbe
Interactive-mode selected
USER1: create a new mbuf pool <mbuf_pool_socket_0>: n=203456, size=2176, socket=0
MBUF: error setting mempool handler
EAL: Error - exiting with code: 1
Cause: Creation of mbuf pool for socket 0 failed: Invalid argument
2. 问题分析
gdb调试代码,发现错误问题不是由于内存不足,而是因为rte_mempool_ops_table中没有名为ring_mp_mc的ops信息,导致rte_mempool_set_ops_byname失败(返回-EINVAL)所致。
/* create the mempool */
struct rte_mempool *
rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
unsigned cache_size, unsigned private_data_size,
rte_mempool_ctor_t *mp_init, void *mp_init_arg,
rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
int socket_id, unsigned flags)
{
int ret;
struct rte_mempool *mp;
mp = rte_mempool_create_empty(name, n, elt_size, cache_size,
private_data_size, socket_id, flags);
if (mp == NULL)
return NULL;
/*
* Since we have 4 combinations of the SP/SC/MP/MC examine the flags to
* set the correct index into the table of ops structs.
*/
if ((flags & MEMPOOL_F_SP_PUT) && (flags & MEMPOOL_F_SC_GET))
ret = rte_mempool_set_ops_byname(mp, "ring_sp_sc", NULL);
else if (flags & MEMPOOL_F_SP_PUT)
ret = rte_mempool_set_ops_byname(mp, "ring_sp_mc", NULL);
else if (flags & MEMPOOL_F_SC_GET)
ret = rte_mempool_set_ops_byname(mp, "ring_mp_sc", NULL);
else
ret = rte_mempool_set_ops_byname(mp, "ring_mp_mc", NULL); //默认值。此处返回错误码-EINVAL
if (ret)
goto fail;
/* call the mempool priv initializer */
if (mp_init)
mp_init(mp, mp_init_arg);
if (rte_mempool_populate_default(mp) < 0)
goto fail;
/* call the object initializers */
if (obj_init)
rte_mempool_obj_iter(mp, obj_init, obj_init_arg);
return mp;
fail:
rte_mempool_free(mp);
return NULL;
}
/* sets mempool ops previously registered by rte_mempool_register_ops. */
int
rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,
void *pool_config)
{
struct rte_mempool_ops *ops = NULL;
unsigned i;
/* too late, the mempool is already populated. */
if (mp->flags & MEMPOOL_F_POOL_CREATED)
return -EEXIST;
for (i = 0; i < rte_mempool_ops_table.num_ops; i++) {
if (!strcmp(name,
rte_mempool_ops_table.ops[i].name)) {
ops = &rte_mempool_ops_table.ops[i];
break;
}
}
if (ops == NULL) //rte_mempool_ops_table没有名为ring_mp_mc的ops信息,返回-EINVAL
return -EINVAL;
mp->ops_index = i;
mp->pool_config = pool_config;
return 0;
}
rte_mempool_rings.c中的注册函数没有调用,该源文件生成librte_mempool_ring.so库。
static const struct rte_mempool_ops ops_mp_mc = {
.name = "ring_mp_mc",
.alloc = common_ring_alloc,
.free = common_ring_free,
.enqueue = common_ring_mp_enqueue,
.dequeue = common_ring_mc_dequeue,
.get_count = common_ring_get_count,
};
static const struct rte_mempool_ops ops_sp_sc = {
.name = "ring_sp_sc",
.alloc = common_ring_alloc,
.free = common_ring_free,
.enqueue = common_ring_sp_enqueue,
.dequeue = common_ring_sc_dequeue,
.get_count = common_ring_get_count,
};
static const struct rte_mempool_ops ops_mp_sc = {
.name = "ring_mp_sc",
.alloc = common_ring_alloc,
.free = common_ring_free,
.enqueue = common_ring_mp_enqueue,
.dequeue = common_ring_sc_dequeue,
.get_count = common_ring_get_count,
};
static const struct rte_mempool_ops ops_sp_mc = {
.name = "ring_sp_mc",
.alloc = common_ring_alloc,
.free = common_ring_free,
.enqueue = common_ring_sp_enqueue,
.dequeue = common_ring_mc_dequeue,
.get_count = common_ring_get_count,
};
MEMPOOL_REGISTER_OPS(ops_mp_mc);
MEMPOOL_REGISTER_OPS(ops_sp_sc);
MEMPOOL_REGISTER_OPS(ops_mp_sc);
MEMPOOL_REGISTER_OPS(ops_sp_mc);
ldd test的结果中没有librte_mempool_ring.so,也是由于没有加载该动态库所致。
3. 解决方法
参照问题二的解决方法。可以通过EAL -d选项指定加载librte_mempool_ring.so,也可以将librte_mempool_ring.so复制到common_base中配置的CONFIG_RTE_EAL_PMD_PATH目录下。
总结
dpdk默认编译静态库,在centos和ubunt中均可正常使用。
dpdk通过修改common_base中的CONFIG_RTE_BUILD_SHARED_LIB=y,则会编译dpdk动态库。
在centos中使用dpdk动态库时,使用方式与静态库相同。只要编译时指定链接某个动态库,ldd的结果显示程序依赖该动态库,程序运行时也会加载该动态库,
在ubuntu中使用dpdk动态库时,使用方式与静态库稍有不同,主要区别是在程序运行时的驱动库加载上。即使编译时指定链接某个驱动动态库,ldd的结果显示程序不会依赖该驱动动态库,程序运行时不会加载该驱动库,需要通过EAL -d选项指定加载的驱动库,或者将驱动库移动至编译dpdk是指定的驱动目录下。
参考
https://blog.csdn.net/wenqier1222/article/details/83828512
https://www.cnblogs.com/hugetong/p/9366914.html
https://blog.csdn.net/hhd1988/article/details/123247151