From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 21 11:12:51 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9A736106564A; Tue, 21 Aug 2012 11:12:50 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id E885E8FC17; Tue, 21 Aug 2012 11:12:48 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 3DF647300A; Tue, 21 Aug 2012 13:24:15 +0200 (CEST) Date: Tue, 21 Aug 2012 13:24:15 +0200 From: Luigi Rizzo To: Marius Strobl Message-ID: <20120821112415.GA50078@onelab2.iet.unipi.it> References: <50324DB4.6080905@cabletv.dp.ua> <20120821102630.GA89551@alchemy.franken.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120821102630.GA89551@alchemy.franken.de> User-Agent: Mutt/1.4.2.3i Cc: freebsd-hackers@freebsd.org, Mitya , 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 11:12:51 -0000 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