From 58e75cf714fced7ba61602a776441d3d289e8cdc Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 8 Feb 2022 10:49:43 +0000 Subject: [PATCH] nvmf/vfio-user: avoid division in cq_is_full() Avoid using the modulus operator in the hot-path cq_is_full(), by aping how cq_tail_advance() is written. Signed-off-by: John Levon Change-Id: Idbdf1715ab30d08233b38aa7691f0212ae93a542 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11445 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Community-CI: Broadcom CI Community-CI: Mellanox Build Bot --- lib/nvmf/vfio_user.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index 58cd85165..99dec9874 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -469,6 +469,23 @@ cq_tail_advance(struct nvmf_vfio_user_cq *cq) } } +static inline bool +cq_is_full(struct nvmf_vfio_user_ctrlr *ctrlr, struct nvmf_vfio_user_cq *cq) +{ + uint32_t qindex; + + assert(ctrlr != NULL); + assert(cq != NULL); + + qindex = *cq_tailp(cq) + 1; + if (spdk_unlikely(qindex == cq->size)) { + qindex = 0; + } + + return qindex == *cq_dbl_headp(ctrlr, cq); +} + + /* TODO: wrapper to data structure */ static inline size_t vfio_user_migr_data_len(void) @@ -978,16 +995,6 @@ asq_setup(struct nvmf_vfio_user_ctrlr *ctrlr) return 0; } -static inline bool -cq_is_full(struct nvmf_vfio_user_ctrlr *ctrlr, - struct nvmf_vfio_user_cq *cq) -{ - assert(ctrlr != NULL); - assert(cq != NULL); - - return ((*cq_tailp(cq) + 1) % cq->size) == *cq_dbl_headp(ctrlr, cq); -} - static int acq_setup(struct nvmf_vfio_user_ctrlr *ctrlr) {