On Aug 20, 2012, at 8:46 AM, Mitya wrote:

> Hi.
> I found some overhead code in /src/sys/net/if_ethersubr.c and 
> /src/sys/netgraph/ng_ether.c
> 
> It contains strings, like bcopy(src, dst, ETHER_ADDR_LEN);
> When src and dst are "struct ether_addr*", and ETHER_ADDR_LEN equal 6.
> This code call every time, when we send Ethernet packet.
> On example, on my machine in invoked nearly 20K per second.
> 
> Why we are use bcopy(), to copy only 6 bytes?
> Answer - in some architectures we are can not directly copy unaligned data.

True for shorts, longs, etc.  But why do we need it for ether_addr?  It is a 
struct that's just an array...  That's always safe.

> 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__)

Bleck.  that's uber ugly.  We have a define for unaligned vs aligned 
architectures.  we should use that here.  If we even need this ifdef at all.

Warner

>    *dst = *src;
> #else
>    bcopy(src, dst, ETHER_ADDR_LEN);
> #endif
> }
> 
> On platform i386 gcc produce like this code:
>    leal    -30(%ebp), %eax
>    leal    6(%eax), %ecx
>    leal    -44(%ebp), %edx
>    movl    (%edx), %eax
>    movl    %eax, (%ecx)
>    movzwl  4(%edx), %eax
>    movw    %ax, 4(%ecx)
> And clang produce this:
>    movl    -48(%ebp), %ecx
>    movl    %ecx, -26(%ebp)
>    movw    -44(%ebp), %si
>    movw    %si, -22(%ebp)
> 
> 
> All this variants are much faster, than bcopy()
> 
> _______________________________________________
> freebsd-hack...@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

_______________________________________________
freebsd-net@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "freebsd-net-unsubscr...@freebsd.org"

Reply via email to