[Accel-config] Re: [PATCH v1 2/3] accel-config/test: Add source code of operation CRC64
Dave Jiang <dave.jiang at intel.com> Thu, 28 Apr 2022 09:08:16 -0700
| Newsgroups | dev.linux.lists.accel-config |
|---|---|
| Message-ID | <[email protected]> |
On 4/28/2022 2:56 AM, Li Zhang wrote:
> Add source code of operation CRC64 into IAA test.
Do we want to convert all the IAX to IAA since this is new code?
>
> Signed-off-by: Li Zhang <li4.zhang(a)intel.com>
> Reviewed-by: Dave Jiang <dave.jiang(a)intel.com>
> ---
> test/iaa.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++-
> test/iaa.h | 7 ++-
> test/iaa_prep.c | 12 ++++
> test/iaa_test.c | 70 +++++++++++++++++++++
> 4 files changed, 244 insertions(+), 3 deletions(-)
>
> diff --git a/test/iaa.c b/test/iaa.c
> index 639d82f..f5c2f71 100644
> --- a/test/iaa.c
> +++ b/test/iaa.c
> @@ -16,6 +16,48 @@
> #include <accfg/idxd.h>
> #include "accel_test.h"
> #include "iaa.h"
> +#include "algorithms/iaa_crc64.h"
> +
> +static int init_crc64(struct task *tsk, int tflags, int opcode, unsigned long src1_xfer_size)
> +{
> + tsk->pattern = 0x98765432abcdef01;
> + tsk->opcode = opcode;
> + tsk->test_flags = tflags;
> + tsk->xfer_size = src1_xfer_size;
> +
> + tsk->src1 = malloc(src1_xfer_size);
> + if (!tsk->src1)
> + return -ENOMEM;
> + memset_pattern(tsk->src1, tsk->pattern, src1_xfer_size);
> + tsk->iax_crc64_poly = IAX_CRC64_POLYNOMIAL;
> +
> + return ACCTEST_STATUS_OK;
> +}
> +
> +/* this function is re-used by batch task */
> +int init_task(struct task *tsk, int tflags, int opcode, unsigned long src1_xfer_size)
> +{
> + int rc = 0;
> +
> + dbg("initilizing single task %#lx\n", tsk);
> +
> + /* allocate memory: src1*/
> + switch (opcode) {
> + case IAX_OPCODE_CRC64: /* intentionally empty */
> + rc = init_crc64(tsk, tflags, opcode, src1_xfer_size);
> + break;
> + }
> +
> + if (rc != ACCTEST_STATUS_OK) {
> + err("init: opcode %d data failed\n", opcode);
> + return rc;
> + }
> +
> + dbg("Mem allocated: s1 %#lx s2 %#lx d %#lx\n",
> + tsk->src1, tsk->src2, tsk->dst1);
> +
> + return ACCTEST_STATUS_OK;
> +}
>
> static int iax_wait_noop(struct acctest_context *ctx, struct task *tsk)
> {
> @@ -61,15 +103,127 @@ int iax_noop_multi_task_nodes(struct acctest_context *ctx)
> return ret;
> }
>
> +static int iax_wait_crc64(struct acctest_context *ctx, struct task *tsk)
> +{
> + struct completion_record *comp = tsk->comp;
> + int rc;
> +
> + rc = acctest_wait_on_desc_timeout(comp, ctx, ms_timeout);
> + if (rc < 0) {
> + err("crc64 desc timeout\n");
> + return ACCTEST_STATUS_TIMEOUT;
> + }
> +
> + return ACCTEST_STATUS_OK;
> +}
> +
> +int iax_crc64_multi_task_nodes(struct acctest_context *ctx)
> +{
> + struct task_node *tsk_node = ctx->multi_task_node;
> + int ret = ACCTEST_STATUS_OK;
> +
> + while (tsk_node) {
> + tsk_node->tsk->dflags |= (IDXD_OP_FLAG_CRAV | IDXD_OP_FLAG_RCR);
> + if ((tsk_node->tsk->test_flags & TEST_FLAGS_BOF) && ctx->bof)
> + tsk_node->tsk->dflags |= IDXD_OP_FLAG_BOF;
> +
> + iax_prep_crc64(tsk_node->tsk);
> + tsk_node = tsk_node->next;
> + }
> +
> + info("Submitted all crc64 jobs\n");
> + tsk_node = ctx->multi_task_node;
> + while (tsk_node) {
> + acctest_desc_submit(ctx, tsk_node->tsk->desc);
> + tsk_node = tsk_node->next;
> + }
> +
> + tsk_node = ctx->multi_task_node;
> + while (tsk_node) {
> + ret = iax_wait_crc64(ctx, tsk_node->tsk);
> + if (ret != ACCTEST_STATUS_OK)
> + info("Desc: %p failed with ret: %d\n",
> + tsk_node->tsk->desc, tsk_node->tsk->comp->status);
> + tsk_node = tsk_node->next;
> + }
> +
> + return ret;
> +}
> +
> /* mismatch_expected: expect mismatched buffer with success status 0x1 */
> int iax_task_result_verify(struct task *tsk, int mismatch_expected)
> {
> + int ret = ACCTEST_STATUS_OK;
> +
> info("verifying task result for %#lx\n", tsk);
>
> if (tsk->comp->status != IAX_COMP_SUCCESS)
> return tsk->comp->status;
>
> - info("test with op %d passed\n", tsk->opcode);
> + switch (tsk->opcode) {
> + case IAX_OPCODE_CRC64:
> + ret = task_result_verify_crc64(tsk, mismatch_expected);
> + }
>
> - return ACCTEST_STATUS_OK;
> + if (ret == ACCTEST_STATUS_OK)
> + info("test with op %d passed\n", tsk->opcode);
> +
> + return ret;
> +}
> +
> +int iax_task_result_verify_task_nodes(struct acctest_context *ctx, int mismatch_expected)
> +{
> + struct task_node *tsk_node = ctx->multi_task_node;
> + int ret = ACCTEST_STATUS_OK;
> +
> + while (tsk_node) {
> + ret = iax_task_result_verify(tsk_node->tsk, mismatch_expected);
> + if (ret != ACCTEST_STATUS_OK) {
> + err("memory result verify failed %d\n", ret);
> + return ret;
> + }
> + tsk_node = tsk_node->next;
> + }
> +
> + return ret;
> +}
> +
> +int task_result_verify_crc64(struct task *tsk, int mismatch_expected)
> +{
> + int rc;
> + uint64_t crc;
> +
> + if (mismatch_expected)
> + warn("invalid arg mismatch_expected for %d\n", tsk->opcode);
> +
> + if (tsk->iax_crc64_flags == IAX_CRC64_EXTRA_FLAGS_BIT_ORDER) {
> + crc = iax_calculate_crc64(tsk->iax_crc64_poly, tsk->src1,
> + tsk->xfer_size, 1, 0);
> + } else if (tsk->iax_crc64_flags == IAX_CRC64_EXTRA_FLAGS_INVERT_CRC) {
> + crc = iax_calculate_crc64(tsk->iax_crc64_poly, tsk->src1,
> + tsk->xfer_size, 0, 1);
> + } else {
> + err("Unsupported extra flags %#x\n", tsk->iax_crc64_flags);
> + return -EINVAL;
> + }
> +
> + rc = memcmp((void *)(&tsk->comp->crc64_result), (void *)(&crc), sizeof(uint64_t));
> +
> + if (!mismatch_expected) {
> + if (rc) {
> + err("crc64 mismatch, memcmp rc %d\n", rc);
> + err("expected crc=0x%llX, actual crc=0x%llX\n",
> + crc, tsk->comp->crc64_result);
> + return -ENXIO;
> + }
> + return ACCTEST_STATUS_OK;
> + }
> +
> + /* mismatch_expected */
> + if (rc) {
> + info("expected mismatch in crc 0x%llX\n", tsk->comp->crc64_result);
> + return ACCTEST_STATUS_OK;
> + }
> +
> + return -ENXIO;
> }
> diff --git a/test/iaa.h b/test/iaa.h
> index 0560d2c..e0bbad2 100644
> --- a/test/iaa.h
> +++ b/test/iaa.h
> @@ -7,10 +7,15 @@
> #include "accel_test.h"
> #include "accfg_test.h"
>
> -int iax_noop_multi_task_nodes(struct acctest_context *ctx);
> +int init_task(struct task *tsk, int tflags, int opcode, unsigned long src1_xfer_size);
>
> +int iax_noop_multi_task_nodes(struct acctest_context *ctx);
> +int iax_crc64_multi_task_nodes(struct acctest_context *ctx);
> void iax_prep_noop(struct task *tsk);
> +void iax_prep_crc64(struct task *tsk);
>
> int iax_task_result_verify(struct task *tsk, int mismatch_expected);
> +int iax_task_result_verify_task_nodes(struct acctest_context *ctx, int mismatch_expected);
> +int task_result_verify_crc64(struct task *tsk, int mismatch_expected);
>
> #endif
> diff --git a/test/iaa_prep.c b/test/iaa_prep.c
> index f7f8712..8522353 100644
> --- a/test/iaa_prep.c
> +++ b/test/iaa_prep.c
> @@ -19,3 +19,15 @@ void iax_prep_noop(struct task *tsk)
> tsk->desc->completion_addr = (uint64_t)(tsk->comp);
> tsk->comp->status = 0;
> }
> +
> +void iax_prep_crc64(struct task *tsk)
> +{
> + info("preparing descriptor for memcpy\n");
> +
> + acctest_prep_desc_common(tsk->desc, tsk->opcode, 0,
> + (uint64_t)(tsk->src1), tsk->xfer_size, tsk->dflags);
> + tsk->desc->completion_addr = (uint64_t)(tsk->comp);
> + tsk->desc->iax_crc64_flags = tsk->iax_crc64_flags;
> + tsk->desc->iax_crc64_poly = tsk->iax_crc64_poly;
> + tsk->comp->status = 0;
> +}
> diff --git a/test/iaa_test.c b/test/iaa_test.c
> index b398378..cd16949 100644
> --- a/test/iaa_test.c
> +++ b/test/iaa_test.c
> @@ -18,6 +18,7 @@ static void usage(void)
> "-f <test_flags> ; 0x1: block-on-fault\n"
> " ; 0x4: reserved\n"
> " ; 0x8: prefault buffers\n"
> + "-e <extra_flags> ; specified by each opcpde\n"
> "-o <opcode> ; opcode, same value as in IAX spec\n"
> "-d ; wq device such as iax1/wq1.0\n"
> "-n <number of descriptors> ;descriptor count to submit\n"
> @@ -74,6 +75,65 @@ static int test_noop(struct acctest_context *ctx, int tflags, int num_desc)
> return rc;
> }
>
> +static int test_crc64(struct acctest_context *ctx, size_t buf_size, int tflags,
> + int extra_flags, uint32_t opcode, int num_desc)
> +{
> + struct task_node *tsk_node;
> + int rc = ACCTEST_STATUS_OK;
> + int itr = num_desc, i = 0, range = 0;
> +
> + info("testcrc64: opcode %d len %#lx tflags %#x num_desc %ld extra_flags %#lx\n",
> + opcode, buf_size, tflags, num_desc, extra_flags);
> +
> + ctx->is_batch = 0;
> +
> + if (ctx->dedicated == ACCFG_WQ_SHARED)
> + range = ctx->threshold;
> + else
> + range = ctx->wq_size;
> +
> + while (itr > 0 && rc == ACCTEST_STATUS_OK) {
> + i = (itr < range) ? itr : range;
> + /* Allocate memory to all the task nodes, desc, completion record*/
> + rc = acctest_alloc_multiple_tasks(ctx, i);
> + if (rc != ACCTEST_STATUS_OK)
> + return rc;
> +
> + /* allocate memory to src and dest buffers and fill in the desc for all the nodes*/
> + tsk_node = ctx->multi_task_node;
> + while (tsk_node) {
> + tsk_node->tsk->iax_crc64_flags = extra_flags;
> +
> + rc = init_task(tsk_node->tsk, tflags, opcode, buf_size);
> + if (rc != ACCTEST_STATUS_OK)
> + return rc;
> +
> + tsk_node = tsk_node->next;
> + }
> +
> + switch (opcode) {
> + case IAX_OPCODE_CRC64:
> + rc = iax_crc64_multi_task_nodes(ctx);
> + if (rc != ACCTEST_STATUS_OK)
> + return rc;
> +
> + /* Verification of all the nodes*/
> + rc = iax_task_result_verify_task_nodes(ctx, 0);
> + if (rc != ACCTEST_STATUS_OK)
> + return rc;
> + break;
> + default:
> + err("Unsupported op %#x\n", opcode);
> + return -EINVAL;
> + }
> +
> + acctest_free_task(ctx);
> + itr = itr - range;
> + }
> +
> + return rc;
> +}
> +
> int main(int argc, char *argv[])
> {
> struct acctest_context *iax;
> @@ -81,6 +141,7 @@ int main(int argc, char *argv[])
> int wq_type = SHARED;
> unsigned long buf_size = IAX_TEST_SIZE;
> int tflags = TEST_FLAGS_BOF;
> + int extra_flags = 0;
> int opcode = IAX_OPCODE_NOOP;
> int opt;
> char dev_type[MAX_DEV_LEN];
> @@ -100,6 +161,9 @@ int main(int argc, char *argv[])
> case 'f':
> tflags = strtoul(optarg, NULL, 0);
> break;
> + case 'e':
> + extra_flags = strtoul(optarg, NULL, 0);
> + break;
> case 'o':
> opcode = strtoul(optarg, NULL, 0);
> break;
> @@ -149,6 +213,12 @@ int main(int argc, char *argv[])
> goto error;
> break;
>
> + case IAX_OPCODE_CRC64:
> + rc = test_crc64(iax, buf_size, tflags, extra_flags, opcode, num_desc);
> + if (rc != ACCTEST_STATUS_OK)
> + goto error;
> + break;
> +
> default:
> rc = -EINVAL;
> break;