dpdk中的RTE_ETH_FOREACH_DEV宏分析

 

uint16_t
rte_eth_dev_count(void)
{
	uint16_t p;
	uint16_t count;

	count = 0;

    //统计可用的port
	RTE_ETH_FOREACH_DEV(p)
		count++;

	return count;
}



/*
rte_eth_find_next返回的p是一个临时中间变量,每次返回一个满足(unsigned int)p < (unsigned int)RTE_MAX_ETHPORTS的p,说明就有一个可用的port,因此可用计数count即可++
*/
#define RTE_ETH_FOREACH_DEV(p)					\
	for (p = rte_eth_find_next(0);				\
	     (unsigned int)p < (unsigned int)RTE_MAX_ETHPORTS;	\
	     p = rte_eth_find_next(p + 1))



/*
while循环是为了找出满足RTE_ETH_DEV_ATTACHED状态的dev,如果dev的state不满足的话,那么就会使port_id++,因此达到过滤作用。
*/

uint16_t
rte_eth_find_next(uint16_t port_id)
{
	while (port_id < RTE_MAX_ETHPORTS &&
	       rte_eth_devices[port_id].state != RTE_ETH_DEV_ATTACHED)
		port_id++;

	if (port_id >= RTE_MAX_ETHPORTS)
		return RTE_MAX_ETHPORTS;

	return port_id;
}

 

你可能感兴趣的:(dpdk中的RTE_ETH_FOREACH_DEV宏分析)