From 586d1d65718d62f3befd5c823a87e12f5de2e15e Mon Sep 17 00:00:00 2001 From: John Levon Date: Tue, 8 Mar 2022 22:06:42 +0000 Subject: [PATCH] nvmf/vfio-user: don't read from completion entry We were accidentally reading the spdk_nvme_status from the CPL; on one test, this was contributing to 2% of cache misses. Signed-off-by: John Levon Change-Id: I7c967690458a183799f8d835360800d3094c3131 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11849 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Thanos Makatos Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- lib/nvmf/vfio_user.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index 86d9adc2d..720f1fb4c 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -1086,8 +1086,9 @@ static int post_completion(struct nvmf_vfio_user_ctrlr *ctrlr, struct nvmf_vfio_user_cq *cq, uint32_t cdw0, uint16_t sqid, uint16_t cid, uint16_t sc, uint16_t sct) { - struct spdk_nvme_cpl *cpl; + struct spdk_nvme_status cpl_status = { 0 }; const struct spdk_nvmf_registers *regs; + struct spdk_nvme_cpl *cpl; int err; assert(ctrlr != NULL); @@ -1123,11 +1124,17 @@ post_completion(struct nvmf_vfio_user_ctrlr *ctrlr, struct nvmf_vfio_user_cq *cq cpl->sqid = sqid; cpl->cid = cid; cpl->cdw0 = cdw0; - cpl->status.dnr = 0x0; - cpl->status.m = 0x0; - cpl->status.sct = sct; - cpl->status.sc = sc; - cpl->status.p = cq->phase; + + /* + * This is a bitfield: instead of setting the individual bits we need + * directly in cpl->status, which would cause a read-modify-write cycle, + * we'll avoid reading from the CPL altogether by filling in a local + * cpl_status variable, then writing the whole thing. + */ + cpl_status.sct = sct; + cpl_status.sc = sc; + cpl_status.p = cq->phase; + cpl->status = cpl_status; /* Ensure the Completion Queue Entry is visible. */ spdk_wmb();