Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp284364pxk; Thu, 24 Sep 2020 05:49:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywYIlw66w5t67i6LKOkHcqRXCGdzr3FwU/532Hjr+By9tQoxKEC8LCBBLMcXcI5K8GawFq X-Received: by 2002:a17:906:f897:: with SMTP id lg23mr905032ejb.89.1600951742709; Thu, 24 Sep 2020 05:49:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600951742; cv=none; d=google.com; s=arc-20160816; b=eytQtxLtzkKuAP/VVk4X629VLUrmCozAglJkQqVYxNJxQbNLeYXobg415wgaqHJyfi 5LpcrCxrRSsWDEFniRKCAddtQzj4fRRCFzRDEZlCVET4zT1I04NDYxBviV7tCJ1ihunj Fz5UCD8+cbK9CqXZuQC4pgTc3xIITYOtyiMmi60CugGqiIdFC/HnJVjL5pXYo68y1GVm KH8SFmDN+HO0CeA9VIJq8TGnoz2YHps01Z6tEMx+mBywkp8T7J0GARw1dBCfobFjuizV lDyEy9y2YRLJ0TtvuvdrX7sTcLaMI6DYrPIGNDM9N+X2uewX26b7c7NmUXZk9XM/RgM0 8OgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=u2R826hNWDvUWxoTX3vKcw74OqKnezw5rqLakbWlfas=; b=LjzsAr/kfTksmPrqujNQ2F5/l+6zghuwPITAX+vGWja6wDjhCzXVeOpQ6HRfCHsYLV 9tmYt1oCWNb8g+G28eMNZSTOdVE1AeaJABpUl9gXN5IlKi1T4b7QFVxNQ/9WTrY2gr/r 8UPin9s3ivWau6lpb9h0ecx46qzthXXBuSH/vwX59CH4Vp5/dYnqILTM6PMTFgxF5Gfr s69GGzk5fRX2i5ZSnB6bCFALzZPq64cjOeUwuq3cxuM4otUQpZz4g7ELOQV7VoCxMUl7 CQKdRaNlZsnOsp6YhTbIBhMNob8FIX01bhA44nbP/svc0juqaFnDEBumTrZIiGfRWvqQ 44lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hmtGpzDH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gr23si1764279ejb.586.2020.09.24.05.48.39; Thu, 24 Sep 2020 05:49:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=hmtGpzDH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728037AbgIXMqd (ORCPT + 99 others); Thu, 24 Sep 2020 08:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727987AbgIXMqL (ORCPT ); Thu, 24 Sep 2020 08:46:11 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2730BC0613D3; Thu, 24 Sep 2020 05:46:11 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id v14so1542858pjd.4; Thu, 24 Sep 2020 05:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=u2R826hNWDvUWxoTX3vKcw74OqKnezw5rqLakbWlfas=; b=hmtGpzDHV3+upF1VOsB6pw/E4E8IdF/fK3mj1gRX1FYC/FXdo1S1yLg1OdgO/LQGMS po4qTLzH7riF4L1+NQR72MyT1UYvz3PWXrE2R0uh4mtdWqqpuivdIgrro+VBGK5DGT6l gL5P9xagaGE0xyfRTGpnVwVEr7l0bM8H917g6OSbIFN8MbrOIusmRLdZ/Mrp1LnB8Asq rRV5Nrvx7NJnZ6VOhw2vlS4/cLXoKmzA3MU1n0aK+O0ZmC3tbDRlIKyG+AG/GDNht9La bmO3OvQXF1dtejyAEpqAONFConi0rw3/4eESA6OqTaHAOBn+vUaSkjp6cduYvq6k0PTf lGog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=u2R826hNWDvUWxoTX3vKcw74OqKnezw5rqLakbWlfas=; b=SZqFI+Kf3fy/+PTrBjZ3railHf1DAT4ijyZfI7ij030WaS8v4HwjWzX2dPkb9REbye jNO7HCZT4CRhaBIbzcpOgC90QpK+vsKqZdoF/OPZuF7W1eX5ieEw5XDZcD/fRqElK+GC x6fRx1tcXWtkengARNgffXJYxlsh8sUDnIbX8zJ/o4Dy4iQMaJA7+2qCA86TH4eX/u9x lOyLFVzkU252X34sm2xjxHxSrbkC9HIVkmx2UihkudS+iXcPeJlnvANHImzh0OniIARi iJNkNb1adZcTq71hgITPfX9ZUimi0H/qYdpj1yYUKvWl35e09XIlFg6yoZVGUnb4MPkc Xhwg== X-Gm-Message-State: AOAM533JvumyZVQSBDVkPClKrcwfUxc1UoLRj6Adkx1NHMPMeVx4ghY5 6zSRXBeX4Fo+Gy99v+ZVX8o= X-Received: by 2002:a17:90a:1548:: with SMTP id y8mr3810358pja.113.1600951570511; Thu, 24 Sep 2020 05:46:10 -0700 (PDT) Received: from sol (106-69-189-59.dyn.iinet.net.au. [106.69.189.59]) by smtp.gmail.com with ESMTPSA id b18sm2921189pfr.4.2020.09.24.05.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 05:46:09 -0700 (PDT) Date: Thu, 24 Sep 2020 20:46:04 +0800 From: Kent Gibson To: Andy Shevchenko Cc: Linux Kernel Mailing List , "open list:GPIO SUBSYSTEM" , Bartosz Golaszewski , Linus Walleij , Arnd Bergmann Subject: Re: [PATCH v9 11/20] gpiolib: cdev: support GPIO_V2_LINE_SET_VALUES_IOCTL Message-ID: <20200924124604.GA227073@sol> References: <20200922023151.387447-1-warthog618@gmail.com> <20200922023151.387447-12-warthog618@gmail.com> <20200924073248.GA17562@sol> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200924073248.GA17562@sol> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 24, 2020 at 03:32:48PM +0800, Kent Gibson wrote: > On Wed, Sep 23, 2020 at 07:18:08PM +0300, Andy Shevchenko wrote: > > On Tue, Sep 22, 2020 at 5:36 AM Kent Gibson wrote: > > > > > > Add support for the GPIO_V2_LINE_SET_VALUES_IOCTL. > > > > > +static long linereq_set_values_unlocked(struct linereq *lr, > > > + struct gpio_v2_line_values *lv) > > > +{ > > > + DECLARE_BITMAP(vals, GPIO_V2_LINES_MAX); > > > + struct gpio_desc **descs; > > > + unsigned int i, didx, num_set; > > > + int ret; > > > + > > > + bitmap_zero(vals, GPIO_V2_LINES_MAX); > > > + for (num_set = 0, i = 0; i < lr->num_lines; i++) { > > > + if (lv->mask & BIT_ULL(i)) { > > > > Similar idea > > > > DECLARE_BITMAP(mask, 64) = BITMAP_FROM_U64(lv->mask); > > > > num_set = bitmap_weight(); > > > > I had played with this option, but bitmap_weight() counts all > the bits set in the mask - which considers bits >= lr->num_lines. > So you would need to mask lv->mask before converting it to a bitmap. > (I'm ok with ignoring those bits in case userspace wants to be lazy and > use an all 1s mask.) > > But since we're looping over the bitmap anyway we may as well just > count as we go. > > > for_each_set_bit(i, mask, lr->num_lines) > > > > Yeah, that should work. I vaguely recall trying this and finding it > generated larger object code, but I'll give it another try and if it > works out then include it in v10. > Tried it again and, while it works, it does increase the size of gpiolib-cdev.o as follows: u64 -> bitmap x86_64 28360 28616 i386 22056 22100 aarch64 37392 37600 mips32 28008 28016 So for 64-bit platforms changing to bitmap generates larger code, probably as we are forcing them to use 32-bit array semantics where before they could use the native u64. For 32-bit there is a much smaller difference as they were already using 32-bit array semantics to realise the u64. Those are for some of my test builds, so obviously YMMV. It is also only for changing linereq_get_values(), which has three instances of the loop. linereq_set_values_unlocked() has another two, so you could expect another increase of ~2/3 of that seen here if we change that as well. The sizeable increase in x86_64 was what made me revert this last time, and I'm still satisfied with that choice. Are you still eager to switch to for_each_set_bit()? Cheers, Kent.