mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage
@ 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
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nicholas A. Bellinger @ 2011-07-26  7:10 UTC (permalink / raw)
  To: target-devel, linux-scsi, linux-kernel
  Cc: Christoph Hellwig, Andy Grover, Hannes Reinecke, Roland Dreier,
	James Bottomley, Andrew Morton, Linus Torvalds,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

Add new DIV_ROUND_UP_ULL macro usage for 32-bit architectures requiring
unsigned long long division of sectors * dev_max_sectors.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
---
 include/linux/kernel.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 953352a..016dcc9 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -56,6 +56,8 @@
 
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#define DIV_ROUND_UP_ULL(ll,d) \
+	({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; })
 
 /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
 #define roundup(x, y) (					\
-- 
1.7.2.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] target: Convert to DIV_ROUND_UP_ULL usage for sectors / dev_max_sectors
  2011-07-26  7:10 [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage Nicholas A. Bellinger
@ 2011-07-26  7:10 ` 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
  2 siblings, 0 replies; 6+ messages in thread
From: Nicholas A. Bellinger @ 2011-07-26  7:10 UTC (permalink / raw)
  To: target-devel, linux-scsi, linux-kernel
  Cc: Christoph Hellwig, Andy Grover, Hannes Reinecke, Roland Dreier,
	James Bottomley, Andrew Morton, Linus Torvalds,
	Nicholas Bellinger

From: Nicholas Bellinger <nab@linux-iscsi.org>

This patch adds the new macro usage of include/linux/kernel.h:DIV_ROUND_UP_ULL
for transport_allocate_data_tasks() usage in target_core_mod v4.1

Reported-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
---
 drivers/target/target_core_transport.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index a244c90..8032e1e 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -4054,17 +4054,16 @@ static int transport_allocate_data_tasks(
 	struct se_task *task;
 	struct se_device *dev = cmd->se_dev;
 	unsigned long flags;
-	sector_t sectors;
 	int task_count, i, ret;
-	sector_t dev_max_sectors = dev->se_sub_dev->se_dev_attrib.max_sectors;
+	sector_t sectors, dev_max_sectors = dev->se_sub_dev->se_dev_attrib.max_sectors;
 	u32 sector_size = dev->se_sub_dev->se_dev_attrib.block_size;
 	struct scatterlist *sg;
 	struct scatterlist *cmd_sg;
 
 	WARN_ON(cmd->data_length % sector_size);
 	sectors = DIV_ROUND_UP(cmd->data_length, sector_size);
-	task_count = DIV_ROUND_UP(sectors, dev_max_sectors);
-
+	task_count = DIV_ROUND_UP_ULL(sectors, dev_max_sectors);
+	
 	cmd_sg = sgl;
 	for (i = 0; i < task_count; i++) {
 		unsigned int task_size;
-- 
1.7.2.5


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage
  2011-07-26  7:10 [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage 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 ` Nicholas A. Bellinger
  2011-07-26  7:53 ` Joe Perches
  2 siblings, 0 replies; 6+ messages in thread
From: Nicholas A. Bellinger @ 2011-07-26  7:36 UTC (permalink / raw)
  To: target-devel
  Cc: linux-scsi, linux-kernel, Christoph Hellwig, Andy Grover,
	Hannes Reinecke, Roland Dreier, James Bottomley, Andrew Morton,
	Linus Torvalds

On Tue, 2011-07-26 at 07:10 +0000, Nicholas A. Bellinger wrote:
> From: Nicholas Bellinger <nab@linux-iscsi.org>
> 
> Add new DIV_ROUND_UP_ULL macro usage for 32-bit architectures requiring
> unsigned long long division of sectors * dev_max_sectors.
> 

Rebasing to fix the incorrect change log here before pushing.

Thanks,

--nab



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage
  2011-07-26  7:10 [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage 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
  2 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2011-07-26  7:53 UTC (permalink / raw)
  To: Nicholas A. Bellinger
  Cc: target-devel, linux-scsi, linux-kernel, Christoph Hellwig,
	Andy Grover, Hannes Reinecke, Roland Dreier, James Bottomley,
	Andrew Morton, Linus Torvalds

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;						\
})



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage
  2011-07-26  7:53 ` Joe Perches
@ 2011-07-26  8:07   ` Nicholas A. Bellinger
  2011-07-26 16:54     ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Nicholas A. Bellinger @ 2011-07-26  8:07 UTC (permalink / raw)
  To: Joe Perches
  Cc: target-devel, linux-scsi, linux-kernel, Christoph Hellwig,
	Andy Grover, Hannes Reinecke, Roland Dreier, James Bottomley,
	Andrew Morton, Linus Torvalds

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,

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

--nab



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage
  2011-07-26  8:07   ` Nicholas A. Bellinger
@ 2011-07-26 16:54     ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2011-07-26 16:54 UTC (permalink / raw)
  To: Nicholas A. Bellinger
  Cc: target-devel, linux-scsi, linux-kernel, Christoph Hellwig,
	Andy Grover, Hannes Reinecke, Roland Dreier, James Bottomley,
	Andrew Morton, Linus Torvalds

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



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-07-26 16:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-26  7:10 [PATCH 1/2] kernel.h: Add DIV_ROUND_UP_ULL usage 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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome