From patchwork Tue Sep 23 08:54:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 392278 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 D30051400B2 for ; Tue, 23 Sep 2014 19:00:51 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754124AbaIWI76 (ORCPT ); Tue, 23 Sep 2014 04:59:58 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:22318 "EHLO mailhub1.si.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753071AbaIWI74 (ORCPT ); Tue, 23 Sep 2014 04:59:56 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id DF55A1C8507; Tue, 23 Sep 2014 10:59:54 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from mailhub1.si.c-s.fr ([192.168.12.234]) by localhost (mailhub1.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zlC-NJABZ9xE; Tue, 23 Sep 2014 10:59:54 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id C57441C8506; Tue, 23 Sep 2014 10:59:54 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 8A0C2C73CA; Tue, 23 Sep 2014 10:59:54 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id hfSwoxtkZlHu; Tue, 23 Sep 2014 10:59:54 +0200 (CEST) Received: from PO10863.localdomain (unknown [192.168.4.167]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 2DFA6C73C9; Tue, 23 Sep 2014 10:59:53 +0200 (CEST) Received: by localhost.localdomain (Postfix, from userid 0) id 09C5A1AB26A; Tue, 23 Sep 2014 10:54:32 +0200 (CEST) From: Christophe Leroy To: "David S. Miller" CC: linux-kernel@vger.kernel.org, Eric Dumazet , netdev@vger.kernel.org Subject: [PATCH] net: optimise csum_replace4() Message-Id: <20140923085433.09C5A1AB26A@localhost.localdomain> Date: Tue, 23 Sep 2014 10:54:32 +0200 (CEST) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org csum_partial() is a generic function which is not optimised for small fixed length calculations, and its use requires to store "from" and "to" values in memory while we already have them available in registers. This also has impact, especially on RISC processors. In the same spirit as the change done by Eric Dumazet on csum_replace2(), this patch rewrites inet_proto_csum_replace4() taking into account RFC1624. I spotted during a NATted tcp transfert that csum_partial() is one of top 5 consuming functions (around 8%), and the second user of csum_partial() is inet_proto_csum_replace4(). I have proposed the same modification to inet_proto_csum_replace4() in another patch. Signed-off-by: Christophe Leroy Acked-by: Eric Dumazet --- include/net/checksum.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/net/checksum.h b/include/net/checksum.h index 87cb190..6465bae 100644 --- a/include/net/checksum.h +++ b/include/net/checksum.h @@ -122,9 +122,7 @@ static inline __wsum csum_partial_ext(const void *buff, int len, __wsum sum) static inline void csum_replace4(__sum16 *sum, __be32 from, __be32 to) { - __be32 diff[] = { ~from, to }; - - *sum = csum_fold(csum_partial(diff, sizeof(diff), ~csum_unfold(*sum))); + *sum = csum_fold(csum_add(csum_sub(~csum_unfold(*sum), from), to)); } /* Implements RFC 1624 (Incremental Internet Checksum)