问题描述
在dpdk 17.05中,
结构lcore_config是公共的,而pthread_t可以通过lcore_config [lcore_id] .thread_id获得。 在18.11结构中,lcore_config是私有的,如何获得pthread_t作为lcore_id?
问题-我无法使用pthread_setname_np(
rte_gettid()
返回int
,但我需要pthread_t
解决方法
在DPDK rte_lcore.h
中,API rte_thread_setname
负责设置备用名称,而不是DPDK分配的名称。在Linux中,DPDK在内部调用pthread_setname_np
。
DPDK版本:dpdk-stable-18.11.10 如果glbc> 2.12,请按照DPDK代码库的设置名[edit-1] glibc版本:Ubuntu GLIBC 2.30-0ubuntu2.2
在C文件中修改的代码:
printf("hello from core %u\n",lcore_id);
snprintf(name,100,"hello-%d",lcore_id);
if (rte_thread_setname( pthread_self(),name) == 0)
printf(" thread name %s\n",name);
CFLAGS已添加到Makefile:
CFLAGS += -DALLOW_EXPERIMENTAL_API
或使用EXTRA_CFLAGS=-DALLOW_EXPERIMENTAL_API make
36986 root 20 0 227916 6996 6024 R 93.8 0.0 0:40.60 helloworld
37004 root 20 0 227916 6996 6024 R 93.8 0.0 0:40.61 lcore-slave-1
37005 root 20 0 227916 6996 6024 R 93.8 0.0 0:40.61 lcore-slave-2
37006 root 20 0 227916 6996 6024 R 93.8 0.0 0:40.61 lcore-slave-3
调用后
15326 root 20 0 153312 7728 5976 T 0.0 0.2 0:03.32 hello-0
15327 root 20 0 153312 7728 5976 T 0.0 0.2 0:00.00 eal-intr-thread
15328 root 20 0 153312 7728 5976 T 0.0 0.2 0:00.00 rte_mp_handle
15329 root 20 0 153312 7728 5976 T 0.0 0.2 0:03.32 hello-1
15330 root 20 0 153312 7728 5976 T 0.0 0.2 0:03.32 hello-2
15331 root 20 0 153312 7728 5976 T 0.0 0.2 0:03.32 hello-3