From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 24 00:39:34 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 420E7106566B; Fri, 24 Aug 2012 00:39:34 +0000 (UTC) (envelope-from bde@FreeBSD.org) Received: from ref10-i386.freebsd.org (unknown [IPv6:2001:4f8:fff6::5e]) by mx1.freebsd.org (Postfix) with ESMTP id 2B38E8FC08; Fri, 24 Aug 2012 00:39:34 +0000 (UTC) Received: from ref10-i386.freebsd.org (localhost [127.0.0.1]) by ref10-i386.freebsd.org (8.14.5/8.14.5) with ESMTP id q7O0dYZK029436; Fri, 24 Aug 2012 00:39:34 GMT (envelope-from bde@ref10-i386.freebsd.org) Received: (from bde@localhost) by ref10-i386.freebsd.org (8.14.5/8.14.5/Submit) id q7O0dUbl029143; Fri, 24 Aug 2012 00:39:30 GMT (envelope-from bde) Date: Fri, 24 Aug 2012 00:39:30 GMT From: Bruce Evans Message-Id: <201208240039.q7O0dUbl029143@ref10-i386.freebsd.org> To: jhb@FreeBSD.org, rizzo@iet.unipi.it In-Reply-To: <20120822215244.GC67796@onelab2.iet.unipi.it> Cc: freebsd-hackers@FreeBSD.org, adrian@FreeBSD.org, mitya@cabletv.dp.ua, wojtek@wojtek.tensor.gdynia.pl, 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: Fri, 24 Aug 2012 00:39:34 -0000 >From owner-freebsd-net@FreeBSD.org Thu Aug 23 10:58:03 2012 Delivered-To: freebsd-net@freebsd.org Date: Wed, 22 Aug 2012 23:52:44 +0200 From: Luigi Rizzo To: John Baldwin References: <50324DB4.6080905@cabletv.dp.ua> <201208220802.14588.jhb@freebsd.org> <201208221521.06954.jhb@freebsd.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201208221521.06954.jhb@freebsd.org> User-Agent: Mutt/1.4.2.3i Cc: freebsd-hackers@FreeBSD.org, Adrian Chadd , Mitya , Wojciech Puchar , freebsd-net@FreeBSD.org Subject: Re: Replace bcopy() to update ether_addr X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: owner-freebsd-net@FreeBSD.org Errors-To: owner-freebsd-net@FreeBSD.org Content-Length: 2762 Lines: 64 On Wed, Aug 22, 2012 at 03:21:06PM -0400, John Baldwin wrote: > On Wednesday, August 22, 2012 2:54:07 pm Adrian Chadd wrote: > > On 22 August 2012 05:02, John Baldwin wrote: > > > On Tuesday, August 21, 2012 12:34:42 pm Adrian Chadd wrote: > > >> Hi, > > >> > > >> What about just creating an ETHER_ADDR_COPY(dst, src) and putting that > > >> in a relevant include file, then hide the ugliness there? > > >> > > >> The same benefits will likely appear when copying wifi MAC addresses > > >> to/from headers. > > >> > > >> Thanks, I'm glad someone noticed this. > > > > > > I doubt we even _need_ the ugliness. We should just use *dst = *src > > > unless there is a compelling reason not to. > > > > Because it's not very clear? :-) I'd much prefer my array-of-things > > copies to be explicit. > > Eh? 'struct foo *src, *dst; *dst = *src' is pretty bog-standard C. That > isn't really all that obtuse. the thread has probably forked causing people to miss the explanation that Bruce gave: quite often the function is called by casting arbitrary pointers into 'struct foo *', so the compiler's expectations about alignment do not necessarily match the user's lies. Unfortunately we are building kernels with many compiler checks disabled, so there is a fair chance that the compiler will not detect such invalid casts. Probably addresses are aligned to 2-byte boundaries, but certainly not on a 4-byte, which means that a safe copy might require 3 instructions, even though a compiler could otherwise decide to align all non-packed 'struct foo' to a 4- or 8-byte boundary and possibly do the copy with 2 or even 1 instruction. I would also suggest to try the code i posted in response to bruce so you can check how good or bad are the various solutions on different architectures or CPUs, and see if there is a reasonable compromise. cheers luigi > > Also, the optimisation and compiler silliness may not be THAT obvious > > on intel (except when you're luigi and using netmap) but I can't help > > but wonder whether the same does hold for MIPS/ARM. Getting it wrong > > there will lead to some very very poor performing code. > > Don't you think there's a really good chance the compiler knows how to copy a > structure appropriately for each architecture already? > > -- > John Baldwin > _______________________________________________ > 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" _______________________________________________ freebsd-net@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-net To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"