声明:此文档只做学习交流使用,请勿用作其他商业用途
author:朝阳_tonyLast Change: 2013年7月5日15:49:38 星期五
如果不知道dpdk,请了解我之前写的文章
intel dpdk安装部署http://blog.csdn.net/linzhaolove/article/details/9251433
平是在linux下使用vim开发,所以查看源码要用ctags比较方便;
进入dpdk主目录设置环境变量;
export RTE_SDK=`pwd` export RTE_TARGET=x86_64-default-linuxapp-gcc
创建tags文件;
cd ${RTE_SDK} ctags -R --c++-kinds=+x --fields=+iazS --extra=+q --if0=yes --exclude=x86_64-default-linuxapp-gcc
vim examples/helloworld/main.c
static int lcore_hello(__attribute__((unused)) void *arg) { unsigned lcore_id; lcore_id = rte_lcore_id(); printf("hello from core %u\n", lcore_id); return 0; } int MAIN(int argc, char **argv) { int ret; unsigned lcore_id; ret = rte_eal_init(argc, argv); if (ret < 0) rte_panic("Cannot init EAL\n"); /* call lcore_hello() on every slave lcore */ RTE_LCORE_FOREACH_SLAVE(lcore_id) { rte_eal_remote_launch(lcore_hello, NULL, lcore_id); } /* call it on master lcore too */ lcore_hello(NULL); rte_eal_mp_wait_lcore(); return 0; }
观察rte_eal_init()
dpdk内部初始函数,这个函数去调用一些dpdk初始化函数进行初始化;
例如:
rte_eal_log_early_init()// 初始化log记录信息
eal_parse_args(argc, argv);//解析执行程序时传进来的参数;其内部getopt_long(argc, argvopt, "b:c:d:m:n:r:v",lgopts, &option_index)
eal_hugepage_info_init();//初始化hugepage
rte_config_init();//配置rte_config结构体;会创建结构体的共享内存,然后方便其他程序调用;
rte_eal_alarm_init();//配置时钟中断;
rte_eal_intr_init();// 配置中断;
rte_eal_hpet_init();//初始化hpet;
rte_eal_pci_init();//初始化网卡pci,会初始化网卡驱动挂接;
接下来还会初始化各个子线程;等等;
rte_eal_mp_wait_lcore();//回收各子线程,
cd ${RTE_SDK}/example/helloworld make ./build/helloworld -c f -n 4
运行结果
# ./build/helloworld -c f -n 4 EAL: coremask set to f EAL: Using native RDTSC EAL: Detected lcore 0 on socket 0 EAL: Detected lcore 1 on socket 0 EAL: Detected lcore 2 on socket 0 EAL: Detected lcore 3 on socket 0 EAL: Detected lcore 4 on socket 0 EAL: Detected lcore 5 on socket 0 EAL: Detected lcore 6 on socket 0 EAL: Detected lcore 7 on socket 0 EAL: Detected lcore 8 on socket 0 EAL: Detected lcore 9 on socket 0 EAL: Detected lcore 10 on socket 0 EAL: Detected lcore 11 on socket 0 EAL: Requesting 1024 pages of size 2097152 EAL: Ask a virtual area of 0x80000000 bytes EAL: Virtual area found at 0x7f1b41600000 (size = 0x80000000) EAL: Master core 0 is ready (tid=c2569800) EAL: Core 3 is ready (tid=3f5fb700) EAL: Core 2 is ready (tid=3fdfc700) EAL: Core 1 is ready (tid=405fd700) hello from core 1 hello from core 2 hello from core 3 hello from core 0