From patchwork Fri Apr 21 10:51:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Machek X-Patchwork-Id: 753282 X-Patchwork-Delegate: boris.brezillon@free-electrons.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3w8Xbs1mRQz9s7B for ; Fri, 21 Apr 2017 20:51:37 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="daqSU6KT"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type:Cc: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: In-Reply-To:MIME-Version:References:Message-ID:Subject:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jNABIbap326VcdtkxepUmGMGfbHQw2RbtK7LXmrQD0A=; b=daqSU6KTwLhCRVQbHb9yS1PE5 8JCeQ3qL01Fkobk8BBRaFcnszXmCmyyMzykyiwGlXfxFHsuOlMGuK8nIN+FpU2JAMvye6yu2GVGtr R/R/A+Gveios/H758PjT7/1o/eu/PZcdIYjXEz6K7PzIiKlol9rEp6lAY83uXgkYoEVpM/aTxAh61 IME+X3I4sV+yu65pOYEzg9jBg3tC8I57RGZF575ugv0/nvaM6ZuYn9UyaMYS7WeR8MnxjEmrnXwt8 iYsZaFt9peJuq3Ith5MqCS66CNoeJ54I8cO1zZubUsSHW8Fo/be23tCPIKVXuKHq1Pi/AKhBqZgXH VODT6qBDQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d1WA1-0007UL-UX; Fri, 21 Apr 2017 10:51:33 +0000 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d1W9y-0007Sa-5V for linux-mtd@lists.infradead.org; Fri, 21 Apr 2017 10:51:32 +0000 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id B98AD81D59; Fri, 21 Apr 2017 12:51:07 +0200 (CEST) Date: Fri, 21 Apr 2017 12:51:07 +0200 From: Pavel Machek To: Boris Brezillon Subject: [PATCH] nand_base: optimize checking of erased buffers Message-ID: <20170421105107.GA7259@amd> References: <20170419121332.GA26979@amd> <20170419231804.5a04ed69@bbrezillon> <20170419221507.GA24914@amd> <20170420002748.5c76c9b9@bbrezillon> <20170420114057.GA4705@amd> MIME-Version: 1.0 In-Reply-To: <20170420114057.GA4705@amd> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170421_035130_377221_C264DBF5 X-CRM114-Status: GOOD ( 11.89 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-4.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [195.113.26.193 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, mark.marshall@omicronenergy.com, linux-kernel@vger.kernel.org, marek.vasut@gmail.com, linux-mtd@lists.infradead.org, cyrille.pitchen@atmel.com, computersforpeace@gmail.com, dwmw2@infradead.org, prabhakar@freescale.com, b44839@freescale.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If we see ~0UL in flash, there's no need for hweight, and no need to check number of bitflips. So this should be net win. Signed-off-by: Pavel Machek diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index b0524f8..96c27ec 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -1357,7 +1357,10 @@ static int nand_check_erased_buf(void *buf, int len, int bitflips_threshold) for (; len >= sizeof(long); len -= sizeof(long), bitmap += sizeof(long)) { - weight = hweight_long(*((unsigned long *)bitmap)); + unsigned long d = *((unsigned long *)bitmap); + if (d == ~0UL) + continue; + weight = hweight_long(d); bitflips += BITS_PER_LONG - weight; if (unlikely(bitflips > bitflips_threshold)) return -EBADMSG;