[dpdk-dev,1/2] ixgbe: remove static qualifier for thread safety

Message ID 1413975345-24326-2-git-send-email-bruce.richardson@intel.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Bruce Richardson Oct. 22, 2014, 10:55 a.m. UTC
  Remove the "static" prefix to the template mbuf variable in
ixgbe_rxq_vec_setup function. This will then allow different
threads to initialize different RX queues at the same time,
without one overwriting the other's data.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Masaru OKI Oct. 22, 2014, 11:43 p.m. UTC | #1
Hi,

in this code, pointer of local variable (mb_def) is returned by your changes.
mb_def should be static for each thread.

2014-10-22 19:55 GMT+09:00 Bruce Richardson <bruce.richardson@intel.com>:
> Remove the "static" prefix to the template mbuf variable in
> ixgbe_rxq_vec_setup function. This will then allow different
> threads to initialize different RX queues at the same time,
> without one overwriting the other's data.
>
> Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> ---
>  lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
> index a0d3d78..e813e43 100644
> --- a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
> +++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
> @@ -730,7 +730,7 @@ static struct ixgbe_txq_ops vec_txq_ops = {
>  int
>  ixgbe_rxq_vec_setup(struct igb_rx_queue *rxq)
>  {
> -       static struct rte_mbuf mb_def = {
> +       struct rte_mbuf mb_def = {
>                 .nb_segs = 1,
>                 .data_off = RTE_PKTMBUF_HEADROOM,
>  #ifdef RTE_MBUF_REFCNT
> --
> 1.9.3
>
  
Bruce Richardson Oct. 24, 2014, 10:34 a.m. UTC | #2
On Thu, Oct 23, 2014 at 08:43:39AM +0900, Masaru Oki wrote:
> Hi,
> 
> in this code, pointer of local variable (mb_def) is returned by your changes.
> mb_def should be static for each thread.

Actually, no. A copy is made of 8 bytes of the mb_def variable and stored as 
an mbuf initializer inside the rxq structure. No use of the memory occupied 
by mb_def is made outside of the function, so the value does not need to be 
static.

/Bruce
> 
> 2014-10-22 19:55 GMT+09:00 Bruce Richardson <bruce.richardson@intel.com>:
> > Remove the "static" prefix to the template mbuf variable in
> > ixgbe_rxq_vec_setup function. This will then allow different
> > threads to initialize different RX queues at the same time,
> > without one overwriting the other's data.
> >
> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
> > ---
> >  lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
> > index a0d3d78..e813e43 100644
> > --- a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
> > +++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
> > @@ -730,7 +730,7 @@ static struct ixgbe_txq_ops vec_txq_ops = {
> >  int
> >  ixgbe_rxq_vec_setup(struct igb_rx_queue *rxq)
> >  {
> > -       static struct rte_mbuf mb_def = {
> > +       struct rte_mbuf mb_def = {
> >                 .nb_segs = 1,
> >                 .data_off = RTE_PKTMBUF_HEADROOM,
> >  #ifdef RTE_MBUF_REFCNT
> > --
> > 1.9.3
> >
  
Masaru OKI Oct. 24, 2014, 11 a.m. UTC | #3
Oh, sorry, you are right.  I had missed first * for copy.
thank you.

2014-10-24 19:34 GMT+09:00 Bruce Richardson <bruce.richardson@intel.com>:
> On Thu, Oct 23, 2014 at 08:43:39AM +0900, Masaru Oki wrote:
>> Hi,
>>
>> in this code, pointer of local variable (mb_def) is returned by your changes.
>> mb_def should be static for each thread.
>
> Actually, no. A copy is made of 8 bytes of the mb_def variable and stored as
> an mbuf initializer inside the rxq structure. No use of the memory occupied
> by mb_def is made outside of the function, so the value does not need to be
> static.
>
> /Bruce
>>
>> 2014-10-22 19:55 GMT+09:00 Bruce Richardson <bruce.richardson@intel.com>:
>> > Remove the "static" prefix to the template mbuf variable in
>> > ixgbe_rxq_vec_setup function. This will then allow different
>> > threads to initialize different RX queues at the same time,
>> > without one overwriting the other's data.
>> >
>> > Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
>> > ---
>> >  lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
>> > index a0d3d78..e813e43 100644
>> > --- a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
>> > +++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
>> > @@ -730,7 +730,7 @@ static struct ixgbe_txq_ops vec_txq_ops = {
>> >  int
>> >  ixgbe_rxq_vec_setup(struct igb_rx_queue *rxq)
>> >  {
>> > -       static struct rte_mbuf mb_def = {
>> > +       struct rte_mbuf mb_def = {
>> >                 .nb_segs = 1,
>> >                 .data_off = RTE_PKTMBUF_HEADROOM,
>> >  #ifdef RTE_MBUF_REFCNT
>> > --
>> > 1.9.3
>> >
  

Patch

diff --git a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
index a0d3d78..e813e43 100644
--- a/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
+++ b/lib/librte_pmd_ixgbe/ixgbe_rxtx_vec.c
@@ -730,7 +730,7 @@  static struct ixgbe_txq_ops vec_txq_ops = {
 int
 ixgbe_rxq_vec_setup(struct igb_rx_queue *rxq)
 {
-	static struct rte_mbuf mb_def = {
+	struct rte_mbuf mb_def = {
 		.nb_segs = 1,
 		.data_off = RTE_PKTMBUF_HEADROOM,
 #ifdef RTE_MBUF_REFCNT