diff mbox series

[v3,06/23] net/softnic: add traffic manager object

Message ID 20180627163123.135686-7-jasvinder.singh@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Cristian Dumitrescu
Headers show
Series [v3,01/23] net/softnic: restructuring | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Singh, Jasvinder June 27, 2018, 4:31 p.m. UTC
Add traffic manager(tmgr) object to the softnic.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
 drivers/net/softnic/rte_eth_softnic.c           |  70 +++++++++++++++-
 drivers/net/softnic/rte_eth_softnic.h           |  11 ++-
 drivers/net/softnic/rte_eth_softnic_internals.h |  39 +++++++--
 drivers/net/softnic/rte_eth_softnic_tm.c        | 103 +++++++++++++++++++++---
 4 files changed, 201 insertions(+), 22 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c
index 6dd8463..d7580f6 100644
--- a/drivers/net/softnic/rte_eth_softnic.c
+++ b/drivers/net/softnic/rte_eth_softnic.c
@@ -20,10 +20,23 @@ 
 
 #define PMD_PARAM_FIRMWARE                                 "firmware"
 #define PMD_PARAM_CPU_ID                                   "cpu_id"
+#define PMD_PARAM_SCRIPT                                   "script"
+#define PMD_PARAM_CONN_PORT                                "conn_port"
+#define PMD_PARAM_CPU_ID                                   "cpu_id"
+#define PMD_PARAM_TM_N_QUEUES                              "tm_n_queues"
+#define PMD_PARAM_TM_QSIZE0                                "tm_qsize0"
+#define PMD_PARAM_TM_QSIZE1                                "tm_qsize1"
+#define PMD_PARAM_TM_QSIZE2                                "tm_qsize2"
+#define PMD_PARAM_TM_QSIZE3                                "tm_qsize3"
 
 static const char *pmd_valid_args[] = {
 	PMD_PARAM_FIRMWARE,
 	PMD_PARAM_CPU_ID,
+	PMD_PARAM_TM_N_QUEUES,
+	PMD_PARAM_TM_QSIZE0,
+	PMD_PARAM_TM_QSIZE1,
+	PMD_PARAM_TM_QSIZE2,
+	PMD_PARAM_TM_QSIZE3,
 	NULL
 };
 
@@ -154,7 +167,7 @@  pmd_link_update(struct rte_eth_dev *dev __rte_unused,
 static int
 pmd_tm_ops_get(struct rte_eth_dev *dev __rte_unused, void *arg)
 {
-	*(const struct rte_tm_ops **)arg = NULL;
+	*(const struct rte_tm_ops **)arg = &pmd_tm_ops;
 
 	return 0;
 }
@@ -225,6 +238,8 @@  pmd_init(struct pmd_params *params)
 	mempool_init(p);
 	swq_init(p);
 	link_init(p);
+	tm_init(p);
+	tmgr_init(p);
 	tap_init(p);
 
 	return p;
@@ -237,6 +252,8 @@  pmd_free(struct pmd_internals *p)
 		return;
 
 	tap_free(p);
+	tmgr_free(p);
+	tm_free(p);
 	link_free(p);
 	swq_free(p);
 	mempool_free(p);
@@ -322,6 +339,11 @@  pmd_parse_args(struct pmd_params *p, const char *params)
 	memset(p, 0, sizeof(*p));
 	p->firmware = SOFTNIC_FIRMWARE;
 	p->cpu_id = SOFTNIC_CPU_ID;
+	p->tm.n_queues = SOFTNIC_TM_N_QUEUES;
+	p->tm.qsize[0] = SOFTNIC_TM_QUEUE_SIZE;
+	p->tm.qsize[1] = SOFTNIC_TM_QUEUE_SIZE;
+	p->tm.qsize[2] = SOFTNIC_TM_QUEUE_SIZE;
+	p->tm.qsize[3] = SOFTNIC_TM_QUEUE_SIZE;
 
 	/* Firmware script (optional) */
 	if (rte_kvargs_count(kvlist, PMD_PARAM_FIRMWARE) == 1) {
@@ -339,6 +361,43 @@  pmd_parse_args(struct pmd_params *p, const char *params)
 			goto out_free;
 	}
 
+	/* TM number of queues (optional) */
+	if (rte_kvargs_count(kvlist, PMD_PARAM_TM_N_QUEUES) == 1) {
+		ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_N_QUEUES,
+			&get_uint32, &p->tm.n_queues);
+		if (ret < 0)
+			goto out_free;
+	}
+
+	/* TM queue size 0 .. 3 (optional) */
+	if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE0) == 1) {
+		ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE0,
+			&get_uint32, &p->tm.qsize[0]);
+		if (ret < 0)
+			goto out_free;
+	}
+
+	if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE1) == 1) {
+		ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE1,
+			&get_uint32, &p->tm.qsize[1]);
+		if (ret < 0)
+			goto out_free;
+	}
+
+	if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE2) == 1) {
+		ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE2,
+			&get_uint32, &p->tm.qsize[2]);
+		if (ret < 0)
+			goto out_free;
+	}
+
+	if (rte_kvargs_count(kvlist, PMD_PARAM_TM_QSIZE3) == 1) {
+		ret = rte_kvargs_process(kvlist, PMD_PARAM_TM_QSIZE3,
+			&get_uint32, &p->tm.qsize[3]);
+		if (ret < 0)
+			goto out_free;
+	}
+
 out_free:
 	rte_kvargs_free(kvlist);
 	return ret;
