From 863200c7d48f69870bb537996e5562a65fd1f589 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 12 Apr 2022 14:49:36 -0700 Subject: [PATCH] idxd: Rearrange logic in spdk_idxd_process_events If we don't find a completion, break out of the loop at the top. This removes a level of indentation but most importantly makes it very clear that we only remove elements from ops_outstanding from the front of the list. Signed-off-by: Ben Walker Change-Id: I5e8784a5af5449c14ff7015bc8e6062e6aee6b4e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12257 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Tomasz Zawadzki Reviewed-by: Dong Yi Reviewed-by: Paul Luse --- lib/idxd/idxd.c | 89 ++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 45 deletions(-) diff --git a/lib/idxd/idxd.c b/lib/idxd/idxd.c index 779d1cbcc..9d8f94d8f 100644 --- a/lib/idxd/idxd.c +++ b/lib/idxd/idxd.c @@ -1267,51 +1267,7 @@ spdk_idxd_process_events(struct spdk_idxd_io_channel *chan) assert(chan != NULL); TAILQ_FOREACH_SAFE(op, &chan->ops_outstanding, link, tmp) { - if (IDXD_COMPLETION(op->hw.status)) { - - TAILQ_REMOVE(&chan->ops_outstanding, op, link); - rc++; - - if (spdk_unlikely(IDXD_FAILURE(op->hw.status))) { - status = -EINVAL; - _dump_sw_error_reg(chan); - } - - switch (op->desc->opcode) { - case IDXD_OPCODE_BATCH: - SPDK_DEBUGLOG(idxd, "Complete batch %p\n", op->batch); - break; - case IDXD_OPCODE_CRC32C_GEN: - case IDXD_OPCODE_COPY_CRC: - if (spdk_likely(status == 0 && op->crc_dst != NULL)) { - *op->crc_dst = op->hw.crc32c_val; - *op->crc_dst ^= ~0; - } - break; - case IDXD_OPCODE_COMPARE: - if (spdk_likely(status == 0)) { - status = op->hw.result; - } - break; - } - - cb_fn = op->cb_fn; - cb_arg = op->cb_arg; - op->hw.status = 0; - if (op->desc->opcode == IDXD_OPCODE_BATCH) { - _free_batch(op->batch, chan); - TAILQ_INSERT_HEAD(&chan->ops_pool, op, link); - } else if (!op->batch) { - TAILQ_INSERT_HEAD(&chan->ops_pool, op, link); - } - - if (cb_fn) { - cb_fn(cb_arg, status); - } - - /* reset the status */ - status = 0; - } else { + if (!IDXD_COMPLETION(op->hw.status)) { /* * oldest locations are at the head of the list so if * we've polled a location that hasn't completed, bail @@ -1319,6 +1275,49 @@ spdk_idxd_process_events(struct spdk_idxd_io_channel *chan) */ break; } + + TAILQ_REMOVE(&chan->ops_outstanding, op, link); + rc++; + + if (spdk_unlikely(IDXD_FAILURE(op->hw.status))) { + status = -EINVAL; + _dump_sw_error_reg(chan); + } + + switch (op->desc->opcode) { + case IDXD_OPCODE_BATCH: + SPDK_DEBUGLOG(idxd, "Complete batch %p\n", op->batch); + break; + case IDXD_OPCODE_CRC32C_GEN: + case IDXD_OPCODE_COPY_CRC: + if (spdk_likely(status == 0 && op->crc_dst != NULL)) { + *op->crc_dst = op->hw.crc32c_val; + *op->crc_dst ^= ~0; + } + break; + case IDXD_OPCODE_COMPARE: + if (spdk_likely(status == 0)) { + status = op->hw.result; + } + break; + } + + cb_fn = op->cb_fn; + cb_arg = op->cb_arg; + op->hw.status = 0; + if (op->desc->opcode == IDXD_OPCODE_BATCH) { + _free_batch(op->batch, chan); + TAILQ_INSERT_HEAD(&chan->ops_pool, op, link); + } else if (!op->batch) { + TAILQ_INSERT_HEAD(&chan->ops_pool, op, link); + } + + if (cb_fn) { + cb_fn(cb_arg, status); + } + + /* reset the status */ + status = 0; } /* Submit any built-up batch */