DPDK patches and discussions
 help / color / mirror / Atom feed
From: Alexander Kozyrev <akozyrev@nvidia.com>
To: <dev@dpdk.org>
Cc: <orika@nvidia.com>, <thomas@monjalon.net>,
	<ivan.malov@oktetlabs.ru>, <andrew.rybchenko@oktetlabs.ru>,
	<ferruh.yigit@intel.com>, <mohammad.abdul.awal@intel.com>,
	<qi.z.zhang@intel.com>, <jerinj@marvell.com>,
	<ajit.khaparde@broadcom.com>
Subject: [PATCH 08/10] app/testpmd: implement rte flow queue drain
Date: Tue, 18 Jan 2022 07:08:00 +0200	[thread overview]
Message-ID: <20220118050802.3915187-9-akozyrev@nvidia.com> (raw)
In-Reply-To: <20220118050802.3915187-6-akozyrev@nvidia.com>

Add testpmd support for the rte_flow_q_drain API.
Provide the command line interface for the queue draining.
Usage example: flow queue 0 drain 0

Signed-off-by: Alexander Kozyrev <akozyrev@nvidia.com>
---
 app/test-pmd/cmdline_flow.c                 | 56 ++++++++++++++++++++-
 app/test-pmd/config.c                       | 28 +++++++++++
 app/test-pmd/testpmd.h                      |  1 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 21 ++++++++
 4 files changed, 105 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 6a8e6fc683..e94c01cf75 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -93,6 +93,7 @@ enum index {
 	TUNNEL,
 	FLEX,
 	QUEUE,
+	DRAIN,
 
 	/* Flex arguments */
 	FLEX_ITEM_INIT,
@@ -131,6 +132,9 @@ enum index {
 	QUEUE_DESTROY_ID,
 	QUEUE_DESTROY_DRAIN,
 
+	/* Drain arguments. */
+	DRAIN_QUEUE,
+
 	/* Table arguments. */
 	TABLE_CREATE,
 	TABLE_DESTROY,
@@ -2155,6 +2159,9 @@ static int parse_qo(struct context *, const struct token *,
 static int parse_qo_destroy(struct context *, const struct token *,
 			    const char *, unsigned int,
 			    void *, unsigned int);
+static int parse_drain(struct context *, const struct token *,
+		       const char *, unsigned int,
+		       void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -2432,7 +2439,8 @@ static const struct token token_list[] = {
 			      ISOLATE,
 			      TUNNEL,
 			      FLEX,
-			      QUEUE)),
+			      QUEUE,
+			      DRAIN)),
 		.call = parse_init,
 	},
 	/* Top-level command. */
@@ -2767,6 +2775,21 @@ static const struct token token_list[] = {
 		.call = parse_qo_destroy,
 	},
 	/* Top-level command. */
+	[DRAIN] = {
+		.name = "drain",
+		.help = "drain a flow queue",
+		.next = NEXT(NEXT_ENTRY(DRAIN_QUEUE), NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_drain,
+	},
+	/* Sub-level commands. */
+	[DRAIN_QUEUE] = {
+		.name = "queue",
+		.help = "specify queue id",
+		.next = NEXT(NEXT_ENTRY(END), NEXT_ENTRY(COMMON_QUEUE_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, queue)),
+	},
+	/* Top-level command. */
 	[INDIRECT_ACTION] = {
 		.name = "indirect_action",
 		.type = "{command} {port_id} [{arg} [...]]",
@@ -8385,6 +8408,34 @@ parse_qo_destroy(struct context *ctx, const struct token *token,
 	}
 }
 
+/** Parse tokens for drain queue command. */
+static int
+parse_drain(struct context *ctx, const struct token *token,
+	    const char *str, unsigned int len,
+	    void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != DRAIN)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.vc.data = (uint8_t *)out + size;
+	}
+	return len;
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -9749,6 +9800,9 @@ cmd_flow_parsed(const struct buffer *in)
 					in->args.destroy.rule_n,
 					in->args.destroy.rule);
 		break;