@@ -417,9 +476,16 @@  static struct rte_vdev_driver pmd_softnic_drv = {
 RTE_PMD_REGISTER_VDEV(net_softnic, pmd_softnic_drv);
 RTE_PMD_REGISTER_PARAM_STRING(net_softnic,
 	PMD_PARAM_FIRMWARE "=<string> "
-	PMD_PARAM_CPU_ID "=<uint32>");
+	PMD_PARAM_CPU_ID "=<uint32> "
+	PMD_PARAM_TM_N_QUEUES "=<uint32> "
+	PMD_PARAM_TM_QSIZE0 "=<uint32> "
+	PMD_PARAM_TM_QSIZE1 "=<uint32> "
+	PMD_PARAM_TM_QSIZE2 "=<uint32> "
+	PMD_PARAM_TM_QSIZE3 "=<uint32>"
+);
 
 RTE_INIT(pmd_softnic_init_log);
+
 static void
 pmd_softnic_init_log(void)
 {
diff --git a/drivers/net/softnic/rte_eth_softnic.h b/drivers/net/softnic/rte_eth_softnic.h
index fb1d170..98b0828 100644
--- a/drivers/net/softnic/rte_eth_softnic.h
+++ b/drivers/net/softnic/rte_eth_softnic.h
@@ -21,6 +21,16 @@  extern "C" {
 #define SOFTNIC_CPU_ID                                     0
 #endif
 
+/** Traffic Manager: Number of scheduler queues. */
+#ifndef SOFTNIC_TM_N_QUEUES
+#define SOFTNIC_TM_N_QUEUES                                (64 * 1024)
+#endif
+
+/** Traffic Manager: Scheduler queue size (per traffic class). */
+#ifndef SOFTNIC_TM_QUEUE_SIZE
+#define SOFTNIC_TM_QUEUE_SIZE                              64
+#endif
+
 /**
  * Soft NIC run.
  *
@@ -29,7 +39,6 @@  extern "C" {
  * @return
  *    Zero on success, error code otherwise.
  */
-
 int
 rte_pmd_softnic_run(uint16_t port_id);
 
diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h
index 6b7004c..e724cba 100644
--- a/drivers/net/softnic/rte_eth_softnic_internals.h
+++ b/drivers/net/softnic/rte_eth_softnic_internals.h
@@ -89,7 +89,7 @@  struct link {
 TAILQ_HEAD(link_list, link);
 
 /**
- * Traffic Management (TM) Internals
+ * TMGR
  */
 
 #ifndef TM_MAX_SUBPORTS
@@ -200,6 +200,14 @@  struct tm_internals {
 	struct rte_sched_port *sched;
 };
 
+struct tmgr_port {
+	TAILQ_ENTRY(tmgr_port) node;
+	char name[NAME_SIZE];
+	struct rte_sched_port *s;
+};
+
+TAILQ_HEAD(tmgr_port_list, tmgr_port);
+
 /**
  * TAP
  */
@@ -218,7 +226,6 @@  struct pmd_internals {
 	/** Params */
 	struct pmd_params params;
 
-	/** Soft device */
 	struct {
 		struct tm_internals tm; /**< Traffic Management */
 	} soft;
@@ -226,6 +233,7 @@  struct pmd_internals {
 	struct mempool_list mempool_list;
 	struct swq_list swq_list;
 	struct link_list link_list;
+	struct tmgr_port_list tmgr_port_list;
 	struct tap_list tap_list;
 };
 
@@ -284,12 +292,25 @@  link_create(struct pmd_internals *p,
 	struct link_params *params);
 
 /**
- * Traffic Management (TM) Operation
+ * TMGR
  */
-extern const struct rte_tm_ops pmd_tm_ops;
+int
+tmgr_init(struct pmd_internals *p);
+
+void
+tmgr_free(struct pmd_internals *p);
+
+struct tmgr_port *
+tmgr_port_find(struct pmd_internals *p,
+	const char *name);
+
+struct tmgr_port *
+tmgr_port_create(struct pmd_internals *p,
+	const char *name,
+	struct rte_sched_port *sched);
 
 int
-tm_init(struct pmd_internals *p, struct pmd_params *params, int numa_node);
+tm_init(struct pmd_internals *p);
 
 void
 tm_free(struct pmd_internals *p);
@@ -301,11 +322,15 @@  void
 tm_stop(struct pmd_internals *p);
 
 static inline int
-tm_used(struct rte_eth_dev *dev __rte_unused)
+tm_used(struct rte_eth_dev *dev)
 {
-	return 0;
+	struct pmd_internals *p = dev->data->dev_private;
+
+	return p->soft.tm.h.n_tm_nodes[TM_NODE_LEVEL_PORT];
 }
 
+extern const struct rte_tm_ops pmd_tm_ops;
+
 /**
  * TAP
  */
diff --git a/drivers/net/softnic/rte_eth_softnic_tm.c b/drivers/net/softnic/rte_eth_softnic_tm.c
index 8da8310..dd7ab3a 100644
--- a/drivers/net/softnic/rte_eth_softnic_tm.c
+++ b/drivers/net/softnic/rte_eth_softnic_tm.c
@@ -7,14 +7,83 @@ 
 #include <string.h>
 
 #include <rte_malloc.h>
+#include <rte_string_fns.h>
 
 #include "rte_eth_softnic_internals.h"
 #include "rte_eth_softnic.h"
 
-#define BYTES_IN_MBPS		(1000 * 1000 / 8)
 #define SUBPORT_TC_PERIOD	10
 #define PIPE_TC_PERIOD		40
 
+int
+tmgr_init(struct pmd_internals *p)
+{
+	TAILQ_INIT(&p->tmgr_port_list);
+
+	return 0;
+}
+
+void
+tmgr_free(struct pmd_internals *p)
+{
+	for ( ; ; ) {
+		struct tmgr_port *tmgr_port;
+
+		tmgr_port = TAILQ_FIRST(&p->tmgr_port_list);
+		if (tmgr_port == NULL)
+			break;
+
+		TAILQ_REMOVE(&p->tmgr_port_list, tmgr_port, node);
+		free(tmgr_port);
+	}
+}
+
+struct tmgr_port *
+tmgr_port_find(struct pmd_internals *p,
+	const char *name)
+{
+	struct tmgr_port *tmgr_port;
+
+	if (name == NULL)
+		return NULL;
+
+	TAILQ_FOREACH(tmgr_port, &p->tmgr_port_list, node)
+		if (strcmp(tmgr_port->name, name) == 0)
+			return tmgr_port;
+
+	return NULL;
+}
+
+struct tmgr_port *
+tmgr_port_create(struct pmd_internals *p,
+	const char *name,
+	struct rte_sched_port *sched)
+{
+	struct tmgr_port *tmgr_port;
+
+	/* Check input params */
+	if (name == NULL ||
+		tmgr_port_find(p, name) ||
+		sched == NULL)
+		return NULL;
+
+	/* Resource */
+
+	/* Node allocation */
+	tmgr_port = calloc(1, sizeof(struct tmgr_port));
+	if (tmgr_port == NULL)
+		return NULL;
+
+	/* Node fill in */
+	strlcpy(tmgr_port->name, name, sizeof(tmgr_port->name));
+	tmgr_port->s = sched;
+
+	/* Node add to list */
+	TAILQ_INSERT_TAIL(&p->tmgr_port_list, tmgr_port, node);
+
+	return tmgr_port;
+}
+
 static void
 tm_hierarchy_init(struct pmd_internals *p)
 {
@@ -89,9 +158,7 @@  tm_hierarchy_uninit(struct pmd_internals *p)
 }
 
 int
-tm_init(struct pmd_internals *p,
-	struct pmd_params *params __rte_unused,
-	int numa_node __rte_unused)
+tm_init(struct pmd_internals *p)
 {
 	tm_hierarchy_init(p);
 
@@ -107,7 +174,9 @@  tm_free(struct pmd_internals *p)
 int
 tm_start(struct pmd_internals *p)
 {
+	struct tmgr_port *tmgr_port;
 	struct tm_params *t = &p->soft.tm.params;
+	struct rte_sched_port *sched;
 	uint32_t n_subports, subport_id;
 	int status;
 
@@ -116,8 +185,8 @@  tm_start(struct pmd_internals *p)
 		return -1;
 
 	/* Port */
-	p->soft.tm.sched = rte_sched_port_config(&t->port_params);
-	if (p->soft.tm.sched == NULL)
+	sched = rte_sched_port_config(&t->port_params);
+	if (sched == NULL)
 		return -1;
 
 	/* Subport */
@@ -127,11 +196,11 @@  tm_start(struct pmd_internals *p)
 			t->port_params.n_pipes_per_subport;
 		uint32_t pipe_id;
 
-		status = rte_sched_subport_config(p->soft.tm.sched,
+		status = rte_sched_subport_config(sched,
 			subport_id,
 			&t->subport_params[subport_id]);
 		if (status) {
-			rte_sched_port_free(p->soft.tm.sched);
+			rte_sched_port_free(sched);
 			return -1;
 		}
 
@@ -145,26 +214,36 @@  tm_start(struct pmd_internals *p)
 			if (profile_id < 0)
 				continue;
 
-			status = rte_sched_pipe_config(p->soft.tm.sched,
+			status = rte_sched_pipe_config(sched,
 				subport_id,
 				pipe_id,
 				profile_id);
 			if (status) {
-				rte_sched_port_free(p->soft.tm.sched);
+				rte_sched_port_free(sched);
 				return -1;
 			}
 		}
 	}
 
+	tmgr_port = tmgr_port_create(p, "TMGR", sched);
+	if (tmgr_port == NULL) {
+		rte_sched_port_free(sched);
+		return -1;
+	}
+
+	/* Commit */
+	p->soft.tm.sched = sched;
+
 	return 0;
 }
 
 void
 tm_stop(struct pmd_internals *p)
 {
-	if (p->soft.tm.sched)
+	if (p->soft.tm.sched) {
 		rte_sched_port_free(p->soft.tm.sched);
-
+		p->soft.tm.sched = NULL;
+	}
 	/* Unfreeze hierarchy */
 	p->soft.tm.hierarchy_frozen = 0;
 }