From 0754417fa9313f03f57c45348557228f2194a466 Mon Sep 17 00:00:00 2001 From: Alexey Marchuk Date: Mon, 15 Jul 2019 12:52:00 +0000 Subject: [PATCH] rdma: Use optimal ceiling integer division This form of the celinig division allows to remove an extra condition Change-Id: I8a2de792172ec9115563e7fb914745c476f16e8d Signed-off-by: Alexey Marchuk Signed-off-by: Sasha Kotchubievsky Signed-off-by: Evgenii Kochetov Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/462198 Reviewed-by: Seth Howell Reviewed-by: Darek Stojaczyk Reviewed-by: Shuhei Matsumoto Tested-by: SPDK CI Jenkins --- include/spdk/util.h | 7 +++++-- lib/nvmf/rdma.c | 10 ++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/spdk/util.h b/include/spdk/util.h index 658a9b13d..8655112bf 100644 --- a/include/spdk/util.h +++ b/include/spdk/util.h @@ -1,8 +1,8 @@ /*- * BSD LICENSE * - * Copyright (c) Intel Corporation. - * All rights reserved. + * Copyright (c) Intel Corporation. All rights reserved. + * Copyright (c) 2019 Mellanox Technologies LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -54,6 +54,9 @@ extern "C" { #define SPDK_SEC_TO_USEC 1000000ULL #define SPDK_SEC_TO_NSEC 1000000000ULL +/* Ceiling division of unsigned integers */ +#define SPDK_CEIL_DIV(x,y) (((x)+(y)-1)/(y)) + static inline uint32_t spdk_u32log2(uint32_t x) { diff --git a/lib/nvmf/rdma.c b/lib/nvmf/rdma.c index 1cbce29d9..41357fa6d 100644 --- a/lib/nvmf/rdma.c +++ b/lib/nvmf/rdma.c @@ -1574,10 +1574,7 @@ spdk_nvmf_rdma_request_fill_iovs(struct spdk_nvmf_rdma_transport *rtransport, rgroup = rqpair->poller->group; rdma_req->req.iovcnt = 0; - num_buffers = rdma_req->req.length / rtransport->transport.opts.io_unit_size; - if (rdma_req->req.length % rtransport->transport.opts.io_unit_size) { - num_buffers++; - } + num_buffers = SPDK_CEIL_DIV(rdma_req->req.length, rtransport->transport.opts.io_unit_size); if (nvmf_rdma_request_get_buffers(rdma_req, &rgroup->group, &rtransport->transport, num_buffers)) { return -ENOMEM; @@ -1636,10 +1633,7 @@ nvmf_rdma_request_fill_iovs_multi_sgl(struct spdk_nvmf_rdma_transport *rtranspor desc = (struct spdk_nvme_sgl_descriptor *)rdma_req->recv->buf + inline_segment->address; for (i = 0; i < num_sgl_descriptors; i++) { - num_buffers += desc->keyed.length / rtransport->transport.opts.io_unit_size; - if (desc->keyed.length % rtransport->transport.opts.io_unit_size) { - num_buffers++; - } + num_buffers += SPDK_CEIL_DIV(desc->keyed.length, rtransport->transport.opts.io_unit_size); desc++; } /* If the number of buffers is too large, then we know the I/O is larger than allowed. Fail it. */