[dpdk-dev] [PATCH] net: introduce big and little endian types

Neil Horman nhorman at tuxdriver.com
Tue Dec 6 18:29:27 CET 2016


On Tue, Dec 06, 2016 at 05:00:05PM +0000, Ananyev, Konstantin wrote:
> 
> 
> > -----Original Message-----
> > From: Nélio Laranjeiro [mailto:nelio.laranjeiro at 6wind.com]
> > Sent: Tuesday, December 6, 2016 4:28 PM
> > To: Morten Brørup <mb at smartsharesystems.com>
> > Cc: Wiles, Keith <keith.wiles at intel.com>; Ananyev, Konstantin <konstantin.ananyev at intel.com>; Richardson, Bruce
> > <bruce.richardson at intel.com>; dev at dpdk.org; Olivier Matz <olivier.matz at 6wind.com>; Lu, Wenzhuo <wenzhuo.lu at intel.com>; Adrien
> > Mazarguil <adrien.mazarguil at 6wind.com>
> > Subject: Re: [dpdk-dev] [PATCH] net: introduce big and little endian types
> > 
> > Hi all,
> > 
> > On Tue, Dec 06, 2016 at 04:34:07PM +0100, Morten Brørup wrote:
> > > Hi all,
> > >
> > > Being a big fan of strong typing, I really like the concept of
> > > explicit endian types. Especially if type mismatches can be caught at
> > > compile time.
> > 
> > +1,
> > 
> > > However, I think it is too late! That train left the station when the
> > > rest of the world - including libraries and headers that might be
> > > linked with a DPDK application - decided to use implicit big endian
> > > types for network protocols, and has been doing so for decades. And,
> > > with all respect, I don't think the DPDK community has the momentum
> > > required to change this tradition outside the community.
> > 
> > I don't think, those types can be use from now on to help new API to
> > expose explicitly the type they are handling.  For older ones, it can
> > come in a second step, even if there are not so numerous.  Only few of
> > them touches the network types.
> > 
> > > Furthermore: If not enforced throughout DPDK (and beyond), it might
> > > confuse more than it helps.
> > 
> > The current situation is more confusing,  nobody at any layer can rely
> > on a precise information, at each function entry we need to verify if
> > the callee has already handled the job.  The only solution is to browse
> > the code to have this information.
> > 
> > Think about any function manipulating network headers (like flow director
> > or rte_flow) from the API down to the PMD, it may take a lot of time to
> > know at the end if the data is CPU or network ordered, with those types
> > it takes less than a second.
> 
> Hmm, suppose I have such piece of code:
> 
> struct ipv4_hdr iph;
> iph.total_length = val0;
> iph.packet_id = val1;
> ...
> iph.dst_addr = valn;
> 
> hton_whole_ipv4_hdr_at_once(&iph);
> 
> How I suppose to indicate via these new types that 
> hton_whole_ipv4_hdr_at_once() expects ipv4_hdr fields in host byte order?
> Other than just putting it into the doc?
> Konstantin
> 
You aren't.  Your implication is correct in that, if you have a struct that
needs to store data in either cpu endian order or in network endian order, its
best to leave endian tagging out of the type, because it will by definition be
wrong at least 50% of the team, leading to more confusion than it rectifies

That isn't to say that endian coded types don't have a place.  They're often
fairly useful when reading hardware registers and the like, or if a speciic bit
of data is to be extracted from a network payload.  But in the use case above,
no, its not useful.

The best idea it seems is to provide the types, as well as endian-typed and
untyped variants to the endian conversion routines, so that developers can
choose what works best for them.  Since the conversions are all macros with
casts anyway, it should be a no harm no foul addition in my mind.

To be clear, I don't support the patch as it exists, but I would support a
variant that just offered the types and conversion routines.

Neil
 
> 
> 
> 
> 


More information about the dev mailing list