Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1917883imm; Thu, 27 Sep 2018 04:44:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV60/TgVyzikwntzZEDG32yg8xGmoQNiqeQObe+8YMC0KSQlnCQgOBnmLimyVd2+2UVrn8hRQ X-Received: by 2002:a62:8559:: with SMTP id u86-v6mr11187184pfd.32.1538048659315; Thu, 27 Sep 2018 04:44:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538048659; cv=none; d=google.com; s=arc-20160816; b=d7/pFFrBGIFCeVdBOs2AC2+mJYEUn0CncXeSurl0nnEJGXuZPJhAcTQAuQTxH0myOU nhH0hsLs047wxHkM3xZh2g5ZBIk7iegZsGdE58yWlsLtQzdJ5ntykEQE1Ugarvl9qjsZ UJpjrPecrMCvPrPnMkksvJrdFZlAFm2JRxClFaiNfq1si23QdbDPlfVTnm3RbVbg8EES EG9Z7HSeZ/NLlKL+d3mc907mL/2/Wy/7JEujdFOflwRevjwaws7Cn0wdbDT2b81A3FxU yKnNJbIXG5n3wyULRnpSy8kkiJarx+uq8JngkkGnm+saM089bLKpQ8kvjJORFjIm/mOh jvUg== 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:message-id:subject:cc:to:from:date; bh=JXz3MWDdk6ccthrR6XHcVqI+y7e6+H/euMBdH74qwcY=; b=KdNjTZZKgMqeXveU4Z4kFVDlO3TmYkVykV5golHhiGKIBDQ6UUAz9MfLzR5SacPu4R Zg07A3kgEq56I4HySK4dNJHraXMyJwmkMXs4ZLhQvmDC8EkbUmIY9lrmZaIBqs5maPT4 NbxUtHE/EMJTQdWjq9Tle3V6qjoh8+dHIdgQ1G2Rbc1i2zbaNMbLdxaZeZsHzhTQRdS4 Ps1YuzmH+ZrHk4WvSVUGANoKhGgO/VRlHSxXtJzI8zs2vQqtvxftctRoWex3U7Y4dKoO Rmzzz8zJZ1nRNBi8c5Ai5P9ChvnkeNFW4RsqdZMdmUWMePGoMVtdeQtmwRJKeITBc61x cxsA== 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 p3-v6si1797993pfn.97.2018.09.27.04.44.03; Thu, 27 Sep 2018 04:44:19 -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 S1727232AbeI0SAV (ORCPT + 99 others); Thu, 27 Sep 2018 14:00:21 -0400 Received: from mail.bootlin.com ([62.4.15.54]:51102 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727105AbeI0SAV (ORCPT ); Thu, 27 Sep 2018 14:00:21 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 3708C208A1; Thu, 27 Sep 2018 13:42:26 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (guest-nat.fw1.untrust.par1.mozilla.net [185.155.181.200]) by mail.bootlin.com (Postfix) with ESMTPSA id 0F3D1207CF; Thu, 27 Sep 2018 13:42:16 +0200 (CEST) Date: Thu, 27 Sep 2018 13:42:16 +0200 From: Boris Brezillon To: Ricardo Ribalda Delgado Cc: David Woodhouse , Brian Norris , Marek Vasut , Richard Weinberger , Zhouyang Jia , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org (open list) Subject: Re: [PATCH v2 5/8] mtd: maps: gpio-addr-flash: Replace array with an integer Message-ID: <20180927134216.1952f668@bbrezillon> In-Reply-To: <20180905143643.9871-6-ricardo.ribalda@gmail.com> References: <20180905143643.9871-1-ricardo.ribalda@gmail.com> <20180905143643.9871-6-ricardo.ribalda@gmail.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 5 Sep 2018 16:36:40 +0200 Ricardo Ribalda Delgado wrote: > By replacing the array with an integer we can avoid completely > the bit comparison loop if the value has not changed (by far > the most common case). > > Signed-off-by: Ricardo Ribalda Delgado > --- > drivers/mtd/maps/gpio-addr-flash.c | 31 +++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) > > diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c > index 22e100f07112..8f5e3dce9be3 100644 > --- a/drivers/mtd/maps/gpio-addr-flash.c > +++ b/drivers/mtd/maps/gpio-addr-flash.c > @@ -43,7 +43,7 @@ struct async_state { > struct map_info map; > size_t gpio_count; > unsigned *gpio_addrs; > - int *gpio_values; > + unsigned int gpio_values; > unsigned int win_order; > }; > #define gf_map_info_to_state(mi) ((struct async_state *)(mi)->map_priv_1) > @@ -55,22 +55,25 @@ struct async_state { > * > * Rather than call the GPIO framework every time, cache the last-programmed > * value. This speeds up sequential accesses (which are by far the most common > - * type). We rely on the GPIO framework to treat non-zero value as high so > - * that we don't have to normalize the bits. > + * type). > */ > static void gf_set_gpios(struct async_state *state, unsigned long ofs) > { > - size_t i = 0; > - int value; > + int i; > > ofs >>= state->win_order; > - do { > - value = ofs & (1 << i); > - if (state->gpio_values[i] != value) { > - gpio_set_value(state->gpio_addrs[i], value); > - state->gpio_values[i] = value; > - } > - } while (++i < state->gpio_count); > + > + if (ofs == state->gpio_values) > + return; > + > + for (i = 0; i < state->gpio_count; i++) { > + if ((ofs & BIT(i)) == (state->gpio_values & BIT(i))) Parens around the xx & BIT(i) operations are unneeded. > + continue; > + > + gpio_set_value(state->gpio_addrs[i], !!(ofs & BIT(i))); > + } > + > + state->gpio_values = ofs; > } > > /** > @@ -215,7 +218,7 @@ static int gpio_flash_probe(struct platform_device *pdev) > if (!memory || !gpios || !gpios->end) > return -EINVAL; > > - arr_size = sizeof(int) * gpios->end; > + arr_size = sizeof(state->gpio_addrs[0]) * gpios->end; > state = devm_kzalloc(&pdev->dev, sizeof(*state) + arr_size, GFP_KERNEL); > if (!state) > return -ENOMEM; > @@ -226,9 +229,7 @@ static int gpio_flash_probe(struct platform_device *pdev) > */ > state->gpio_count = gpios->end; > state->gpio_addrs = (void *)(unsigned long)gpios->start; > - state->gpio_values = (void *)(state + 1); > state->win_order = get_bitmask_order(resource_size(memory)) - 1; > - memset(state->gpio_values, 0xff, arr_size); > > state->map.name = DRIVER_NAME; > state->map.read = gf_read;