[dpdk-dev] [PATCH v1 07/28] eal/soc: add rte_eal_soc_register/unregister logic

Jan Viktorin viktorin at rehivetech.com
Fri May 6 15:47:49 CEST 2016


Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
---
 app/test/test_soc.c                             | 106 ++++++++++++++++++++++++
 lib/librte_eal/bsdapp/eal/Makefile              |   1 +
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |   3 +
 lib/librte_eal/common/eal_common_soc.c          |  55 ++++++++++++
 lib/librte_eal/common/include/rte_soc.h         |  23 +++++
 lib/librte_eal/linuxapp/eal/Makefile            |   1 +
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |   4 +
 7 files changed, 193 insertions(+)
 create mode 100644 lib/librte_eal/common/eal_common_soc.c

diff --git a/app/test/test_soc.c b/app/test/test_soc.c
index a49fc9b..f6288dc 100644
--- a/app/test/test_soc.c
+++ b/app/test/test_soc.c
@@ -74,6 +74,103 @@ static int test_compare_addr(void)
 	free(a2.name);
 	free(a1.name);
 	free(a0.name);
+
+	return 0;
+}
+
+/**
+ * Empty PMD driver based on the SoC infra.
+ *
+ * The rte_soc_device is usually wrapped in some higher-level struct
+ * (eth_driver). We simulate such a wrapper with an anonymous struct here.
+ */
+struct test_wrapper {
+	struct rte_soc_driver soc_drv;
+};
+
+struct test_wrapper empty_pmd0 = {
+	.soc_drv = {
+		.name = "empty_pmd0",
+	},
+};
+
+struct test_wrapper empty_pmd1 = {
+	.soc_drv = {
+		.name = "empty_pmd1",
+	},
+};
+
+static int
+count_registered_socdrvs(void)
+{
+	int i;
+	struct rte_soc_driver *drv;
+
+	i = 0;
+	TAILQ_FOREACH(drv, &soc_driver_list, next)
+		i += 1;
+
+	return i;
+}
+
+static int
+test_register_unregister(void)
+{
+	struct rte_soc_driver *drv;
+	int count;
+
+	rte_eal_soc_register(&empty_pmd0.soc_drv);
+
+	TEST_ASSERT(!TAILQ_EMPTY(&soc_driver_list),
+		"No PMD is present but the empty_pmd0 should be there");
+	drv = TAILQ_FIRST(&soc_driver_list);
+	TEST_ASSERT(!strcmp(drv->name, "empty_pmd0"),
+		"The registered PMD is not empty_pmd but '%s'", drv->name);
+
+	rte_eal_soc_register(&empty_pmd1.soc_drv);
+
+	count = count_registered_socdrvs();
+	TEST_ASSERT_EQUAL(count, 2, "Expected 2 PMDs but detected %d", count);
+
+	rte_eal_soc_unregister(&empty_pmd0.soc_drv);
+	count = count_registered_socdrvs();
+	TEST_ASSERT_EQUAL(count, 1, "Expected 1 PMDs but detected %d", count);
+
+	rte_eal_soc_unregister(&empty_pmd1.soc_drv);
+
+	printf("%s has been successful\n", __func__);
+	return 0;
+}
+
+/* save real devices and drivers until the tests finishes */
+struct soc_driver_list real_soc_driver_list =
+	TAILQ_HEAD_INITIALIZER(real_soc_driver_list);
+
+static int test_soc_setup(void)
+{
+	struct rte_soc_driver *drv;
+
+	/* no real drivers for the test */
+	while (!TAILQ_EMPTY(&soc_driver_list)) {
+		drv = TAILQ_FIRST(&soc_driver_list);
+		rte_eal_soc_unregister(drv);
+		TAILQ_INSERT_TAIL(&real_soc_driver_list, drv, next);
+	}
+
+	return 0;
+}
+
+static int test_soc_cleanup(void)
+{
+	struct rte_soc_driver *drv;
+
+	/* bring back real drivers after the test */
+	while (!TAILQ_EMPTY(&real_soc_driver_list)) {
+		drv = TAILQ_FIRST(&real_soc_driver_list);
+		TAILQ_REMOVE(&real_soc_driver_list, drv, next);
+		rte_eal_soc_register(drv);
+	}
+
 	return 0;
 }
 
