From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 12F1DA0548; Fri, 24 Sep 2021 12:30:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AEAF241318; Fri, 24 Sep 2021 12:30:15 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 0935D41316 for ; Fri, 24 Sep 2021 12:30:13 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10116"; a="203541167" X-IronPort-AV: E=Sophos;i="5.85,319,1624345200"; d="scan'208";a="203541167" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2021 03:30:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.85,319,1624345200"; d="scan'208";a="436117797" Received: from silpixa00399126.ir.intel.com ([10.237.223.29]) by orsmga006.jf.intel.com with ESMTP; 24 Sep 2021 03:30:11 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: conor.walsh@intel.com, kevin.laatz@intel.com, fengchengwen@huawei.com, jerinj@marvell.com, Bruce Richardson Date: Fri, 24 Sep 2021 11:29:40 +0100 Message-Id: <20210924102942.2878051-8-bruce.richardson@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210924102942.2878051-1-bruce.richardson@intel.com> References: <20210826183301.333442-1-bruce.richardson@intel.com> <20210924102942.2878051-1-bruce.richardson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v6 07/13] app/test: add basic dmadev copy tests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" For each dmadev instance, perform some basic copy tests to validate that functionality. Signed-off-by: Bruce Richardson Reviewed-by: Kevin Laatz Reviewed-by: Conor Walsh --- app/test/test_dmadev.c | 175 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) diff --git a/app/test/test_dmadev.c b/app/test/test_dmadev.c index 9c19659b26..21600686e8 100644 --- a/app/test/test_dmadev.c +++ b/app/test/test_dmadev.c @@ -6,6 +6,10 @@ #include #include +#include +#include +#include +#include #include #include "test.h" @@ -15,6 +19,11 @@ extern int test_dma_api(uint16_t dev_id); #define ERR_RETURN(...) do { print_err(__func__, __LINE__, __VA_ARGS__); return -1; } while (0) +#define COPY_LEN 1024 + +static struct rte_mempool *pool; +static uint16_t id_count; + static void __rte_format_printf(3, 4) print_err(const char *func, int lineno, const char *format, ...) @@ -27,10 +36,155 @@ print_err(const char *func, int lineno, const char *format, ...) va_end(ap); } +static int +runtest(const char *printable, int (*test_fn)(int dev_id, uint16_t vchan), int iterations, + int dev_id, uint16_t vchan, bool check_err_stats) +{ + struct rte_dma_stats stats; + int i; + + rte_dma_stats_reset(dev_id, vchan); + printf("DMA Dev %d: Running %s Tests %s\n", dev_id, printable, + check_err_stats ? " " : "(errors expected)"); + for (i = 0; i < iterations; i++) { + if (test_fn(dev_id, vchan) < 0) + return -1; + + rte_dma_stats_get(dev_id, 0, &stats); + printf("Ops submitted: %"PRIu64"\t", stats.submitted); + printf("Ops completed: %"PRIu64"\t", stats.completed); + printf("Errors: %"PRIu64"\r", stats.errors); + + if (stats.completed != stats.submitted) + ERR_RETURN("\nError, not all submitted jobs are reported as completed\n"); + if (check_err_stats && stats.errors != 0) + ERR_RETURN("\nErrors reported during op processing, aborting tests\n"); + } + printf("\n"); + return 0; +} + +static void +await_hw(int dev_id, uint16_t vchan) +{ + enum rte_dma_vchan_status st; + + if (rte_dma_vchan_status(dev_id, vchan, &st) < 0) { + /* for drivers that don't support this op, just sleep for 1 millisecond */ + rte_delay_us_sleep(1000); + return; + } + + /* for those that do, *max* end time is one second from now, but all should be faster */ + const uint64_t end_cycles = rte_get_timer_cycles() + rte_get_timer_hz(); + while (st == RTE_DMA_VCHAN_ACTIVE && rte_get_timer_cycles() < end_cycles) { + rte_pause(); + rte_dma_vchan_status(dev_id, vchan, &st); + } +} + +static int +test_enqueue_copies(int dev_id, uint16_t vchan) +{ + unsigned int i; + uint16_t id; + + /* test doing a single copy */ + do { + struct rte_mbuf *src, *dst; + char *src_data, *dst_data; + + src = rte_pktmbuf_alloc(pool); + dst = rte_pktmbuf_alloc(pool); + src_data = rte_pktmbuf_mtod(src, char *); + dst_data = rte_pktmbuf_mtod(dst, char *); + + for (i = 0; i < COPY_LEN; i++) + src_data[i] = rte_rand() & 0xFF; + + id = rte_dma_copy(dev_id, vchan, rte_pktmbuf_iova(src), rte_pktmbuf_iova(dst), + COPY_LEN, RTE_DMA_OP_FLAG_SUBMIT); + if (id != id_count) + ERR_RETURN("Error with rte_dma_copy, got %u, expected %u\n", + id, id_count); + + /* give time for copy to finish, then check it was done */ + await_hw(dev_id, vchan); + + for (i = 0; i < COPY_LEN; i++) + if (dst_data[i] != src_data[i]) + ERR_RETURN("Data mismatch at char %u [Got %02x not %02x]\n", i, + dst_data[i], src_data[i]); + + /* now check completion works */ + if (rte_dma_completed(dev_id, vchan, 1, &id, NULL) != 1) + ERR_RETURN("Error with rte_dma_completed\n"); + + if (id != id_count) + ERR_RETURN("Error:incorrect job id received, %u [expected %u]\n", + id, id_count); + + rte_pktmbuf_free(src); + rte_pktmbuf_free(dst); + + /* now check completion returns nothing more */ + if (rte_dma_completed(dev_id, 0, 1, NULL, NULL) != 0) + ERR_RETURN("Error with rte_dma_completed in empty check\n"); + + id_count++; + + } while (0); + + /* test doing a multiple single copies */ + do { + const uint16_t max_ops = 4; + struct rte_mbuf *src, *dst; + char *src_data, *dst_data; + uint16_t count; + + src = rte_pktmbuf_alloc(pool); + dst = rte_pktmbuf_alloc(pool); + src_data = rte_pktmbuf_mtod(src, char *); + dst_data = rte_pktmbuf_mtod(dst, char *); + + for (i = 0; i < COPY_LEN; i++) + src_data[i] = rte_rand() & 0xFF; + + /* perform the same copy times */ + for (i = 0; i < max_ops; i++) + if (rte_dma_copy(dev_id, vchan, + rte_pktmbuf_iova(src), + rte_pktmbuf_iova(dst), + COPY_LEN, RTE_DMA_OP_FLAG_SUBMIT) != id_count++) + ERR_RETURN("Error with rte_dma_copy\n"); + + await_hw(dev_id, vchan); + + count = rte_dma_completed(dev_id, vchan, max_ops * 2, &id, NULL); + if (count != max_ops) + ERR_RETURN("Error with rte_dma_completed, got %u not %u\n", + count, max_ops); + + if (id != id_count - 1) + ERR_RETURN("Error, incorrect job id returned: got %u not %u\n", + id, id_count - 1); + + for (i = 0; i < COPY_LEN; i++) + if (dst_data[i] != src_data[i]) + ERR_RETURN("Data mismatch at char %u\n", i); + + rte_pktmbuf_free(src); + rte_pktmbuf_free(dst); + } while (0); + + return 0; +} + static int test_dmadev_instance(uint16_t dev_id) { #define TEST_RINGSIZE 512 +#define CHECK_ERRS true struct rte_dma_stats stats; struct rte_dma_info info; const struct rte_dma_conf conf = { .nb_vchans = 1}; @@ -67,10 +221,31 @@ test_dmadev_instance(uint16_t dev_id) ERR_RETURN("Error device stats are not all zero: completed = %"PRIu64", " "submitted = %"PRIu64", errors = %"PRIu64"\n", stats.completed, stats.submitted, stats.errors); + id_count = 0; + + /* create a mempool for running tests */ + pool = rte_pktmbuf_pool_create("TEST_DMADEV_POOL", + TEST_RINGSIZE * 2, /* n == num elements */ + 32, /* cache size */ + 0, /* priv size */ + 2048, /* data room size */ + info.numa_node); + if (pool == NULL) + ERR_RETURN("Error with mempool creation\n"); + /* run the test cases, use many iterations to ensure UINT16_MAX id wraparound */ + if (runtest("copy", test_enqueue_copies, 640, dev_id, vchan, CHECK_ERRS) < 0) + goto err; + + rte_mempool_free(pool); rte_dma_stop(dev_id); rte_dma_stats_reset(dev_id, vchan); return 0; + +err: + rte_mempool_free(pool); + rte_dma_stop(dev_id); + return -1; } static int -- 2.30.2