mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
Cc: target-devel <target-devel@vger.kernel.org>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Christoph Hellwig <hch@lst.de>, Andy Grover <agrover@redhat.com>,
	Hannes Reinecke <hare@suse.de>,
	Roland Dreier <roland@purestorage.com>,
	James Bottomley <James.Bottomley@HansenPartnership.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage
Date: Tue, 26 Jul 2011 09:54:35 -0700	[thread overview]
Message-ID: <1311699275.15386.14.camel@Joe-Laptop> (raw)
In-Reply-To: <1311667641.17766.249.camel@haakon2.linux-iscsi.org>

On Tue, 2011-07-26 at 01:07 -0700, Nicholas A. Bellinger wrote:
> On Tue, 2011-07-26 at 00:53 -0700, Joe Perches wrote:
> > On Tue, 2011-07-26 at 07:10 +0000, Nicholas A. Bellinger wrote:
> > > Add new DIV_ROUND_UP_ULL macro usage for 32-bit architectures requiring
> > > unsigned long long division of sectors * dev_max_sectors.
> > []
> > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> > []
> > > +#define DIV_ROUND_UP_ULL(ll,d) \
> > > +	({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; })
> > Maybe use uint64_t and a temporary for d?
> > #define DIV_ROUND_UP_ULL(ll, d)				\
> > ({							\
> > 	typeof(d) _d = d;				\
> > 	uint64_t _tmp = (uint64_t)(ll) + _d - 1;	\
> > 	do_div(_tmp, _d);				\
> > 	_tmp;						\
> > })

> Hi Joe,

Hi Nicholas.

> Not sure on this one myself..  Would this case ever be strictly required
> for proper 32-bit operation with unsigned long long division with
> sector_t..?

It's just for correctness.

For 32 bit uses, if ll is a unsigned long and not an
unsigned long long then without the cast the addition
will be done as a 32 bit value.

e.g.:

$ cat t.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char** argv)
{
	unsigned long l = 0xFFFFFFFFUL;
	unsigned long long ull = l + 1;
	unsigned long long ull2 = (unsigned long long)l + 1;

	printf("l: %lu, ull:%llu, ull2: %llu\n", l, ull, ull2);
}
$ gcc t.c
$ ./a.out
l: 4294967295, ull:0, ull2: 4294967296



      reply	other threads:[~2011-07-26 16:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-26  7:10 Nicholas A. Bellinger
2011-07-26  7:10 ` [PATCH 2/2] target: Convert to DIV_ROUND_UP_ULL usage for sectors / dev_max_sectors Nicholas A. Bellinger
2011-07-26  7:36 ` [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage Nicholas A. Bellinger
2011-07-26  7:53 ` Joe Perches
2011-07-26  8:07   ` Nicholas A. Bellinger
2011-07-26 16:54     ` Joe Perches [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=1311699275.15386.14.camel@Joe-Laptop \
    --to=joe@perches.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=agrover@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=nab@linux-iscsi.org \
    --cc=roland@purestorage.com \
    --cc=target-devel@vger.kernel.org \
    --cc=torvalds@linux-foundation.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

all inboxes | Powered by JetHome®