From 9623a0402bc4e5612b45079ba5de4de03e7e6196 Mon Sep 17 00:00:00 2001 From: paul luse Date: Sun, 10 Jan 2021 10:51:49 -0500 Subject: [PATCH] idxd: perf optimization, remove reg read In the completion handler there's no need to do an MMIO read unless the completion record indicates there's an error. Signed-off-by: paul luse Change-Id: Ic4850d803a23413f9813da30ac6f1b611804f1b5 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5847 Tested-by: SPDK CI Jenkins Community-CI: Mellanox Build Bot Reviewed-by: Shuhei Matsumoto Reviewed-by: Ziye Yang Reviewed-by: Jim Harris --- lib/idxd/idxd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/idxd/idxd.c b/lib/idxd/idxd.c index ae304162b..f850d9bc3 100644 --- a/lib/idxd/idxd.c +++ b/lib/idxd/idxd.c @@ -37,6 +37,7 @@ #include "spdk/env.h" #include "spdk/util.h" #include "spdk/memory.h" +#include "spdk/likely.h" #include "spdk/log.h" #include "spdk_internal/idxd.h" @@ -1385,6 +1386,9 @@ _dump_error_reg(struct spdk_idxd_io_channel *chan) * needs to look at each array bit to know whether it should even check that completion record. That may be * faster though, need to experiment. */ +#define IDXD_COMPLETION(x) ((x) > (0) ? (1) : (0)) +#define IDXD_FAILURE(x) ((x) > (1) ? (1) : (0)) +#define IDXD_SW_ERROR(x) ((x) &= (0x1) ? (1) : (0)) void spdk_idxd_process_events(struct spdk_idxd_io_channel *chan) { @@ -1393,13 +1397,16 @@ spdk_idxd_process_events(struct spdk_idxd_io_channel *chan) int status = 0; TAILQ_FOREACH_SAFE(comp_ctx, &chan->comp_ctx_oustanding, link, tmp) { - if (comp_ctx->hw.status == 1) { + if (IDXD_COMPLETION(comp_ctx->hw.status)) { TAILQ_REMOVE(&chan->comp_ctx_oustanding, comp_ctx, link); - sw_error_0 = _idxd_read_8(chan->idxd, IDXD_SWERR_OFFSET); - if (sw_error_0 & 0x1) { - _dump_error_reg(chan); - status = -EINVAL; + + if (spdk_unlikely(IDXD_FAILURE(comp_ctx->hw.status))) { + sw_error_0 = _idxd_read_8(chan->idxd, IDXD_SWERR_OFFSET); + if (IDXD_SW_ERROR(sw_error_0)) { + _dump_error_reg(chan); + status = -EINVAL; + } } switch (comp_ctx->desc->opcode) {