From owner-freebsd-net@FreeBSD.ORG Mon Aug 20 16:41:17 2012 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CFCB51065673 for ; Mon, 20 Aug 2012 16:41:17 +0000 (UTC) (envelope-from imp@bsdimp.com) Received: from mail-pz0-f54.google.com (mail-pz0-f54.google.com [209.85.210.54]) by mx1.freebsd.org (Postfix) with ESMTP id 9B9CC8FC16 for ; Mon, 20 Aug 2012 16:41:17 +0000 (UTC) Received: by dadr6 with SMTP id r6so2427082dad.13 for ; Mon, 20 Aug 2012 09:41:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=ATR+a737mE2XVMGayWXiEhZO8qe2Cf9Rroa14hntcsI=; b=YCYYkvsfNnvMnrhxIHmnhWD3mydy1LNDxCmIG28PwxktlUAZsdQ70jmcrjZ3qL1Dh/ ZbRmyFNfLQCTxfflHTWUcRJkPTU0//eQp+16AFIxkJlXWEzJ8FDGL0iBD2RuUx2TL8We 3493rvVS2xpwSnLQf39hRDp9V0LZLw2JVvOfhR7FlwIr1e7TfkdA0LgmmCLLtSUWJx97 9WcY8+hOmQr0r7uz7K1z/xmG9K8w+phC7/WyW8IP6q7iOPsxtSY8rjtn4hQmVrmMKXqW 9ljdYQ5fiIy32Lki8+RhWK5Rkz0f2tI0o7jQcmZNv9y87WvJrzXY+B3s/zEBi9dexBDd 4JYA== Received: by 10.66.74.100 with SMTP id s4mr30960611pav.27.1345480877170; Mon, 20 Aug 2012 09:41:17 -0700 (PDT) Received: from fusionlt2834a.int.fusionio.com ([216.51.42.66]) by mx.google.com with ESMTPS id kt2sm11392939pbc.73.2012.08.20.09.41.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 20 Aug 2012 09:41:16 -0700 (PDT) Sender: Warner Losh Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii From: Warner Losh In-Reply-To: <50324DB4.6080905@cabletv.dp.ua> Date: Mon, 20 Aug 2012 10:41:15 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: <4C06696D-EF17-411D-A229-B738B9D47B8A@bsdimp.com> References: <50324DB4.6080905@cabletv.dp.ua> To: Mitya X-Mailer: Apple Mail (2.1084) X-Gm-Message-State: ALoCoQmXtRg5Rupgvl6j+HNifceKG1AVoGjzRLfyVzo5HxT7hhZhdAmMeyReRDbXdh7TMyfSNIOT Cc: freebsd-hackers@freebsd.org, 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: , X-List-Received-Date: Mon, 20 Aug 2012 16:41:17 -0000 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"