Subject: Re: Data alignment
To: Craig Metz <cmetz@sundance.itd.nrl.navy.mil>
From: Matt Thomas <matt@lkg.dec.com>
List: tech-net
Date: 05/21/1996 19:06:27
In  <9605211849.aa19840@sundance.itd.nrl.navy.mil> , you wrote:

> In message <199605211835.SAA09295@whydos.lkg.dec.com>, you write:
> >On the x86, coping the data such that it would be aligned actually causes
> >worse performance that just accessing the data unaligned.  So just leave
> >the unaligned if that's the way it came in.
> 
> 	I'd have to look, but I'm not sure this is the case. Especially
> if you have more complex header manipulation to do (more load/stores in
> those headers) than the optimized TCP over IPv4 case.

I am positive that it is the case.  The 21x4x (de driver) chips do not 
DMA the data such that the Ethernet header is longword aligned.  At 10Mb/s
the difference between aligned and unaligned data is rather small.  However,
at 100Mb/s, the overhead of the copy the input dramatically dropped 
throughput.

Think about it.  Long ~60-80 bytes of data (IP + TCP + options) need to be
aligned whereas the other 1400 probably does not matter since it will be
copyied out to the users buffer.  Coping this packet is wasteful.  >90%
of the data does not care about alignment and you will causing double 
buffer copies.

By accessing the IP and TCP unaligned incurs a relatively small performance
penalty (<2%) while the copy on receive caused a major (>40%) performance
hit. 

> >On those architecures that require the alignment, you are forced to do
> >the data copy.
> 
> 	Why not simply waste two bytes prepadding the mbuf before filling
> it in with Ethernet data? My impression was that 4.4 does something
> similar to this. The result is that the Ethernet MAC header is unaligned
> (yippie -- it's mostly ignoed), but the IP header is four-byte aligned.
> This means no need to do an extra copy and you get the alignment.

On output, that is exactly what is done.  On input, depending on the
hardware, it should be done but it's not always possible.

> 	I guess it's not clear to me why NetBSD is doing this differently
> than 4.4.

Experience.
-- 
Matt Thomas               Internet:   matt@3am-software.com
3am Software Foundry      WWW URL:    http://www.3am-software.com/bio/matt.html
Westford, MA              Disclaimer: I disavow all knowledge of this message