Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2692725imm; Sun, 12 Aug 2018 21:32:00 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwfNLCbVo6W3hSwuvvFdGo30VA7WvjIvWWf10Pnwg9etHr1kI/oNQjBZpmj2S/u2vJExNCQ X-Received: by 2002:a63:6b03:: with SMTP id g3-v6mr15671517pgc.57.1534134720514; Sun, 12 Aug 2018 21:32:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534134720; cv=none; d=google.com; s=arc-20160816; b=Li0p3MRphNZ0ryx0pVttCLSrMnUAgnuKGGcdXrXe8lO7ag9nM48JoGLkQud32FfHP+ TGfZo284iDchpqQh4/2FBOG8bzu71+LnX8wB6F7/H9erKtyogl9eo1EtD6E7dzCoYLWs RhPwU6FbkIcVzMfZieJ6lOHu5zejYHQBZWs49dlOccCQczqmi59rJhdJ63eSlYiJS7mJ fDOkWyvLzpkZy0+7jLphbOaRojQrrEnuHBEBHE4DK0ts6Sz94no+D4BOJyZSrBvEZtNN Sp5SVt9TBjVco81JER+7GPLrRqwd6nUcaXG/Na2zhRIPMARU7cf8t4o2ZraFV2UidGrq cwcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=Pf9aOgyTGgYzRGhwJWQuGr6qBSTdrT0OvXXsc5ZTnlk=; b=m5Ztj8yEeNF4hRYI7MWSe2cphCUtxfl8qF5xyVRveLExO0eSKmM8wSZ5LYEScIv6zM rZKOgPnj8JIzW8U5+1L/JOj4p7UG5G9+acSosLq80TRkcN03EeTiYRAZg1WgXkkLstu+ YQJ7AsI17NzxBui0+lOq4mLWrr1l1GfJmzw+UiIMkirReuYOrC4pavqBXX4m/wH1QvnJ 3EDdGDzK5654Gcz5OZKPp1cENFx8a3c/gMWyyEy0ZklsxTdtzDAI2yot6novUTcLPK/P hdwz9VSzX5u6Mu6eIGv3ZfYLZVJFSsNg+cEA5nTFD/ilPnu0D0/GzfrS+YTcIhjDE81P 1IpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g12-v6si14542620pll.384.2018.08.12.21.31.33; Sun, 12 Aug 2018 21:32:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728127AbeHMHKb (ORCPT + 99 others); Mon, 13 Aug 2018 03:10:31 -0400 Received: from smtprelay0164.hostedemail.com ([216.40.44.164]:36357 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726447AbeHMHKb (ORCPT ); Mon, 13 Aug 2018 03:10:31 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id 50FEE837F27E; Mon, 13 Aug 2018 04:30:02 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1544:1593:1594:1605:1711:1730:1747:1777:1792:1981:2194:2198:2199:2200:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3622:3865:3866:3867:3868:3870:3871:3872:3874:4037:4250:4321:4605:5007:6119:7903:7904:8603:9008:9108:10004:10394:10848:11026:11232:11473:11658:11914:12043:12050:12291:12438:12555:12683:12740:12760:12895:12986:13138:13146:13230:13231:13439:14093:14097:14659:14721:14819:21080:21433:21451:21611:21627:21740:21789:21795:30051:30054:30090:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:30,LUA_SUMMARY:none X-HE-Tag: low95_57582cfad060a X-Filterd-Recvd-Size: 5447 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf07.hostedemail.com (Postfix) with ESMTPA; Mon, 13 Aug 2018 04:30:00 +0000 (UTC) Message-ID: Subject: Re: [PATCH] Performance Improvement in CRC16 Calculations. From: Joe Perches To: dgilbert@interlog.com, Nicolas Pitre Cc: Jeff Lien , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, herbert@gondor.apana.org.au, tim.c.chen@linux.intel.com, martin.petersen@oracle.com, david.darrington@wdc.com, jeff.furlong@wdc.com Date: Sun, 12 Aug 2018 21:29:58 -0700 In-Reply-To: References: <1533928331-21303-1-git-send-email-jeff.lien@wdc.com> <9b5b906f42dfab78f382c90f66851717d258a15d.camel@perches.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2018-08-12 at 23:36 -0400, Douglas Gilbert wrote: > On 2018-08-10 08:11 PM, Joe Perches wrote: > > On Fri, 2018-08-10 at 16:02 -0400, Nicolas Pitre wrote: > > > On Fri, 10 Aug 2018, Joe Perches wrote: > > > > > > > On Fri, 2018-08-10 at 14:12 -0500, Jeff Lien wrote: > > > > > This patch provides a performance improvement for the CRC16 calculations done in read/write > > > > > workloads using the T10 Type 1/2/3 guard field. For example, today with sequential write > > > > > workloads (one thread/CPU of IO) we consume 100% of the CPU because of the CRC16 computation > > > > > bottleneck. Today's block devices are considerably faster, but the CRC16 calculation prevents > > > > > folks from utilizing the throughput of such devices. To speed up this calculation and expose > > > > > the block device throughput, we slice the old single byte for loop into a 16 byte for loop, > > > > > with a larger CRC table to match. The result has shown 5x performance improvements on various > > > > > big endian and little endian systems running the 4.18.0 kernel version. > > > > > > > > Thanks. > > > > > > > > This seems a sensible tradeoff for the 4k text size increase. > > > > > > More like 7.5KB. Would be best if this was configurable so the small > > > version remained available. > > > > Maybe something like: (compiled, untested) > > --- > > crypto/Kconfig | 10 + > > crypto/crct10dif_common.c | 543 +++++++++++++++++++++++++++++++++++++++++++++- > > 2 files changed, 549 insertions(+), 4 deletions(-) > > > > diff --git a/crypto/Kconfig b/crypto/Kconfig > > index f3e40ac56d93..88d9d17bb18a 100644 > > --- a/crypto/Kconfig > > +++ b/crypto/Kconfig > > @@ -618,6 +618,16 @@ config CRYPTO_CRCT10DIF > > a crypto transform. This allows for faster crc t10 diff > > transforms to be used if they are available. > > > > +config CRYPTO_CRCT10DIF_TABLE_SIZE > > + int "Size of CRCT10DIF crc tables (as a power of 2)" > > + depends on CRYPTO_CRCT10DIF > > + range 1 5 > > + default 1 if EMBEDDED > > + default 5 > > + help > > + Set the table size used by the CRYPTO_CRCT10DIF crc calculation > > + Larger values use more memory and are faster. > > + > > config CRYPTO_CRCT10DIF_PCLMUL > > tristate "CRCT10DIF PCLMULQDQ hardware acceleration" > > depends on X86 && 64BIT && CRC_T10DIF > > diff --git a/crypto/crct10dif_common.c b/crypto/crct10dif_common.c > > index b2fab366f518..4eb1c50c3688 100644 > > --- a/crypto/crct10dif_common.c > > +++ b/crypto/crct10dif_common.c > > @@ -32,7 +32,8 @@ > > * x^16 + x^15 + x^11 + x^9 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 > > * gt: 0x8bb7 > > */ > > -static const __u16 t10_dif_crc_table[256] = { > > +static const __u16 t10dif_crc_table[][256] = { > > > > > }; > > > > __u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer, size_t len) > > { > > - unsigned int i; > > + const u8 *ptr = (const __u8 *)buffer; > > + const u8 *ptr_end = ptr + len; > > +#if CONFIG_CRYPTO_CRCT10DIF_TABLE_SIZE > 1 > > + size_t tablesize = 1 << (CONFIG_CRYPTO_CRCT10DIF_TABLE_SIZE - 1); > > + const u8 *ptr_last = ptr + (len / tablesize * tablesize); > > > > - for (i = 0 ; i < len ; i++) > > - crc = (crc << 8) ^ t10_dif_crc_table[((crc >> 8) ^ buffer[i]) & 0xff]; > > + while (ptr < ptr_last) { > > + size_t index = tablesize; > > + __u16 t; > > + > > + t = t10dif_crc_table[--index][*ptr++ ^ (u8)(crc >> 8)]; > > + t ^= t10dif_crc_table[--index][*ptr++ ^ (u8)crc]; > > + crc = t; > > + while (index > 0) > > + crc ^= t10dif_crc_table[--index][*ptr++]; > > + } > > +#endif > > + while (ptr < ptr_end) > > + crc = t10dif_crc_table[0][*ptr++ ^ (u8)(crc >> 8)] ^ (crc << 8); > > > > return crc; > > } > > > > > > The attached patch is on top of the one above. I tested it in the user space > where it is around 20% faster (with a full size table). Also tried swab16 but > there was no gain from that (perhaps around a 2% loss). I don't get a significant difference in performance. gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)