eal: introduce integer log2 function

At some places, the log2() function is used despite this function
works on float. This introduces a dependency to the math lib but
most of the time it is not required because we want an integer log2.

Add a new helper to do this job and fix nfp driver.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Alejandro Lucero <alejandro.lucero@netronome.com>
This commit is contained in:
Olivier Matz 2017-04-06 16:15:36 +02:00 committed by Thomas Monjalon
parent 5142318c81
commit fed524ce53
3 changed files with 20 additions and 5 deletions

View File

@ -39,8 +39,6 @@
* Netronome vNIC DPDK Poll-Mode Driver: Main entry point * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
*/ */
#include <math.h>
#include <rte_byteorder.h> #include <rte_byteorder.h>
#include <rte_common.h> #include <rte_common.h>
#include <rte_log.h> #include <rte_log.h>
@ -1473,7 +1471,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
* of descriptors in log2 format * of descriptors in log2 format
*/ */
nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(queue_idx), rxq->dma); nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(queue_idx), rxq->dma);
nn_cfg_writeb(hw, NFP_NET_CFG_RXR_SZ(queue_idx), log2(nb_desc)); nn_cfg_writeb(hw, NFP_NET_CFG_RXR_SZ(queue_idx), rte_log2_u32(nb_desc));
return 0; return 0;
} }
@ -1628,7 +1626,7 @@ nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
* of descriptors in log2 format * of descriptors in log2 format
*/ */
nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(queue_idx), txq->dma); nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(queue_idx), txq->dma);
nn_cfg_writeb(hw, NFP_NET_CFG_TXR_SZ(queue_idx), log2(nb_desc)); nn_cfg_writeb(hw, NFP_NET_CFG_TXR_SZ(queue_idx), rte_log2_u32(nb_desc));
return 0; return 0;
} }

View File

@ -336,6 +336,23 @@ rte_bsf32(uint32_t v)
return __builtin_ctz(v); return __builtin_ctz(v);
} }
/**
* Return the rounded-up log2 of a integer.
*
* @param v
* The input parameter.
* @return
* The rounded-up log2 of the input, or 0 if the input is 0.
*/
static inline uint32_t
rte_log2_u32(uint32_t v)
{
if (v == 0)
return 0;
v = rte_align32pow2(v);
return rte_bsf32(v);
}
#ifndef offsetof #ifndef offsetof
/** Return the offset of a field in a structure. */ /** Return the offset of a field in a structure. */
#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)

View File

@ -128,7 +128,7 @@ endif
_LDLIBS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += -lrte_pmd_lio _LDLIBS-$(CONFIG_RTE_LIBRTE_LIO_PMD) += -lrte_pmd_lio
_LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += -lrte_pmd_mlx4 -libverbs _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD) += -lrte_pmd_mlx4 -libverbs
_LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += -lrte_pmd_mlx5 -libverbs _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD) += -lrte_pmd_mlx5 -libverbs
_LDLIBS-$(CONFIG_RTE_LIBRTE_NFP_PMD) += -lrte_pmd_nfp -lm _LDLIBS-$(CONFIG_RTE_LIBRTE_NFP_PMD) += -lrte_pmd_nfp
_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_NULL) += -lrte_pmd_null _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_NULL) += -lrte_pmd_null
_LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lrte_pmd_pcap -lpcap _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += -lrte_pmd_pcap -lpcap
_LDLIBS-$(CONFIG_RTE_LIBRTE_QEDE_PMD) += -lrte_pmd_qede _LDLIBS-$(CONFIG_RTE_LIBRTE_QEDE_PMD) += -lrte_pmd_qede