intel dpdk api helloworld 源码学习

来源:互联网 发布:百度云盘 for mac 编辑:程序博客网 时间:2024/05/21 10:43

声明:此文档只做学习交流使用,请勿用作其他商业用途

author:朝阳_tony
E-mail : linzhaolover@gmail.com
Create Date:2013年7月5日15:49:30 星期五
转载请注明出处:http://blog.csdn.net/linzhaolover

Last Change: 2013年7月5日15:49:38 星期五


如果不知道dpdk,请了解我之前写的文章

intel dpdk安装部署http://blog.csdn.net/linzhaolove/article/details/9251433


1、查看源码

平是在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 intlcore_hello(__attribute__((unused)) void *arg){    unsigned lcore_id;    lcore_id = rte_lcore_id();    printf("hello from core %u\n", lcore_id);    return 0;}intMAIN(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_remote_launch(lcore_hello, NULL, lcore_id);//让子线程区调用 lcore_hello()函数

rte_eal_mp_wait_lcore();//回收各子线程,


2、编译运行程序

cd ${RTE_SDK}/example/helloworldmake./build/helloworld -c f -n 4 


运行结果

# ./build/helloworld -c f -n 4 EAL: coremask set to fEAL: Using native RDTSCEAL: Detected lcore 0 on socket 0EAL: Detected lcore 1 on socket 0EAL: Detected lcore 2 on socket 0EAL: Detected lcore 3 on socket 0EAL: Detected lcore 4 on socket 0EAL: Detected lcore 5 on socket 0EAL: Detected lcore 6 on socket 0EAL: Detected lcore 7 on socket 0EAL: Detected lcore 8 on socket 0EAL: Detected lcore 9 on socket 0EAL: Detected lcore 10 on socket 0EAL: Detected lcore 11 on socket 0EAL: Requesting 1024 pages of size 2097152EAL: Ask a virtual area of 0x80000000 bytesEAL: 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 1hello from core 2hello from core 3hello from core 0