kernel.h: Add DIV_ROUND_UP_ULL usage
Subsystems (2)
PATCH 1/2 kernel.h: Add DIV_ROUND_UP_ULL usage
From: Nicholas Bellinger <[email protected]>
Add new DIV_ROUND_UP_ULL macro usage for 32-bit architectures requiring unsigned long long division of sectors * dev_max_sectors.
--- include/linux/kernel.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
include/linux/kernel.h +2 -0
@@ -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) ( \
Signature · 1 line
1.7.2.5
PATCH 2/2 target: Convert to DIV_ROUND_UP_ULL usage for sectors / dev_max_sectors
From: Nicholas Bellinger <[email protected]>
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
--- drivers/target/target_core_transport.c | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/target/target_core_transport.c +3 -4
@@ -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;
Signature · 1 line
1.7.2.5
Quoted 5 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
Add new
DIV_ROUND_UP_ULLmacro 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
Quoted 2 lines · Nicholas A. Bellinger
Add new
DIV_ROUND_UP_ULLmacro usage for 32-bit architectures requiring unsigned long long division of sectors *dev_max_sectors.
[]
include/linux/kernel.h
Quoted 1 line
include/linux/kernel.h +0
-0
[]
include/linux/kernel.h line 60
Quoted 2 lines
include/linux/kernel.h +2
-0+#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; \
})Quoted 11 lines · Joe Perches
Quoted 2 lines · Nicholas A. Bellinger
Add new
DIV_ROUND_UP_ULLmacro usage for 32-bit architectures requiring unsigned long long division of sectors *dev_max_sectors.[]
include/linux/kernel.h
Quoted 1 line
include/linux/kernel.h +0
-0[]
include/linux/kernel.h line 60
Quoted 2 lines
include/linux/kernel.h +2
-0+#define DIV_ROUND_UP_ULL (ll,d) \ + ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; })Maybe use
uint64_tand a temporary for d?
Quoted 9 lines
#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
Quoted 18 lines · Nicholas A. Bellinger
Quoted 10 lines · Joe Perches
Quoted 2 lines · Nicholas A. Bellinger
Add new
DIV_ROUND_UP_ULLmacro usage for 32-bit architectures requiring unsigned long long division of sectors *dev_max_sectors.[]
include/linux/kernel.h
Quoted 1 line
include/linux/kernel.h +0
-0[]
include/linux/kernel.h line 60
Quoted 2 lines
include/linux/kernel.h +2
-0+#define DIV_ROUND_UP_ULL (ll,d) \ + ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; })Maybe use
uint64_tand a temporary for d?
#defineDIV_ROUND_UP_ULL(ll, d)\Quoted 6 lines
({ \ typeof(d) _d = d; \ uint64_t _tmp = (uint64_t)(ll) + _d - 1; \ do_div(_tmp, _d); \ _tmp; \ })
Quoted 1 line
Hi Joe,
Hi Nicholas.
Quoted 3 lines
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