本博客为《深入浅出DPDK》的简要笔记
想要学习一门技术,先要了解该技术的前后背景,已经为什么采用?它的优缺点是什么?这是所有的开端。
出现缘由:DPDK最初的动机很简单,就是证明IA多核处理器能够支撑高性能 数据包处理。随着早期目标的达成和更多通用处理器体系的加入, DPDK逐渐成为通用多核处理器高性能数据包处理的业界标杆。
DPDK能做什么?
通过 核心库Core Libs,PMD库,Classify库,QoS库等 模块,减少cache+DRAM的子系统的访问,在linux底层实现更快的数据包处理。
为什么需要绕开linux本身的协议栈呢?因为linux协议栈处理包当中,需要对包进行大量的复制等,性能有影响。而基本的SDN就是在linux协议栈的基础上进行搭建的,两个方向都有发展,如果有需要可以学习有关ovs源码实现等等。
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》