DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH v2 05/10] eal: add internal APIs to query loaded driver paths
Date: Thu,  4 Dec 2025 18:20:42 +0000	[thread overview]
Message-ID: <20251204182047.3154429-6-bruce.richardson@intel.com> (raw)
In-Reply-To: <20251204182047.3154429-1-bruce.richardson@intel.com>

Add APIs for internal DPDK use to allow querying the paths of drivers
loaded into the running instance.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/eal/common/eal_common_options.c | 54 ++++++++++++++++++++++++++---
 lib/eal/include/rte_eal.h           | 52 +++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 4 deletions(-)

diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index b1fb670ea0..a4afbb80a2 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -263,6 +263,7 @@ struct shared_driver {
 
 	char    name[PATH_MAX];
 	void*   lib_handle;
+	bool    from_cmdline; /**< true if from -d flag, false if driver found in a directory */
 };
 
 /* List of external loadable drivers */
@@ -533,7 +534,7 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 }
 
 static int
-eal_plugin_add(const char *path)
+eal_plugin_add(const char *path, bool from_cmdline)
 {
 	struct shared_driver *solib;
 
@@ -544,6 +545,7 @@ eal_plugin_add(const char *path)
 	}
 	memset(solib, 0, sizeof(*solib));
 	strlcpy(solib->name, path, PATH_MAX);
+	solib->from_cmdline = from_cmdline;
 	TAILQ_INSERT_TAIL(&solib_list, solib, next);
 
 	return 0;
@@ -595,7 +597,7 @@ eal_plugindir_init(const char *path)
 		if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
 			continue;
 
-		if (eal_plugin_add(sopath) == -1)
+		if (eal_plugin_add(sopath, false) == -1)
 			break;
 	}
 
@@ -727,7 +729,7 @@ eal_plugins_init(void)
 			*default_solib_dir != '\0' &&
 			stat(default_solib_dir, &sb) == 0 &&
 			S_ISDIR(sb.st_mode))
-		eal_plugin_add(default_solib_dir);
+		eal_plugin_add(default_solib_dir, false);
 
 	TAILQ_FOREACH(solib, &solib_list, next) {
 
@@ -751,6 +753,50 @@ eal_plugins_init(void)
 }
 #endif
 
+RTE_EXPORT_SYMBOL(rte_eal_driver_path_next)
+const char *
+rte_eal_driver_path_next(const char *start, bool cmdline_only)
+{
+	struct shared_driver *solib;
+
+	if (start == NULL) {
+		solib = TAILQ_FIRST(&solib_list);
+	} else {
+		/* Find the current entry based on the name string */
+		TAILQ_FOREACH(solib, &solib_list, next) {
+			if (start == solib->name) {
+				solib = TAILQ_NEXT(solib, next);
+				break;
+			}
+		}
+		if (solib == NULL)
+			return NULL;
+	}
+
+	/* Skip entries that were expanded from directories if cmdline_only is true */
+	if (cmdline_only) {
+		while (solib != NULL && !solib->from_cmdline)
+			solib = TAILQ_NEXT(solib, next);
+	}
+
+	return solib ? solib->name : NULL;
+}
+
+RTE_EXPORT_SYMBOL(rte_eal_driver_path_count)
+unsigned int
+rte_eal_driver_path_count(bool cmdline_only)
+{
+	struct shared_driver *solib;
+	unsigned int count = 0;
+
+	TAILQ_FOREACH(solib, &solib_list, next) {
+		if (!cmdline_only || solib->from_cmdline)
+			count++;
+	}
+
+	return count;
+}
+
 /*
  * Parse the coremask given as argument (hexadecimal string) and fill
  * the global configuration (core role and core count) with the parsed
@@ -1929,7 +1975,7 @@ eal_parse_args(void)
 			return -1;
 	/* driver loading options */
 	TAILQ_FOREACH(arg, &args.driver_path, next)
