DPDK /example/helloworld代码详读

static int
lcore_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;
}

int
main(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;
}

有问题相互交流学习

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值