Skip to contentSkip to conversation

nvme-pci: avoid 64-bit divisions in the HMB code

PATCH New Christoph Hellwig 3 participants 3 messages Jun 6, 2017 NVMe

lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH 1/1 nvme-pci: avoid 64-bit divisions in the HMB code

[to be folded into "nvme-pci: implement host memory buffer support"]

Avoid 64-bit division by using shifts instead. All involved sizez are powers of two.

Signed-off-by Christoph Hellwig <hch at lst.de>
---
 drivers/nvme/host/pci.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/nvme/host/pci.c +5 -4
index a81833fd4b1b..380ad905acbf 100644
@@ -1567,8 +1567,8 @@ static int nvme_set_host_mem(struct nvme_dev *dev, u32 bits)
 	c.features.opcode	= nvme_admin_set_features;
 	c.features.fid		= cpu_to_le32(NVME_FEAT_HOST_MEM_BUF);
 	c.features.dword11	= cpu_to_le32(bits);
-	c.features.dword12	= cpu_to_le32(dev->host_mem_size /
-					      dev->ctrl.page_size);
+	c.features.dword12	= cpu_to_le32(dev->host_mem_size >>
+					      ilog2(dev->ctrl.page_size));
 	c.features.dword13	= cpu_to_le32(lower_32_bits(dma_addr));
 	c.features.dword14	= cpu_to_le32(upper_32_bits(dma_addr));
 	c.features.dword15	= cpu_to_le32(dev->nr_host_mem_descs);
@@ -1641,7 +1641,8 @@ static int nvme_alloc_host_mem(struct nvme_dev *dev, u64 min, u64 preferred)
 	}
 
 	dev_info(dev->ctrl.device,
-		"allocated %lld MiB host memory buffer.\n", size / SZ_1M);
+		"allocated %lld MiB host memory buffer.\n",
+		size >> ilog2(SZ_1M));
 	dev->nr_host_mem_descs = i;
 	dev->host_mem_size = size;
 	dev->host_mem_descs = descs;
@@ -1680,7 +1681,7 @@ static void nvme_setup_host_mem(struct nvme_dev *dev)
 	if (min > max) {
 		dev_warn(dev->ctrl.device,
 			"min host memory (%lld MiB) above limit (%d MiB).\n",
-			min / SZ_1M, max_host_mem_size_mb);
+			min >> ilog2(SZ_1M), max_host_mem_size_mb);
 		nvme_free_host_mem(dev);
 		return;
 	}
Signature · 1 line
2.11.0
maintainer
#1 lore raw

PATCH 1/1 nvme-pci: avoid 64-bit divisions in the HMB code

Quoted 6 lines

[to be folded into "nvme-pci: implement host memory buffer support"]

Avoid 64-bit division by using shifts instead. All involved sizez are powers of two.

Signed-off-by Christoph Hellwig <hch at lst.de>
Reviewed-by Sagi Grimberg <sagi at grimberg.me>
#2 lore raw

PATCH 1/1 nvme-pci: avoid 64-bit divisions in the HMB code

In reply to Christoph Hellwig
Quoted 3 lines · Christoph Hellwig

[to be folded into "nvme-pci: implement host memory buffer support"]

Avoid 64-bit division by using shifts instead. All involved sizez are

small type: sizez --> sizes

Quoted 4 lines

powers of two.

Signed-off-by Christoph Hellwig <hch at lst.de>

---

Looks good,
Reviewed-by: Max Gurtovoy <maxg at mellanox.com>