From patchwork Tue Mar 24 21:06:50 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 25028 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id 13C87DDF9B for ; Wed, 25 Mar 2009 08:07:10 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752420AbZCXVHE (ORCPT ); Tue, 24 Mar 2009 17:07:04 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752009AbZCXVHD (ORCPT ); Tue, 24 Mar 2009 17:07:03 -0400 Received: from gw1.cosmosbay.com ([212.99.114.194]:48570 "EHLO gw1.cosmosbay.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751867AbZCXVHB convert rfc822-to-8bit (ORCPT ); Tue, 24 Mar 2009 17:07:01 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) by gw1.cosmosbay.com (8.13.7/8.13.7) with ESMTP id n2OL6phP013937; Tue, 24 Mar 2009 22:06:52 +0100 Message-ID: <49C94B6A.5020304@cosmosbay.com> Date: Tue, 24 Mar 2009 22:06:50 +0100 From: Eric Dumazet User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) MIME-Version: 1.0 To: David Miller CC: kaber@trash.net, netdev@vger.kernel.org, netfilter-devel@vger.kernel.org Subject: Re: netfilter 07/41: arp_tables: unfold two critical loops in arp_packet_match() References: <20090324140302.31401.37732.sendpatchset@x2.localnet> <20090324140312.31401.89168.sendpatchset@x2.localnet> <20090324.132954.148903398.davem@davemloft.net> In-Reply-To: <20090324.132954.148903398.davem@davemloft.net> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (gw1.cosmosbay.com [0.0.0.0]); Tue, 24 Mar 2009 22:06:52 +0100 (CET) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org David Miller a écrit : > From: Patrick McHardy > Date: Tue, 24 Mar 2009 15:03:16 +0100 (MET) > >> +/* >> + * Unfortunatly, _b and _mask are not aligned to an int (or long int) >> + * Some arches dont care, unrolling the loop is a win on them. >> + */ >> +static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask) >> +{ >> +#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS >> + const unsigned long *a = (const unsigned long *)_a; >> + const unsigned long *b = (const unsigned long *)_b; > > I think we can at least give some help for the platforms which > require alignment. > > We can, for example, assume 16-bit alignment and thus loop > over u16's Right. How about this incremental patch ? Thanks [PATCH] arp_tables: ifname_compare() can assume 16bit alignment Arches without efficient unaligned access can still perform a loop assuming 16bit alignment in ifname_compare() Signed-off-by: Eric Dumazet --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c index 64a7c6c..84b9c17 100644 --- a/net/ipv4/netfilter/arp_tables.c +++ b/net/ipv4/netfilter/arp_tables.c @@ -76,6 +76,7 @@ static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap, /* * Unfortunatly, _b and _mask are not aligned to an int (or long int) * Some arches dont care, unrolling the loop is a win on them. + * For other arches, we only have a 16bit alignement. */ static unsigned long ifname_compare(const char *_a, const char *_b, const char *_mask) { @@ -95,10 +96,13 @@ static unsigned long ifname_compare(const char *_a, const char *_b, const char * BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long)); #else unsigned long ret = 0; + const u16 *a = (const u16 *)_a; + const u16 *b = (const u16 *)_b; + const u16 *mask = (const u16 *)_mask; int i; - for (i = 0; i < IFNAMSIZ; i++) - ret |= (_a[i] ^ _b[i]) & _mask[i]; + for (i = 0; i < IFNAMSIZ/sizeof(u16); i++) + ret |= (a[i] ^ b[i]) & mask[i]; #endif return ret; }