DPDK /example/helloworld代码详读

来源:互联网 发布:mac ps没有足够内存 编辑:程序博客网 时间:2024/06/13 06:44
static intlcore_hello(__attribute__((unused)) void *arg)  //__attribute__((unused))表示该函数或变量可能不使用,告诉编译器不要给出告警;{unsigned lcore_id;lcore_id = rte_lcore_id();  //返回正在运行的执行单元的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);//初始化EAL工作,返回0表示初始化成功,DPDK很多函数用返回值为0表示功能实现;if (ret < 0)rte_panic("Cannot init EAL\n");/* call lcore_hello() on every slave lcore */RTE_LCORE_FOREACH_SLAVE(lcore_id) {   //RTE_LCORE_FOREACH_SLAVE其实是一个循环,遍历除当前主核之外的所有逻辑核;rte_eal_remote_launch(lcore_hello, NULL, lcore_id);//在逻辑核ID=lcore_id的核上运行lcore_hello;}/* call it on master lcore too */lcore_hello(NULL);         //在主逻辑核调用lcore_hello(),因为获取的id为当前核;rte_eal_mp_wait_lcore();return 0;}

有问题相互交流学习

原创粉丝点击