DPDK网卡设备概念

DPDK网卡初始化流程中涉及的几个对象

port

端口对象,例如一个pcie网卡

rx_queue/tx_queue

端口收发队列对象
多核环境下,端口收到包后可指定响应的cpu来处理这个包。
通过增加收发队列,根据五元组哈希分配处理的core,实现计算资源的初步负载均衡
每个端口进来的包通过rss模块计算hash后,发送到对应cpu的queue上等待处理

tx_desc/rx_desc

网卡驱动中收发dma的队列数量。
收发desc中描述了dma收发需要的信息,如源/目的地址、长度等

相关API

根据设备名称获取端口号

int
rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)

驱动probe阶段识别到网卡后,层层深入调用到rte_eth_dev_allocate,从rte_eth_devices数组中分配一个未使用的结构
后续API中的port_id其实访问的就是rte_eth_devices[port_id]

设置端口的收发队列数量,以及端口参数

int rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_queue,
		uint16_t nb_tx_queue, const struct rte_eth_conf *eth_conf);

nb_rx_queue/nb_tx_queue配置依据:收发包处理的core数量

设置端口接收队列。rte_eth_dev_info_get可以获取rx_conf的默认配置

int rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
		uint16_t nb_rx_desc, unsigned int socket_id,
		const struct rte_eth_rxconf *rx_conf,
		struct rte_mempool *mb_pool);

nb_rx_desc配置依据:网卡硬件,不能超过mb_pool中ring的数量
mb_pool:网卡->驱动接收包时分配的内存池

设置端口发送队列。rte_eth_dev_info_get可以获取tx_conf的默认配置

int rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
		uint16_t nb_tx_desc, unsigned int socket_id,
		const struct rte_eth_txconf *tx_conf);

nb_tx_desc配置依据:网卡硬件

每张网卡的tx/rx descriptor是确定的,所有port的队列共享这些descriptor
rte_eth_rx_queue_setup和rte_eth_tx_queue_setup允许具体分配每个队列占用的descriptor数量,初步实现基于队列的Qos

原文地址:https://www.cnblogs.com/zl-yang/p/11058277.html