Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Aug 2012 10:41:15 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Mitya <mitya@cabletv.dp.ua>
Cc:        freebsd-hackers@freebsd.org, freebsd-net@freebsd.org
Subject:   Re: Replace bcopy() to update ether_addr
Message-ID:  <4C06696D-EF17-411D-A229-B738B9D47B8A@bsdimp.com>
In-Reply-To: <50324DB4.6080905@cabletv.dp.ua>
References:  <50324DB4.6080905@cabletv.dp.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

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
>=20
> 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.
>=20
> 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.
>=20
> In file /usr/src/include/net/ethernet.h add this lines:
>=20
> 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 =3D *src;
> #else
>    bcopy(src, dst, ETHER_ADDR_LEN);
> #endif
> }
>=20
> 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)
>=20
>=20
> All this variants are much faster, than bcopy()
>=20
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to =
"freebsd-hackers-unsubscribe@freebsd.org"




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4C06696D-EF17-411D-A229-B738B9D47B8A>