LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Michal Kubecek <mkubecek@suse.cz>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>,
	Doug Ledford <dledford@redhat.com>,
	Ariel Levkovich <lariel@mellanox.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mlx5: avoid 64-bit division
Date: Mon, 27 May 2019 22:47:27 +0200	[thread overview]
Message-ID: <20190527204727.GH30439@unicorn.suse.cz> (raw)
In-Reply-To: <20190527181534.GA10029@ziepe.ca>

On Mon, May 27, 2019 at 03:15:34PM -0300, Jason Gunthorpe wrote:
> On Mon, May 20, 2019 at 01:19:02PM +0200, Michal Kubecek wrote:
> > diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c
> > index abac70ad5c7c..340290b883fe 100644
> > +++ b/drivers/infiniband/hw/mlx5/main.c
> > @@ -2344,7 +2344,7 @@ static int handle_alloc_dm_sw_icm(struct ib_ucontext *ctx,
> >  	/* Allocation size must a multiple of the basic block size
> >  	 * and a power of 2.
> >  	 */
> > -	act_size = roundup(attr->length, MLX5_SW_ICM_BLOCK_SIZE(dm_db->dev));
> > +	act_size = round_up(attr->length, MLX5_SW_ICM_BLOCK_SIZE(dm_db->dev));
> >  	act_size = roundup_pow_of_two(act_size);
> 
> It is kind of weird that we have round_up and the bitshift
> version.. None of this is performance critical so why not just use
> round_up everywhere?
> 
> Ariel, it is true MLX5_SW_ICM_BLOCK_SIZE will always be a power of
> two?

If it weren't, the requirements from the comment above could never be
satisfied as a power of two can only be a multiple of another power of
two. Which also means that what the code above does is in fact
equivalent to

	act_size = max_t(u64, roundup_pow_of_two(attr->length),
			 MLX5_SW_ICM_BLOCK_SIZE(dm_db->dev));

or

	act_size = roundup_pow_of_two(max_t(u64, attr->length,
					    MLX5_SW_ICM_BLOCK_SIZE(dm_db->dev));

Michal Kubecek

  reply	other threads:[~2019-05-27 20:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20 11:19 Michal Kubecek
2019-05-20 11:28 ` Leon Romanovsky
2019-05-28 14:01   ` Leon Romanovsky
2019-05-28 14:44     ` Ariel Levkovich
2019-05-27 18:15 ` Jason Gunthorpe
2019-05-27 20:47   ` Michal Kubecek [this message]
2019-05-29 16:08 ` Jason Gunthorpe

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=20190527204727.GH30439@unicorn.suse.cz \
    --to=mkubecek@suse.cz \
    --cc=dledford@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=lariel@mellanox.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --subject='Re: [PATCH] mlx5: avoid 64-bit division' \
    /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

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).