Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Aug 2012 13:24:15 +0200
From:      Luigi Rizzo <rizzo@iet.unipi.it>
To:        Marius Strobl <marius@alchemy.franken.de>
Cc:        freebsd-hackers@freebsd.org, Mitya <mitya@cabletv.dp.ua>, freebsd-net@freebsd.org
Subject:   Re: Replace bcopy() to update ether_addr
Message-ID:  <20120821112415.GA50078@onelab2.iet.unipi.it>
In-Reply-To: <20120821102630.GA89551@alchemy.franken.de>
References:  <50324DB4.6080905@cabletv.dp.ua> <20120821102630.GA89551@alchemy.franken.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Aug 21, 2012 at 12:26:30PM +0200, Marius Strobl wrote:
...
> > Why we are use bcopy(), to copy only 6 bytes?
> > Answer - in some architectures we are can not directly copy unaligned data.
> > 
> > I propose this solution.
> > 
> > In file /usr/src/include/net/ethernet.h add this lines:
> > 
> > static inline void ether_addr_copy(ether_addr* src, ether_addr* dst) {
> > #if defined(__i386__) || defined(__amd64__)
> >     *dst = *src;
> > #else
> >     bcopy(src, dst, ETHER_ADDR_LEN);
> > #endif
> > }
...
> > All this variants are much faster, than bcopy()
> > 
> 
> A bit orthogonal to this but also related to the performance
> impact of these bcopy() calls, for !__NO_STRICT_ALIGNMENT
> architectures these places probably should use memcpy()
> instead as bcopy() additionally has to check for overlap
> while the former does not. Overlaps unlikely are an issue
> in these cases and at least NetBSD apparently has done the
> switch to memcpy() 5.5 years ago.

even more orthogonal:

I found that copying 8n + (5, 6 or 7) bytes was much much slower than
copying a multiple of 8 bytes. For n=0, 1,2,4,8 bytes are efficient,
other cases are slow (turned into 2 or 3 different writes).

The netmap code uses a pkt_copy routine that does exactly this
rounding, gaining some 10-20ns per packet for small sizes.

cheers
luigi



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120821112415.GA50078>