DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] common: introduce an integer log2 function
@ 2017-04-06 14:15 Olivier Matz
  2017-04-06 14:23 ` Olivier MATZ
  2017-07-03  8:48 ` Thomas Monjalon
  0 siblings, 2 replies; 6+ messages in thread
From: Olivier Matz @ 2017-04-06 14:15 UTC (permalink / raw)
  To: dev

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 2 drivers.

Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
---
 drivers/net/nfp/nfp_net.c                  |  6 ++----
 lib/librte_eal/common/include/rte_common.h | 17 +++++++++++++++++
 mk/rte.app.mk                              |  2 +-
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index a1ad97ad5..0e6a729ef 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -39,8 +39,6 @@
  * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
  */
 
-#include <math.h>
-
 #include <rte_byteorder.h>
 #include <rte_common.h>
 #include <rte_log.h>
@@ -1493,7 +1491,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
 	 * of descriptors in log2 format
 	 */
 	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;
 }
@@ -1647,7 +1645,7 @@ nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
 	 * of descriptors in log2 format
 	 */
 	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;
 }
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index e057f6e21..eea0054c1 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -326,6 +326,23 @@ rte_bsf32(uint32_t 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
 /** Return the offset of a field in a structure. */
 #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
diff --git a/mk/rte.app.mk b/mk/rte.app.mk
index 4c659e971..2fcd388e6 100644
--- a/mk/rte.app.mk
+++ b/mk/rte.app.mk
@@ -125,7 +125,7 @@ endif
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LIO_PMD)        += -lrte_pmd_lio
 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD)       += -lrte_pmd_mlx4 -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_PCAP)       += -lrte_pmd_pcap -lpcap
 _LDLIBS-$(CONFIG_RTE_LIBRTE_QEDE_PMD)       += -lrte_pmd_qede
-- 
2.11.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] common: introduce an integer log2 function
  2017-04-06 14:15 [dpdk-dev] [PATCH] common: introduce an integer log2 function Olivier Matz
@ 2017-04-06 14:23 ` Olivier MATZ
  2017-04-06 15:11   ` Jerin Jacob
  2017-07-01 14:37   ` Thomas Monjalon
  2017-07-03  8:48 ` Thomas Monjalon
  1 sibling, 2 replies; 6+ messages in thread
From: Olivier MATZ @ 2017-04-06 14:23 UTC (permalink / raw)
  To: dev, Jerin Jacob; +Cc: alejandro.lucero

I forgot to CC Alejandro for nfp.

Also CC Jerin: I think the same could be done in thunderx, but
I did not want to do the patch since it changes the base/ driver.


