mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leonardo Bras <leonardo@linux.ibm.com>
To: Jens Axboe <axboe@kernel.dk>, linux-kernel@vger.kernel.org
Cc: Dennis Zhou <dennis@kernel.org>, Hannes Reinecke <hare@suse.com>,
	Damien Le Moal <damien.lemoal@wdc.com>, Tejun Heo <tj@kernel.org>,
	"Dennis Zhou (Facebook)" <dennisszhou@gmail.com>,
	Johannes Thumshirn <jthumshirn@suse.de>,
	Sagi Grimberg <sagi@grimberg.me>
Subject: Re: [PATCH 1/1] block: Use bits.h macros to improve readability
Date: Thu, 08 Aug 2019 15:35:11 -0300	[thread overview]
Message-ID: <6ce7545a7a83e8d92fe09110b7f47de7068262fe.camel@linux.ibm.com> (raw)
In-Reply-To: <a41b5530-f2e1-0932-1f39-0ce66ce902ae@kernel.dk>

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

On Fri, 2019-08-02 at 21:18 -0700, Jens Axboe wrote:
> On 8/1/19 6:00 PM, Leonardo Bras wrote:
> > Applies some bits.h macros in order to improve readability of
> > linux/blk_types.h.
> > 
> > Signed-off-by: Leonardo Bras <leonardo@linux.ibm.com>
> > ---
> >   include/linux/blk_types.h | 55 ++++++++++++++++++++-------------------
> >   1 file changed, 28 insertions(+), 27 deletions(-)
> > 
> > diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
> > index 95202f80676c..31c8c6d274f6 100644
> > --- a/include/linux/blk_types.h
> > +++ b/include/linux/blk_types.h
> > @@ -9,6 +9,7 @@
> >   #include <linux/types.h>
> >   #include <linux/bvec.h>
> >   #include <linux/ktime.h>
> > +#include <linux/bits.h>
> >   
> >   struct bio_set;
> >   struct bio;
> > @@ -101,13 +102,13 @@ static inline bool blk_path_error(blk_status_t error)
> >   #define BIO_ISSUE_SIZE_BITS     12
> >   #define BIO_ISSUE_RES_SHIFT     (64 - BIO_ISSUE_RES_BITS)
> >   #define BIO_ISSUE_SIZE_SHIFT    (BIO_ISSUE_RES_SHIFT - BIO_ISSUE_SIZE_BITS)
> > -#define BIO_ISSUE_TIME_MASK     ((1ULL << BIO_ISSUE_SIZE_SHIFT) - 1)
> > +#define BIO_ISSUE_TIME_MASK     GENMASK_ULL(BIO_ISSUE_SIZE_SHIFT - 1, 0)
> 
> Not sure why we even have these helpers, I'd argue that patches like
> this HURT readability, not improve it. When I see
> 
> ((1ULL << SOME_SHIFT) - 1)
> 
> I know precisely what that does, whereas I have to think about the other
> one, maybe even look it up to be sure. For instance, without looking
> now, I have no idea what the second argument is. Looking at the git log,
> I see numerous instances of:
> 
> "xxx: Fix misuses of GENMASK macro
> 
>  Arguments are supposed to be ordered high then low."
> 
> Hence it seems GENMASK_ULL is easy to misuse or get wrong, the very
> opposite of what you'd want in a helper. How is it helping readability
> if the helper is easy to misuse?
> 
> Ditto with
> 
> (1ULL << SOME_SHIFT)
> 
> vs BIT_ULL. But at least that one doesn't have a mysterious 2nd
> argument.
> 
> Hence I'm not inclined to apply this patch.
> 

Well, as a newbie, macros like GENMASK(a,b) look way simpler. I to read
than (((1 << a) - 1) << b), or (~((1 << c) - 1)).
I mean, in GENMASK all bits >= a, <=b are set. 

But I agree that once you get used to reading masks created with <<, it
doesn't look that harder.

Well, thanks for this feedback.

Regards, 
Leonardo Brás

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

      parent reply	other threads:[~2019-08-08 18:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-02  0:00 Leonardo Bras
2019-08-03  4:18 ` Jens Axboe
2019-08-04 20:17   ` Joe Perches
2019-08-04 21:10     ` Jens Axboe
2019-08-08 18:35   ` Leonardo Bras [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=6ce7545a7a83e8d92fe09110b7f47de7068262fe.camel@linux.ibm.com \
    --to=leonardo@linux.ibm.com \
    --cc=axboe@kernel.dk \
    --cc=damien.lemoal@wdc.com \
    --cc=dennis@kernel.org \
    --cc=dennisszhou@gmail.com \
    --cc=hare@suse.com \
    --cc=jthumshirn@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sagi@grimberg.me \
    --cc=tj@kernel.org \
    /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

Powered by JetHome