From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 21 10:26:34 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E6C7D1065674; Tue, 21 Aug 2012 10:26:34 +0000 (UTC) (envelope-from marius@alchemy.franken.de) Received: from alchemy.franken.de (alchemy.franken.de [194.94.249.214]) by mx1.freebsd.org (Postfix) with ESMTP id 7E2B48FC0A; Tue, 21 Aug 2012 10:26:34 +0000 (UTC) Received: from alchemy.franken.de (localhost [127.0.0.1]) by alchemy.franken.de (8.14.4/8.14.4/ALCHEMY.FRANKEN.DE) with ESMTP id q7LAQVup089793; Tue, 21 Aug 2012 12:26:31 +0200 (CEST) (envelope-from marius@alchemy.franken.de) Received: (from marius@localhost) by alchemy.franken.de (8.14.4/8.14.4/Submit) id q7LAQVVM089792; Tue, 21 Aug 2012 12:26:31 +0200 (CEST) (envelope-from marius) Date: Tue, 21 Aug 2012 12:26:30 +0200 From: Marius Strobl To: Mitya Message-ID: <20120821102630.GA89551@alchemy.franken.de> References: <50324DB4.6080905@cabletv.dp.ua> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50324DB4.6080905@cabletv.dp.ua> User-Agent: Mutt/1.4.2.3i Cc: freebsd-hackers@freebsd.org, freebsd-net@freebsd.org Subject: Re: Replace bcopy() to update ether_addr X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Aug 2012 10:26:35 -0000 On Mon, Aug 20, 2012 at 05:46:12PM +0300, 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. > > 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 > } > > 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() > 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. Marius