第一章 认识DPDK

本博客为《深入浅出DPDK》的简要笔记
想要学习一门技术,先要了解该技术的前后背景,已经为什么采用?它的优缺点是什么?这是所有的开端。

出现缘由:DPDK最初的动机很简单,就是证明IA多核处理器能够支撑高性能 数据包处理。随着早期目标的达成和更多通用处理器体系的加入, DPDK逐渐成为通用多核处理器高性能数据包处理的业界标杆。

DPDK能做什么?
通过 核心库Core Libs,PMD库,Classify库,QoS库等 模块,减少cache+DRAM的子系统的访问,在linux底层实现更快的数据包处理。
为什么需要绕开linux本身的协议栈呢?因为linux协议栈处理包当中,需要对包进行大量的复制等,性能有影响。而基本的SDN就是在linux协议栈的基础上进行搭建的,两个方向都有发展,如果有需要可以学习有关ovs源码实现等等。
DPDK主要模块分解

DPDK是为了什么?
是为了寻找IA(Intel Architecture)的性能天花板,怎么样实现,上面的模块的作用又是什么,后续再进一步学习。

下面是DPDK的一些简要例子,可以对DPDK有一个简单的认识。
例1:

int main(int argc, char **argv) 
{ 
	int ret; 
	unsigned lcore_id;
	ret = rte_eal_init(argc, argv); // 初始化,rte是指 runtime environment,eal是指environment abstraction layer
	if (ret < 0) rte_panic(“Cannot init EAL\n”); 	
	RTE_LCORE_FOREACH_SLAVE(lcore_id) { 
		// 遍历所有EAL 指定可以使用的lcore,执行lcore_hello函数
		rte_eal_remote_launch(lcore_hello, NULL, lcore_id);  /* call lcore_hello() on every slave lcore */
	}
	lcore_hello(NULL);/* call it on master lcore too */
	rte_eal_mp_wait_lcore(); 
	return 0; 
}

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;
}
	

例2:

int main(int argc, char *argv[]) {
	struct rte_mempool *mbuf_pool; 
	unsigned nb_ports; 
	uint8_t portid; 
	
	/* Initialize the Environment Abstraction Layer (EAL). */ 
	int ret = rte_eal_init(argc, argv); 
	
	/* Check that there is an even number of ports t send/receive on. */ 
	nb_ports = rte_eth_dev_count(); 
	
	if (nb_ports < 2 || (nb_ports & 1)) rte_exit(EXIT_FAILURE, "Error: number of ports must be even\n"); 
	
	/* Creates a new mempool in memory to hold the mbufs. */ 
	mbuf_pool = rte_pktmbuf_pool_create("MBUF_POOL", NUM_MBUFS * nb_ports, MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id()); 
	
	/* Initialize all ports. */ 
	for (portid = 0; portid < nb_ports; portid++) 
		if (port_init(portid, mbuf_pool) != 0) 
			rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n", portid);
	
	/* Call lcore_main on the master core only. */ 
	lcore_main(); 
	return 0; 
}

如果还需要更详细的例子,请查看《深入浅出DPDK》

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值