-		if (eal_plugin_add(arg->arg) < 0)
+		if (eal_plugin_add(arg->arg, true) < 0)
 			return -1;
 
 	if (remap_lcores && args.remap_lcore_ids != (void *)1) {
diff --git a/lib/eal/include/rte_eal.h b/lib/eal/include/rte_eal.h
index 619b8fbade..cd0b77c13f 100644
--- a/lib/eal/include/rte_eal.h
+++ b/lib/eal/include/rte_eal.h
@@ -491,6 +491,58 @@ rte_eal_mbuf_user_pool_ops(void);
 const char *
 rte_eal_get_runtime_dir(void);
 
+/**
+ * @internal
+ * Iterate to the next driver path.
+ *
+ * This function iterates through the list of dynamically loaded drivers,
+ * or driver paths that were specified via -d or --driver-path command-line
+ * options during EAL initialization.
+ *
+ * @param start
+ *   Starting iteration point. The iteration will start at the first driver path if NULL.
+ * @param cmdline_only
+ *   If true, only iterate paths from command line (-d flags).
+ *   If false, iterate all paths including those expanded from directories.
+ *
+ * @return
+ *   Next driver path string, NULL if there is none.
+ */
+const char *
+rte_eal_driver_path_next(const char *start, bool cmdline_only);
+
+/**
+ * @internal
+ * Iterate over all driver paths.
+ *
+ * This macro provides a convenient way to iterate through all driver paths
+ * that were loaded via -d flags during EAL initialization.
+ *
+ * @param path
+ *   Iterator variable of type const char *
+ * @param cmdline_only
+ *   If true, only iterate paths from command line (-d flags).
+ *   If false, iterate all paths including those expanded from directories.
+ */
+#define RTE_EAL_DRIVER_PATH_FOREACH(path, cmdline_only) \
+	for (path = rte_eal_driver_path_next(NULL, cmdline_only); \
+	     path != NULL; \
+	     path = rte_eal_driver_path_next(path, cmdline_only))
+
+/**
+ * @internal
+ * Get count of driver paths.
+ *
+ * @param cmdline_only
+ *   If true, only count paths from command line (-d flags).
+ *   If false, count all paths including those expanded from directories.
+ *
+ * @return
+ *   Number of driver paths.
+ */
+unsigned int
+rte_eal_driver_path_count(bool cmdline_only);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.51.0


  parent reply	other threads:[~2025-12-04 18:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-02 15:49 [PATCH 0/2] improve fast-tests suite Bruce Richardson
2025-12-02 15:49 ` [PATCH 1/2] app/test: add some unattached tests to fast-test suite Bruce Richardson
2025-12-02 15:49 ` [PATCH 2/2] app/test: make parameters clearer when adding fast tests Bruce Richardson
2025-12-02 16:53   ` Marat Khalili
2025-12-02 18:16     ` Bruce Richardson
2025-12-04 18:20 ` [PATCH v2 00/10] Assign all unit tests to suites Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 01/10] app/test: make parameters clearer when adding fast tests Bruce Richardson
2025-12-05 10:10     ` Marat Khalili
2025-12-05 10:17       ` Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 02/10] app/test: fix undefined behaviour in red autotest Bruce Richardson
2025-12-05 10:25     ` Marat Khalili
2025-12-04 18:20   ` [PATCH v2 03/10] app/test: reduce duration of secondary timer test Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 04/10] app/test: fix timer loop hang on secondary process failure Bruce Richardson
2025-12-04 18:20   ` Bruce Richardson [this message]
2025-12-04 18:20   ` [PATCH v2 06/10] app/test: pass loaded driver info to secondary procs Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 07/10] app/test: skip power capabilities test if unsupported Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 08/10] app/test: add some unattached tests to fast-test suite Bruce Richardson
2025-12-05 12:37     ` David Marchand
2025-12-05 12:43       ` Bruce Richardson
2025-12-05 12:50         ` David Marchand
2025-12-05 12:53           ` Bruce Richardson
2025-12-05 13:08             ` David Marchand
2025-12-04 18:20   ` [PATCH v2 09/10] app/test: add tests to driver test suite Bruce Richardson
2025-12-04 18:20   ` [PATCH v2 10/10] buildtools/get-test-suites: suppress empty output Bruce Richardson
2025-12-05 10:29     ` Marat Khalili

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=20251204182047.3154429-6-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /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).