Skip to contentSkip to conversation

kernel.h: Add DIV_ROUND_UP_ULL and DIV_ROUND_UP_SECTOR_T macro usage

PATCH In review Nicholas A. Bellinger 1 participant 3 messages Jul 26, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 kernel.h: Add DIV_ROUND_UP_ULL and DIV_ROUND_UP_SECTOR_T macro usage

From: Nicholas Bellinger <[email protected]>

Add new DIV_ROUND_UP_SECTOR_T macro usage for 32-bit architectures requiring a new DIV_ROUND_UP_ULL, and existing 64-bit usage with DIV_ROUND_UP.

---
 include/linux/kernel.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/linux/kernel.h +8 -0
index 953352a..e81b647 100644
@@ -56,6 +56,14 @@
 
 #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; })
+
+#if BITS_PER_LONG == 32
+# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d)
+#else
+# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d)
+#endif
 
 /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */
 #define roundup(x, y) (					\
Signature · 1 line
1.7.2.5
#1 lore raw

PATCH v2 2/2 target: Convert to DIV_ROUND_UP_SECTOR_T 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_SECTOR_T usage to use the new DIV_ROUND_UP_ULL() usage for 32-bit architectures with the unsigned long long sector_t division in transport_allocate_data_tasks() usage for 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
index a244c90..301d5a0 100644
@@ -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_SECTOR_T(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
#2 lore raw
In reply to Nicholas A. Bellinger
Quoted 19 lines · Nicholas A. Bellinger

From: Nicholas Bellinger <[email protected]>

Add new DIV_ROUND_UP_SECTOR_T macro usage for 32-bit architectures requiring a new DIV_ROUND_UP_ULL, and existing 64-bit usage with DIV_ROUND_UP.

---
 include/linux/kernel.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
include/linux/kernel.h +0 -0
index 953352a..e81b647 100644
@@ -56,6 +56,14 @@
 
 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))

include/linux/kernel.h line 67

Quoted 10 lines
include/linux/kernel.h +8 -0
 #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; })
+
+#if BITS_PER_LONG == 32
+# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d)
+#else
+# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d)
+#endif
 

Hi Andrew,

Is CONFIG_LBDAF=n usage going to have problems with the above..?

Things are looking as expected AFAICT with some quick tests with CONFIG_LBDAF=y on i386, but still need to verify the CONFIG_LBDAF=n on 32-bit as well. Any more comments here are appercitated.

Thank you,

--nab