[dpdk-dev] [PATCH v2 02/14] ring: create common structure for prod and cons metadata

Bruce Richardson bruce.richardson at intel.com
Fri Mar 24 17:57:18 CET 2017


On Fri, Mar 24, 2017 at 05:41:34PM +0100, Olivier Matz wrote:
> Hi Bruce,
> 
> On Fri, 24 Mar 2017 14:55:36 +0000, Bruce Richardson <bruce.richardson at intel.com> wrote:
> > On Wed, Mar 15, 2017 at 03:01:49PM +0100, Thomas Monjalon wrote:
> > > clang error below:
> > > 
> > > 2017-03-07 11:32, Bruce Richardson:  
> > > > +       union {
> > > > +               uint32_t sp_enqueue; /**< True, if single producer. */
> > > > +               uint32_t sc_dequeue; /**< True, if single consumer. */
> > > > +       };  
> > > 
> > > error: anonymous unions are a C11 extension  
> > 
> > Olivier, Thomas, feedback on suggestions for fixing this? Note: I'm
> > still waiting to hear back on what compiler settings are needed to
> > trigger this error.
> > 
> > Two immediately obvious options:
> > * replace the union with a single variable called e.g. "single", i.e.
> >   prod.single indicates single producer, and cons.single indicates
> >   single consumer. The downside of this approach is that it makes the
> >   patch a little bigger - as other code needs to be modified to use the
> >   new name - and is not backward compatible for apps which
> >   may reference this public structure memeber.
> > * just remove the union without renaming anything, leaving two structure
> >   members called sp_enqueue and sc_dequeue. This uses a little more
> >   space in the structure, which is not a big deal since it needs to fill
> >   a cacheline anyway, but it is backward compatible in that no other
> >   code should need to be modified.
> > 
> > Other options? My preference is for the first one. Given we are breaking
> > the ring API anyway, I think we might as well use the shorter name and
> > eliminate the need for the union, or multiple variables.
> 
> What about adding RTE_STD_C11 like it's done in rte_mbuf?
> 
> I didn't try, but since mbuf compiles, it should solve this issue in ring.
> 
Yes, it might well. However, looking at the resulting code, I actually
think it's cleaner to have just one variable called "single" in the
structure. The union is really for backward compatibility, and there is
little point in doing so since we are changing the rest of the structure
in other ways.

Struct now looks like:
 /* structure to hold a pair of head/tail values and other metadata */
 struct rte_ring_headtail {
        volatile uint32_t head;  /**< Prod/consumer head. */
        volatile uint32_t tail;  /**< Prod/consumer tail. */
        uint32_t single;         /**< True if single prod/cons */
 };

And the code checks read e.g. for single producer:

       if (r->prod.single)

/Bruce


More information about the dev mailing list