linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: andrew.murray@arm.com, maz@kernel.org,
	linux-kernel@vger.kernel.org,
	"Michael Turquette" <mturquette@baylibre.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Emilio López" <emilio@elopez.com.ar>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Chen-Yu Tsai" <wens@csie.org>,
	"Mike Marciniszyn" <mike.marciniszyn@intel.com>,
	"Dennis Dalessandro" <dennis.dalessandro@intel.com>,
	"Yishai Hadas" <yishaih@mellanox.com>,
	"Moni Shoua" <monis@mellanox.com>,
	"David Woodhouse" <dwmw2@infradead.org>,
	"Lu Baolu" <baolu.lu@linux.intel.com>,
	"Joerg Roedel" <joro@8bytes.org>,
	"Tom Lendacky" <thomas.lendacky@amd.com>,
	"Mirko Lindner" <mlindner@marvell.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Jiri Pirko" <jiri@resnulli.us>,
	"Solarflare linux maintainers" <linux-net-drivers@solarflare.com>,
	"Edward Cree" <ecree@solarflare.com>,
	"Martin Habets" <mhabets@solarflare.com>,
	"Eric Biederman" <ebiederm@xmission.com>,
	"Thomas Graf" <tgraf@suug.ch>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	james.quinlan@broadcom.com, mbrugger@suse.com,
	f.fainelli@gmail.com, phil@raspberrypi.org, wahrenst@gmx.net,
	jeremy.linton@arm.com, linux-pci@vger.kernel.org,
	linux-rpi-kernel@lists.infradead.org,
	"Robin Murphy" <robin.murphy@arm.con>,
	"Doug Ledford" <dledford@redhat.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"David S. Miller" <davem@davemloft.net>,
	"Trond Myklebust" <trond.myklebust@hammerspace.com>,
	"Anna Schumaker" <anna.schumaker@netapp.com>,
	"J. Bruce Fields" <bfields@fieldses.org>,
	"Chuck Lever" <chuck.lever@oracle.com>,
	linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rdma@vger.kernel.org, iommu@lists.linux-foundation.org,
	netdev@vger.kernel.org, kexec@lists.infradead.org,
	linux-nfs@vger.kernel.org
Subject: Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two()
Date: Thu, 12 Dec 2019 14:16:27 +0100	[thread overview]
Message-ID: <b35922dfd7f62489d35ab15362891a90bf46c3d2.camel@suse.de> (raw)
In-Reply-To: <20191205223044.GA250573@google.com>

[-- Attachment #1: Type: text/plain, Size: 2374 bytes --]

On Thu, 2019-12-05 at 16:30 -0600, Bjorn Helgaas wrote:
> You got the "n" on "down" in the subject, but still missing "of" ;)

Yes, sorry about that, I tend to re-read what I meant to say instead of what
it's actually written.

> On Tue, Dec 03, 2019 at 12:47:40PM +0100, Nicolas Saenz Julienne wrote:
> > Some users need to make sure their rounding function accepts and returns
> > 64bit long variables regardless of the architecture. Sadly
> > roundup/rounddown_pow_two() takes and returns unsigned longs. It turns
> > out ilog2() already handles 32/64bit calculations properly, and being
> > the building block to the round functions we can rework them as a
> > wrapper around it.
> 
> Missing "of" in the function names here.
> s/a wrapper/wrappers/

Noted

> IIUC the point of this is that roundup_pow_of_two() returned
> "unsigned long", which can be either 32 or 64 bits (worth pointing
> out, I think), and many callers need something that returns
> "unsigned long long" (always 64 bits).

I'll update the commit message to be a more explicit.

> It's a nice simplification to remove the "__" variants.  Just as a
> casual reader of this commit message, I'd like to know why we had both
> the roundup and the __roundup versions in the first place, and why we
> no longer need both.

So, the commit that introduced it (312a0c170945b) meant to use the '__' variant
as a helper, but, due to the fact this is a header file, some found it and made
use of it. I went over some if the commits introducing '__' usages and none of
them seem to acknowledge its use as opposed to the macro version. I think it's
fair to say it's a case of cargo-culting.

> > -#define roundup_pow_of_two(n)			\
> > -(						\
> > -	__builtin_constant_p(n) ? (		\
> > -		(n == 1) ? 1 :			\
> > -		(1UL << (ilog2((n) - 1) + 1))	\
> > -				   ) :		\
> > -	__roundup_pow_of_two(n)			\
> > - )
> > +#define roundup_pow_of_two(n)			  \
> > +(						  \
> > +	(__builtin_constant_p(n) && ((n) == 1)) ? \
> > +	1 : (1ULL << (ilog2((n) - 1) + 1))        \
> > +)
> 
> Should the resulting type of this expression always be a ULL, even
> when n==1, i.e., should it be this?
> 
>   1ULL : (1ULL << (ilog2((n) - 1) + 1))        \
> 
> Or maybe there's no case where that makes a difference?

It should be 1ULL on either case.

Regards,
Nicolas


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2019-12-12 13:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-03 11:47 [PATCH v4 0/8] Raspberry Pi 4 PCIe support Nicolas Saenz Julienne
2019-12-03 11:47 ` [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two() Nicolas Saenz Julienne
2019-12-03 16:39   ` Chuck Lever
2019-12-04 10:56   ` Martin Habets
2019-12-04 14:17   ` Leon Romanovsky
2019-12-05  0:39   ` Lu Baolu
2019-12-05 17:48   ` Robin Murphy
2019-12-12 12:31     ` Nicolas Saenz Julienne
2019-12-05 22:30   ` Bjorn Helgaas
2019-12-12 13:16     ` Nicolas Saenz Julienne [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b35922dfd7f62489d35ab15362891a90bf46c3d2.camel@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=andrew.murray@arm.com \
    --cc=anna.schumaker@netapp.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=bfields@fieldses.org \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=dennis.dalessandro@intel.com \
    --cc=dledford@redhat.com \
    --cc=dwmw2@infradead.org \
    --cc=ebiederm@xmission.com \
    --cc=ecree@solarflare.com \
    --cc=emilio@elopez.com.ar \
    --cc=f.fainelli@gmail.com \
    --cc=helgaas@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=iommu@lists.linux-foundation.org \
    --cc=james.quinlan@broadcom.com \
    --cc=jeremy.linton@arm.com \
    --cc=jgg@ziepe.ca \
    --cc=jiri@resnulli.us \
    --cc=joro@8bytes.org \
    --cc=kexec@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-net-drivers@solarflare.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=mbrugger@suse.com \
    --cc=mhabets@solarflare.com \
    --cc=mike.marciniszyn@intel.com \
    --cc=mlindner@marvell.com \
    --cc=monis@mellanox.com \
    --cc=mripard@kernel.org \
    --cc=mturquette@baylibre.com \
    --cc=netdev@vger.kernel.org \
    --cc=phil@raspberrypi.org \
    --cc=robin.murphy@arm.con \
    --cc=sboyd@kernel.org \
    --cc=stephen@networkplumber.org \
    --cc=tgraf@suug.ch \
    --cc=thomas.lendacky@amd.com \
    --cc=trond.myklebust@hammerspace.com \
    --cc=wahrenst@gmx.net \
    --cc=wens@csie.org \
    --cc=yishaih@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).