[dpdk-dev] [PATCH v3 09/13] examples/ipsec-secgw: add event helper config init/uninit

Lukasz Bartosik lbartosik at marvell.com
Tue Feb 4 14:58:37 CET 2020


Add eventmode helper eh_conf_init and eh_conf_uninit
functions which purpose is to initialize and
unitialize eventmode helper configuration.

Signed-off-by: Anoob Joseph <anoobj at marvell.com>
Signed-off-by: Lukasz Bartosik <lbartosik at marvell.com>
---
 examples/ipsec-secgw/event_helper.c | 103 ++++++++++++++++++++++++++++++++++++
 examples/ipsec-secgw/event_helper.h |  23 ++++++++
 2 files changed, 126 insertions(+)

diff --git a/examples/ipsec-secgw/event_helper.c b/examples/ipsec-secgw/event_helper.c
index 6b21884..423576d 100644
--- a/examples/ipsec-secgw/event_helper.c
+++ b/examples/ipsec-secgw/event_helper.c
@@ -1385,6 +1385,109 @@ eh_display_link_conf(struct eventmode_conf *em_conf)
 	EH_LOG_INFO("");
 }
 
+struct eh_conf *
+eh_conf_init(void)
+{
+	struct eventmode_conf *em_conf = NULL;
+	struct eh_conf *conf = NULL;
+	unsigned int eth_core_id;
+	void *bitmap = NULL;
+	uint32_t nb_bytes;
+
+	/* Allocate memory for config */
+	conf = calloc(1, sizeof(struct eh_conf));
+	if (conf == NULL) {
+		EH_LOG_ERR("Failed to allocate memory for eventmode helper "
+			   "config");
+		return NULL;
+	}
+
+	/* Set default conf */
+
+	/* Packet transfer mode: poll */
+	conf->mode = EH_PKT_TRANSFER_MODE_POLL;
+
+	/* Keep all ethernet ports enabled by default */
+	conf->eth_portmask = -1;
+
+	/* Allocate memory for event mode params */
+	conf->mode_params = calloc(1, sizeof(struct eventmode_conf));
+	if (conf->mode_params == NULL) {
+		EH_LOG_ERR("Failed to allocate memory for event mode params");
+		goto free_conf;
+	}
+
+	/* Get eventmode conf */
+	em_conf = conf->mode_params;
+
+	/* Allocate and initialize bitmap for eth cores */
+	nb_bytes = rte_bitmap_get_memory_footprint(RTE_MAX_LCORE);
+	if (!nb_bytes) {
+		EH_LOG_ERR("Failed to get bitmap footprint");
+		goto free_em_conf;
+	}
+
+	bitmap = rte_zmalloc("event-helper-ethcore-bitmap", nb_bytes,
+			     RTE_CACHE_LINE_SIZE);
+	if (!bitmap) {
+		EH_LOG_ERR("Failed to allocate memory for eth cores bitmap\n");
+		goto free_em_conf;
+	}
+
+	em_conf->eth_core_mask = rte_bitmap_init(RTE_MAX_LCORE, bitmap,
+						 nb_bytes);
+	if (!em_conf->eth_core_mask) {
+		EH_LOG_ERR("Failed to initialize bitmap");
+		goto free_bitmap;
+	}
+
+	/* Set schedule type as not set */
+	em_conf->ext_params.sched_type = SCHED_TYPE_NOT_SET;
+
+	/* Set two cores as eth cores for Rx & Tx */
+
+	/* Use first core other than master core as Rx core */
+	eth_core_id = rte_get_next_lcore(0,	/* curr core */
+					 1,	/* skip master core */
+					 0	/* wrap */);
+
+	rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
+
+	/* Use next core as Tx core */
+	eth_core_id = rte_get_next_lcore(eth_core_id,	/* curr core */
+					 1,		/* skip master core */
+					 0		/* wrap */);
+
+	rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
+
+	return conf;
+
+free_bitmap:
+	rte_free(bitmap);
+free_em_conf:
+	free(em_conf);
+free_conf:
+	free(conf);
+	return NULL;
+}
+
+void
+eh_conf_uninit(struct eh_conf *conf)
+{
+	struct eventmode_conf *em_conf = NULL;
+
+	if (!conf || !conf->mode_params)
+		return;
+
+	/* Get eventmode conf */
+	em_conf = conf->mode_params;
+
+	/* Free evenmode configuration memory */
+	rte_free(em_conf->eth_core_mask);
+	free(em_conf);
+	free(conf);
+}
+
 void
 eh_display_conf(struct eh_conf *conf)
 {
diff --git a/examples/ipsec-secgw/event_helper.h b/examples/ipsec-secgw/event_helper.h
index 15a7bd6..7ad975f 100644
--- a/examples/ipsec-secgw/event_helper.h
+++ b/examples/ipsec-secgw/event_helper.h
@@ -50,6 +50,9 @@ extern "C" {
 /* Max adapters that one Tx core can handle */
 #define EVENT_MODE_MAX_ADAPTERS_PER_TX_CORE EVENT_MODE_MAX_TX_ADAPTERS
 
+/* Used to indicate that queue schedule type is not set */
+#define SCHED_TYPE_NOT_SET	3
+
 /**
  * Packet transfer mode of the application
  */
@@ -204,6 +207,26 @@ struct eh_app_worker_params {
 };
 
 /**
+ * Allocate memory for event helper configuration and initialize
+ * it with default values.
+ *
+ * @return
+ * - pointer to event helper configuration structure on success.
+ * - NULL on failure.
+ */
+struct eh_conf *
+eh_conf_init(void);
+
+/**
+ * Uninitialize event helper configuration and release its memory
+. *
+ * @param conf
+ *   Event helper configuration
+ */
+void
+eh_conf_uninit(struct eh_conf *conf);
+
+/**
  * Initialize event mode devices
  *
  * Application can call this function to get the event devices, eth devices
-- 
2.7.4



More information about the dev mailing list