+	case DRAIN:
+		port_queue_flow_drain(in->port, in->queue);
+		break;
 	case INDIRECT_ACTION_CREATE:
 		port_action_handle_create(
 				in->port, in->args.vc.attr.group,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 31164d6bf6..c6469dd06f 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -2564,6 +2564,34 @@ port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
 	return ret;
 }
 
+/** Drain all the queue operations down the queue. */
+int
+port_queue_flow_drain(portid_t port_id, queueid_t queue_id)
+{
+	struct rte_port *port;
+	struct rte_flow_error error;
+	int ret = 0;
+
+	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+	    port_id == (portid_t)RTE_PORT_ALL)
+		return -EINVAL;
+	port = &ports[port_id];
+
+	if (queue_id >= port->queue_nb) {
+		printf("Queue #%u is invalid\n", queue_id);
+		return -EINVAL;
+	}
+
+	memset(&error, 0x55, sizeof(error));
+	ret = rte_flow_q_drain(port_id, queue_id, &error);
+	if (ret < 0) {
+		printf("Failed to drain queue\n");
+		return -EINVAL;
+	}
+	printf("Queue #%u drained\n", queue_id);
+	return ret;
+}
+
 /** Create flow rule. */
 int
 port_flow_create(portid_t port_id,
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 99845b9e2f..bf4597e7ba 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -934,6 +934,7 @@ int port_queue_flow_create(portid_t port_id, queueid_t queue_id,
 			   const struct rte_flow_action *actions);
 int port_queue_flow_destroy(portid_t port_id, queueid_t queue_id,
 			    bool drain, uint32_t n, const uint32_t *rule);
+int port_queue_flow_drain(portid_t port_id, queueid_t queue_id);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index eb9dff7221..2ff4e4aef1 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3368,6 +3368,10 @@ following sections.
    flow queue {port_id} destroy {queue_id}
        [drain {boolean}] rule {rule_id} [...]
 
+- Drain a queue::
+
+   flow drain {port_id} queue {queue_id}
+
 - Create a flow rule::
 
    flow create {port_id}
@@ -3561,6 +3565,23 @@ The usual error message is shown when a table cannot be destroyed::
 
    Caught error type [...] ([...]): [...]
 
+Draining a flow queue
+~~~~~~~~~~~~~~~~~~~~~
+
+``flow drain`` drains the specific queue to push all the
+outstanding queued operations to the underlying device immediately.
+It is bound to ``rte_flow_q_drain()``::
+
+   flow drain {port_id} queue {queue_id}
+
+If successful, it will show::
+
+   Queue #[...] drained
+
+The usual error message is shown when a queue cannot be drained::
+
+   Caught error type [...] ([...]): [...]
+
 Creating a tunnel stub for offload
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.18.2


  parent reply	other threads:[~2022-01-18  5:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-18  5:07 [PATCH 05/10] app/testpmd: implement rte flow item/action template Alexander Kozyrev
2022-01-18  5:07 ` [PATCH 06/10] app/testpmd: implement rte flow table Alexander Kozyrev
2022-01-18  5:07 ` [PATCH 07/10] app/testpmd: implement rte flow queue create flow Alexander Kozyrev
2022-01-18  5:08 ` Alexander Kozyrev [this message]
2022-01-18  5:08 ` [PATCH 09/10] app/testpmd: implement rte flow queue dequeue Alexander Kozyrev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220118050802.3915187-9-akozyrev@nvidia.com \
    --to=akozyrev@nvidia.com \
    --cc=ajit.khaparde@broadcom.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=ivan.malov@oktetlabs.ru \
    --cc=jerinj@marvell.com \
    --cc=mohammad.abdul.awal@intel.com \
    --cc=orika@nvidia.com \
    --cc=qi.z.zhang@intel.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).