@@ -83,6 +180,15 @@ test_soc(void)
 	if (test_compare_addr())
 		return -1;
 
+	if (test_soc_setup())
+		return -1;
+
+	if (test_register_unregister())
+		return -1;
+
+	if (test_soc_cleanup())
+		return -1;
+
 	return 0;
 }
 
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 9054ad6..d956808 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -71,6 +71,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_launch.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_soc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_pci.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_memory.c
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 4d075df..c430b4b 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -158,4 +158,7 @@ DPDK_16.07 {
 	rte_eal_dev_attach;
 	rte_eal_dev_detach;
 
+	rte_eal_soc_register;
+	rte_eal_soc_unregister;
+
 } DPDK_16.04;
diff --git a/lib/librte_eal/common/eal_common_soc.c b/lib/librte_eal/common/eal_common_soc.c
new file mode 100644
index 0000000..afeed2f
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_soc.c
@@ -0,0 +1,55 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2016 RehiveTech. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of RehiveTech nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/queue.h>
+
+#include <rte_log.h>
+
+#include "eal_private.h"
+
+struct soc_driver_list soc_driver_list =
+	TAILQ_HEAD_INITIALIZER(soc_driver_list);
+
+/* register a driver */
+void
+rte_eal_soc_register(struct rte_soc_driver *driver)
+{
+	TAILQ_INSERT_TAIL(&soc_driver_list, driver, next);
+}
+
+/* unregister a driver */
+void
+rte_eal_soc_unregister(struct rte_soc_driver *driver)
+{
+	TAILQ_REMOVE(&soc_driver_list, driver, next);
+}
diff --git a/lib/librte_eal/common/include/rte_soc.h b/lib/librte_eal/common/include/rte_soc.h
index cde588a..28c1798 100644
--- a/lib/librte_eal/common/include/rte_soc.h
+++ b/lib/librte_eal/common/include/rte_soc.h
@@ -46,11 +46,17 @@ extern "C" {
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/queue.h>
 #include <stdint.h>
 #include <inttypes.h>
 #include <string.h>
 
 #include <rte_debug.h>
+#include <rte_eal.h>
+
+TAILQ_HEAD(soc_driver_list, rte_soc_driver); /**< SoC drivers in D-linked Q. */
+
+extern struct soc_driver_list soc_driver_list; /**< Global list of SoC drivers. */
 
 struct rte_soc_id {
 	const char *compatible; /**< OF compatible specification */
@@ -131,4 +137,21 @@ rte_eal_compare_soc_addr(const struct rte_soc_addr *a0,
 	return strcmp(a0->name, a1->name);
 }
 
+/**
+ * Register a SoC driver.
+ */
+void rte_eal_soc_register(struct rte_soc_driver *driver);
+
+#define RTE_EAL_SOC_REGISTER(name) \
+RTE_INIT(socinitfn_ ##name); \
+static void socinitfn_ ##name(void) \
+{ \
+	rte_eal_soc_register(&name.soc_drv); \
+}
+
+/**
+ * Unregister a SoC driver.
+ */
+void rte_eal_soc_unregister(struct rte_soc_driver *driver);
+
 #endif
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index e109361..37ab8d5 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -82,6 +82,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_timer.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_launch.c
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_soc.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_pci.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_memory.c
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 0404a52..6ff38b8 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -161,4 +161,8 @@ DPDK_16.07 {
 	rte_eal_dev_attach;
 	rte_eal_dev_detach;
 
+	soc_driver_list;
+	rte_eal_soc_register;
+	rte_eal_soc_unregister;
+
 } DPDK_16.04;
-- 
2.8.0



More information about the dev mailing list