On Thu,  6 Apr 2017 16:15:36 +0200, Olivier Matz <olivier.matz@6wind.com> wrote:
> 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 2 drivers.
> 
> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
> ---
>  drivers/net/nfp/nfp_net.c                  |  6 ++----
>  lib/librte_eal/common/include/rte_common.h | 17 +++++++++++++++++
>  mk/rte.app.mk                              |  2 +-
>  3 files changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
> index a1ad97ad5..0e6a729ef 100644
> --- a/drivers/net/nfp/nfp_net.c
> +++ b/drivers/net/nfp/nfp_net.c
> @@ -39,8 +39,6 @@
>   * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
>   */
>  
> -#include <math.h>
> -
>  #include <rte_byteorder.h>
>  #include <rte_common.h>
>  #include <rte_log.h>
> @@ -1493,7 +1491,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
>  	 * of descriptors in log2 format
>  	 */
>  	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;
>  }
> @@ -1647,7 +1645,7 @@ nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
>  	 * of descriptors in log2 format
>  	 */
>  	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;
>  }
> diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> index e057f6e21..eea0054c1 100644
> --- a/lib/librte_eal/common/include/rte_common.h
> +++ b/lib/librte_eal/common/include/rte_common.h
> @@ -326,6 +326,23 @@ rte_bsf32(uint32_t 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
>  /** Return the offset of a field in a structure. */
>  #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
> diff --git a/mk/rte.app.mk b/mk/rte.app.mk
> index 4c659e971..2fcd388e6 100644
> --- a/mk/rte.app.mk
> +++ b/mk/rte.app.mk
> @@ -125,7 +125,7 @@ endif
>  _LDLIBS-$(CONFIG_RTE_LIBRTE_LIO_PMD)        += -lrte_pmd_lio
>  _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD)       += -lrte_pmd_mlx4 -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_PCAP)       += -lrte_pmd_pcap -lpcap
>  _LDLIBS-$(CONFIG_RTE_LIBRTE_QEDE_PMD)       += -lrte_pmd_qede

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] common: introduce an integer log2 function
  2017-04-06 14:23 ` Olivier MATZ
@ 2017-04-06 15:11   ` Jerin Jacob
  2017-07-01 14:37   ` Thomas Monjalon
  1 sibling, 0 replies; 6+ messages in thread
From: Jerin Jacob @ 2017-04-06 15:11 UTC (permalink / raw)
  To: Olivier MATZ; +Cc: dev, alejandro.lucero

-----Original Message-----
> Date: Thu, 6 Apr 2017 16:23:55 +0200
> From: Olivier MATZ <olivier.matz@6wind.com>
> To: dev@dpdk.org, Jerin Jacob <jerin.jacob@caviumnetworks.com>
> Cc: alejandro.lucero@netronome.com
> Subject: Re: [dpdk-dev] [PATCH] common: introduce an integer log2 function
> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
> 
> I forgot to CC Alejandro for nfp.
> 
> Also CC Jerin: I think the same could be done in thunderx, but
> I did not want to do the patch since it changes the base/ driver.
> 
> 
> On Thu,  6 Apr 2017 16:15:36 +0200, Olivier Matz <olivier.matz@6wind.com> wrote:
> > 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 2 drivers.
> > 
> > Signed-off-by: Olivier Matz <olivier.matz@6wind.com>
> > ---
> >  drivers/net/nfp/nfp_net.c                  |  6 ++----
> >  lib/librte_eal/common/include/rte_common.h | 17 +++++++++++++++++
> >  mk/rte.app.mk                              |  2 +-
> >  3 files changed, 20 insertions(+), 5 deletions(-)
> > 
> > diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
> > index a1ad97ad5..0e6a729ef 100644
> > --- a/drivers/net/nfp/nfp_net.c
> > +++ b/drivers/net/nfp/nfp_net.c
> > @@ -39,8 +39,6 @@
> >   * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
> >   */
> >  
> > -#include <math.h>
> > -
> >  #include <rte_byteorder.h>
> >  #include <rte_common.h>
> >  #include <rte_log.h>
> > @@ -1493,7 +1491,7 @@ nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
> >  	 * of descriptors in log2 format
> >  	 */
> >  	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;
> >  }
> > @@ -1647,7 +1645,7 @@ nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
> >  	 * of descriptors in log2 format
> >  	 */
> >  	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;
> >  }
> > diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
> > index e057f6e21..eea0054c1 100644
> > --- a/lib/librte_eal/common/include/rte_common.h
> > +++ b/lib/librte_eal/common/include/rte_common.h
> > @@ -326,6 +326,23 @@ rte_bsf32(uint32_t 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);
> > +}

I think, It will good be if we add unit test case for the same.

> > +
> >  #ifndef offsetof
> >  /** Return the offset of a field in a structure. */
> >  #define offsetof(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
> > diff --git a/mk/rte.app.mk b/mk/rte.app.mk
> > index 4c659e971..2fcd388e6 100644
> > --- a/mk/rte.app.mk
> > +++ b/mk/rte.app.mk
> > @@ -125,7 +125,7 @@ endif
> >  _LDLIBS-$(CONFIG_RTE_LIBRTE_LIO_PMD)        += -lrte_pmd_lio
> >  _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD)       += -lrte_pmd_mlx4 -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_PCAP)       += -lrte_pmd_pcap -lpcap
> >  _LDLIBS-$(CONFIG_RTE_LIBRTE_QEDE_PMD)       += -lrte_pmd_qede
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] common: introduce an integer log2 function
  2017-04-06 14:23 ` Olivier MATZ
  2017-04-06 15:11   ` Jerin Jacob
@ 2017-07-01 14:37   ` Thomas Monjalon
  2017-07-03  8:16     ` Alejandro Lucero
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas Monjalon @ 2017-07-01 14:37 UTC (permalink / raw)
  To: alejandro.lucero; +Cc: dev, Olivier MATZ, Jerin Jacob

Alejandro,

Are you OK to replace log2 by rte_log2_u32?
I'm waiting your ack to apply this patch.


06/04/2017 16:23, Olivier MATZ:
> I forgot to CC Alejandro for nfp.
[...]
> >  drivers/net/nfp/nfp_net.c                  |  6 ++----
> >  lib/librte_eal/common/include/rte_common.h | 17 +++++++++++++++++
> >  mk/rte.app.mk                              |  2 +-
> >  3 files changed, 20 insertions(+), 5 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] common: introduce an integer log2 function
  2017-07-01 14:37   ` Thomas Monjalon
@ 2017-07-03  8:16     ` Alejandro Lucero
  0 siblings, 0 replies; 6+ messages in thread
From: Alejandro Lucero @ 2017-07-03  8:16 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Olivier MATZ, Jerin Jacob

Hi,

Sorry for the late answer.

Yes, that's fine.

Thank you



On Sat, Jul 1, 2017 at 3:37 PM, Thomas Monjalon <thomas@monjalon.net> wrote:

> Alejandro,
>
> Are you OK to replace log2 by rte_log2_u32?
> I'm waiting your ack to apply this patch.
>
>
> 06/04/2017 16:23, Olivier MATZ:
> > I forgot to CC Alejandro for nfp.
> [...]
> > >  drivers/net/nfp/nfp_net.c                  |  6 ++----
> > >  lib/librte_eal/common/include/rte_common.h | 17 +++++++++++++++++
> > >  mk/rte.app.mk                              |  2 +-
> > >  3 files changed, 20 insertions(+), 5 deletions(-)
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [dpdk-dev] [PATCH] common: introduce an integer log2 function
  2017-04-06 14:15 [dpdk-dev] [PATCH] common: introduce an integer log2 function Olivier Matz
  2017-04-06 14:23 ` Olivier MATZ
@ 2017-07-03  8:48 ` Thomas Monjalon
  1 sibling, 0 replies; 6+ messages in thread
From: Thomas Monjalon @ 2017-07-03  8:48 UTC (permalink / raw)
  To: Olivier Matz; +Cc: dev

06/04/2017 16:15, Olivier Matz:
> 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 2 drivers.

Only nfp driver is fixed.

> Signed-off-by: Olivier Matz <olivier.matz@6wind.com>

Acked-by: Alejandro Lucero <alejandro.lucero@netronome.com>

Applied, thanks

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-07-03  8:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-06 14:15 [dpdk-dev] [PATCH] common: introduce an integer log2 function Olivier Matz
2017-04-06 14:23 ` Olivier MATZ
2017-04-06 15:11   ` Jerin Jacob
2017-07-01 14:37   ` Thomas Monjalon
2017-07-03  8:16     ` Alejandro Lucero
2017-07-03  8:48 ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).