From patchwork Mon Jul 18 13:16:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 105274 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.180.67]) by ozlabs.org (Postfix) with ESMTP id 8867FB6F86 for ; Mon, 18 Jul 2011 23:17:46 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756948Ab1GRNQp (ORCPT ); Mon, 18 Jul 2011 09:16:45 -0400 Received: from mail-ww0-f44.google.com ([74.125.82.44]:36189 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756835Ab1GRNQn (ORCPT ); Mon, 18 Jul 2011 09:16:43 -0400 Received: by wwe5 with SMTP id 5so3169191wwe.1 for ; Mon, 18 Jul 2011 06:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding; bh=UQqTkinNA2qLDf8iPnqItflcEe7eGEDn8J5gSbIzE70=; b=pHLhdC3rDgwPExqSiwdKRrXUxIJwrpnimpmcM7XCDnG1t+RPHODU0LUMVHsQBENdAA epxfCkzh5STzIY2ZwUnnzk8E04xV37ygs5ay3qbaWCuiq8N9CAYExUvGoq3gQsNXBthV rBwGaMDdVh8XQqztVlSmzuGO2OEWbRiC2FESA= Received: by 10.227.196.80 with SMTP id ef16mr5484885wbb.27.1310995002452; Mon, 18 Jul 2011 06:16:42 -0700 (PDT) Received: from [10.150.51.213] (gw0.net.jmsp.net [212.23.165.14]) by mx.google.com with ESMTPS id eo18sm3451507wbb.29.2011.07.18.06.16.41 (version=SSLv3 cipher=OTHER); Mon, 18 Jul 2011 06:16:41 -0700 (PDT) Subject: [PATCH net-next-2.6] ipv4: save cpu cycles from check_leaf() From: Eric Dumazet To: David Miller Cc: netdev@vger.kernel.org In-Reply-To: <20110717.122949.1167434585296050332.davem@davemloft.net> References: <20110717.122949.1167434585296050332.davem@davemloft.net> Date: Mon, 18 Jul 2011 15:16:33 +0200 Message-ID: <1310994993.5756.27.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC> Mime-Version: 1.0 X-Mailer: Evolution 2.32.2 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Le dimanche 17 juillet 2011 à 12:29 -0700, David Miller a écrit : > I guess the indirection removal is a non-trivial improvement because > these changes knock a full 2 seconds off of my udpflood tests. :-) Excellent ! One other improvement is to get rid of ntohl(inet_make_mask(plen)) stuff in check_leaf(), this saves 0.5 second on udpflood on my machine (27.25 second -> 26.75) [PATCH net-next-2.6] ipv4: save cpu cycles from check_leaf() Compiler is not smart enough to avoid double BSWAP instructions in ntohl(inet_make_mask(plen)). Lets cache this value in struct leaf_info, (fill a hole on 64bit arches) With route cache disabled, this saves ~2% of cpu in udpflood bench on x86_64 machine. Signed-off-by: Eric Dumazet --- net/ipv4/fib_trie.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) -- 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/fib_trie.c b/net/ipv4/fib_trie.c index 58c25ea..de9e297 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -110,9 +110,10 @@ struct leaf { struct leaf_info { struct hlist_node hlist; - struct rcu_head rcu; int plen; + u32 mask_plen; /* ntohl(inet_make_mask(plen)) */ struct list_head falh; + struct rcu_head rcu; }; struct tnode { @@ -451,6 +452,7 @@ static struct leaf_info *leaf_info_new(int plen) struct leaf_info *li = kmalloc(sizeof(struct leaf_info), GFP_KERNEL); if (li) { li->plen = plen; + li->mask_plen = ntohl(inet_make_mask(plen)); INIT_LIST_HEAD(&li->falh); } return li; @@ -1359,10 +1361,8 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l, hlist_for_each_entry_rcu(li, node, hhead, hlist) { struct fib_alias *fa; - int plen = li->plen; - __be32 mask = inet_make_mask(plen); - if (l->key != (key & ntohl(mask))) + if (l->key != (key & li->mask_plen)) continue; list_for_each_entry_rcu(fa, &li->falh, fa_list) { @@ -1394,7 +1394,7 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l, #ifdef CONFIG_IP_FIB_TRIE_STATS t->stats.semantic_match_passed++; #endif - res->prefixlen = plen; + res->prefixlen = li->plen; res->nh_sel = nhsel; res->type = fa->fa_type; res->scope = fa->fa_info->fib_scope; @@ -1402,7 +1402,7 @@ static int check_leaf(struct fib_table *tb, struct trie *t, struct leaf *l, res->table = tb; res->fa_head = &li->falh; if (!(fib_flags & FIB_LOOKUP_NOREF)) - atomic_inc(&res->fi->fib_clntref); + atomic_inc(&fi->fib_clntref); return 0; } }