From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 190E5A0547;
	Fri, 10 Sep 2021 19:27:58 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 1AE3241130;
	Fri, 10 Sep 2021 19:27:49 +0200 (CEST)
Received: from mga02.intel.com (mga02.intel.com [134.134.136.20])
 by mails.dpdk.org (Postfix) with ESMTP id 9E9EB410F5
 for <dev@dpdk.org>; Fri, 10 Sep 2021 19:27:45 +0200 (CEST)
X-IronPort-AV: E=McAfee;i="6200,9189,10103"; a="208363255"
X-IronPort-AV: E=Sophos;i="5.85,283,1624345200"; d="scan'208";a="208363255"
Received: from fmsmga006.fm.intel.com ([10.253.24.20])
 by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 10 Sep 2021 10:27:45 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.85,283,1624345200"; d="scan'208";a="694959577"
Received: from silpixa00401122.ir.intel.com ([10.55.128.10])
 by fmsmga006.fm.intel.com with ESMTP; 10 Sep 2021 10:27:43 -0700
From: Kevin Laatz <kevin.laatz@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, fengchengwen@huawei.com, conor.walsh@intel.com,
 Konstantin Ananyev <konstantin.ananyev@intel.com>
Date: Fri, 10 Sep 2021 17:27:33 +0000
Message-Id: <20210910172737.2561156-3-kevin.laatz@intel.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20210910172737.2561156-1-kevin.laatz@intel.com>
References: <20210910172737.2561156-1-kevin.laatz@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Subject: [dpdk-dev] [PATCH 2/6] examples/ioat: add cmd-line option to
 control DMA batch size
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

From: Konstantin Ananyev <konstantin.ananyev@intel.com>

Add a commandline options to control the HW copy batch size in the
application.

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
 examples/ioat/ioatfwd.c | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/examples/ioat/ioatfwd.c b/examples/ioat/ioatfwd.c
index 617c8c3dfb..19d5116465 100644
--- a/examples/ioat/ioatfwd.c
+++ b/examples/ioat/ioatfwd.c
@@ -24,6 +24,7 @@
 #define CMD_LINE_OPT_NB_QUEUE "nb-queue"
 #define CMD_LINE_OPT_COPY_TYPE "copy-type"
 #define CMD_LINE_OPT_RING_SIZE "ring-size"
+#define CMD_LINE_OPT_BATCH_SIZE "dma-batch-size"
 
 /* configurable number of RX/TX ring descriptors */
 #define RX_DEFAULT_RINGSIZE 1024
@@ -102,6 +103,8 @@ static uint16_t nb_txd = TX_DEFAULT_RINGSIZE;
 
 static volatile bool force_quit;
 
+static uint32_t ioat_batch_sz = MAX_PKT_BURST;
+
 /* ethernet addresses of ports */
 static struct rte_ether_addr ioat_ports_eth_addr[RTE_MAX_ETHPORTS];
 
@@ -374,15 +377,25 @@ ioat_enqueue_packets(struct rte_mbuf *pkts[], struct rte_mbuf *pkts_copy[],
 
 static inline uint32_t
 ioat_enqueue(struct rte_mbuf *pkts[], struct rte_mbuf *pkts_copy[],
-	uint32_t num, uint16_t dev_id)
+		uint32_t num, uint32_t step, uint16_t dev_id)
 {
-	uint32_t n;
+	uint32_t i, k, m, n;
+
+	k = 0;
+	for (i = 0; i < num; i += m) {
+
+		m = RTE_MIN(step, num - i);
+		n = ioat_enqueue_packets(pkts + i, pkts_copy + i, m, dev_id);
+		k += n;
+		if (n > 0)
+			rte_ioat_perform_ops(dev_id);
 
-	n = ioat_enqueue_packets(pkts, pkts_copy, num, dev_id);
-	if (n > 0)
-		rte_ioat_perform_ops(dev_id);
+		/* don't try to enqueue more if HW queue is full */
+		if (n != m)
+			break;
+	}
 
-	return n;
+	return k;
 }
 
 static inline uint32_t
@@ -439,7 +452,7 @@ ioat_rx_port(struct rxtx_port_config *rx_config)
 
 			/* enqueue packets for  hardware copy */
 			nb_enq = ioat_enqueue(pkts_burst, pkts_burst_copy,
-				nb_rx, rx_config->ioat_ids[i]);
+				nb_rx, ioat_batch_sz, rx_config->ioat_ids[i]);
 
 			/* free any not enqueued packets. */
 			rte_mempool_put_bulk(ioat_pktmbuf_pool,
@@ -590,6 +603,7 @@ static void
 ioat_usage(const char *prgname)
 {
 	printf("%s [EAL options] -- -p PORTMASK [-q NQ]\n"
+		"  -b --dma-batch-size: number of requests per DMA batch\n"
 		"  -p --portmask: hexadecimal bitmask of ports to configure\n"
 		"  -q NQ: number of RX queues per port (default is 1)\n"
 		"  --[no-]mac-updating: Enable or disable MAC addresses updating (enabled by default)\n"
@@ -631,9 +645,10 @@ static int
 ioat_parse_args(int argc, char **argv, unsigned int nb_ports)
 {
 	static const char short_options[] =
+		"b:"  /* dma batch size */
+		"c:"  /* copy type (sw|hw) */
 		"p:"  /* portmask */
 		"q:"  /* number of RX queues per port */
-		"c:"  /* copy type (sw|hw) */
 		"s:"  /* ring size */
 		;
 
@@ -644,6 +659,7 @@ ioat_parse_args(int argc, char **argv, unsigned int nb_ports)
 		{CMD_LINE_OPT_NB_QUEUE, required_argument, NULL, 'q'},
 		{CMD_LINE_OPT_COPY_TYPE, required_argument, NULL, 'c'},
 		{CMD_LINE_OPT_RING_SIZE, required_argument, NULL, 's'},
+		{CMD_LINE_OPT_BATCH_SIZE, required_argument, NULL, 'b'},
 		{NULL, 0, 0, 0}
 	};
 
@@ -660,6 +676,14 @@ ioat_parse_args(int argc, char **argv, unsigned int nb_ports)
 			lgopts, &option_index)) != EOF) {
 
 		switch (opt) {
+		case 'b':
+			ioat_batch_sz = atoi(optarg);
+			if (ioat_batch_sz > MAX_PKT_BURST) {
+				printf("Invalid dma batch size, %s.\n", optarg);
+				ioat_usage(prgname);
+				return -1;
+			}
+			break;
 		/* portmask */
 		case 'p':
 			ioat_enabled_port_mask = ioat_parse_portmask(optarg);
-- 
2.30.2