Skip to contentSkip to conversation

Allow intitializing EAL without argc/argv

RFC PATCH In review Bruce Richardson 2 participants 174 messages Apr 29 – Nov 26 Page 3 of 4

Subsystems (2)
lore
Share & tools
lore
#91 lore raw

PATCH 39/39 eal: provide hooks for init with externally supplied config

In reply to Bruce Richardson

Now that we have a split EAL init, where most work is done on a configured eal_user_cfg structure, add in hooks to allow other libraries to init EAL by passing in that structure pre-configured.

We export an internal function that wraps the second stage init, while taking care of the run_once flag, before calling the main initialization function with a prepopulated config.

Also, export internally the platform info function so that any callers of this new function can do any necessary validation of parameters as part of their setup.

---
 lib/eal/common/eal_common_config.c  |  5 +--
 lib/eal/common/eal_common_lcore.c   |  6 ++--
 lib/eal/common/eal_common_thread.c  |  2 +-
 lib/eal/common/eal_internal_cfg.h   |  8 ++++-
 lib/eal/freebsd/eal.c               | 53 ++++++++++++++++++++++++---
 lib/eal/freebsd/eal_hugepage_info.c |  2 +-
 lib/eal/freebsd/eal_memory.c        |  6 ++--
 lib/eal/linux/eal.c                 | 51 +++++++++++++++++++++++---
 lib/eal/linux/eal_hugepage_info.c   |  2 +-
 lib/eal/windows/eal.c               | 56 ++++++++++++++++++++++++++++-
 lib/eal/windows/eal_hugepages.c     |  2 +-
 lib/eal/windows/eal_memalloc.c      |  2 +-
 12 files changed, 171 insertions(+), 24 deletions(-)
lib/eal/common/eal_common_config.c +3 -2
index 97bb68069b..cb96680e5b 100644
@@ -68,8 +68,9 @@ eal_get_user_configuration(void)
 }
 
 /* Return a pointer to the platform state structure */
+RTE_EXPORT_INTERNAL_SYMBOL(rte_eal_get_platform_info)
 const struct eal_platform_info *
-eal_get_platform_info(void)
+rte_eal_get_platform_info(void)
 {
 	/* platform-discovered and runtime EAL state */
 	static struct eal_platform_info eal_platform_info;
@@ -302,7 +303,7 @@ int
 eal_apply_hugepage_mem_sz_limits(void)
 {
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int i;
 
lib/eal/common/eal_common_lcore.c +3 -3
index 0020e6a178..7b2936489d 100644
@@ -54,7 +54,7 @@ RTE_EXPORT_SYMBOL(rte_lcore_to_cpu_id)
 int rte_lcore_to_cpu_id(int lcore_id)
 {
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	unsigned int cpu;
 
 	if (unlikely(lcore_id >= RTE_MAX_LCORE))
@@ -267,7 +267,7 @@ RTE_EXPORT_SYMBOL(rte_socket_count)
 unsigned int
 rte_socket_count(void)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	return platform_info->numa_node_count;
 }
 
@@ -275,7 +275,7 @@ RTE_EXPORT_SYMBOL(rte_socket_id_by_idx)
 int
 rte_socket_id_by_idx(unsigned int idx)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	if (idx >= platform_info->numa_node_count) {
 		rte_errno = EINVAL;
 		return -1;
lib/eal/common/eal_common_thread.c +1 -1
index a2e08242bd..b56dd4f2b6 100644
@@ -40,7 +40,7 @@ unsigned rte_socket_id(void)
 int
 eal_cpuset_socket_id(const rte_cpuset_t *cpusetp)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	int socket_id = SOCKET_ID_ANY;
 
 	if (cpusetp == NULL)
lib/eal/common/eal_internal_cfg.h +7 -1
index 120ce37a47..2115ee7fe2 100644
@@ -25,6 +25,7 @@
 #include <rte_bitset.h>
 #include <rte_stdatomic.h>
 #include "eal_thread.h"
+#include "rte_compat.h"
 
 /* Forward declaration — full definition is in eal_memcfg.h */
 struct rte_mem_config;
@@ -385,8 +386,13 @@ struct eal_runtime_state {
 	struct eal_solib_list loaded_plugins; /**< all plugins loaded by eal_plugins_init() */
 };
 
-const struct eal_platform_info *eal_get_platform_info(void);
+__rte_internal
+const struct eal_platform_info *rte_eal_get_platform_info(void);
 struct eal_user_cfg *eal_get_user_configuration(void);
 struct eal_runtime_state *eal_get_runtime_state(void);
 
+__rte_internal
+int
+rte_eal_runtime_init(const char *progname, const struct eal_user_cfg *user_provided_cfg);
+
 #endif /* EAL_INTERNAL_CFG_H */
lib/eal/freebsd/eal.c +48 -5

95 lines not on this page · raw message

lib/eal/freebsd/eal_hugepage_info.c +1 -1
index 9c97897cc3..28e1a04528 100644
@@ -87,7 +87,7 @@ eal_get_platform_hp_info(struct eal_platform_info *platform_info)
 int
 eal_hugepage_info_init(void)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	int num_buffers, fd;
 	int64_t buffer_size;
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
lib/eal/freebsd/eal_memory.c +3 -3
index ffb44d8286..5fda56b1d3 100644
@@ -72,7 +72,7 @@ rte_eal_hugepage_init(void)
 	void *addr;
 	unsigned int i, j, seg_idx = 0;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* get pointer to global configuration */
@@ -285,7 +285,7 @@ attach_segment(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
 int
 rte_eal_hugepage_attach(void)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct hugepage_info *hpi;
 	int fd_hugepage = -1;
@@ -354,7 +354,7 @@ memseg_primary_init(void)
 	int hpi_idx, msl_idx = 0;
 	struct rte_memseg_list *msl;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* no-huge does not need this at all */
lib/eal/linux/eal.c +47 -4

87 lines not on this page · raw message

lib/eal/linux/eal_hugepage_info.c +1 -1
index a6bf807f90..7be3fe3b65 100644
@@ -518,7 +518,7 @@ hugepage_info_init(void)
 	unsigned int reusable_pages;
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	int failed = 0;
 
 	/* platform_info->hugepage_sizes[] is already sorted largest to smallest */
lib/eal/windows/eal.c +55 -1

91 lines not on this page · raw message

lib/eal/windows/eal_hugepages.c +1 -1
index 0c62f5ff48..0870495c78 100644
@@ -59,7 +59,7 @@ hugepage_claim_privilege(void)
 static int
 hugepage_info_init(void)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct hugepage_info *hpi;
 	unsigned int socket_id;
 	int ret = 0;
lib/eal/windows/eal_memalloc.c +1 -1
index 3ab8af0466..0c34c65603 100644
@@ -314,7 +314,7 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs,
 	int ret = -1;
 	struct alloc_walk_param wa;
 	const struct hugepage_info *hi = NULL;
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
Signature · 1 line
2.53.0
#92 lore raw

Re: [PATCH 00/39] Rework EAL configuration

In reply to Bruce Richardson
Quoted 139 lines · On Tue, 21 Jul 2026 10:45:08 +0100 Bruce Richardson…

This patchset reworks how configuration is stored and managed in EAL. The existing "internal_config", "rte_config", "lcore_config" structures, which sometimes have arbitrary separation between them (especially the first two) are replaced by three new structures with clearly defined roles:

- eal_platform_info - contains the raw HW info for the system, details of CPUs and hugepage mounts. This is initialized on first use - even before EAL init is called - and is then immutable, since our HW should not change much underneath us. Its early availability means that it can be used to sanity check the contents of the other structs as they are being built up.

- eal_user_cfg - contains the config settings passed in by the user. For existing rte_eal_init, this is built up in the arg parse stage, and it's contents verified against the platform info, e.g. to check core masks are valid etc. Once argument parsing is completed, is also immutable.

- runtime_cfg - basically all the runtime settings that need to be there for DPDK to run, or which change over time. Largely combined content of the old rte_config, internal_config and lcore_config structs. This is initialized from the other two structs by eal initialization and can be modified by EAL at any time.

Once that is done, we have a clean separation between user provided configuration and the rest of EAL, we can split EAL init into two parts, the first of which parses cmdline arguments and then calls the second which takes the eal_user_cfg struct result of that parse and does the actual initialization. The longer-term objective is to have other first-stage functions that prepare the user_cfg struct for initialization, so that we can move away from argc/argv as the only method of configuring DPDK initialization.

Bruce Richardson (39):
telemetry: make cpuset init parameter const
argparse: check for range overflow in CPU lists
eal: define new functionally distinct config structs
eal: move memory request fields to user config
eal: move NUMA request fields to user config
eal: move hugepage policy fields to user config
eal: move process policy fields to user config
eal: move hugepage limit fields to new config structs
eal: move advanced user config options to user cfg struct
eal: move hugepage size info to platform info struct
eal: move runtime state to appropriate structure
eal: record details of all cpus in platform info
eal: use platform info for lcore lookups
eal: add macro for lowest set CPU bit in a set
eal: store lcore configuration in runtime data
eal: move core indices bitset to runtime state
eal: cleanup CPU init function
eal: move NUMA node information to platform info struct
eal: move lcore role and count to runtime state
eal: make lcore role a field in lcore config struct
eal: move main lcore setting to runtime config struct
eal: move IOVA mode and process type to runtime cfg
eal: move memory config pointer to runtime state struct
eal: remove rte_config structure
eal: separate runtime state update from arg parsing
eal: move device options staging list into user cfg
eal: separate plugin paths from loaded plugin objects
eal: simplify internal driver path iteration APIs
eal: move trace config into user config struct
eal: record service cores in user config struct
eal: store user-provided lcore info in user config struct
eal: clarify docs on params taking lcore IDs
eal: remove internal config reset function
eal: move functions setting runtime state
eal: initialize platform info on first use
eal: remove duplicated scan of sysfs for hugepage details
eal: add utilities for working with user config struct
eal: split EAL init into two stages
eal: provide hooks for init with externally supplied config

 app/test/process.h                        |   4 +-
 app/test/test_argparse.c                  |  10 +
 doc/guides/linux_gsg/eal_args.include.rst |  38 +-
 lib/argparse/rte_argparse.c               |   5 +
 lib/eal/common/eal_common_bus.c           |   4 +-
 lib/eal/common/eal_common_config.c        | 264 ++++++-
 lib/eal/common/eal_common_dev.c           |  10 +-
 lib/eal/common/eal_common_dynmem.c        |  70 +-
 lib/eal/common/eal_common_fbarray.c       |  10 +-
 lib/eal/common/eal_common_launch.c        |  25 +-
 lib/eal/common/eal_common_lcore.c         | 267 ++++---
 lib/eal/common/eal_common_mcfg.c          |  44 +-
 lib/eal/common/eal_common_memalloc.c      |   5 +-
 lib/eal/common/eal_common_memory.c        | 104 ++-
 lib/eal/common/eal_common_memzone.c       |  24 +-
 lib/eal/common/eal_common_options.c       | 899 ++++++++--------------
 lib/eal/common/eal_common_proc.c          |  43 +-
 lib/eal/common/eal_common_tailqs.c        |   6 +-
 lib/eal/common/eal_common_thread.c        |  67 +-
 lib/eal/common/eal_common_timer.c         |   2 +-
 lib/eal/common/eal_common_trace.c         |  30 +-
 lib/eal/common/eal_common_trace_utils.c   | 104 ---
 lib/eal/common/eal_hugepages.h            |   8 +
 lib/eal/common/eal_internal_cfg.h         | 386 ++++++++--
 lib/eal/common/eal_memcfg.h               |   3 +
 lib/eal/common/eal_option_list.h          |   6 +-
 lib/eal/common/eal_options.h              |   8 +-
 lib/eal/common/eal_private.h              | 121 ++-
 lib/eal/common/eal_trace.h                |  11 -
 lib/eal/common/malloc_elem.c              |  15 +-
 lib/eal/common/malloc_heap.c              |  41 +-
 lib/eal/common/malloc_mp.c                |   2 +-
 lib/eal/common/rte_malloc.c               |  14 +-
 lib/eal/common/rte_service.c              |  17 +-
 lib/eal/freebsd/eal.c                     | 287 ++++---
 lib/eal/freebsd/eal_hugepage_info.c       |  78 +-
 lib/eal/freebsd/eal_lcore.c               |  16 +-
 lib/eal/freebsd/eal_memory.c              |  46 +-
 lib/eal/freebsd/include/rte_os.h          |   2 +
 lib/eal/include/rte_eal.h                 |  35 +-
 lib/eal/include/rte_memzone.h             |  10 +-
 lib/eal/include/rte_tailq.h               |   2 +-
 lib/eal/linux/eal.c                       | 296 ++++---
 lib/eal/linux/eal_hugepage_info.c         | 231 +++---
 lib/eal/linux/eal_lcore.c                 |  43 ++
 lib/eal/linux/eal_memalloc.c              | 168 ++--
 lib/eal/linux/eal_memory.c                | 168 ++--
 lib/eal/linux/eal_timer_hpet.c            |  21 +-
 lib/eal/linux/eal_vfio.c                  |  11 +-
 lib/eal/linux/include/rte_os.h            |  10 +
 lib/eal/unix/eal_unix_thread.c            |  11 +-
 lib/eal/windows/eal.c                     | 193 +++--
 lib/eal/windows/eal_hugepages.c           |  60 +-
 lib/eal/windows/eal_lcore.c               |   6 +
 lib/eal/windows/eal_memalloc.c            |  37 +-
 lib/eal/windows/eal_memory.c              |  14 +-
 lib/eal/windows/eal_thread.c              |  11 +-
 lib/eal/windows/eal_windows.h             |   8 -
 lib/eal/windows/include/rte_os.h          |   1 +
 lib/eal/windows/include/sched.h           |  10 +
 lib/telemetry/telemetry.c                 |   4 +-
 lib/telemetry/telemetry_internal.h        |   2 +-
 62 files changed, 2499 insertions(+), 1949 deletions(-)
Quoted 3 lines

--
2.53.0

Ran deeper AI review on this and it found a couple small things:

Review of "eal: rework EAL initialization" (39 patches)

Series applies cleanly to main (9231dc7). All 39 commits build individually with -Dwerror=true, so bisect is safe. Findings verified against the merged tree rather than the diffs alone.

Patch 02/39 - argparse: check for range overflow in CPU lists

Warning: missing Fixes: and Cc: stable.

This is an out-of-bounds write, not a cleanup - CPU_SET(min, cpuset) with min >= CPU_SETSIZE writes past the end of rte_cpuset_t. The introducing commit is in v25.11, so it needs backporting:

Fixes d78103fb9488 ("argparse: support core lists")

The fix itself is correct and complete: all three branches assign max before the new check, min >= 0 is guaranteed by the isdigit() gate, and min <= max holds in every branch, so the CPU_SET loop is fully bounded.

Patch 33/39 - eal: remove internal config reset function

Error: removing eal_reset_internal_config() drops the lock_descriptor = -1 preset, which can lead to close(0) on stdin. Linux only.

The deleted function did:

    for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
        memset(&internal_cfg->hugepage_info[i], 0, ...);
        internal_cfg->hugepage_info[i].lock_descriptor = -1;
    }

That -1 was the invariant eal_hugedirs_unlock() relied on. hugepage_info[] now lives in eal_runtime_state, which is a static initialised only with .mem_config, so every lock_descriptor starts at 0 - a valid fd.

This patch compensates by widening the guard:

    if (hugepage_info[i].hugepage_sz == 0 ||
            hugepage_info[i].lock_descriptor < 0)
        continue;

but hugepage_sz == 0 is not a sufficient proxy. In hugepage_info_init() (lib/eal/linux/eal_hugepage_info.c) hpi->hugepage_sz is assigned *before* the mountpoint check, and the no-mountpoint path continues without ever assigning lock_descriptor:

    hpi = &rs->hugepage_info[num_sizes];
    hpi->hugepage_sz = hps->size;          /* set first */

    if (get_hugepage_dir(...) < 0) {
        if (user_cfg->in_memory) {
            calc_num_pages(hpi, hps, 0);
            num_sizes++;                   /* entry accepted */
        }
        continue;                          /* lock_descriptor never set */
    }

    hpi->lock_descriptor = open(hpi->hugedir, O_RDONLY);

Two reachable cases:

(a) --in-memory with a reserved-but-unmounted size (e.g. 1G reserved,

      only 2M mounted). The entry is accepted with hugepage_sz != 0 and
      lock_descriptor == 0.

(b) Default mode where the *last* size has no mountpoint. num_sizes is not incremented, so slot [num_sizes] keeps a nonzero hugepage_sz with lock_descriptor == 0. eal_hugedirs_unlock() iterates to MAX_HUGEPAGE_SIZES, not num_hugepage_sizes, so it still visits it.

In both, the guard passes and the code runs flock(0, LOCK_UN) followed by close(0) on the normal init path (lib/eal/linux/eal.c:831, unconditional after rte_eal_memory_init()). Confirmed with a standalone harness reproducing the two functions' control flow.

FreeBSD is unaffected (single entry, fd assigned unconditionally, no unlock loop); Windows sets -1 explicitly in eal_hugepages.c.

Simplest fix is to restore the invariant rather than widen the guard - set lock_descriptor = -1 for all MAX_HUGEPAGE_SIZES entries when runtime state is set up, or initialise the entry immediately after hugepage_sz is assigned in hugepage_info_init(). Bounding the unlock loop by num_hugepage_sizes would fix (b) but not (a).

The other non-zero defaults from the deleted function are all preserved
correctly: hugepage_file.unlink_existing, no_hpet, and max_simd_bitwidth.bitwidth are in EAL_USER_CFG_INITIALIZER, and RTE_IOVA_DC / RTE_INTR_MODE_NONE / RTE_PROC_PRIMARY are all genuinely 0. lock_descriptor is the only one lost.

Patch 29/39 - eal: move trace config into user config struct

Warning: --trace-dir accumulate semantics changed, plus a leak on repeat.

The old path went through trace_dir_update(), which concatenated onto any existing value:

    asprintf(&dir, "%s%s", trace->dir != NULL ? trace->dir : "", str);

The new code does a plain asprintf into user_cfg->trace_dir. Passing --trace-dir more than once now replaces rather than appends, and the earlier allocation leaks since trace_dir is overwritten without a free. If the replace behaviour is intended, worth saying so in the commit message; otherwise free the previous value first.

Patch 39/39 - eal: provide hooks for init with externally supplied config

Error: rte_eal_runtime_init() returns -1 without setting rte_errno on the platform-info path. Identical in all three platform copies:

    if (rte_eal_get_platform_info() == NULL) {
        rte_eal_init_alert("Platform information is not available.");
        return -1;              /* rte_errno not set */
    }

The other two error paths in the same function set EINVAL and EALREADY, and the equivalent path in rte_eal_init() sets ENOTSUP. A caller checking rte_errno gets a stale value. Suggest rte_errno = ENOTSUP to match.

Warning: the stated purpose is not reachable as posted.

The commit message says the hooks let "other libraries init EAL by passing in that structure pre-configured", but struct eal_user_cfg and both new prototypes live in lib/eal/common/eal_internal_cfg.h. lib/meson.build:143 only adds eal/common to the include path when RTE_LIB_EAL is not yet set, i.e. for EAL's own sub-build; afterwards dependent libraries get deps += ['eal'], which exposes only EAL's public include dirs. No in-tree library can declare the type or call the function without the explicit include_directories() hack used by drivers/common/mlx5/linux/meson.build. Either make the header reachable or note that a follow-up is required.

Warning: both new __rte_internal symbols have no in-tree consumer and no test, so the deep-copy path in eal_user_cfg_copy() is never exercised by anything. A test driving rte_eal_runtime_init() with a hand-populated config would be worth adding alongside.

Info: eal_internal_cfg.h uses #include "rte_compat.h" while every other public RTE header in the same file uses angle brackets.

Checked and found correct

Recording these so they are not re-reviewed:

- eal_user_cfg_copy() deep copy is sound. device_option uses a flexible char arg[], so calloc(1, sizeof(*copy) + arglen) is right; eal_plugin_path uses a fixed char name[PATH_MAX], so malloc(sizeof(*p)) plus memcpy(..., sizeof(name)) is right. Both lists, trace patterns, all four heap strings and the per-lcore cpusets are deep-copied, so cleaning up both user_cfg_from_args and the global config is not a double free. The error path calls eal_user_cfg_cleanup(dst), which is idempotent, so the later eal_cleanup_config() in eal_runtime_init()'s err_out is safe.

- EAL_USER_CFG_INITIALIZER(self): the self-referencing TAILQ_HEAD_INITIALIZER((self).devopt_list) is legal - the object's scope begins after its declarator, and tqh_last correctly points at the final object rather than the compound-literal temporary.

- rte_eal_get_platform_info() double-checked locking has correct acquire/release pairing under a spinlock.

- rte_eal_cpu_init() error paths all free and NULL both cpu_info and numa_nodes, so the caller's fail label cannot double-free. No leak on the numa_node_count > RTE_MAX_NUMA_NODES path.

- eal_expand_cpuset_to_map() and the --lcores parser both NULL entries as they free, so the later eal_user_cfg_cleanup() is safe.

- Every added malloc/calloc/strdup/asprintf checks its return. sprintf(pattern, "%s*", ...) into calloc(1, len + 2) is exactly sized.

- No public ABI change; the only new exports are two RTE_EXPORT_INTERNAL_SYMBOLs and no version.map is hand-edited.

#93 lore raw

Re: [PATCH 00/39] Rework EAL configuration

Quoted 36 lines · Stephen Hemminger
Quoted 33 lines · On Tue, 21 Jul 2026 10:45:08 +0100 Bruce Richardson…

This patchset reworks how configuration is stored and managed in EAL. The existing "internal_config", "rte_config", "lcore_config" structures, which sometimes have arbitrary separation between them (especially the first two) are replaced by three new structures with clearly defined roles:

- eal_platform_info - contains the raw HW info for the system, details of CPUs and hugepage mounts. This is initialized on first use - even before EAL init is called - and is then immutable, since our HW should not change much underneath us. Its early availability means that it can be used to sanity check the contents of the other structs as they are being built up.

- eal_user_cfg - contains the config settings passed in by the user. For existing rte_eal_init, this is built up in the arg parse stage, and it's contents verified against the platform info, e.g. to check core masks are valid etc. Once argument parsing is completed, is also immutable.

- runtime_cfg - basically all the runtime settings that need to be there for DPDK to run, or which change over time. Largely combined content of the old rte_config, internal_config and lcore_config structs. This is initialized from the other two structs by eal initialization and can be modified by EAL at any time.

Once that is done, we have a clean separation between user provided configuration and the rest of EAL, we can split EAL init into two parts, the first of which parses cmdline arguments and then calls the second which takes the eal_user_cfg struct result of that parse and does the actual initialization. The longer-term objective is to have other first-stage functions that prepare the user_cfg struct for initialization, so that we can move away from argc/argv as the only method of configuring DPDK initialization.

<snip>

Quoted 21 lines
Quoted 3 lines

--
2.53.0

Ran deeper AI review on this and it found a couple small things:

Review of "eal: rework EAL initialization" (39 patches)

Series applies cleanly to main (9231dc7). All 39 commits build individually with -Dwerror=true, so bisect is safe. Findings verified against the merged tree rather than the diffs alone.

Patch 02/39 - argparse: check for range overflow in CPU lists

Warning: missing Fixes: and Cc: stable.

This is an out-of-bounds write, not a cleanup - CPU_SET(min, cpuset) with min >= CPU_SETSIZE writes past the end of rte_cpuset_t. The introducing commit is in v25.11, so it needs backporting:

Quoted 7 lines
Fixes d78103fb9488 ("argparse: support core lists")

The fix itself is correct and complete: all three branches assign max before the new check, min >= 0 is guaranteed by the isdigit() gate, and min <= max holds in every branch, so the CPU_SET loop is fully bounded.

Added in v2

Quoted 66 lines

Patch 33/39 - eal: remove internal config reset function

Error: removing eal_reset_internal_config() drops the lock_descriptor = -1 preset, which can lead to close(0) on stdin. Linux only.

The deleted function did:

    for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
        memset(&internal_cfg->hugepage_info[i], 0, ...);
        internal_cfg->hugepage_info[i].lock_descriptor = -1;
    }

That -1 was the invariant eal_hugedirs_unlock() relied on. hugepage_info[] now lives in eal_runtime_state, which is a static initialised only with .mem_config, so every lock_descriptor starts at 0 - a valid fd.

This patch compensates by widening the guard:

    if (hugepage_info[i].hugepage_sz == 0 ||
            hugepage_info[i].lock_descriptor < 0)
        continue;

but hugepage_sz == 0 is not a sufficient proxy. In hugepage_info_init() (lib/eal/linux/eal_hugepage_info.c) hpi->hugepage_sz is assigned *before* the mountpoint check, and the no-mountpoint path continues without ever assigning lock_descriptor:

    hpi = &rs->hugepage_info[num_sizes];
    hpi->hugepage_sz = hps->size;          /* set first */

    if (get_hugepage_dir(...) < 0) {
        if (user_cfg->in_memory) {
            calc_num_pages(hpi, hps, 0);
            num_sizes++;                   /* entry accepted */
        }
        continue;                          /* lock_descriptor never set */
    }

    hpi->lock_descriptor = open(hpi->hugedir, O_RDONLY);

Two reachable cases:

(a) --in-memory with a reserved-but-unmounted size (e.g. 1G reserved,

      only 2M mounted). The entry is accepted with hugepage_sz != 0 and
      lock_descriptor == 0.

(b) Default mode where the *last* size has no mountpoint. num_sizes is not incremented, so slot [num_sizes] keeps a nonzero hugepage_sz with lock_descriptor == 0. eal_hugedirs_unlock() iterates to MAX_HUGEPAGE_SIZES, not num_hugepage_sizes, so it still visits it.

In both, the guard passes and the code runs flock(0, LOCK_UN) followed by close(0) on the normal init path (lib/eal/linux/eal.c:831, unconditional after rte_eal_memory_init()). Confirmed with a standalone harness reproducing the two functions' control flow.

FreeBSD is unaffected (single entry, fd assigned unconditionally, no unlock loop); Windows sets -1 explicitly in eal_hugepages.c.

Simplest fix is to restore the invariant rather than widen the guard - set lock_descriptor = -1 for all MAX_HUGEPAGE_SIZES entries when runtime state is set up, or initialise the entry immediately after hugepage_sz is assigned in hugepage_info_init(). Bounding the unlock loop by num_hugepage_sizes would fix (b) but not (a).

Quoted 6 lines

The other non-zero defaults from the deleted function are all preserved
correctly: hugepage_file.unlink_existing, no_hpet, and max_simd_bitwidth.bitwidth are in EAL_USER_CFG_INITIALIZER, and RTE_IOVA_DC / RTE_INTR_MODE_NONE / RTE_PROC_PRIMARY are all genuinely 0. lock_descriptor is the only one lost.

Yes, this is a valid issue. Reworked a couple of patches to fix it for v2.

Quoted 8 lines

Patch 29/39 - eal: move trace config into user config struct

Warning: --trace-dir accumulate semantics changed, plus a leak on repeat.

The old path went through trace_dir_update(), which concatenated onto any existing value:

Quoted 8 lines
    asprintf(&dir, "%s%s", trace->dir != NULL ? trace->dir : "", str);

The new code does a plain asprintf into user_cfg->trace_dir. Passing --trace-dir more than once now replaces rather than appends, and the earlier allocation leaks since trace_dir is overwritten without a free. If the replace behaviour is intended, worth saying so in the commit message; otherwise free the previous value first.

This I believe to be a false positive. The trace-dir EAL flag can only be specified once on the command line, enforced by the argparse library, so the fact that the later functions don't handle multiple values is not a problem. The concatenation here is actually for appending a filename to an existing trace dir.

Quoted 6 lines

Patch 39/39 - eal: provide hooks for init with externally supplied config

Error: rte_eal_runtime_init() returns -1 without setting rte_errno on the platform-info path. Identical in all three platform copies:

Quoted 9 lines
    if (rte_eal_get_platform_info() == NULL) {
        rte_eal_init_alert("Platform information is not available.");
        return -1;              /* rte_errno not set */
    }

The other two error paths in the same function set EINVAL and EALREADY, and the equivalent path in rte_eal_init() sets ENOTSUP. A caller checking rte_errno gets a stale value. Suggest rte_errno = ENOTSUP to match.

Fixed in v2. Explicitly set rte_errno = 0 at the start of function and set it explicitly only when it's not already set by a subfunction of get_platform_info.

Quoted 12 lines

Warning: the stated purpose is not reachable as posted.

The commit message says the hooks let "other libraries init EAL by passing in that structure pre-configured", but struct eal_user_cfg and both new prototypes live in lib/eal/common/eal_internal_cfg.h. lib/meson.build:143 only adds eal/common to the include path when RTE_LIB_EAL is not yet set, i.e. for EAL's own sub-build; afterwards dependent libraries get deps += ['eal'], which exposes only EAL's public include dirs. No in-tree library can declare the type or call the function without the explicit include_directories() hack used by drivers/common/mlx5/linux/meson.build. Either make the header reachable or note that a follow-up is required.

Expected. In RFC I included an example of use, but dropped from this v1 series as it's already long enough.

Quoted 5 lines

Warning: both new __rte_internal symbols have no in-tree consumer and no test, so the deep-copy path in eal_user_cfg_copy() is never exercised by anything. A test driving rte_eal_runtime_init() with a hand-populated config would be worth adding alongside.

As above, will hopefully be added later if this makes it in.

Quoted 6 lines

Info: eal_internal_cfg.h uses #include "rte_compat.h" while every other public RTE header in the same file uses angle brackets.

Checked and found correct

<snip>

#94 lore raw

v3 cover Rework EAL configuration

In reply to Bruce Richardson

This patchset reworks how configuration is stored and managed in EAL. The existing "internal_config", "rte_config", "lcore_config" structures, which sometimes have arbitrary separation between them (especially the first two) are replaced by three new structures with clearly defined roles:

- eal_platform_info - contains the raw HW info for the system, details of CPUs and hugepage mounts. This is initialized on first use - even before EAL init is called - and is then immutable, since our HW should not change much underneath us. Its early availability means that it can be used to sanity check the contents of the other structs as they are being built up.

- eal_user_cfg - contains the config settings passed in by the user. For existing rte_eal_init, this is built up in the arg parse stage, and it's contents verified against the platform info, e.g. to check core masks are valid etc. Once argument parsing is completed, is also immutable.

- runtime_cfg - basically all the runtime settings that need to be there for DPDK to run, or which change over time. Largely combined content of the old rte_config, internal_config and lcore_config structs. This is initialized from the other two structs by eal initialization and can be modified by EAL at any time.

Once that is done, we have a clean separation between user provided configuration and the rest of EAL, we can split EAL init into two parts, the first of which parses cmdline arguments and then calls the second which takes the eal_user_cfg struct result of that parse and does the actual initialization. The longer-term objective is to have other first-stage functions that prepare the user_cfg struct for initialization, so that we can move away from argc/argv as the only method of configuring DPDK initialization.

v3: rebase for 27.03
v2: minor rework following AI review.

Bruce Richardson (39):
telemetry: make cpuset init parameter const
argparse: check for range overflow in CPU lists
eal: define new functionally distinct config structs
eal: move memory request fields to user config
eal: move NUMA request fields to user config
eal: move hugepage policy fields to user config
eal: move process policy fields to user config
eal: move hugepage limit fields to new config structs
eal: move advanced user config options to user cfg struct
eal: move hugepage size info to platform info struct
eal: move runtime state to appropriate structure
eal: record details of all cpus in platform info
eal: use platform info for lcore lookups
eal: add macro for lowest set CPU bit in a set
eal: store lcore configuration in runtime data
eal: move core indices bitset to runtime state
eal: cleanup CPU init function
eal: move NUMA node information to platform info struct
eal: move lcore role and count to runtime state
eal: make lcore role a field in lcore config struct
eal: move main lcore setting to runtime config struct
eal: move IOVA mode and process type to runtime cfg
eal: move memory config pointer to runtime state struct
eal: remove rte_config structure
eal: separate runtime state update from arg parsing
eal: move device options staging list into user cfg
eal: separate plugin paths from loaded plugin objects
eal: simplify internal driver path iteration APIs
eal: move trace config into user config struct
eal: record service cores in user config struct
eal: store user-provided lcore info in user config struct
eal: clarify docs on params taking lcore IDs
eal: remove internal config reset function
eal: move functions setting runtime state
eal: initialize platform info on first use
eal: remove duplicated scan of sysfs for hugepage details
eal: add utilities for working with user config struct
eal: split EAL init into two stages
eal: provide hooks for init with externally supplied config

 app/test/process.c                        |   4 +-
 app/test/test_argparse.c                  |  10 +
 doc/guides/linux_gsg/eal_args.include.rst |  38 +-
 lib/argparse/rte_argparse.c               |   5 +
 lib/eal/common/eal_common_bus.c           |   4 +-
 lib/eal/common/eal_common_config.c        | 267 ++++++-
 lib/eal/common/eal_common_dynmem.c        |  70 +-
 lib/eal/common/eal_common_fbarray.c       |  10 +-
 lib/eal/common/eal_common_launch.c        |  25 +-
 lib/eal/common/eal_common_lcore.c         | 267 ++++---
 lib/eal/common/eal_common_mcfg.c          |  46 +-
 lib/eal/common/eal_common_memalloc.c      |   5 +-
 lib/eal/common/eal_common_memory.c        | 104 ++-
 lib/eal/common/eal_common_memzone.c       |  24 +-
 lib/eal/common/eal_common_options.c       | 899 ++++++++--------------
 lib/eal/common/eal_common_proc.c          |  10 +-
 lib/eal/common/eal_common_tailqs.c        |   6 +-
 lib/eal/common/eal_common_thread.c        |  67 +-
 lib/eal/common/eal_common_timer.c         |   2 +-
 lib/eal/common/eal_common_trace.c         |  30 +-
 lib/eal/common/eal_common_trace_utils.c   | 104 ---
 lib/eal/common/eal_hugepages.h            |   8 +
 lib/eal/common/eal_internal_cfg.h         | 385 +++++++--
 lib/eal/common/eal_memcfg.h               |   3 +
 lib/eal/common/eal_option_list.h          |   6 +-
 lib/eal/common/eal_options.h              |   8 +-
 lib/eal/common/eal_private.h              | 121 ++-
 lib/eal/common/eal_trace.h                |  11 -
 lib/eal/common/malloc_elem.c              |  15 +-
 lib/eal/common/malloc_heap.c              |  41 +-
 lib/eal/common/malloc_mp.c                |   2 +-
 lib/eal/common/rte_malloc.c               |  14 +-
 lib/eal/common/rte_service.c              |  17 +-
 lib/eal/freebsd/eal.c                     | 291 ++++---
 lib/eal/freebsd/eal_hugepage_info.c       |  78 +-
 lib/eal/freebsd/eal_lcore.c               |  16 +-
 lib/eal/freebsd/eal_memory.c              |  46 +-
 lib/eal/freebsd/include/rte_os.h          |   2 +
 lib/eal/include/rte_eal.h                 |  35 +-
 lib/eal/include/rte_memzone.h             |  10 +-
 lib/eal/include/rte_tailq.h               |   2 +-
 lib/eal/linux/eal.c                       | 297 ++++---
 lib/eal/linux/eal_hugepage_info.c         | 231 +++---
 lib/eal/linux/eal_lcore.c                 |  43 ++
 lib/eal/linux/eal_memalloc.c              | 168 ++--
 lib/eal/linux/eal_memory.c                | 167 ++--
 lib/eal/linux/eal_timer_hpet.c            |  21 +-
 lib/eal/linux/include/rte_os.h            |  10 +
 lib/eal/unix/eal_unix_thread.c            |  11 +-
 lib/eal/windows/eal.c                     | 197 +++--
 lib/eal/windows/eal_hugepages.c           |  60 +-
 lib/eal/windows/eal_lcore.c               |   6 +
 lib/eal/windows/eal_memalloc.c            |  37 +-
 lib/eal/windows/eal_memory.c              |  14 +-
 lib/eal/windows/eal_thread.c              |  11 +-
 lib/eal/windows/eal_windows.h             |   8 -
 lib/eal/windows/include/rte_os.h          |   1 +
 lib/eal/windows/include/sched.h           |  10 +
 lib/telemetry/telemetry.c                 |   4 +-
 lib/telemetry/telemetry_internal.h        |   2 +-
 60 files changed, 2492 insertions(+), 1914 deletions(-)

--
2.55.0

#95 lore raw

PATCH v3 1/39 telemetry: make cpuset init parameter const

The cpuset parameter to telemetry_init is not modified so can be marked as const. This can allow callers to pass the parameter from a const structure rather than a modifiable one.

---
 lib/telemetry/telemetry.c          | 4 ++--
 lib/telemetry/telemetry_internal.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
lib/telemetry/telemetry.c +2 -2
index f5218df4b8..9b7e78dffd 100644
@@ -54,7 +54,7 @@ static struct socket v1_socket; /* socket for v1 telemetry */
 
 static const char *telemetry_version; /* save rte_version */
 static const char *socket_dir;        /* runtime directory */
-static rte_cpuset_t *thread_cpuset;
+static const rte_cpuset_t *thread_cpuset;
 
 RTE_LOG_REGISTER_DEFAULT(logtype, WARNING);
 #define RTE_LOGTYPE_TELEMETRY logtype
@@ -656,7 +656,7 @@ telemetry_v2_init(void)
 
 RTE_EXPORT_INTERNAL_SYMBOL(rte_telemetry_init)
 int32_t
-rte_telemetry_init(const char *runtime_dir, const char *rte_version, rte_cpuset_t *cpuset)
+rte_telemetry_init(const char *runtime_dir, const char *rte_version, const rte_cpuset_t *cpuset)
 {
 	telemetry_version = rte_version;
 	socket_dir = runtime_dir;
lib/telemetry/telemetry_internal.h +1 -1
index 2fd9fbd7c1..4a6b2e9838 100644
@@ -119,6 +119,6 @@ typedef int (*rte_log_fn)(uint32_t level, uint32_t logtype, const char *format,
  */
 __rte_internal
 int
-rte_telemetry_init(const char *runtime_dir, const char *rte_version, rte_cpuset_t *cpuset);
+rte_telemetry_init(const char *runtime_dir, const char *rte_version, const rte_cpuset_t *cpuset);
 
 #endif
Signature · 1 line
2.55.0
#96 lore raw

PATCH v3 2/39 argparse: check for range overflow in CPU lists

In reply to Bruce Richardson

The rte_cpuset_t type cannot handle core ids greater than CPU_SETSIZE Add an explicit check for out of range values when processes a corelist.

Fixes d78103fb9488 ("argparse: support core lists")
---
 app/test/test_argparse.c    | 10 ++++++++++
 lib/argparse/rte_argparse.c |  5 +++++
 2 files changed, 15 insertions(+)
app/test/test_argparse.c +10 -0
index fdc6dd113c..318f8df9fb 100644
@@ -834,9 +834,13 @@ test_argparse_parse_type_corelist(void)
 	char *corelist_invalid_special_chars = test_strdup("1,2@3");
 	char *corelist_invalid_comma_only = test_strdup(",");
 	char *corelist_invalid_out_of_range = test_strdup("70000");
+	char corelist_invalid_cpu_set[32];
 	rte_cpuset_t val_cpuset;
 	int ret;
 
+	snprintf(corelist_invalid_cpu_set, sizeof(corelist_invalid_cpu_set),
+		"0-%d", CPU_SETSIZE);
+
 	/* test valid single core */
 	CPU_ZERO(&val_cpuset);
 	ret = rte_argparse_parse_type(corelist_valid_single,
@@ -966,6 +970,12 @@ test_argparse_parse_type_corelist(void)
 			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
 	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (out of range) should have failed!");
 
+	/* test invalid corelist that exceeds the destination CPU set */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_cpu_set,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist outside CPU set should have failed!");
+
 	return 0;
 }
 
lib/argparse/rte_argparse.c +5 -0
index 88c3e7740c..158c413bdc 100644
@@ -623,6 +623,11 @@ parse_arg_corelist(const struct rte_argparse_arg *arg, const char *value)
 				/* range from low to high */
 				max = idx;
 			}
+			if (max >= CPU_SETSIZE) {
+				ARGPARSE_LOG(ERR, "argument %s contains a core outside the CPU set range!",
+					arg->name_long);
+				return -EINVAL;
+			}
 
 			for (; min <= max; min++)
 				CPU_SET(min, cpuset);
Signature · 1 line
2.55.0
#97 lore raw

PATCH v3 3/39 eal: define new functionally distinct config structs

In reply to Bruce Richardson

Rather than having a generic internal_config structure which mixes system configuration, memory configuration, and user options in one struct, create separate structures for the platform info, system runtime state and the user provided config. Later patches will complete these with data moved from the current location.

---
 lib/eal/common/eal_common_config.c | 31 ++++++++++++++++++++++++++++++
 lib/eal/common/eal_internal_cfg.h  | 28 +++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
lib/eal/common/eal_common_config.c +31 -0
index e2e69a75fb..5427b30659 100644
@@ -5,6 +5,7 @@
 #include <rte_string_fns.h>
 
 #include <eal_export.h>
+#include "eal_internal_cfg.h"
 #include "eal_private.h"
 #include "eal_filesystem.h"
 #include "eal_memcfg.h"
@@ -27,6 +28,15 @@ static struct rte_config rte_config = {
 /* platform-specific runtime dir */
 static char runtime_dir[UNIX_PATH_MAX];
 
+/* user-provided EAL configuration */
+static struct eal_user_cfg eal_user_cfg;
+
+/* platform-discovered and runtime EAL state */
+static struct eal_platform_info eal_platform_info;
+
+/* internal runtime configuration */
+static struct eal_runtime_state eal_runtime_state;
+
 /* internal configuration */
 static struct internal_config internal_config;
 
@@ -63,6 +73,27 @@ eal_get_internal_configuration(void)
 	return &internal_config;
 }
 
+/* Return a pointer to the user configuration structure */
+struct eal_user_cfg *
+eal_get_user_configuration(void)
+{
+	return &eal_user_cfg;
+}
+
+/* Return a pointer to the platform state structure */
+struct eal_platform_info *
+eal_get_platform_info(void)
+{
+	return &eal_platform_info;
+}
+
+/* Return a pointer to the runtime state structure */
+struct eal_runtime_state *
+eal_get_runtime_state(void)
+{
+	return &eal_runtime_state;
+}
+
 RTE_EXPORT_SYMBOL(rte_eal_iova_mode)
 enum rte_iova_mode
 rte_eal_iova_mode(void)
lib/eal/common/eal_internal_cfg.h +28 -0
index 1221e03253..cd24270f02 100644
@@ -54,6 +54,31 @@ struct hugepage_file_discipline {
 	bool unlink_existing;
 };
 
+/**
+ * User-provided EAL initialization configuration.
+ * Immutable after initialization, so no need for atomic types or locks.
+ */
+struct eal_user_cfg {
+	uint8_t reserved;
+};
+
+/**
+ * Discovered information about cores, memory, etc. on the system.
+ * Immutable after initialization, so no need for atomic types or locks.
+ */
+struct eal_platform_info {
+	uint8_t reserved;
+};
+
+/**
+ * Internal EAL runtime state
+ * May be modified at runtime, so access must be protected by locks or atomic types
+ * as appropriate.
+ */
+struct eal_runtime_state {
+	uint8_t reserved;
+};
+
 /**
  * internal configuration
  */
@@ -121,6 +146,9 @@ struct internal_config {
 	unsigned int no_auto_probing; /**< true to switch from block-listing to allow-listing */
 };
 
+struct eal_user_cfg *eal_get_user_configuration(void);
+struct eal_platform_info *eal_get_platform_info(void);
+struct eal_runtime_state *eal_get_runtime_state(void);
 void eal_reset_internal_config(struct internal_config *internal_cfg);
 
 #endif /* EAL_INTERNAL_CFG_H */
Signature · 1 line
2.55.0
#98 lore raw

PATCH v3 4/39 eal: move memory request fields to user config

In reply to Bruce Richardson

Move the basic memory request information supplied by the user from the internal-config to the user config structure in EAL. For the number of channels or ranks of memory, limit the data size to uint8_t rather than having a full 32-bit value per entry.

---
 lib/eal/common/eal_common_dynmem.c  | 11 ++++---
 lib/eal/common/eal_common_memory.c  |  8 ++---
 lib/eal/common/eal_common_options.c | 47 ++++++++++++++++++++++-------
 lib/eal/common/eal_internal_cfg.h   |  8 ++---
 lib/eal/freebsd/eal.c               |  7 +++--
 lib/eal/freebsd/eal_memory.c        | 11 ++++---
 lib/eal/linux/eal.c                 |  5 +--
 lib/eal/linux/eal_memory.c          | 12 ++++----
 lib/eal/windows/eal.c               |  5 +--
 lib/eal/windows/eal_memory.c        |  3 +-
 10 files changed, 74 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_dynmem.c +6 -5
index 063470a28a..4643c13fb0 100644
@@ -378,7 +378,8 @@ eal_dynmem_calc_num_pages_per_socket(
 	uint64_t remaining_mem, cur_mem;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
-	uint64_t total_mem = internal_conf->memory;
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	uint64_t total_mem = user_cfg->memory;
 
 	if (num_hp_info == 0)
 		return -1;
@@ -402,12 +403,12 @@ eal_dynmem_calc_num_pages_per_socket(
 		 * sockets according to number of cores from CPU mask present
 		 * on each socket.
 		 */
-		total_size = internal_conf->memory;
+		total_size = user_cfg->memory;
 		for (socket = 0; socket < RTE_MAX_NUMA_NODES && total_size != 0;
 				socket++) {
 
 			/* Set memory amount per socket */
-			default_size = internal_conf->memory *
+			default_size = user_cfg->memory *
 				cpu_per_socket[socket] / rte_lcore_count();
 
 			/* Limit to maximum available memory on socket */
@@ -438,7 +439,7 @@ eal_dynmem_calc_num_pages_per_socket(
 		/* in 32-bit mode, allocate all of the memory only on main
 		 * lcore socket
 		 */
-		total_size = internal_conf->memory;
+		total_size = user_cfg->memory;
 		for (socket = 0; socket < RTE_MAX_NUMA_NODES && total_size != 0;
 				socket++) {
 			struct rte_config *cfg = rte_eal_get_configuration();
@@ -522,7 +523,7 @@ eal_dynmem_calc_num_pages_per_socket(
 
 	/* if we didn't satisfy total memory requirements */
 	if (total_mem > 0) {
-		requested = internal_conf->memory / 0x100000;
+		requested = user_cfg->memory / 0x100000;
 		available = requested - (total_mem / 0x100000);
 		EAL_LOG(ERR, "Not enough memory available! Requested: %uMB, available: %uMB",
 			requested, available);
lib/eal/common/eal_common_memory.c +4 -4
index 33681e7a37..3caf97963d 100644
@@ -686,15 +686,15 @@ static int
 rte_eal_memdevice_init(void)
 {
 	struct rte_config *config;
-	const struct internal_config *internal_conf;
+	const struct eal_user_cfg *user_cfg;
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
 		return 0;
 
-	internal_conf = eal_get_internal_configuration();
+	user_cfg = eal_get_user_configuration();
 	config = rte_eal_get_configuration();
-	config->mem_config->nchannel = internal_conf->force_nchannel;
-	config->mem_config->nrank = internal_conf->force_nrank;
+	config->mem_config->nchannel = user_cfg->force_nchannel;
+	config->mem_config->nrank = user_cfg->force_nrank;
 
 	return 0;
 }
lib/eal/common/eal_common_options.c +36 -11

89 lines not on this page · raw message

lib/eal/common/eal_internal_cfg.h +4 -4
index cd24270f02..e56014cf73 100644
@@ -13,6 +13,7 @@
 #include <rte_eal.h>
 #include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
+#include <stdint.h>
 
 #include "eal_thread.h"
 
@@ -59,7 +60,9 @@ struct hugepage_file_discipline {
  * Immutable after initialization, so no need for atomic types or locks.
  */
 struct eal_user_cfg {
-	uint8_t reserved;
+	size_t memory;           /**< amount of asked memory */
+	uint8_t force_nchannel;  /**< force number of channels */
+	uint8_t force_nrank;     /**< force number of ranks */
 };
 
 /**
@@ -83,9 +86,6 @@ struct eal_runtime_state {
  * internal configuration
  */
 struct internal_config {
-	volatile size_t memory;           /**< amount of asked memory */
-	volatile unsigned force_nchannel; /**< force number of channels */
-	volatile unsigned force_nrank;    /**< force number of ranks */
 	volatile unsigned no_hugetlbfs;   /**< true to disable hugetlbfs */
 	struct hugepage_file_discipline hugepage_file;
 	volatile unsigned no_pci;         /**< true to disable PCI */
lib/eal/freebsd/eal.c +4 -3
index faf5f0e911..ef48082770 100644
@@ -414,6 +414,7 @@ rte_eal_init(int argc, char **argv)
 	const struct rte_config *config = rte_eal_get_configuration();
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	bool has_phys_addr;
 	enum rte_iova_mode iova_mode;
 
@@ -592,11 +593,11 @@ rte_eal_init(int argc, char **argv)
 		}
 	}
 
-	if (internal_conf->memory == 0 && internal_conf->force_numa == 0) {
+	if (user_cfg->memory == 0 && internal_conf->force_numa == 0) {
 		if (internal_conf->no_hugetlbfs)
-			internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE;
+			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 		else
-			internal_conf->memory = eal_get_hugepage_mem_size();
+			user_cfg->memory = eal_get_hugepage_mem_size();
 	}
 
 	if (internal_conf->vmware_tsc_map == 1) {
lib/eal/freebsd/eal_memory.c +6 -5
index d87e479863..f65089a521 100644
@@ -82,11 +82,12 @@ rte_eal_hugepage_init(void)
 		struct rte_memseg_list *msl;
 		uint64_t mem_sz, page_sz;
 		int n_segs;
+		const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 		/* create a memseg list */
 		msl = &mcfg->memsegs[0];
 
-		mem_sz = internal_conf->memory;
+		mem_sz = user_cfg->memory;
 		page_sz = RTE_PGSIZE_4K;
 		n_segs = mem_sz / page_sz;
 
@@ -121,7 +122,7 @@ rte_eal_hugepage_init(void)
 		hpi = &internal_conf->hugepage_info[i];
 		page_sz = hpi->hugepage_sz;
 		max_pages = hpi->num_pages[0];
-		mem_needed = RTE_ALIGN_CEIL(internal_conf->memory - total_mem,
+		mem_needed = RTE_ALIGN_CEIL(eal_get_user_configuration()->memory - total_mem,
 				page_sz);
 
 		n_pages = RTE_MIN(mem_needed / page_sz, max_pages);
@@ -248,14 +249,14 @@ rte_eal_hugepage_init(void)
 
 			total_mem += seg->len;
 		}
-		if (total_mem >= internal_conf->memory)
+		if (total_mem >= eal_get_user_configuration()->memory)
 			break;
 	}
-	if (total_mem < internal_conf->memory) {
+	if (total_mem < eal_get_user_configuration()->memory) {
 		EAL_LOG(ERR, "Couldn't reserve requested memory, "
 				"requested: %" PRIu64 "M "
 				"available: %" PRIu64 "M",
-				internal_conf->memory >> 20, total_mem >> 20);
+				eal_get_user_configuration()->memory >> 20, total_mem >> 20);
 		return -1;
 	}
 	return 0;
lib/eal/linux/eal.c +3 -2
index 278504237d..e06c356932 100644
@@ -574,6 +574,7 @@ rte_eal_init(int argc, char **argv)
 	const struct rte_config *config = rte_eal_get_configuration();
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* first check if we have been run before */
 	if (!rte_atomic_compare_exchange_strong_explicit(&run_once, &has_run, 1,
@@ -763,9 +764,9 @@ rte_eal_init(int argc, char **argv)
 		}
 	}
 
-	if (internal_conf->memory == 0 && internal_conf->force_numa == 0) {
+	if (user_cfg->memory == 0 && internal_conf->force_numa == 0) {
 		if (internal_conf->no_hugetlbfs)
-			internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE;
+			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 	}
 
 	if (internal_conf->vmware_tsc_map == 1) {
lib/eal/linux/eal_memory.c +6 -6
index 0edf66eea5..4566f2ef4c 100644
@@ -1173,7 +1173,7 @@ eal_legacy_hugepage_init(void)
 		/* create a memseg list */
 		msl = &mcfg->memsegs[0];
 
-		mem_sz = internal_conf->memory;
+		mem_sz = eal_get_user_configuration()->memory;
 		page_sz = RTE_PGSIZE_4K;
 		n_segs = mem_sz / page_sz;
 
@@ -1194,7 +1194,7 @@ eal_legacy_hugepage_init(void)
 			EAL_LOG(DEBUG, "Falling back to anonymous map");
 		} else {
 			/* we got an fd - now resize it */
-			if (ftruncate(memfd, internal_conf->memory) < 0) {
+			if (ftruncate(memfd, eal_get_user_configuration()->memory) < 0) {
 				EAL_LOG(ERR, "Cannot resize memfd: %s",
 						strerror(errno));
 				EAL_LOG(ERR, "Falling back to anonymous map");
@@ -1350,8 +1350,8 @@ eal_legacy_hugepage_init(void)
 
 	huge_recover_sigbus();
 
-	if (internal_conf->memory == 0 && internal_conf->force_numa == 0)
-		internal_conf->memory = eal_get_hugepage_mem_size();
+	if (eal_get_user_configuration()->memory == 0 && internal_conf->force_numa == 0)
+		eal_get_user_configuration()->memory = eal_get_hugepage_mem_size();
 
 	nr_hugefiles = nr_hugepages;
 
@@ -1750,7 +1750,7 @@ memseg_primary_init_32(void)
 			total_requested_mem += mem;
 		}
 	else
-		total_requested_mem = internal_conf->memory;
+		total_requested_mem = eal_get_user_configuration()->memory;
 
 	if (total_requested_mem > mem32_max_mem) {
 		EAL_LOG(ERR, "Invalid parameters: 32-bit process can at most use %uM of memory",
@@ -1814,7 +1814,7 @@ memseg_primary_init_32(void)
 		/* max amount of memory on this socket */
 		max_socket_mem = (active_sockets != 0 ?
 					internal_conf->numa_mem[socket_id] :
-					internal_conf->memory) +
+					eal_get_user_configuration()->memory) +
 					extra_mem_per_socket;
 		cur_socket_mem = 0;
 
lib/eal/windows/eal.c +3 -2
index 7309986910..efbee01757 100644
@@ -166,6 +166,7 @@ rte_eal_init(int argc, char **argv)
 	const struct rte_config *config = rte_eal_get_configuration();
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	bool has_phys_addr;
 	enum rte_iova_mode iova_mode;
 	int ret;
@@ -241,9 +242,9 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	if (internal_conf->memory == 0 && !internal_conf->force_numa) {
+	if (user_cfg->memory == 0 && !internal_conf->force_numa) {
 		if (internal_conf->no_hugetlbfs)
-			internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE;
+			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 	}
 
 	if (rte_eal_intr_init() < 0) {
lib/eal/windows/eal_memory.c +2 -1
index 9f85191016..caaa557694 100644
@@ -680,13 +680,14 @@ eal_nohuge_init(void)
 	mcfg = rte_eal_get_configuration()->mem_config;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* nohuge mode is legacy mode */
 	internal_conf->legacy_mem = 1;
 
 	msl = &mcfg->memsegs[0];
 
-	mem_sz = internal_conf->memory;
+	mem_sz = user_cfg->memory;
 	page_sz = RTE_PGSIZE_4K;
 	n_segs = mem_sz / page_sz;
 
Signature · 1 line
2.55.0
#99 lore raw

PATCH v3 5/39 eal: move NUMA request fields to user config

In reply to Bruce Richardson

As with basic memory user parameters, move the NUMA-specific parameters to the user config struct. Update flag types to bool in the process.

---
 lib/eal/common/eal_common_dynmem.c  | 15 +++++++--------
 lib/eal/common/eal_common_options.c | 24 +++++++++++-------------
 lib/eal/common/eal_internal_cfg.h   | 11 ++++-------
 lib/eal/common/malloc_heap.c        |  2 +-
 lib/eal/freebsd/eal.c               |  2 +-
 lib/eal/linux/eal.c                 |  2 +-
 lib/eal/linux/eal_memory.c          | 23 ++++++++++++-----------
 lib/eal/windows/eal.c               |  2 +-
 8 files changed, 38 insertions(+), 43 deletions(-)
lib/eal/common/eal_common_dynmem.c +7 -8
index 4643c13fb0..a5652ebd5f 100644
@@ -232,6 +232,7 @@ eal_dynmem_hugepage_init(void)
 	int hp_sz_idx, socket_id;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	memset(used_hp, 0, sizeof(used_hp));
 
@@ -268,7 +269,7 @@ eal_dynmem_hugepage_init(void)
 
 	/* make a copy of numa_mem, needed for balanced allocation. */
 	for (hp_sz_idx = 0; hp_sz_idx < RTE_MAX_NUMA_NODES; hp_sz_idx++)
-		memory[hp_sz_idx] = internal_conf->numa_mem[hp_sz_idx];
+		memory[hp_sz_idx] = user_cfg->numa_mem[hp_sz_idx];
 
 	/* calculate final number of pages */
 	if (eal_dynmem_calc_num_pages_per_socket(memory,
@@ -336,10 +337,10 @@ eal_dynmem_hugepage_init(void)
 	}
 
 	/* if socket limits were specified, set them */
-	if (internal_conf->force_numa_limits) {
+	if (user_cfg->force_numa_limits) {
 		unsigned int i;
 		for (i = 0; i < RTE_MAX_NUMA_NODES; i++) {
-			uint64_t limit = internal_conf->numa_limit[i];
+			uint64_t limit = user_cfg->numa_limit[i];
 			if (limit == 0)
 				continue;
 			if (rte_mem_alloc_validator_register("socket-limit",
@@ -376,8 +377,6 @@ eal_dynmem_calc_num_pages_per_socket(
 	unsigned int requested, available;
 	int total_num_pages = 0;
 	uint64_t remaining_mem, cur_mem;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	uint64_t total_mem = user_cfg->memory;
 
@@ -385,7 +384,7 @@ eal_dynmem_calc_num_pages_per_socket(
 		return -1;
 
 	/* if specific memory amounts per socket weren't requested */
-	if (internal_conf->force_numa == 0) {
+	if (!user_cfg->force_numa) {
 		size_t total_size;
 #ifdef RTE_ARCH_64
 		int cpu_per_socket[RTE_MAX_NUMA_NODES];
@@ -512,8 +511,8 @@ eal_dynmem_calc_num_pages_per_socket(
 
 		/* if we didn't satisfy all memory requirements per socket */
 		if (memory[socket] > 0 &&
-				internal_conf->numa_mem[socket] != 0) {
-			requested = internal_conf->numa_mem[socket] / 0x100000;
+				user_cfg->numa_mem[socket] != 0) {
+			requested = user_cfg->numa_mem[socket] / 0x100000;
 			available = requested - (memory[socket] / 0x100000);
 			EAL_LOG(ERR, "Not enough memory available on socket %u! Requested: %uMB, available: %uMB",
 				socket, requested, available);
lib/eal/common/eal_common_options.c +11 -13
index 31c58004cc..57c2bfc180 100644
@@ -515,18 +515,16 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 	user_cfg->memory = 0;
 	user_cfg->force_nrank = 0;
 	user_cfg->force_nchannel = 0;
+	user_cfg->force_numa = false;
+	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
+		user_cfg->numa_mem[i] = 0;
+	user_cfg->force_numa_limits = false;
+	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
+		user_cfg->numa_limit[i] = 0;
 	internal_cfg->hugefile_prefix = NULL;
 	internal_cfg->hugepage_dir = NULL;
 	internal_cfg->hugepage_file.unlink_before_mapping = false;
 	internal_cfg->hugepage_file.unlink_existing = true;
-	internal_cfg->force_numa = 0;
-	/* zero out the NUMA config */
-	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
-		internal_cfg->numa_mem[i] = 0;
-	internal_cfg->force_numa_limits = 0;
-	/* zero out the NUMA limits config */
-	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
-		internal_cfg->numa_limit[i] = 0;
 	/* zero out hugedir descriptors */
 	for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
 		memset(&internal_cfg->hugepage_info[i], 0,
@@ -2306,18 +2304,18 @@ eal_parse_args(void)
 		}
 	}
 	if (args.numa_mem != NULL) {
-		if (eal_parse_socket_arg(args.numa_mem, int_cfg->numa_mem) < 0) {
+		if (eal_parse_socket_arg(args.numa_mem, user_cfg->numa_mem) < 0) {
 			EAL_LOG(ERR, "invalid numa-mem parameter: '%s'", args.numa_mem);
 			return -1;
 		}
-		int_cfg->force_numa = 1;
+		user_cfg->force_numa = true;
 	}
 	if (args.numa_limit != NULL) {
-		if (eal_parse_socket_arg(args.numa_limit, int_cfg->numa_limit) < 0) {
+		if (eal_parse_socket_arg(args.numa_limit, user_cfg->numa_limit) < 0) {
 			EAL_LOG(ERR, "invalid numa-limit parameter: '%s'", args.numa_limit);
 			return -1;
 		}
-		int_cfg->force_numa_limits = 1;
+		user_cfg->force_numa_limits = true;
 	}
 	TAILQ_FOREACH(arg, &args.pagesz_mem, next) {
 		if (eal_parse_pagesz_mem(arg->arg, int_cfg) < 0) {
@@ -2509,7 +2507,7 @@ eal_adjust_config(struct internal_config *internal_cfg)
 	/* if no memory amounts were requested, this will result in 0 and
 	 * will be overridden later, right after eal_hugepage_info_init() */
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
-		user_cfg->memory += internal_cfg->numa_mem[i];
+		user_cfg->memory += user_cfg->numa_mem[i];
 
 	return 0;
 }
lib/eal/common/eal_internal_cfg.h +4 -7
index e56014cf73..fe67bb95e1 100644
@@ -63,6 +63,10 @@ struct eal_user_cfg {
 	size_t memory;           /**< amount of asked memory */
 	uint8_t force_nchannel;  /**< force number of channels */
 	uint8_t force_nrank;     /**< force number of ranks */
+	bool force_numa;         /**< true to request memory on specific NUMA nodes */
+	bool force_numa_limits;  /**< true to apply per-NUMA memory limits */
+	uint64_t numa_mem[RTE_MAX_NUMA_NODES];    /**< amount of memory per NUMA node */
+	uint64_t numa_limit[RTE_MAX_NUMA_NODES];  /**< limit amount of memory per NUMA node */
 };
 
 /**
@@ -99,13 +103,6 @@ struct internal_config {
 	 */
 	volatile unsigned create_uio_dev; /**< true to create /dev/uioX devices */
 	volatile enum rte_proc_type_t process_type; /**< multi-process proc type */
-	/** true to try allocating memory on specific NUMA nodes */
-	volatile unsigned force_numa;
-	/** amount of memory per NUMA node */
-	volatile uint64_t numa_mem[RTE_MAX_NUMA_NODES];
-	volatile unsigned force_numa_limits;
-	/** limit amount of memory per NUMA node */
-	volatile uint64_t numa_limit[RTE_MAX_NUMA_NODES];
 	uintptr_t base_virtaddr;          /**< base address to try and reserve memory from */
 	volatile unsigned legacy_mem;
 	/**< true to enable legacy memory behavior (no dynamic allocation,
lib/eal/common/malloc_heap.c +1 -1
index 39240c261c..77f364158a 100644
@@ -701,7 +701,7 @@ malloc_heap_alloc_on_heap_id(size_t size, unsigned int heap_id, unsigned int fla
 static unsigned int
 malloc_get_numa_socket(void)
 {
-	const struct internal_config *conf = eal_get_internal_configuration();
+	const struct eal_user_cfg *conf = eal_get_user_configuration();
 	unsigned int socket_id = rte_socket_id();
 	unsigned int idx;
 
lib/eal/freebsd/eal.c +1 -1
index ef48082770..9e027405ca 100644
@@ -593,7 +593,7 @@ rte_eal_init(int argc, char **argv)
 		}
 	}
 
-	if (user_cfg->memory == 0 && internal_conf->force_numa == 0) {
+	if (user_cfg->memory == 0 && !user_cfg->force_numa) {
 		if (internal_conf->no_hugetlbfs)
 			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 		else
lib/eal/linux/eal.c +1 -1
index e06c356932..dc252cab37 100644
@@ -764,7 +764,7 @@ rte_eal_init(int argc, char **argv)
 		}
 	}
 
-	if (user_cfg->memory == 0 && internal_conf->force_numa == 0) {
+	if (user_cfg->memory == 0 && !user_cfg->force_numa) {
 		if (internal_conf->no_hugetlbfs)
 			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 	}
lib/eal/linux/eal_memory.c +12 -11
index 4566f2ef4c..df4df5be8d 100644
@@ -274,8 +274,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 	struct bitmask *oldmask = NULL;
 	bool have_numa = true;
 	unsigned long maxnode = 0;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* Check if kernel supports NUMA. */
 	if (numa_available() != 0) {
@@ -294,7 +293,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 			oldpolicy = MPOL_DEFAULT;
 		}
 		for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
-			if (internal_conf->numa_mem[i])
+			if (user_cfg->numa_mem[i])
 				maxnode = i + 1;
 	}
 #endif
@@ -313,7 +312,7 @@ map_all_hugepages(struct hugepage_file *hugepg_tbl, struct hugepage_info *hpi,
 
 			if (j == maxnode) {
 				node_id = (node_id + 1) % maxnode;
-				while (!internal_conf->numa_mem[node_id]) {
+				while (!user_cfg->numa_mem[node_id]) {
 					node_id++;
 					node_id %= maxnode;
 				}
@@ -1142,6 +1141,7 @@ eal_legacy_hugepage_init(void)
 	struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	uint64_t memory[RTE_MAX_NUMA_NODES];
 
@@ -1282,7 +1282,7 @@ eal_legacy_hugepage_init(void)
 
 	/* make a copy of numa_mem, needed for balanced allocation. */
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
-		memory[i] = internal_conf->numa_mem[i];
+		memory[i] = user_cfg->numa_mem[i];
 
 	/* map all hugepages and sort them */
 	for (i = 0; i < (int)internal_conf->num_hugepage_sizes; i++) {
@@ -1350,7 +1350,7 @@ eal_legacy_hugepage_init(void)
 
 	huge_recover_sigbus();
 
-	if (eal_get_user_configuration()->memory == 0 && internal_conf->force_numa == 0)
+	if (eal_get_user_configuration()->memory == 0 && !user_cfg->force_numa)
 		eal_get_user_configuration()->memory = eal_get_hugepage_mem_size();
 
 	nr_hugefiles = nr_hugepages;
@@ -1378,7 +1378,7 @@ eal_legacy_hugepage_init(void)
 
 	/* make a copy of numa_mem, needed for number of pages calculation */
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
-		memory[i] = internal_conf->numa_mem[i];
+		memory[i] = user_cfg->numa_mem[i];
 
 	/* calculate final number of pages */
 	nr_hugepages = eal_dynmem_calc_num_pages_per_socket(memory,
@@ -1712,6 +1712,7 @@ memseg_primary_init_32(void)
 	uint64_t extra_mem_per_socket, total_extra_mem, total_requested_mem;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* no-huge does not need this at all */
 	if (internal_conf->no_hugetlbfs)
@@ -1736,12 +1737,12 @@ memseg_primary_init_32(void)
 	 */
 	active_sockets = 0;
 	total_requested_mem = 0;
-	if (internal_conf->force_numa)
+	if (user_cfg->force_numa)
 		for (i = 0; i < rte_socket_count(); i++) {
 			uint64_t mem;
 
 			socket_id = rte_socket_id_by_idx(i);
-			mem = internal_conf->numa_mem[socket_id];
+			mem = user_cfg->numa_mem[socket_id];
 
 			if (mem == 0)
 				continue;
@@ -1798,7 +1799,7 @@ memseg_primary_init_32(void)
 
 		/* if we didn't specifically request memory on this socket */
 		skip = active_sockets != 0 &&
-				internal_conf->numa_mem[socket_id] == 0;
+				user_cfg->numa_mem[socket_id] == 0;
 		/* ...or if we didn't specifically request memory on *any*
 		 * socket, and this is not main lcore
 		 */
@@ -1813,7 +1814,7 @@ memseg_primary_init_32(void)
 
 		/* max amount of memory on this socket */
 		max_socket_mem = (active_sockets != 0 ?
-					internal_conf->numa_mem[socket_id] :
+					user_cfg->numa_mem[socket_id] :
 					eal_get_user_configuration()->memory) +
 					extra_mem_per_socket;
 		cur_socket_mem = 0;
lib/eal/windows/eal.c +1 -1
index efbee01757..d8c9fa26e3 100644
@@ -242,7 +242,7 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	if (user_cfg->memory == 0 && !internal_conf->force_numa) {
+	if (user_cfg->memory == 0 && !user_cfg->force_numa) {
 		if (internal_conf->no_hugetlbfs)
 			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 	}
Signature · 1 line
2.55.0
#100 lore raw

PATCH v3 6/39 eal: move hugepage policy fields to user config

In reply to Bruce Richardson

Continue moving fields from the internal config to the user config, in this case the hugepage policy fields. As with previous fields, any flags are adjusted from unsigned to boolean.

---
 lib/eal/common/eal_common_config.c  |  2 +-
 lib/eal/common/eal_common_dynmem.c  |  3 ++-
 lib/eal/common/eal_common_options.c | 39 +++++++++++++++--------------
 lib/eal/common/eal_internal_cfg.h   |  9 ++++---
 lib/eal/freebsd/eal.c               |  6 ++---
 lib/eal/freebsd/eal_memory.c        |  9 ++++---
 lib/eal/linux/eal.c                 |  7 +++---
 lib/eal/linux/eal_hugepage_info.c   | 12 ++++-----
 lib/eal/linux/eal_memalloc.c        | 25 ++++++++++--------
 lib/eal/linux/eal_memory.c          | 13 +++++-----
 lib/eal/windows/eal.c               |  6 ++---
 lib/eal/windows/eal_memory.c        |  5 ++--
 12 files changed, 71 insertions(+), 65 deletions(-)
lib/eal/common/eal_common_config.c +1 -1
index 5427b30659..4ebf938f31 100644
@@ -131,7 +131,7 @@ RTE_EXPORT_SYMBOL(rte_eal_has_hugepages)
 int
 rte_eal_has_hugepages(void)
 {
-	return !internal_config.no_hugetlbfs;
+	return !eal_user_cfg.no_hugetlbfs;
 }
 
 RTE_EXPORT_SYMBOL(rte_eal_has_pci)
lib/eal/common/eal_common_dynmem.c +2 -1
index a5652ebd5f..97f8a05b30 100644
@@ -36,9 +36,10 @@ eal_dynmem_memseg_lists_init(void)
 	void *mem_va_addr = NULL;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* no-huge does not need this at all */
-	if (internal_conf->no_hugetlbfs)
+	if (user_cfg->no_hugetlbfs)
 		return 0;
 
 	/*
lib/eal/common/eal_common_options.c +20 -19
index 57c2bfc180..133175c068 100644
@@ -3,6 +3,7 @@
  * Copyright(c) 2014 6WIND S.A.
  */
 
+#include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
@@ -498,11 +499,10 @@ eal_option_device_parse(void)
 const char *
 eal_get_hugefile_prefix(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	if (internal_conf->hugefile_prefix != NULL)
-		return internal_conf->hugefile_prefix;
+	if (user_cfg->hugefile_prefix != NULL)
+		return user_cfg->hugefile_prefix;
 	return HUGEFILE_PREFIX_DEFAULT;
 }
 
@@ -521,10 +521,11 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 	user_cfg->force_numa_limits = false;
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
 		user_cfg->numa_limit[i] = 0;
-	internal_cfg->hugefile_prefix = NULL;
-	internal_cfg->hugepage_dir = NULL;
-	internal_cfg->hugepage_file.unlink_before_mapping = false;
-	internal_cfg->hugepage_file.unlink_existing = true;
+	user_cfg->no_hugetlbfs = false;
+	user_cfg->hugefile_prefix = NULL;
+	user_cfg->hugepage_dir = NULL;
+	user_cfg->hugepage_file.unlink_before_mapping = false;
+	user_cfg->hugepage_file.unlink_existing = true;
 	/* zero out hugedir descriptors */
 	for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
 		memset(&internal_cfg->hugepage_info[i], 0,
@@ -2250,7 +2251,7 @@ eal_parse_args(void)
 		user_cfg->force_nrank = (uint8_t)nrank;
 	}
 	if (args.no_huge) {
-		int_cfg->no_hugetlbfs = 1;
+		user_cfg->no_hugetlbfs = true;
 		/* no-huge is legacy mem */
 		int_cfg->legacy_mem = 1;
 	}
@@ -2258,7 +2259,7 @@ eal_parse_args(void)
 		int_cfg->in_memory = 1;
 		/* in-memory is a superset of noshconf and huge-unlink */
 		int_cfg->no_shconf = 1;
-		int_cfg->hugepage_file.unlink_before_mapping = true;
+		user_cfg->hugepage_file.unlink_before_mapping = true;
 	}
 	if (args.legacy_mem) {
 		int_cfg->legacy_mem = 1;
@@ -2272,9 +2273,9 @@ eal_parse_args(void)
 			EAL_LOG(ERR, "Invalid hugepage dir parameter");
 			return -1;
 		}
-		free(int_cfg->hugepage_dir);  /* free old hugepage dir */
-		int_cfg->hugepage_dir = strdup(args.huge_dir);
-		if (int_cfg->hugepage_dir == NULL) {
+		free(user_cfg->hugepage_dir);  /* free old hugepage dir */
+		user_cfg->hugepage_dir = strdup(args.huge_dir);
+		if (user_cfg->hugepage_dir == NULL) {
 			EAL_LOG(ERR, "failed to allocate memory for hugepage dir parameter");
 			return -1;
 		}
@@ -2288,9 +2289,9 @@ eal_parse_args(void)
 			EAL_LOG(ERR, "Invalid char, '%%', in file_prefix parameter");
 			return -1;
 		}
-		free(int_cfg->hugefile_prefix);  /* free old file prefix */
-		int_cfg->hugefile_prefix = strdup(args.file_prefix);
-		if (int_cfg->hugefile_prefix == NULL) {
+		free(user_cfg->hugefile_prefix);  /* free old file prefix */
+		user_cfg->hugefile_prefix = strdup(args.file_prefix);
+		if (user_cfg->hugefile_prefix == NULL) {
 			EAL_LOG(ERR, "failed to allocate memory for file prefix parameter");
 			return -1;
 		}
@@ -2298,7 +2299,7 @@ eal_parse_args(void)
 	if (args.huge_unlink != NULL) {
 		if (args.huge_unlink == (void *)1)
 			args.huge_unlink = NULL;
-		if (eal_parse_huge_unlink(args.huge_unlink, &int_cfg->hugepage_file) < 0) {
+		if (eal_parse_huge_unlink(args.huge_unlink, &user_cfg->hugepage_file) < 0) {
 			EAL_LOG(ERR, "invalid huge-unlink parameter");
 			return -1;
 		}
@@ -2486,8 +2487,8 @@ compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
 int
 eal_cleanup_config(struct internal_config *internal_cfg)
 {
-	free(internal_cfg->hugefile_prefix);
-	free(internal_cfg->hugepage_dir);
+	free(eal_get_user_configuration()->hugefile_prefix);
+	free(eal_get_user_configuration()->hugepage_dir);
 	free(internal_cfg->user_mbuf_pool_ops_name);
 
 	return 0;
lib/eal/common/eal_internal_cfg.h +5 -4
index fe67bb95e1..bf7d6792d2 100644
@@ -14,6 +14,7 @@
 #include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
 #include <stdint.h>
+#include <stdbool.h>
 
 #include "eal_thread.h"
 
@@ -65,6 +66,10 @@ struct eal_user_cfg {
 	uint8_t force_nrank;     /**< force number of ranks */
 	bool force_numa;         /**< true to request memory on specific NUMA nodes */
 	bool force_numa_limits;  /**< true to apply per-NUMA memory limits */
+	bool no_hugetlbfs;       /**< true to disable hugetlbfs */
+	struct hugepage_file_discipline hugepage_file;
+	char *hugefile_prefix;   /**< the base filename of hugetlbfs files */
+	char *hugepage_dir;      /**< specific hugetlbfs directory to use */
 	uint64_t numa_mem[RTE_MAX_NUMA_NODES];    /**< amount of memory per NUMA node */
 	uint64_t numa_limit[RTE_MAX_NUMA_NODES];  /**< limit amount of memory per NUMA node */
 };
@@ -90,8 +95,6 @@ struct eal_runtime_state {
  * internal configuration
  */
 struct internal_config {
-	volatile unsigned no_hugetlbfs;   /**< true to disable hugetlbfs */
-	struct hugepage_file_discipline hugepage_file;
 	volatile unsigned no_pci;         /**< true to disable PCI */
 	volatile unsigned no_hpet;        /**< true to disable HPET */
 	volatile unsigned vmware_tsc_map; /**< true to use VMware TSC mapping
@@ -118,8 +121,6 @@ struct internal_config {
 	volatile enum rte_intr_mode vfio_intr_mode;
 	/** the shared VF token for VFIO-PCI bound PF and VFs devices */
 	rte_uuid_t vfio_vf_token;
-	char *hugefile_prefix;      /**< the base filename of hugetlbfs files */
-	char *hugepage_dir;         /**< specific hugetlbfs directory to use */
 	char *user_mbuf_pool_ops_name;
 			/**< user defined mbuf pool ops name */
 	unsigned num_hugepage_sizes;      /**< how many sizes on this system */
lib/eal/freebsd/eal.c +3 -3
index 9e027405ca..500135e5ac 100644
@@ -535,7 +535,7 @@ rte_eal_init(int argc, char **argv)
 	 * If contigmem is inaccessible, rte_eal_hugepage_init() will fail
 	 * with a message describing the cause.
 	 */
-	has_phys_addr = internal_conf->no_hugetlbfs == 0;
+	has_phys_addr = !user_cfg->no_hugetlbfs;
 
 	/* Always call rte_bus_get_iommu_class() to trigger DMA mask detection and validation */
 	enum rte_iova_mode bus_iova_mode = rte_bus_get_iommu_class();
@@ -575,7 +575,7 @@ rte_eal_init(int argc, char **argv)
 	EAL_LOG(INFO, "Selected IOVA mode '%s'",
 		rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
 
-	if (internal_conf->no_hugetlbfs == 0) {
+	if (!user_cfg->no_hugetlbfs) {
 		/* rte_config isn't initialized yet */
 		ret = internal_conf->process_type == RTE_PROC_PRIMARY ?
 			eal_hugepage_info_init() :
@@ -594,7 +594,7 @@ rte_eal_init(int argc, char **argv)
 	}
 
 	if (user_cfg->memory == 0 && !user_cfg->force_numa) {
-		if (internal_conf->no_hugetlbfs)
+		if (user_cfg->no_hugetlbfs)
 			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 		else
 			user_cfg->memory = eal_get_hugepage_mem_size();
lib/eal/freebsd/eal_memory.c +5 -4
index f65089a521..01bec37f3c 100644
@@ -73,16 +73,16 @@ rte_eal_hugepage_init(void)
 	unsigned int i, j, seg_idx = 0;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* get pointer to global configuration */
 	mcfg = rte_eal_get_configuration()->mem_config;
 
 	/* for debug purposes, hugetlbfs can be disabled */
-	if (internal_conf->no_hugetlbfs) {
+	if (user_cfg->no_hugetlbfs) {
 		struct rte_memseg_list *msl;
 		uint64_t mem_sz, page_sz;
 		int n_segs;
-		const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 		/* create a memseg list */
 		msl = &mcfg->memsegs[0];
@@ -122,7 +122,7 @@ rte_eal_hugepage_init(void)
 		hpi = &internal_conf->hugepage_info[i];
 		page_sz = hpi->hugepage_sz;
 		max_pages = hpi->num_pages[0];
-		mem_needed = RTE_ALIGN_CEIL(eal_get_user_configuration()->memory - total_mem,
+		mem_needed = RTE_ALIGN_CEIL(user_cfg->memory - total_mem,
 				page_sz);
 
 		n_pages = RTE_MIN(mem_needed / page_sz, max_pages);
@@ -359,9 +359,10 @@ memseg_primary_init(void)
 	struct rte_memseg_list *msl;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* no-huge does not need this at all */
-	if (internal_conf->no_hugetlbfs)
+	if (user_cfg->no_hugetlbfs)
 		return 0;
 
 	/* FreeBSD has an issue where core dump will dump the entire memory
lib/eal/linux/eal.c +4 -3
index dc252cab37..9b52ef262d 100644
@@ -746,7 +746,7 @@ rte_eal_init(int argc, char **argv)
 	EAL_LOG(INFO, "Selected IOVA mode '%s'",
 		rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
 
-	if (internal_conf->no_hugetlbfs == 0) {
+	if (!user_cfg->no_hugetlbfs) {
 		/* rte_config isn't initialized yet */
 		ret = internal_conf->process_type == RTE_PROC_PRIMARY ?
 				eal_hugepage_info_init() :
@@ -765,7 +765,7 @@ rte_eal_init(int argc, char **argv)
 	}
 
 	if (user_cfg->memory == 0 && !user_cfg->force_numa) {
-		if (internal_conf->no_hugetlbfs)
+		if (user_cfg->no_hugetlbfs)
 			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 	}
 
@@ -989,9 +989,10 @@ rte_eal_cleanup(void)
 	 */
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
-			internal_conf->hugepage_file.unlink_existing)
+			user_cfg->hugepage_file.unlink_existing)
 		rte_memseg_walk(mark_freeable, NULL);
 
 	rte_service_finalize();
lib/eal/linux/eal_hugepage_info.c +6 -6
index 05c5b3f613..2f889b291e 100644
@@ -215,22 +215,21 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len)
 	static uint64_t default_size = 0;
 	const char pagesize_opt[] = "pagesize=";
 	const size_t pagesize_opt_len = sizeof(pagesize_opt) - 1;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct mntent *mnt;
 	FILE *fp;
 
 	/* Fast path: hugepage_dir explicitly specified */
-	if (internal_conf->hugepage_dir != NULL) {
+	if (user_cfg->hugepage_dir != NULL) {
 		struct statfs sfs;
 
 		/* Query info about mounted filesystem */
-		if (statfs(internal_conf->hugepage_dir, &sfs) != 0 ||
+		if (statfs(user_cfg->hugepage_dir, &sfs) != 0 ||
 				(uint32_t)sfs.f_type != HUGETLBFS_MAGIC ||
 				(uint64_t)sfs.f_bsize != hugepage_sz)
 			return -1;
 
-		strlcpy(hugedir, internal_conf->hugepage_dir, len);
+		strlcpy(hugedir, user_cfg->hugepage_dir, len);
 		return 0;
 	}
 
@@ -457,6 +456,7 @@ hugepage_info_init(void)
 	struct dirent *dirent;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	dir = opendir(sys_dir_path);
 	if (dir == NULL) {
@@ -527,7 +527,7 @@ hugepage_info_init(void)
 		 * or count how many of them can be reused.
 		 */
 		reusable_pages = 0;
-		if (!internal_conf->hugepage_file.unlink_existing) {
+		if (!user_cfg->hugepage_file.unlink_existing) {
 			reusable_bytes = 0;
 			if (inspect_hugedir(hpi->hugedir,
 					&reusable_bytes) < 0)
lib/eal/linux/eal_memalloc.c +14 -11
index 8bfcbb1469..4ac5c14668 100644
@@ -268,6 +268,7 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 	int ret;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (dirty != NULL)
 		*dirty = false;
@@ -306,7 +307,7 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 			__func__, path, strerror(errno));
 		return -1;
 	}
-	if (!internal_conf->hugepage_file.unlink_existing && ret == 0 &&
+	if (!user_cfg->hugepage_file.unlink_existing && ret == 0 &&
 			dirty != NULL)
 		*dirty = true;
 
@@ -323,7 +324,7 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 	 * whether they will be dirty depends on the part that is mapped.
 	 */
 	if (!internal_conf->single_file_segments &&
-			internal_conf->hugepage_file.unlink_existing &&
+			user_cfg->hugepage_file.unlink_existing &&
 			rte_eal_process_type() == RTE_PROC_PRIMARY &&
 			ret == 0) {
 		/* coverity[toctou] */
@@ -376,8 +377,7 @@ static int
 resize_hugefile_in_filesystem(int fd, uint64_t fa_offset, uint64_t page_sz,
 		bool grow, bool *dirty)
 {
-	const struct internal_config *internal_conf =
-			eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	bool again = false;
 
 	do {
@@ -449,7 +449,7 @@ resize_hugefile_in_filesystem(int fd, uint64_t fa_offset, uint64_t page_sz,
 				 * dirty, unless the file is a fresh one.
 				 */
 				if (dirty != NULL)
-					*dirty &= !internal_conf->hugepage_file.unlink_existing;
+					*dirty &= !user_cfg->hugepage_file.unlink_existing;
 			}
 		}
 	} while (again);
@@ -517,6 +517,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 	void *new_addr;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	alloc_sz = hi->hugepage_sz;
 
@@ -549,7 +550,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 			EAL_LOG(DEBUG, "%s(): ftruncate() failed: %s", __func__, strerror(errno));
 			goto resized;
 		}
-		if (internal_conf->hugepage_file.unlink_before_mapping &&
+		if (user_cfg->hugepage_file.unlink_before_mapping &&
 				!internal_conf->in_memory) {
 			if (unlink(path)) {
 				EAL_LOG(DEBUG, "%s(): unlink() failed: %s",
@@ -683,7 +684,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 			close_hugefile(fd, path, list_idx);
 	} else {
 		/* only remove file if we can take out a write lock */
-		if (!internal_conf->hugepage_file.unlink_before_mapping &&
+		if (!user_cfg->hugepage_file.unlink_before_mapping &&
 				internal_conf->in_memory == 0 &&
 				lock(fd, LOCK_EX) == 1)
 			unlink(path);
@@ -702,6 +703,7 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
 	int fd, ret = 0;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* erase page data */
 	memset(ms->addr, 0, ms->len);
@@ -737,8 +739,8 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
 		 * holding onto this page.
 		 */
 		if (!internal_conf->in_memory &&
-				internal_conf->hugepage_file.unlink_existing &&
-				!internal_conf->hugepage_file.unlink_before_mapping) {
+				user_cfg->hugepage_file.unlink_existing &&
+				!user_cfg->hugepage_file.unlink_before_mapping) {
 			ret = lock(fd, LOCK_EX);
 			if (ret >= 0) {
 				/* no one else is using this page */
@@ -1663,6 +1665,7 @@ eal_memalloc_init(void)
 {
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
 		/*  memory_hotplug_lock is held during initialization, so it's
@@ -1679,8 +1682,8 @@ eal_memalloc_init(void)
 			return -1;
 		}
 		/* safety net, should be impossible to configure */
-		if (internal_conf->hugepage_file.unlink_before_mapping &&
-				!internal_conf->hugepage_file.unlink_existing) {
+		if (user_cfg->hugepage_file.unlink_before_mapping &&
+				!user_cfg->hugepage_file.unlink_existing) {
 			EAL_LOG(ERR, "Unlinking existing hugepage files is prohibited, cannot unlink them before mapping.");
 			return -1;
 		}
lib/eal/linux/eal_memory.c +6 -7
index df4df5be8d..3816ddf8c5 100644
@@ -683,6 +683,7 @@ static int
 remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct rte_memseg_list *msl;
 	struct rte_fbarray *arr;
 	int cur_page, seg_len;
@@ -691,9 +692,7 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
 	uint64_t page_sz;
 	size_t memseg_len;
 	int socket_id;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
-	const bool dirty = !internal_conf->hugepage_file.unlink_existing;
+	const bool dirty = !user_cfg->hugepage_file.unlink_existing;
 
 	page_sz = hugepages[seg_start].size;
 	socket_id = hugepages[seg_start].socket_id;
@@ -794,7 +793,7 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
 		/* we have a new address, so unmap previous one */
 #ifndef RTE_ARCH_64
 		/* in 32-bit legacy mode, we have already unmapped the page */
-		if (!internal_conf->legacy_mem)
+		if (!eal_get_internal_configuration()->legacy_mem)
 			munmap(hfile->orig_va, page_sz);
 #else
 		munmap(hfile->orig_va, page_sz);
@@ -1156,7 +1155,7 @@ eal_legacy_hugepage_init(void)
 	mcfg = rte_eal_get_configuration()->mem_config;
 
 	/* hugetlbfs can be disabled */
-	if (internal_conf->no_hugetlbfs) {
+	if (user_cfg->no_hugetlbfs) {
 		void *prealloc_addr;
 		size_t mem_sz;
 		struct rte_memseg_list *msl;
@@ -1453,7 +1452,7 @@ eal_legacy_hugepage_init(void)
 	}
 
 	/* free the hugepage backing files */
-	if (internal_conf->hugepage_file.unlink_before_mapping &&
+	if (user_cfg->hugepage_file.unlink_before_mapping &&
 		unlink_hugepage_files(tmp_hp, internal_conf->num_hugepage_sizes) < 0) {
 		EAL_LOG(ERR, "Unlinking hugepage files failed!");
 		goto fail;
@@ -1715,7 +1714,7 @@ memseg_primary_init_32(void)
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* no-huge does not need this at all */
-	if (internal_conf->no_hugetlbfs)
+	if (user_cfg->no_hugetlbfs)
 		return 0;
 
 	/* this is a giant hack, but desperate times call for desperate
lib/eal/windows/eal.c +3 -3
index d8c9fa26e3..5f10e1f0eb 100644
@@ -230,12 +230,12 @@ rte_eal_init(int argc, char **argv)
 		internal_conf->no_shconf = 1;
 	}
 
-	if (!internal_conf->no_hugetlbfs && (eal_hugepage_info_init() < 0)) {
+	if (!user_cfg->no_hugetlbfs && (eal_hugepage_info_init() < 0)) {
 		rte_eal_init_alert("Cannot get hugepage information");
 		rte_errno = EACCES;
 		goto err_out;
 	}
-	if (!internal_conf->no_hugetlbfs &&
+	if (!user_cfg->no_hugetlbfs &&
 			eal_apply_hugepage_mem_sz_limits(internal_conf) < 0) {
 		rte_eal_init_alert("Cannot apply hugepage memory limits");
 		rte_errno = EINVAL;
@@ -243,7 +243,7 @@ rte_eal_init(int argc, char **argv)
 	}
 
 	if (user_cfg->memory == 0 && !user_cfg->force_numa) {
-		if (internal_conf->no_hugetlbfs)
+		if (user_cfg->no_hugetlbfs)
 			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 	}
 
lib/eal/windows/eal_memory.c +2 -3
index caaa557694..3140d7b9c3 100644
@@ -723,10 +723,9 @@ eal_nohuge_init(void)
 int
 rte_eal_hugepage_init(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	return internal_conf->no_hugetlbfs ?
+	return user_cfg->no_hugetlbfs ?
 		eal_nohuge_init() : eal_dynmem_hugepage_init();
 }
 
Signature · 1 line
2.55.0
#101 lore raw

PATCH v3 7/39 eal: move process policy fields to user config

In reply to Bruce Richardson

Move process/runtime policy request fields from internal_config into eal_user_cfg, updating flag types to bool in the process.

---
 lib/eal/common/eal_common_config.c  |  2 +-
 lib/eal/common/eal_common_fbarray.c | 10 +++---
 lib/eal/common/eal_common_mcfg.c    |  3 +-
 lib/eal/common/eal_common_memory.c  | 12 +++-----
 lib/eal/common/eal_common_options.c | 47 ++++++++++++++++-------------
 lib/eal/common/eal_internal_cfg.h   | 20 +++++-------
 lib/eal/freebsd/eal.c               | 42 ++++++++++++--------------
 lib/eal/freebsd/eal_hugepage_info.c |  3 +-
 lib/eal/linux/eal.c                 | 38 +++++++++++------------
 lib/eal/linux/eal_hugepage_info.c   |  5 +--
 lib/eal/linux/eal_memalloc.c        | 37 +++++++++--------------
 lib/eal/linux/eal_memory.c          |  5 ++-
 lib/eal/linux/eal_timer_hpet.c      | 21 ++++++-------
 lib/eal/windows/eal.c               |  6 ++--
 14 files changed, 116 insertions(+), 135 deletions(-)
lib/eal/common/eal_common_config.c +1 -1
index 4ebf938f31..5efc6623d6 100644
@@ -138,5 +138,5 @@ RTE_EXPORT_SYMBOL(rte_eal_has_pci)
 int
 rte_eal_has_pci(void)
 {
-	return !internal_config.no_pci;
+	return !eal_user_cfg.no_pci;
 }
lib/eal/common/eal_common_fbarray.c +4 -6
index 834e3d7ef0..80ae7c1e31 100644
@@ -697,8 +697,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
 	struct mem_area *ma = NULL;
 	void *data = NULL;
 	int fd = -1;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (arr == NULL) {
 		rte_errno = EINVAL;
@@ -734,7 +733,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len,
 
 	fd = -1;
 
-	if (internal_conf->no_shconf) {
+	if (user_cfg->no_shconf) {
 		/* remap virtual area as writable */
 		static const int flags = RTE_MAP_FORCE_ADDRESS |
 			RTE_MAP_PRIVATE | RTE_MAP_ANONYMOUS;
@@ -964,8 +963,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr)
 	size_t mmap_len;
 	int fd, ret;
 	char path[PATH_MAX];
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (arr == NULL) {
 		rte_errno = EINVAL;
@@ -999,7 +997,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr)
 		goto out;
 	}
 	/* with no shconf, there were never any files to begin with */
-	if (!internal_conf->no_shconf) {
+	if (!user_cfg->no_shconf) {
 		/*
 		 * attempt to get an exclusive lock on the file, to ensure it
 		 * has been detached by all other processes
lib/eal/common/eal_common_mcfg.c +2 -1
index 32f5f50015..4cac2d8cb2 100644
@@ -61,13 +61,14 @@ eal_mcfg_update_internal(void)
 void
 eal_mcfg_update_from_internal(void)
 {
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 
 	mcfg->legacy_mem = internal_conf->legacy_mem;
 	mcfg->single_file_segments = internal_conf->single_file_segments;
-	if (internal_conf->no_shconf)
+	if (user_cfg->no_shconf)
 		rte_mp_disable(); /* multi-process requires shared config */
 	/* record current DPDK version */
 	mcfg->version = RTE_VERSION;
lib/eal/common/eal_common_memory.c +5 -7
index 3caf97963d..9657d7ad8a 100644
@@ -1084,13 +1084,12 @@ rte_extmem_detach(void *va_addr, size_t len)
 int
 rte_eal_memory_detach(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	size_t page_sz = rte_mem_page_size();
 	unsigned int i;
 
-	if (internal_conf->in_memory == 1)
+	if (user_cfg->in_memory)
 		return 0;
 
 	rte_rwlock_write_lock(&mcfg->memory_hotplug_lock);
@@ -1133,7 +1132,7 @@ rte_eal_memory_detach(void)
 	 * config - we can't zero it out because it might still be referenced
 	 * by other processes.
 	 */
-	if (internal_conf->no_shconf == 0 && mcfg->mem_cfg_addr != 0) {
+	if (!user_cfg->no_shconf && mcfg->mem_cfg_addr != 0) {
 		if (rte_mem_unmap(mcfg, RTE_ALIGN(sizeof(*mcfg), page_sz)) != 0)
 			EAL_LOG(ERR, "Could not unmap shared memory config: %s",
 					rte_strerror(rte_errno));
@@ -1147,8 +1146,7 @@ rte_eal_memory_detach(void)
 int
 rte_eal_memory_init(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	int retval;
 
 	EAL_LOG(DEBUG, "Setting up physically contiguous memory...");
@@ -1165,7 +1163,7 @@ rte_eal_memory_init(void)
 	if (retval < 0)
 		goto fail;
 
-	if (internal_conf->no_shconf == 0 && rte_eal_memdevice_init() < 0)
+	if (!user_cfg->no_shconf && rte_eal_memdevice_init() < 0)
 		goto fail;
 
 	return 0;
lib/eal/common/eal_common_options.c +26 -21

108 lines not on this page · raw message

lib/eal/common/eal_internal_cfg.h +8 -12
index bf7d6792d2..f84867e2dc 100644
@@ -62,11 +62,19 @@ struct hugepage_file_discipline {
  */
 struct eal_user_cfg {
 	size_t memory;           /**< amount of asked memory */
+	enum rte_proc_type_t process_type; /**< requested process type */
 	uint8_t force_nchannel;  /**< force number of channels */
 	uint8_t force_nrank;     /**< force number of ranks */
 	bool force_numa;         /**< true to request memory on specific NUMA nodes */
 	bool force_numa_limits;  /**< true to apply per-NUMA memory limits */
 	bool no_hugetlbfs;       /**< true to disable hugetlbfs */
+	bool no_pci;             /**< true to disable PCI */
+	bool no_hpet;            /**< true to disable HPET */
+	bool vmware_tsc_map;     /**< true to use VMware TSC mapping */
+	bool no_shconf;          /**< true if there is no shared config */
+	bool in_memory;          /**< true to run with no shared runtime files */
+	bool create_uio_dev;     /**< true to create /dev/uioX devices */
+	bool no_telemetry;       /**< true to disable telemetry */
 	struct hugepage_file_discipline hugepage_file;
 	char *hugefile_prefix;   /**< the base filename of hugetlbfs files */
 	char *hugepage_dir;      /**< specific hugetlbfs directory to use */
@@ -95,17 +103,6 @@ struct eal_runtime_state {
  * internal configuration
  */
 struct internal_config {
-	volatile unsigned no_pci;         /**< true to disable PCI */
-	volatile unsigned no_hpet;        /**< true to disable HPET */
-	volatile unsigned vmware_tsc_map; /**< true to use VMware TSC mapping
-										* instead of native TSC */
-	volatile unsigned no_shconf;      /**< true if there is no shared config */
-	volatile unsigned in_memory;
-	/**< true if DPDK should operate entirely in-memory and not create any
-	 * shared files or runtime data.
-	 */
-	volatile unsigned create_uio_dev; /**< true to create /dev/uioX devices */
-	volatile enum rte_proc_type_t process_type; /**< multi-process proc type */
 	uintptr_t base_virtaddr;          /**< base address to try and reserve memory from */
 	volatile unsigned legacy_mem;
 	/**< true to enable legacy memory behavior (no dynamic allocation,
@@ -137,7 +134,6 @@ struct internal_config {
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
-	unsigned int no_telemetry; /**< true to disable Telemetry */
 	struct simd_bitwidth max_simd_bitwidth;
 	/**< max simd bitwidth path to use */
 	size_t huge_worker_stack_size; /**< worker thread stack size */
lib/eal/freebsd/eal.c +19 -23

124 lines not on this page · raw message

lib/eal/freebsd/eal_hugepage_info.c +2 -1
index 392c225d5b..29c5d986c1 100644
@@ -62,6 +62,7 @@ eal_hugepage_info_init(void)
 
 	/* re-use the linux "internal config" structure for our memory data */
 	struct hugepage_info *hpi = &internal_conf->hugepage_info[0];
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct hugepage_info *tmp_hpi;
 	unsigned int i;
 
@@ -116,7 +117,7 @@ eal_hugepage_info_init(void)
 	hpi->lock_descriptor = fd;
 
 	/* for no shared files mode, do not create shared memory config */
-	if (internal_conf->no_shconf)
+	if (user_cfg->no_shconf)
 		return 0;
 
 	tmp_hpi = create_shared_memory(eal_hugepage_info_path(),
lib/eal/linux/eal.c +17 -21
index 9b52ef262d..a2641d1254 100644
@@ -181,10 +181,11 @@ rte_eal_config_create(void)
 	int retval;
 	const struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	const char *pathname = eal_runtime_config_path();
 
-	if (internal_conf->no_shconf)
+	if (user_cfg->no_shconf)
 		return 0;
 
 	/* map the config before hugepage address so that we don't waste a page */
@@ -262,12 +263,11 @@ rte_eal_config_attach(void)
 {
 	struct rte_config *config = rte_eal_get_configuration();
 	struct rte_mem_config *mem_config;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	const char *pathname = eal_runtime_config_path();
 
-	if (internal_conf->no_shconf)
+	if (user_cfg->no_shconf)
 		return 0;
 
 	if (mem_cfg_fd < 0){
@@ -302,10 +302,9 @@ rte_eal_config_reattach(void)
 	struct rte_config *config = rte_eal_get_configuration();
 	struct rte_mem_config *mem_config;
 	void *rte_mem_cfg_addr;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	if (internal_conf->no_shconf)
+	if (user_cfg->no_shconf)
 		return 0;
 
 	/* save the address primary process has mapped shared config to */
@@ -347,11 +346,10 @@ eal_proc_type_detect(void)
 {
 	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
 	const char *pathname = eal_runtime_config_path();
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* if there no shared config, there can be no secondary processes */
-	if (!internal_conf->no_shconf) {
+	if (!user_cfg->no_shconf) {
 		/* if we can open the file but not get a write-lock we are a
 		 * secondary process. NOTE: if we get a file handle back, we
 		 * keep that open and don't close it to prevent a race condition
@@ -373,10 +371,9 @@ static int
 rte_config_init(void)
 {
 	struct rte_config *config = rte_eal_get_configuration();
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	config->process_type = internal_conf->process_type;
+	config->process_type = user_cfg->process_type;
 
 	switch (config->process_type) {
 	case RTE_PROC_PRIMARY:
@@ -748,7 +745,7 @@ rte_eal_init(int argc, char **argv)
 
 	if (!user_cfg->no_hugetlbfs) {
 		/* rte_config isn't initialized yet */
-		ret = internal_conf->process_type == RTE_PROC_PRIMARY ?
+		ret = user_cfg->process_type == RTE_PROC_PRIMARY ?
 				eal_hugepage_info_init() :
 				eal_hugepage_info_read();
 		if (ret < 0) {
@@ -756,7 +753,7 @@ rte_eal_init(int argc, char **argv)
 			rte_errno = EACCES;
 			goto err_out;
 		}
-		if (internal_conf->process_type == RTE_PROC_PRIMARY &&
+		if (user_cfg->process_type == RTE_PROC_PRIMARY &&
 				eal_apply_hugepage_mem_sz_limits(internal_conf) < 0) {
 			rte_eal_init_alert("Cannot apply hugepage memory limits.");
 			rte_errno = EINVAL;
@@ -769,7 +766,7 @@ rte_eal_init(int argc, char **argv)
 			user_cfg->memory = MEMSIZE_IF_NO_HUGE_PAGE;
 	}
 
-	if (internal_conf->vmware_tsc_map == 1) {
+	if (user_cfg->vmware_tsc_map) {
 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
 		rte_cycles_vmware_tsc_map = 1;
 		EAL_LOG(DEBUG, "Using VMWARE TSC MAP, "
@@ -932,11 +929,11 @@ rte_eal_init(int argc, char **argv)
 	 * In no_shconf mode, no runtime directory is created in the first
 	 * place, so no cleanup needed.
 	 */
-	if (!internal_conf->no_shconf && eal_clean_runtime_dir() < 0) {
+	if (!user_cfg->no_shconf && eal_clean_runtime_dir() < 0) {
 		rte_eal_init_alert("Cannot clear runtime directory");
 		goto err_out;
 	}
-	if (rte_eal_process_type() == RTE_PROC_PRIMARY && !internal_conf->no_telemetry) {
+	if (rte_eal_process_type() == RTE_PROC_PRIMARY && !user_cfg->no_telemetry) {
 		if (rte_telemetry_init(rte_eal_get_runtime_dir(),
 				rte_version(),
 				&internal_conf->ctrl_cpuset) != 0)
@@ -1015,10 +1012,9 @@ rte_eal_cleanup(void)
 RTE_EXPORT_SYMBOL(rte_eal_create_uio_dev)
 int rte_eal_create_uio_dev(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	return internal_conf->create_uio_dev;
+	return user_cfg->create_uio_dev;
 }
 
 RTE_EXPORT_SYMBOL(rte_eal_vfio_intr_mode)
lib/eal/linux/eal_hugepage_info.c +3 -2
index 2f889b291e..44dafa5292 100644
@@ -500,7 +500,7 @@ hugepage_info_init(void)
 			 * init process.
 			 */
 #ifdef MAP_HUGE_SHIFT
-			if (internal_conf->in_memory) {
+			if (user_cfg->in_memory) {
 				EAL_LOG(DEBUG, "In-memory mode enabled, "
 					"hugepages of size %" PRIu64 " bytes "
 					"will be allocated anonymously",
@@ -581,12 +581,13 @@ eal_hugepage_info_init(void)
 	unsigned int i;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (hugepage_info_init() < 0)
 		return -1;
 
 	/* for no shared files mode, we're done */
-	if (internal_conf->no_shconf)
+	if (user_cfg->no_shconf)
 		return 0;
 
 	hpi = &internal_conf->hugepage_info[0];
lib/eal/linux/eal_memalloc.c +15 -22
index 4ac5c14668..d9818dbba5 100644
@@ -276,7 +276,7 @@ get_seg_fd(char *path, int buflen, struct hugepage_info *hi,
 	/* for in-memory mode, we only make it here when we're sure we support
 	 * memfd, and this is a special case.
 	 */
-	if (internal_conf->in_memory)
+	if (user_cfg->in_memory)
 		return get_seg_memfd(hi, list_idx, seg_idx);
 
 	if (internal_conf->single_file_segments) {
@@ -460,13 +460,12 @@ resize_hugefile_in_filesystem(int fd, uint64_t fa_offset, uint64_t page_sz,
 static void
 close_hugefile(int fd, char *path, int list_idx)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	/*
 	 * primary process must unlink the file, but only when not in in-memory
 	 * mode (as in that case there is no file to unlink).
 	 */
-	if (!internal_conf->in_memory &&
+	if (!user_cfg->in_memory &&
 			rte_eal_process_type() == RTE_PROC_PRIMARY &&
 			unlink(path))
 		EAL_LOG(ERR, "%s(): unlinking '%s' failed: %s",
@@ -483,10 +482,9 @@ resize_hugefile(int fd, uint64_t fa_offset, uint64_t page_sz, bool grow,
 	/* in-memory mode is a special case, because we can be sure that
 	 * fallocate() is supported.
 	 */
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	if (internal_conf->in_memory) {
+	if (user_cfg->in_memory) {
 		if (dirty != NULL)
 			*dirty = false;
 		return resize_hugefile_in_memory(fd, fa_offset,
@@ -522,7 +520,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 	alloc_sz = hi->hugepage_sz;
 
 	/* these are checked at init, but code analyzers don't know that */
-	if (internal_conf->in_memory && !anonymous_hugepages_supported) {
+	if (user_cfg->in_memory && !anonymous_hugepages_supported) {
 		EAL_LOG(ERR, "Anonymous hugepages not supported, in-memory mode cannot allocate memory");
 		return -1;
 	}
@@ -551,7 +549,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 			goto resized;
 		}
 		if (user_cfg->hugepage_file.unlink_before_mapping &&
-				!internal_conf->in_memory) {
+				!user_cfg->in_memory) {
 			if (unlink(path)) {
 				EAL_LOG(DEBUG, "%s(): unlink() failed: %s",
 					__func__, strerror(errno));
@@ -685,7 +683,7 @@ alloc_seg(struct rte_memseg *ms, void *addr, int socket_id,
 	} else {
 		/* only remove file if we can take out a write lock */
 		if (!user_cfg->hugepage_file.unlink_before_mapping &&
-				internal_conf->in_memory == 0 &&
+				!user_cfg->in_memory &&
 				lock(fd, LOCK_EX) == 1)
 			unlink(path);
 		close(fd);
@@ -738,7 +736,7 @@ free_seg(struct rte_memseg *ms, struct hugepage_info *hi,
 		/* if we're able to take out a write lock, we're the last one
 		 * holding onto this page.
 		 */
-		if (!internal_conf->in_memory &&
+		if (!user_cfg->in_memory &&
 				user_cfg->hugepage_file.unlink_existing &&
 				!user_cfg->hugepage_file.unlink_before_mapping) {
 			ret = lock(fd, LOCK_EX);
@@ -776,8 +774,7 @@ alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	size_t page_sz;
 	int cur_idx, start_idx, j, dir_fd = -1;
 	unsigned int msl_idx, need, i;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (msl->page_sz != wa->page_sz)
 		return 0;
@@ -832,7 +829,7 @@ alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	 * during init, we already hold a write lock, so don't try to take out
 	 * another one.
 	 */
-	if (wa->hi->lock_descriptor == -1 && !internal_conf->in_memory) {
+	if (wa->hi->lock_descriptor == -1 && !user_cfg->in_memory) {
 		dir_fd = open(wa->hi->hugedir, O_RDONLY);
 		if (dir_fd < 0) {
 			EAL_LOG(ERR, "%s(): Cannot open '%s': %s",
@@ -915,8 +912,7 @@ free_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	struct free_walk_param *wa = arg;
 	uintptr_t start_addr, end_addr;
 	int msl_idx, seg_idx, ret, dir_fd = -1;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	start_addr = (uintptr_t) msl->base_va;
 	end_addr = start_addr + msl->len;
@@ -939,7 +935,7 @@ free_seg_walk(const struct rte_memseg_list *msl, void *arg)
 	 * during init, we already hold a write lock, so don't try to take out
 	 * another one.
 	 */
-	if (wa->hi->lock_descriptor == -1 && !internal_conf->in_memory) {
+	if (wa->hi->lock_descriptor == -1 && !user_cfg->in_memory) {
 		dir_fd = open(wa->hi->hugedir, O_RDONLY);
 		if (dir_fd < 0) {
 			EAL_LOG(ERR, "%s(): Cannot open '%s': %s",
@@ -1104,8 +1100,7 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 int
 eal_memalloc_free_seg(struct rte_memseg *ms)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct internal_config *internal_conf = eal_get_internal_configuration();
 
 	/* dynamic free not supported in legacy mode */
 	if (internal_conf->legacy_mem)
@@ -1663,8 +1658,6 @@ eal_memalloc_cleanup(void)
 int
 eal_memalloc_init(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY)
@@ -1674,7 +1667,7 @@ eal_memalloc_init(void)
 		if (rte_memseg_list_walk_thread_unsafe(secondary_msl_create_walk, NULL) < 0)
 			return -1;
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
-			internal_conf->in_memory) {
+			user_cfg->in_memory) {
 		EAL_LOG(DEBUG, "Using memfd for anonymous memory");
 		/* this cannot ever happen but better safe than sorry */
 		if (!anonymous_hugepages_supported) {
lib/eal/linux/eal_memory.c +2 -3
index 3816ddf8c5..3da8d179e6 100644
@@ -545,11 +545,10 @@ create_shared_memory(const char *filename, const size_t mem_size)
 {
 	void *retval;
 	int fd;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* if no shared files mode is used, create anonymous memory instead */
-	if (internal_conf->no_shconf) {
+	if (user_cfg->no_shconf) {
 		retval = mmap(NULL, mem_size, PROT_READ | PROT_WRITE,
 				MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 		if (retval == MAP_FAILED)
lib/eal/linux/eal_timer_hpet.c +9 -12
index 63e38bd53e..c1a3993e8f 100644
@@ -88,10 +88,9 @@ RTE_EXPORT_SYMBOL(rte_get_hpet_hz)
 uint64_t
 rte_get_hpet_hz(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	if (internal_conf->no_hpet)
+	if (user_cfg->no_hpet)
 		rte_panic("Error, HPET called, but no HPET present\n");
 
 	return eal_hpet_resolution_hz;
@@ -103,10 +102,9 @@ rte_get_hpet_cycles(void)
 {
 	uint32_t t, msb;
 	uint64_t ret;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	if (internal_conf->no_hpet)
+	if (user_cfg->no_hpet)
 		rte_panic("Error, HPET called, but no HPET present\n");
 
 	t = eal_hpet->counter_l;
@@ -126,10 +124,9 @@ int
 rte_eal_hpet_init(int make_default)
 {
 	int fd, ret;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	if (internal_conf->no_hpet) {
+	if (user_cfg->no_hpet) {
 		EAL_LOG(NOTICE, "HPET is disabled");
 		return -1;
 	}
@@ -138,14 +135,14 @@ rte_eal_hpet_init(int make_default)
 	if (fd < 0) {
 		EAL_LOG(ERR, "ERROR: Cannot open "DEV_HPET": %s!",
 			strerror(errno));
-		internal_conf->no_hpet = 1;
+		user_cfg->no_hpet = true;
 		return -1;
 	}
 	eal_hpet = mmap(NULL, 1024, PROT_READ, MAP_SHARED, fd, 0);
 	if (eal_hpet == MAP_FAILED) {
 		EAL_LOG(ERR, "ERROR: Cannot mmap "DEV_HPET"!");
 		close(fd);
-		internal_conf->no_hpet = 1;
+		user_cfg->no_hpet = true;
 		return -1;
 	}
 	close(fd);
@@ -169,7 +166,7 @@ rte_eal_hpet_init(int make_default)
 			hpet_msb_inc, NULL);
 	if (ret != 0) {
 		EAL_LOG(ERR, "ERROR: Cannot create HPET timer thread!");
-		internal_conf->no_hpet = 1;
+		user_cfg->no_hpet = true;
 		return -1;
 	}
 
lib/eal/windows/eal.c +3 -3
index 5f10e1f0eb..3d01b7a16e 100644
@@ -223,11 +223,11 @@ rte_eal_init(int argc, char **argv)
 	}
 
 	/* Prevent creation of shared memory files. */
-	if (internal_conf->in_memory == 0) {
+	if (!user_cfg->in_memory) {
 		EAL_LOG(WARNING, "Multi-process support is requested, "
 			"but not available.");
-		internal_conf->in_memory = 1;
-		internal_conf->no_shconf = 1;
+		user_cfg->in_memory = true;
+		user_cfg->no_shconf = true;
 	}
 
 	if (!user_cfg->no_hugetlbfs && (eal_hugepage_info_init() < 0)) {
Signature · 1 line
2.55.0
#102 lore raw

PATCH v3 8/39 eal: move hugepage limit fields to new config structs

In reply to Bruce Richardson

Move the pagesz-mem fields to the user config structure as these are specified via commandline input. The derived memory limit for hugepages is moved to the runtime configuration, since it's not a direct user input parameter.

---
 lib/eal/common/eal_common_dynmem.c  |  3 ++-
 lib/eal/common/eal_common_options.c | 35 ++++++++++++++++-------------
 lib/eal/common/eal_internal_cfg.h   | 17 +++++++-------
 lib/eal/linux/eal_memory.c          |  3 ++-
 4 files changed, 32 insertions(+), 26 deletions(-)
lib/eal/common/eal_common_dynmem.c +2 -1
index 97f8a05b30..a3f25a79f5 100644
@@ -37,6 +37,7 @@ eal_dynmem_memseg_lists_init(void)
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* no-huge does not need this at all */
 	if (user_cfg->no_hugetlbfs)
@@ -109,7 +110,7 @@ eal_dynmem_memseg_lists_init(void)
 
 		pagesz = type->page_sz;
 		max_mem_per_type =
-			internal_conf->hugepage_mem_sz_limits[type->hpi_idx];
+			runtime_state->hugepage_mem_sz_limits[type->hpi_idx];
 
 		/*
 		 * we need to create a segment list for this type. we must take
lib/eal/common/eal_common_options.c +20 -15
index c3cc41bac8..9a5a57110a 100644
@@ -510,6 +510,7 @@ void
 eal_reset_internal_config(struct internal_config *internal_cfg)
 {
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int i;
 
 	user_cfg->memory = 0;
@@ -521,6 +522,12 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 	user_cfg->force_numa_limits = false;
 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
 		user_cfg->numa_limit[i] = 0;
+	for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
+		runtime_state->hugepage_mem_sz_limits[i] = 0;
+		user_cfg->pagesz_mem_overrides[i].pagesz = 0;
+		user_cfg->pagesz_mem_overrides[i].limit = 0;
+	}
+	user_cfg->num_pagesz_mem_overrides = 0;
 	user_cfg->process_type = RTE_PROC_PRIMARY;
 	user_cfg->no_hugetlbfs = false;
 	user_cfg->no_pci = false;
@@ -533,11 +540,7 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 		memset(&internal_cfg->hugepage_info[i], 0,
 				sizeof(internal_cfg->hugepage_info[0]));
 		internal_cfg->hugepage_info[i].lock_descriptor = -1;
-		internal_cfg->hugepage_mem_sz_limits[i] = 0;
-		internal_cfg->pagesz_mem_overrides[i].pagesz = 0;
-		internal_cfg->pagesz_mem_overrides[i].limit = 0;
 	}
-	internal_cfg->num_pagesz_mem_overrides = 0;
 	internal_cfg->base_virtaddr = 0;
 
 	/* if set to NONE, interrupt mode is determined automatically */
@@ -1903,7 +1906,7 @@ eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
 }
 
 static int
-eal_parse_pagesz_mem(char *strval, struct internal_config *internal_cfg)
+eal_parse_pagesz_mem(char *strval, struct eal_user_cfg *user_cfg)
 {
 	char strval_cpy[1024];
 	char *fields[3];
@@ -1964,8 +1967,8 @@ eal_parse_pagesz_mem(char *strval, struct internal_config *internal_cfg)
 		return -1;
 	}
 
-	for (i = 0; i < internal_cfg->num_pagesz_mem_overrides; i++) {
-		pmo = &internal_cfg->pagesz_mem_overrides[i];
+	for (i = 0; i < user_cfg->num_pagesz_mem_overrides; i++) {
+		pmo = &user_cfg->pagesz_mem_overrides[i];
 		if (pmo->pagesz != pagesz)
 			continue;
 
@@ -1977,17 +1980,17 @@ eal_parse_pagesz_mem(char *strval, struct internal_config *internal_cfg)
 	}
 
 	/* do we have space? */
-	if (internal_cfg->num_pagesz_mem_overrides >= MAX_HUGEPAGE_SIZES) {
+	if (user_cfg->num_pagesz_mem_overrides >= MAX_HUGEPAGE_SIZES) {
 		EAL_LOG(ERR,
 			"--pagesz-mem: too many page size entries (max %d)",
 			MAX_HUGEPAGE_SIZES);
 		return -1;
 	}
 
-	pmo = &internal_cfg->pagesz_mem_overrides[internal_cfg->num_pagesz_mem_overrides];
+	pmo = &user_cfg->pagesz_mem_overrides[user_cfg->num_pagesz_mem_overrides];
 	pmo->pagesz = pagesz;
 	pmo->limit = mem_limit;
-	internal_cfg->num_pagesz_mem_overrides++;
+	user_cfg->num_pagesz_mem_overrides++;
 
 	return 0;
 }
@@ -2324,7 +2327,7 @@ eal_parse_args(void)
 		user_cfg->force_numa_limits = true;
 	}
 	TAILQ_FOREACH(arg, &args.pagesz_mem, next) {
-		if (eal_parse_pagesz_mem(arg->arg, int_cfg) < 0) {
+		if (eal_parse_pagesz_mem(arg->arg, user_cfg) < 0) {
 			EAL_LOG(ERR, "invalid pagesz-mem parameter: '%s'", arg->arg);
 			return -1;
 		}
@@ -2521,6 +2524,8 @@ eal_adjust_config(struct internal_config *internal_cfg)
 int
 eal_apply_hugepage_mem_sz_limits(struct internal_config *internal_cfg)
 {
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int i;
 
 	for (i = 0; i < internal_cfg->num_hugepage_sizes; i++) {
@@ -2533,12 +2538,12 @@ eal_apply_hugepage_mem_sz_limits(struct internal_config *internal_cfg)
 				(uint64_t)RTE_MAX_MEMSEG_PER_TYPE * pagesz);
 
 		/* override with user value for matching page size */
-		for (j = 0; j < (unsigned int)internal_cfg->num_pagesz_mem_overrides; j++) {
-			if (internal_cfg->pagesz_mem_overrides[j].pagesz == pagesz)
-				limit = internal_cfg->pagesz_mem_overrides[j].limit;
+		for (j = 0; j < user_cfg->num_pagesz_mem_overrides; j++) {
+			if (user_cfg->pagesz_mem_overrides[j].pagesz == pagesz)
+				limit = user_cfg->pagesz_mem_overrides[j].limit;
 		}
 
-		internal_cfg->hugepage_mem_sz_limits[i] = limit;
+		runtime_state->hugepage_mem_sz_limits[i] = limit;
 	}
 
 	return 0;
lib/eal/common/eal_internal_cfg.h +8 -9
index f84867e2dc..d380cd1252 100644
@@ -80,6 +80,12 @@ struct eal_user_cfg {
 	char *hugepage_dir;      /**< specific hugetlbfs directory to use */
 	uint64_t numa_mem[RTE_MAX_NUMA_NODES];    /**< amount of memory per NUMA node */
 	uint64_t numa_limit[RTE_MAX_NUMA_NODES];  /**< limit amount of memory per NUMA node */
+	/** storage for user-specified pagesz-mem overrides */
+	struct pagesz_mem_override {
+		uint64_t pagesz;   /**< page size in bytes */
+		uint64_t limit;    /**< memory limit in bytes */
+	} pagesz_mem_overrides[MAX_HUGEPAGE_SIZES];
+	unsigned int num_pagesz_mem_overrides;  /**< number of stored overrides */
 };
 
 /**
@@ -96,7 +102,8 @@ struct eal_platform_info {
  * as appropriate.
  */
 struct eal_runtime_state {
-	uint8_t reserved;
+	uint64_t hugepage_mem_sz_limits[MAX_HUGEPAGE_SIZES];
+	/**< default max memory per hugepage size */
 };
 
 /**
@@ -122,14 +129,6 @@ struct internal_config {
 			/**< user defined mbuf pool ops name */
 	unsigned num_hugepage_sizes;      /**< how many sizes on this system */
 	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
-	uint64_t hugepage_mem_sz_limits[MAX_HUGEPAGE_SIZES];
-	/**< default max memory per hugepage size */
-	/** storage for user-specified pagesz-mem overrides */
-	struct pagesz_mem_override {
-		uint64_t pagesz;   /**< page size in bytes */
-		uint64_t limit;    /**< memory limit in bytes */
-	} pagesz_mem_overrides[MAX_HUGEPAGE_SIZES];
-	unsigned int num_pagesz_mem_overrides;  /**< number of stored overrides */
 	enum rte_iova_mode iova_mode ;    /**< Set IOVA mode on this system  */
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
lib/eal/linux/eal_memory.c +2 -1
index 3da8d179e6..ff55e07fe5 100644
@@ -1711,6 +1711,7 @@ memseg_primary_init_32(void)
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* no-huge does not need this at all */
 	if (user_cfg->no_hugetlbfs)
@@ -1831,7 +1832,7 @@ memseg_primary_init_32(void)
 				continue;
 
 			max_pagesz_mem = max_socket_mem - cur_socket_mem;
-			pagesz_mem_limit = internal_conf->hugepage_mem_sz_limits[hpi_idx];
+			pagesz_mem_limit = runtime_state->hugepage_mem_sz_limits[hpi_idx];
 			max_pagesz_mem = RTE_MIN(max_pagesz_mem, pagesz_mem_limit);
 
 			/* make it multiple of page size */
Signature · 1 line
2.55.0
#103 lore raw

PATCH v3 9/39 eal: move advanced user config options to user cfg struct

In reply to Bruce Richardson

Move the more advanced configuration options, such as for virtual base addresses, vfio interrupt mode, etc., to the user configuration structure, so that all user-provided config options are in a single struct, which does not contain any other fields other than user config options.

---
 lib/eal/common/eal_common_bus.c      |  4 +-
 lib/eal/common/eal_common_config.c   |  6 +-
 lib/eal/common/eal_common_dynmem.c   |  2 +-
 lib/eal/common/eal_common_mcfg.c     | 13 ++--
 lib/eal/common/eal_common_memalloc.c |  5 +-
 lib/eal/common/eal_common_memory.c   | 36 +++++-------
 lib/eal/common/eal_common_options.c  | 88 +++++++++++++---------------
 lib/eal/common/eal_internal_cfg.h    | 33 ++++-------
 lib/eal/common/eal_options.h         |  3 +-
 lib/eal/common/malloc_elem.c         | 15 ++---
 lib/eal/common/malloc_heap.c         | 17 +++---
 lib/eal/freebsd/eal.c                | 15 ++---
 lib/eal/linux/eal.c                  | 26 ++++----
 lib/eal/linux/eal_hugepage_info.c    |  5 +-
 lib/eal/linux/eal_memalloc.c         | 63 ++++++++------------
 lib/eal/linux/eal_memory.c           | 35 +++++------
 lib/eal/windows/eal.c                |  7 +--
 lib/eal/windows/eal_memalloc.c       |  6 +-
 lib/eal/windows/eal_memory.c         |  6 +-
 19 files changed, 165 insertions(+), 220 deletions(-)
lib/eal/common/eal_common_bus.c +2 -2
index 067e7a8b67..1430a20ab7 100644
@@ -345,12 +345,12 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_device_is_ignored)
 bool
 rte_bus_device_is_ignored(const struct rte_bus *bus, const char *dev_name)
 {
-	const struct internal_config *internal_conf = eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct rte_devargs *devargs = rte_bus_find_devargs(bus, dev_name);
 	enum rte_bus_scan_mode scan_mode = bus->conf.scan_mode;
 
 	if (scan_mode == RTE_BUS_SCAN_UNDEFINED) {
-		if (internal_conf->no_auto_probing != 0)
+		if (user_cfg->no_auto_probing)
 			scan_mode = RTE_BUS_SCAN_ALLOWLIST;
 		else
 			scan_mode = RTE_BUS_SCAN_BLOCKLIST;
lib/eal/common/eal_common_config.c +3 -3
index 5efc6623d6..50cba4fa1a 100644
@@ -106,8 +106,8 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_eal_get_baseaddr)
 uint64_t
 rte_eal_get_baseaddr(void)
 {
-	return (internal_config.base_virtaddr != 0) ?
-		       (uint64_t) internal_config.base_virtaddr :
+	return (eal_user_cfg.base_virtaddr != 0) ?
+		       (uint64_t) eal_user_cfg.base_virtaddr :
 		       eal_get_baseaddr();
 }
 
@@ -123,7 +123,7 @@ RTE_EXPORT_SYMBOL(rte_eal_mbuf_user_pool_ops)
 const char *
 rte_eal_mbuf_user_pool_ops(void)
 {
-	return internal_config.user_mbuf_pool_ops_name;
+	return eal_user_cfg.user_mbuf_pool_ops_name;
 }
 
 /* return non-zero if hugepages are enabled. */
lib/eal/common/eal_common_dynmem.c +1 -1
index a3f25a79f5..bb47c8c86c 100644
@@ -83,7 +83,7 @@ eal_dynmem_memseg_lists_init(void)
 
 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
 			/* we can still sort pages by socket in legacy mode */
-			if (!internal_conf->legacy_mem && socket_id > 0)
+			if (!user_cfg->legacy_mem && socket_id > 0)
 				break;
 #endif
 			memtypes[cur_type].page_sz = hugepage_sz;
lib/eal/common/eal_common_mcfg.c +5 -8
index 4cac2d8cb2..e060285f51 100644
@@ -51,11 +51,10 @@ void
 eal_mcfg_update_internal(void)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	internal_conf->legacy_mem = mcfg->legacy_mem;
-	internal_conf->single_file_segments = mcfg->single_file_segments;
+	user_cfg->legacy_mem = mcfg->legacy_mem;
+	user_cfg->single_file_segments = mcfg->single_file_segments;
 }
 
 void
@@ -63,11 +62,9 @@ eal_mcfg_update_from_internal(void)
 {
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 
-	mcfg->legacy_mem = internal_conf->legacy_mem;
-	mcfg->single_file_segments = internal_conf->single_file_segments;
+	mcfg->legacy_mem = user_cfg->legacy_mem;
+	mcfg->single_file_segments = user_cfg->single_file_segments;
 	if (user_cfg->no_shconf)
 		rte_mp_disable(); /* multi-process requires shared config */
 	/* record current DPDK version */
lib/eal/common/eal_common_memalloc.c +2 -3
index 47e782f395..e3eadf0237 100644
@@ -72,15 +72,14 @@ eal_memalloc_is_contig(const struct rte_memseg_list *msl, void *start,
 	void *end, *aligned_start, *aligned_end;
 	size_t pgsz = (size_t)msl->page_sz;
 	const struct rte_memseg *ms;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* for IOVA_VA, it's always contiguous */
 	if (rte_eal_iova_mode() == RTE_IOVA_VA && !msl->external)
 		return true;
 
 	/* for legacy memory, it's always contiguous */
-	if (internal_conf->legacy_mem)
+	if (user_cfg->legacy_mem)
 		return true;
 
 	end = RTE_PTR_ADD(start, len);
lib/eal/common/eal_common_memory.c +15 -21
index 9657d7ad8a..00b5600ff8 100644
@@ -53,8 +53,7 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
 	uint64_t map_sz;
 	void *mapped_addr, *aligned_addr;
 	uint8_t try = 0;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (system_page_sz == 0)
 		system_page_sz = rte_mem_page_size();
@@ -65,12 +64,12 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
 	allow_shrink = (flags & EAL_VIRTUAL_AREA_ALLOW_SHRINK) > 0;
 	unmap = (flags & EAL_VIRTUAL_AREA_UNMAP) > 0;
 
-	if (next_baseaddr == NULL && internal_conf->base_virtaddr != 0 &&
+	if (next_baseaddr == NULL && user_cfg->base_virtaddr != 0 &&
 			rte_eal_process_type() == RTE_PROC_PRIMARY)
-		next_baseaddr = (void *) internal_conf->base_virtaddr;
+		next_baseaddr = (void *) user_cfg->base_virtaddr;
 
 #ifdef RTE_ARCH_64
-	if (next_baseaddr == NULL && internal_conf->base_virtaddr == 0 &&
+	if (next_baseaddr == NULL && user_cfg->base_virtaddr == 0 &&
 			rte_eal_process_type() == RTE_PROC_PRIMARY)
 		next_baseaddr = (void *) eal_get_baseaddr();
 #endif
@@ -151,7 +150,7 @@ eal_get_virtual_area(void *requested_addr, size_t *size,
 		 * demote this warning to debug if we did not explicitly request
 		 * a base virtual address.
 		 */
-		if (internal_conf->base_virtaddr != 0) {
+		if (user_cfg->base_virtaddr != 0) {
 			EAL_LOG(WARNING, "WARNING! Base virtual address hint (%p != %p) not respected!",
 				requested_addr, aligned_addr);
 			EAL_LOG(WARNING, "   This may cause issues with mapping memory into secondary processes");
@@ -409,8 +408,7 @@ void *
 rte_mem_iova2virt(rte_iova_t iova)
 {
 	struct virtiova vi;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	memset(&vi, 0, sizeof(vi));
 
@@ -418,7 +416,7 @@ rte_mem_iova2virt(rte_iova_t iova)
 	/* for legacy mem, we can get away with scanning VA-contiguous segments,
 	 * as we know they are PA-contiguous as well
 	 */
-	if (internal_conf->legacy_mem)
+	if (user_cfg->legacy_mem)
 		rte_memseg_contig_walk(find_virt_legacy, &vi);
 	else
 		rte_memseg_walk(find_virt, &vi);
@@ -502,11 +500,10 @@ int
 rte_mem_event_callback_register(const char *name, rte_mem_event_callback_t clb,
 		void *arg)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* FreeBSD boots with legacy mem enabled by default */
-	if (internal_conf->legacy_mem) {
+	if (user_cfg->legacy_mem) {
 		EAL_LOG(DEBUG, "Registering mem event callbacks not supported");
 		rte_errno = ENOTSUP;
 		return -1;
@@ -518,11 +515,10 @@ RTE_EXPORT_SYMBOL(rte_mem_event_callback_unregister)
 int
 rte_mem_event_callback_unregister(const char *name, void *arg)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* FreeBSD boots with legacy mem enabled by default */
-	if (internal_conf->legacy_mem) {
+	if (user_cfg->legacy_mem) {
 		EAL_LOG(DEBUG, "Registering mem event callbacks not supported");
 		rte_errno = ENOTSUP;
 		return -1;
@@ -535,11 +531,10 @@ int
 rte_mem_alloc_validator_register(const char *name,
 		rte_mem_alloc_validator_t clb, int socket_id, size_t limit)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* FreeBSD boots with legacy mem enabled by default */
-	if (internal_conf->legacy_mem) {
+	if (user_cfg->legacy_mem) {
 		EAL_LOG(DEBUG, "Registering mem alloc validators not supported");
 		rte_errno = ENOTSUP;
 		return -1;
@@ -552,11 +547,10 @@ RTE_EXPORT_SYMBOL(rte_mem_alloc_validator_unregister)
 int
 rte_mem_alloc_validator_unregister(const char *name, int socket_id)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* FreeBSD boots with legacy mem enabled by default */
-	if (internal_conf->legacy_mem) {
+	if (user_cfg->legacy_mem) {
 		EAL_LOG(DEBUG, "Registering mem alloc validators not supported");
 		rte_errno = ENOTSUP;
 		return -1;
lib/eal/common/eal_common_options.c +41 -47

244 lines not on this page · raw message

lib/eal/common/eal_internal_cfg.h +11 -22
index d380cd1252..5e304e6708 100644
@@ -62,7 +62,12 @@ struct hugepage_file_discipline {
  */
 struct eal_user_cfg {
 	size_t memory;           /**< amount of asked memory */
+	size_t huge_worker_stack_size; /**< worker thread stack size */
 	enum rte_proc_type_t process_type; /**< requested process type */
+	enum rte_intr_mode vfio_intr_mode; /**< default interrupt mode for VFIO */
+	enum rte_iova_mode iova_mode; /**< requested IOVA mode */
+	struct simd_bitwidth max_simd_bitwidth; /**< max simd bitwidth path to use */
+	rte_uuid_t vfio_vf_token; /**< shared VF token for VFIO-PCI bound PF and VFs */
 	uint8_t force_nchannel;  /**< force number of channels */
 	uint8_t force_nrank;     /**< force number of ranks */
 	bool force_numa;         /**< true to request memory on specific NUMA nodes */
@@ -75,9 +80,15 @@ struct eal_user_cfg {
 	bool in_memory;          /**< true to run with no shared runtime files */
 	bool create_uio_dev;     /**< true to create /dev/uioX devices */
 	bool no_telemetry;       /**< true to disable telemetry */
+	bool legacy_mem;         /**< true to enable legacy memory behavior */
+	bool match_allocations;  /**< true to free hugepages exactly as allocated */
+	bool no_auto_probing;    /**< true to switch from block-listing to allow-listing */
+	bool single_file_segments; /**< true if storing all pages within single files */
 	struct hugepage_file_discipline hugepage_file;
 	char *hugefile_prefix;   /**< the base filename of hugetlbfs files */
 	char *hugepage_dir;      /**< specific hugetlbfs directory to use */
+	char *user_mbuf_pool_ops_name; /**< user defined mbuf pool ops name */
+	uintptr_t base_virtaddr; /**< base address to try and reserve memory from */
 	uint64_t numa_mem[RTE_MAX_NUMA_NODES];    /**< amount of memory per NUMA node */
 	uint64_t numa_limit[RTE_MAX_NUMA_NODES];  /**< limit amount of memory per NUMA node */
 	/** storage for user-specified pagesz-mem overrides */
@@ -110,33 +121,11 @@ struct eal_runtime_state {
  * internal configuration
  */
 struct internal_config {
-	uintptr_t base_virtaddr;          /**< base address to try and reserve memory from */
-	volatile unsigned legacy_mem;
-	/**< true to enable legacy memory behavior (no dynamic allocation,
-	 * IOVA-contiguous segments).
-	 */
-	volatile unsigned match_allocations;
-	/**< true to free hugepages exactly as allocated */
-	volatile unsigned single_file_segments;
-	/**< true if storing all pages within single files (per-page-size,
-	 * per-node) non-legacy mode only.
-	 */
-	/** default interrupt mode for VFIO */
-	volatile enum rte_intr_mode vfio_intr_mode;
-	/** the shared VF token for VFIO-PCI bound PF and VFs devices */
-	rte_uuid_t vfio_vf_token;
-	char *user_mbuf_pool_ops_name;
-			/**< user defined mbuf pool ops name */
 	unsigned num_hugepage_sizes;      /**< how many sizes on this system */
 	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
-	enum rte_iova_mode iova_mode ;    /**< Set IOVA mode on this system  */
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
-	struct simd_bitwidth max_simd_bitwidth;
-	/**< max simd bitwidth path to use */
-	size_t huge_worker_stack_size; /**< worker thread stack size */
-	unsigned int no_auto_probing; /**< true to switch from block-listing to allow-listing */
 };
 
 struct eal_user_cfg *eal_get_user_configuration(void);
lib/eal/common/eal_options.h +2 -1
index 82cc8be8db..0c5132de6a 100644
@@ -8,13 +8,14 @@
 #include "getopt.h"
 
 struct rte_tel_data;
+struct eal_user_cfg;
 
 int eal_parse_log_options(void);
 int eal_parse_args(void);
 int eal_option_device_parse(void);
 int eal_apply_hugepage_mem_sz_limits(struct internal_config *internal_cfg);
 int eal_adjust_config(struct internal_config *internal_cfg);
-int eal_cleanup_config(struct internal_config *internal_cfg);
+int eal_cleanup_config(const struct eal_user_cfg *user_cfg);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
lib/eal/common/malloc_elem.c +6 -9
index 452b119c20..7a10a66779 100644
@@ -37,8 +37,7 @@ malloc_elem_find_max_iova_contig(struct malloc_elem *elem, size_t align)
 	rte_iova_t expected_iova;
 	struct rte_memseg *ms;
 	size_t page_sz, cur, max;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	page_sz = (size_t)elem->msl->page_sz;
 	data_start = RTE_PTR_ADD(elem, MALLOC_ELEM_HEADER_LEN);
@@ -57,7 +56,7 @@ malloc_elem_find_max_iova_contig(struct malloc_elem *elem, size_t align)
 	 */
 	if (!elem->msl->external &&
 			(rte_eal_iova_mode() == RTE_IOVA_VA ||
-				(internal_conf->legacy_mem &&
+				(user_cfg->legacy_mem &&
 					rte_eal_has_hugepages())))
 		return RTE_PTR_DIFF(data_end, contig_seg_start);
 
@@ -338,24 +337,22 @@ remove_elem(struct malloc_elem *elem)
 static int
 next_elem_is_adjacent(struct malloc_elem *elem)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	return elem->next == RTE_PTR_ADD(elem, elem->size) &&
 			elem->next->msl == elem->msl &&
-			(!internal_conf->match_allocations ||
+			(!user_cfg->match_allocations ||
 			 elem->orig_elem == elem->next->orig_elem);
 }
 
 static int
 prev_elem_is_adjacent(struct malloc_elem *elem)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	return elem == RTE_PTR_ADD(elem->prev, elem->prev->size) &&
 			elem->prev->msl == elem->msl &&
-			(!internal_conf->match_allocations ||
+			(!user_cfg->match_allocations ||
 			 elem->orig_elem == elem->prev->orig_elem);
 }
 
lib/eal/common/malloc_heap.c +7 -10
index 77f364158a..bd25496275 100644
@@ -647,15 +647,14 @@ malloc_heap_alloc_on_heap_id(size_t size, unsigned int heap_id, unsigned int fla
 	unsigned int size_flags = flags & ~RTE_MEMZONE_SIZE_HINT_ONLY;
 	int socket_id;
 	void *ret;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	rte_spinlock_lock(&(heap->lock));
 
 	align = align == 0 ? 1 : align;
 
 	/* for legacy mode, try once and with all flags */
-	if (internal_conf->legacy_mem) {
+	if (user_cfg->legacy_mem) {
 		ret = heap_alloc(heap, size, flags, align, bound, contig);
 		goto alloc_unlock;
 	}
@@ -865,8 +864,7 @@ malloc_heap_free(struct malloc_elem *elem)
 	unsigned int i, n_segs, before_space, after_space;
 	int ret;
 	bool unmapped = false;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (!malloc_elem_cookies_ok(elem) || elem->state != ELEM_BUSY)
 		return -1;
@@ -894,7 +892,7 @@ malloc_heap_free(struct malloc_elem *elem)
 	/* ...of which we can't avail if we are in legacy mode, or if this is an
 	 * externally allocated segment.
 	 */
-	if (internal_conf->legacy_mem || (msl->external > 0))
+	if (user_cfg->legacy_mem || (msl->external > 0))
 		goto free_unlock;
 
 	/* check if we can free any memory back to the system */
@@ -905,7 +903,7 @@ malloc_heap_free(struct malloc_elem *elem)
 	 * we will defer freeing these hugepages until the entire original allocation
 	 * can be freed
 	 */
-	if (internal_conf->match_allocations && elem->size != elem->orig_size)
+	if (user_cfg->match_allocations && elem->size != elem->orig_size)
 		goto free_unlock;
 
 	/* probably, but let's make sure, as we may not be using up full page */
@@ -1401,10 +1399,9 @@ rte_eal_malloc_heap_init(void)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	unsigned int i;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	if (internal_conf->match_allocations)
+	if (user_cfg->match_allocations)
 		EAL_LOG(DEBUG, "Hugepages will be freed exactly as allocated.");
 
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
lib/eal/freebsd/eal.c +6 -9
index 843fd03ad8..c552227079 100644
@@ -96,8 +96,6 @@ static int
 rte_eal_config_create(void)
 {
 	struct rte_config *config = rte_eal_get_configuration();
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	size_t page_sz = rte_mem_page_size();
 	size_t cfg_len = sizeof(struct rte_mem_config);
@@ -111,9 +109,9 @@ rte_eal_config_create(void)
 		return 0;
 
 	/* map the config before base address so that we don't waste a page */
-	if (internal_conf->base_virtaddr != 0)
+	if (user_cfg->base_virtaddr != 0)
 		rte_mem_cfg_addr = (void *)
-			RTE_ALIGN_FLOOR(internal_conf->base_virtaddr -
+			RTE_ALIGN_FLOOR(user_cfg->base_virtaddr -
 			sizeof(struct rte_mem_config), page_sz);
 	else
 		rte_mem_cfg_addr = NULL;
@@ -471,7 +469,7 @@ rte_eal_init(int argc, char **argv)
 	}
 
 	/* FreeBSD always uses legacy memory model */
-	internal_conf->legacy_mem = true;
+	user_cfg->legacy_mem = true;
 	if (user_cfg->in_memory) {
 		EAL_LOG(WARNING, "Warning: ignoring unsupported flag, '--in-memory'");
 		user_cfg->in_memory = false;
@@ -537,7 +535,7 @@ rte_eal_init(int argc, char **argv)
 	/* Always call rte_bus_get_iommu_class() to trigger DMA mask detection and validation */
 	enum rte_iova_mode bus_iova_mode = rte_bus_get_iommu_class();
 
-	iova_mode = internal_conf->iova_mode;
+	iova_mode = user_cfg->iova_mode;
 	if (iova_mode == RTE_IOVA_DC) {
 		EAL_LOG(DEBUG, "Specific IOVA mode is not requested, autodetecting");
 		if (has_phys_addr) {
@@ -780,8 +778,7 @@ rte_eal_cleanup(void)
 		return -1;
 	}
 
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	rte_service_finalize();
 	eal_bus_cleanup();
 	rte_mp_channel_cleanup();
@@ -790,7 +787,7 @@ rte_eal_cleanup(void)
 	eal_trace_fini();
 	/* after this point, any DPDK pointers will become dangling */
 	rte_eal_memory_detach();
-	eal_cleanup_config(internal_conf);
+	eal_cleanup_config(user_cfg);
 	eal_lcore_var_cleanup();
 	return 0;
 }
lib/eal/linux/eal.c +11 -15
index a2641d1254..51f8149710 100644
@@ -179,8 +179,6 @@ rte_eal_config_create(void)
 	size_t cfg_len_aligned = RTE_ALIGN(cfg_len, page_sz);
 	void *rte_mem_cfg_addr, *mapped_mem_cfg_addr;
 	int retval;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	const char *pathname = eal_runtime_config_path();
@@ -189,9 +187,9 @@ rte_eal_config_create(void)
 		return 0;
 
 	/* map the config before hugepage address so that we don't waste a page */
-	if (internal_conf->base_virtaddr != 0)
+	if (user_cfg->base_virtaddr != 0)
 		rte_mem_cfg_addr = (void *)
-			RTE_ALIGN_FLOOR(internal_conf->base_virtaddr -
+			RTE_ALIGN_FLOOR(user_cfg->base_virtaddr -
 			sizeof(struct rte_mem_config), page_sz);
 	else
 		rte_mem_cfg_addr = NULL;
@@ -519,8 +517,9 @@ eal_worker_thread_create(unsigned int lcore_id)
 	pthread_attr_t attr;
 	size_t stack_size;
 	int ret = -1;
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	stack_size = eal_get_internal_configuration()->huge_worker_stack_size;
+	stack_size = user_cfg->huge_worker_stack_size;
 	if (stack_size != 0) {
 		/* Allocate NUMA aware stack memory and set pthread attributes */
 		stack_ptr = rte_zmalloc_socket("lcore_stack", stack_size,
@@ -694,7 +693,7 @@ rte_eal_init(int argc, char **argv)
 	enum rte_iova_mode bus_iova_mode = rte_bus_get_iommu_class();
 
 	/* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */
-	if (internal_conf->iova_mode == RTE_IOVA_DC) {
+	if (user_cfg->iova_mode == RTE_IOVA_DC) {
 		/* autodetect the IOVA mapping mode */
 		enum rte_iova_mode iova_mode = bus_iova_mode;
 
@@ -725,7 +724,7 @@ rte_eal_init(int argc, char **argv)
 		rte_eal_get_configuration()->iova_mode = iova_mode;
 	} else {
 		rte_eal_get_configuration()->iova_mode =
-			internal_conf->iova_mode;
+			user_cfg->iova_mode;
 	}
 
 	if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) {
@@ -984,8 +983,6 @@ rte_eal_cleanup(void)
 	/* if we're in a primary process, we need to mark hugepages as freeable
 	 * so that finalization can release them back to the system.
 	 */
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
@@ -1003,7 +1000,7 @@ rte_eal_cleanup(void)
 	/* after this point, any DPDK pointers will become dangling */
 	rte_eal_memory_detach();
 	rte_eal_malloc_heap_cleanup();
-	eal_cleanup_config(internal_conf);
+	eal_cleanup_config(user_cfg);
 	eal_lcore_var_cleanup();
 	rte_eal_log_cleanup();
 	return 0;
@@ -1021,18 +1018,17 @@ RTE_EXPORT_SYMBOL(rte_eal_vfio_intr_mode)
 enum rte_intr_mode
 rte_eal_vfio_intr_mode(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	return internal_conf->vfio_intr_mode;
+	return user_cfg->vfio_intr_mode;
 }
 
 RTE_EXPORT_SYMBOL(rte_eal_vfio_get_vf_token)
 void
 rte_eal_vfio_get_vf_token(rte_uuid_t vf_token)
 {
-	struct internal_config *cfg = eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	rte_uuid_copy(vf_token, cfg->vfio_vf_token);
+	rte_uuid_copy(vf_token, user_cfg->vfio_vf_token);
 }
 
lib/eal/linux/eal_hugepage_info.c +2 -3
index 44dafa5292..74c55327ff 100644
@@ -401,8 +401,7 @@ calc_num_pages(struct hugepage_info *hpi, struct dirent *dirent,
 {
 	uint64_t total_pages = 0;
 	unsigned int i;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/*
 	 * first, try to put all hugepages into relevant sockets, but
@@ -418,7 +417,7 @@ calc_num_pages(struct hugepage_info *hpi, struct dirent *dirent,
 	 * This could be determined by mapping,
 	 * but it is precisely what hugepage file reuse is trying to avoid.
 	 */
-	if (!internal_conf->legacy_mem && reusable_pages == 0)
+	if (!user_cfg->legacy_mem && reusable_pages == 0)
 		for (i = 0; i < rte_socket_count(); i++) {
 			int socket = rte_socket_id_by_idx(i);
 			unsigned int num_pages =
lib/eal/linux/eal_memalloc.c +26 -37

196 lines not on this page · raw message

lib/eal/linux/eal_memory.c +16 -19
index ff55e07fe5..856ebce91f 100644
@@ -792,7 +792,7 @@ remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
 		/* we have a new address, so unmap previous one */
 #ifndef RTE_ARCH_64
 		/* in 32-bit legacy mode, we have already unmapped the page */
-		if (!eal_get_internal_configuration()->legacy_mem)
+		if (!eal_get_user_configuration()->legacy_mem)
 			munmap(hfile->orig_va, page_sz);
 #else
 		munmap(hfile->orig_va, page_sz);
@@ -1139,7 +1139,7 @@ eal_legacy_hugepage_init(void)
 	struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
-	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	uint64_t memory[RTE_MAX_NUMA_NODES];
 
@@ -1163,10 +1163,10 @@ eal_legacy_hugepage_init(void)
 		uint64_t page_sz;
 
 		/* nohuge mode is legacy mode */
-		internal_conf->legacy_mem = 1;
+		user_cfg->legacy_mem = 1;
 
 		/* nohuge mode is single-file segments mode */
-		internal_conf->single_file_segments = 1;
+		user_cfg->single_file_segments = 1;
 
 		/* create a memseg list */
 		msl = &mcfg->memsegs[0];
@@ -1435,7 +1435,7 @@ eal_legacy_hugepage_init(void)
 
 #ifndef RTE_ARCH_64
 	/* for legacy 32-bit mode, we did not preallocate VA space, so do it */
-	if (internal_conf->legacy_mem &&
+	if (user_cfg->legacy_mem &&
 			prealloc_segments(hugepage, nr_hugefiles)) {
 		EAL_LOG(ERR, "Could not preallocate VA space for hugepages");
 		goto fail;
@@ -1663,10 +1663,9 @@ eal_hugepage_attach(void)
 int
 rte_eal_hugepage_init(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	return internal_conf->legacy_mem ?
+	return user_cfg->legacy_mem ?
 			eal_legacy_hugepage_init() :
 			eal_dynmem_hugepage_init();
 }
@@ -1674,10 +1673,9 @@ rte_eal_hugepage_init(void)
 int
 rte_eal_hugepage_attach(void)
 {
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	return internal_conf->legacy_mem ?
+	return user_cfg->legacy_mem ?
 			eal_legacy_hugepage_attach() :
 			eal_hugepage_attach();
 }
@@ -1727,7 +1725,7 @@ memseg_primary_init_32(void)
 	 * unneeded pages. this will not affect secondary processes, as those
 	 * should be able to mmap the space without (too many) problems.
 	 */
-	if (internal_conf->legacy_mem)
+	if (user_cfg->legacy_mem)
 		return 0;
 
 	/* 32-bit mode is a very special case. we cannot know in advance where
@@ -1792,7 +1790,7 @@ memseg_primary_init_32(void)
 
 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
 		/* we can still sort pages by socket in legacy mode */
-		if (!internal_conf->legacy_mem && socket_id > 0)
+		if (!user_cfg->legacy_mem && socket_id > 0)
 			break;
 #endif
 
@@ -1989,11 +1987,10 @@ static int
 memseg_secondary_init(void)
 {
 #ifdef RTE_ARCH_64
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* for 32-bit dynmem init is same as legacy */
-	if (!internal_conf->legacy_mem)
+	if (!user_cfg->legacy_mem)
 		return memseg_secondary_init_dynmem();
 #endif
 
@@ -2007,8 +2004,8 @@ rte_eal_memseg_init(void)
 	struct rlimit lim;
 
 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg =
+		eal_get_user_configuration();
 #endif
 	if (getrlimit(RLIMIT_NOFILE, &lim) == 0) {
 		/* set limit to maximum */
@@ -2026,7 +2023,7 @@ rte_eal_memseg_init(void)
 		EAL_LOG(ERR, "Cannot get current resource limits");
 	}
 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
-	if (!internal_conf->legacy_mem && rte_socket_count() > 1) {
+	if (!user_cfg->legacy_mem && rte_socket_count() > 1) {
 		EAL_LOG(WARNING, "DPDK is running on a NUMA system, but is compiled without NUMA support.");
 		EAL_LOG(WARNING, "This will have adverse consequences for performance and usability.");
 		EAL_LOG(WARNING, "Please use --legacy-mem option, or recompile with NUMA support.");
lib/eal/windows/eal.c +3 -4
index 3d01b7a16e..318504a694 100644
@@ -144,15 +144,14 @@ RTE_EXPORT_SYMBOL(rte_eal_cleanup)
 int
 rte_eal_cleanup(void)
 {
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	eal_intr_thread_cancel();
 	eal_mem_virt2iova_cleanup();
 	eal_bus_cleanup();
 	/* after this point, any DPDK pointers will become dangling */
 	rte_eal_memory_detach();
-	eal_cleanup_config(internal_conf);
+	eal_cleanup_config(user_cfg);
 	eal_lcore_var_cleanup();
 	return 0;
 }
@@ -282,7 +281,7 @@ rte_eal_init(int argc, char **argv)
 	/* Always call rte_bus_get_iommu_class() to trigger DMA mask detection and validation */
 	enum rte_iova_mode bus_iova_mode = rte_bus_get_iommu_class();
 
-	iova_mode = internal_conf->iova_mode;
+	iova_mode = user_cfg->iova_mode;
 	if (iova_mode == RTE_IOVA_DC) {
 		EAL_LOG(DEBUG, "Specific IOVA mode is not requested, autodetecting");
 		if (has_phys_addr) {
lib/eal/windows/eal_memalloc.c +4 -2
index 232749573a..c68d96c7ec 100644
@@ -321,8 +321,9 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs,
 	struct hugepage_info *hi = NULL;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	if (internal_conf->legacy_mem) {
+	if (user_cfg->legacy_mem) {
 		EAL_LOG(ERR, "dynamic allocation not supported in legacy mode");
 		return -ENOTSUP;
 	}
@@ -374,9 +375,10 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 	int seg, ret = 0;
 	struct internal_config *internal_conf =
 		eal_get_internal_configuration();
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* dynamic free not supported in legacy mode */
-	if (internal_conf->legacy_mem)
+	if (user_cfg->legacy_mem)
 		return -1;
 
 	for (seg = 0; seg < n_segs; seg++) {
lib/eal/windows/eal_memory.c +2 -4
index 3140d7b9c3..8fcd636a3a 100644
@@ -678,12 +678,10 @@ eal_nohuge_init(void)
 	void *addr;
 
 	mcfg = rte_eal_get_configuration()->mem_config;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
-	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* nohuge mode is legacy mode */
-	internal_conf->legacy_mem = 1;
+	user_cfg->legacy_mem = 1;
 
 	msl = &mcfg->memsegs[0];
 
Signature · 1 line
2.55.0
#104 lore raw

PATCH v3 10/39 eal: move hugepage size info to platform info struct

In reply to Bruce Richardson

The hugepage information should not change for the lifetime of the process, so store it in the platform_info structure in EAL, moving it out of the internal_config.

---
 lib/eal/common/eal_common_dynmem.c  | 29 ++++++-------
 lib/eal/common/eal_common_options.c | 14 ++++---
 lib/eal/common/eal_internal_cfg.h   |  5 +--
 lib/eal/common/eal_options.h        |  2 +-
 lib/eal/freebsd/eal.c               |  9 ++--
 lib/eal/freebsd/eal_hugepage_info.c | 28 ++++++-------
 lib/eal/freebsd/eal_memory.c        | 21 ++++------
 lib/eal/linux/eal.c                 | 14 +++----
 lib/eal/linux/eal_hugepage_info.c   | 37 ++++++++---------
 lib/eal/linux/eal_memalloc.c        | 27 ++++++------
 lib/eal/linux/eal_memory.c          | 64 +++++++++++++----------------
 lib/eal/windows/eal.c               |  4 +-
 lib/eal/windows/eal_hugepages.c     |  7 ++--
 lib/eal/windows/eal_memalloc.c      | 26 ++++++------
 14 files changed, 130 insertions(+), 157 deletions(-)
lib/eal/common/eal_common_dynmem.c +13 -16
index bb47c8c86c..d5c1c62879 100644
@@ -34,8 +34,7 @@ eal_dynmem_memseg_lists_init(void)
 	size_t mem_va_len, mem_va_page_sz;
 	unsigned int n_memtypes, cur_type;
 	void *mem_va_addr = NULL;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
@@ -59,7 +58,7 @@ eal_dynmem_memseg_lists_init(void)
 	 */
 
 	/* maximum number of memtypes we're ever going to get */
-	n_memtypes = internal_conf->num_hugepage_sizes * rte_socket_count();
+	n_memtypes = platform_info->num_hugepage_sizes * rte_socket_count();
 
 	/* can we fit all memtypes into the memseg lists? */
 	if (n_memtypes > RTE_MAX_MEMSEG_LISTS) {
@@ -70,12 +69,12 @@ eal_dynmem_memseg_lists_init(void)
 
 	/* populate mem types */
 	cur_type = 0;
-	for (hpi_idx = 0; hpi_idx < (int) internal_conf->num_hugepage_sizes;
+	for (hpi_idx = 0; hpi_idx < (int) platform_info->num_hugepage_sizes;
 			hpi_idx++) {
 		struct hugepage_info *hpi;
 		uint64_t hugepage_sz;
 
-		hpi = &internal_conf->hugepage_info[hpi_idx];
+		hpi = &platform_info->hugepage_info[hpi_idx];
 		hugepage_sz = hpi->hugepage_sz;
 
 		for (i = 0; i < (int) rte_socket_count(); i++, cur_type++) {
@@ -232,14 +231,13 @@ eal_dynmem_hugepage_init(void)
 	struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
 	uint64_t memory[RTE_MAX_NUMA_NODES];
 	int hp_sz_idx, socket_id;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	memset(used_hp, 0, sizeof(used_hp));
 
 	for (hp_sz_idx = 0;
-			hp_sz_idx < (int) internal_conf->num_hugepage_sizes;
+			hp_sz_idx < (int) platform_info->num_hugepage_sizes;
 			hp_sz_idx++) {
 #ifndef RTE_ARCH_64
 		struct hugepage_info dummy;
@@ -247,7 +245,7 @@ eal_dynmem_hugepage_init(void)
 #endif
 		/* also initialize used_hp hugepage sizes in used_hp */
 		struct hugepage_info *hpi;
-		hpi = &internal_conf->hugepage_info[hp_sz_idx];
+		hpi = &platform_info->hugepage_info[hp_sz_idx];
 		used_hp[hp_sz_idx].hugepage_sz = hpi->hugepage_sz;
 
 #ifndef RTE_ARCH_64
@@ -275,12 +273,12 @@ eal_dynmem_hugepage_init(void)
 
 	/* calculate final number of pages */
 	if (eal_dynmem_calc_num_pages_per_socket(memory,
-			internal_conf->hugepage_info, used_hp,
-			internal_conf->num_hugepage_sizes) < 0)
+			platform_info->hugepage_info, used_hp,
+			platform_info->num_hugepage_sizes) < 0)
 		return -1;
 
 	for (hp_sz_idx = 0;
-			hp_sz_idx < (int)internal_conf->num_hugepage_sizes;
+			hp_sz_idx < (int)platform_info->num_hugepage_sizes;
 			hp_sz_idx++) {
 		for (socket_id = 0; socket_id < RTE_MAX_NUMA_NODES;
 				socket_id++) {
@@ -359,11 +357,10 @@ get_socket_mem_size(int socket)
 {
 	uint64_t size = 0;
 	unsigned int i;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
-	for (i = 0; i < internal_conf->num_hugepage_sizes; i++) {
-		struct hugepage_info *hpi = &internal_conf->hugepage_info[i];
+	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
+		struct hugepage_info *hpi = &platform_info->hugepage_info[i];
 		size += hpi->hugepage_sz * hpi->num_pages[socket];
 	}
 
lib/eal/common/eal_common_options.c +8 -6
index a8137a9160..bbdc22d1d6 100644
@@ -511,6 +511,7 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 {
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	int i;
 
 	user_cfg->memory = 0;
@@ -537,9 +538,9 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 	user_cfg->hugepage_file.unlink_existing = true;
 	/* zero out hugedir descriptors */
 	for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
-		memset(&internal_cfg->hugepage_info[i], 0,
-				sizeof(internal_cfg->hugepage_info[0]));
-		internal_cfg->hugepage_info[i].lock_descriptor = -1;
+		memset(&platform_info->hugepage_info[i], 0,
+				sizeof(platform_info->hugepage_info[0]));
+		platform_info->hugepage_info[i].lock_descriptor = -1;
 	}
 	user_cfg->base_virtaddr = 0;
 
@@ -2518,15 +2519,16 @@ eal_adjust_config(struct internal_config *internal_cfg)
 }
 
 int
-eal_apply_hugepage_mem_sz_limits(struct internal_config *internal_cfg)
+eal_apply_hugepage_mem_sz_limits(void)
 {
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int i;
 
-	for (i = 0; i < internal_cfg->num_hugepage_sizes; i++) {
+	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
 		unsigned int j;
-		const uint64_t pagesz = internal_cfg->hugepage_info[i].hugepage_sz;
+		const uint64_t pagesz = platform_info->hugepage_info[i].hugepage_sz;
 		uint64_t limit;
 
 		/* assign default limits */
lib/eal/common/eal_internal_cfg.h +2 -3
index 5e304e6708..764aeff954 100644
@@ -104,7 +104,8 @@ struct eal_user_cfg {
  * Immutable after initialization, so no need for atomic types or locks.
  */
 struct eal_platform_info {
-	uint8_t reserved;
+	uint8_t num_hugepage_sizes;      /**< how many sizes on this system */
+	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
 };
 
 /**
@@ -121,8 +122,6 @@ struct eal_runtime_state {
  * internal configuration
  */
 struct internal_config {
-	unsigned num_hugepage_sizes;      /**< how many sizes on this system */
-	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
lib/eal/common/eal_options.h +1 -1
index 0c5132de6a..58a047a532 100644
@@ -13,7 +13,7 @@ struct eal_user_cfg;
 int eal_parse_log_options(void);
 int eal_parse_args(void);
 int eal_option_device_parse(void);
-int eal_apply_hugepage_mem_sz_limits(struct internal_config *internal_cfg);
+int eal_apply_hugepage_mem_sz_limits(void);
 int eal_adjust_config(struct internal_config *internal_cfg);
 int eal_cleanup_config(const struct eal_user_cfg *user_cfg);
 enum rte_proc_type_t eal_proc_type_detect(void);
lib/eal/freebsd/eal.c +4 -5
index c552227079..1b633946c7 100644
@@ -328,11 +328,10 @@ eal_get_hugepage_mem_size(void)
 {
 	uint64_t size = 0;
 	unsigned i, j;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
-	for (i = 0; i < internal_conf->num_hugepage_sizes; i++) {
-		struct hugepage_info *hpi = &internal_conf->hugepage_info[i];
+	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
+		struct hugepage_info *hpi = &platform_info->hugepage_info[i];
 		if (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) {
 			for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
 				size += hpi->hugepage_sz * hpi->num_pages[j];
@@ -581,7 +580,7 @@ rte_eal_init(int argc, char **argv)
 			goto err_out;
 		}
 		if (user_cfg->process_type == RTE_PROC_PRIMARY &&
-				eal_apply_hugepage_mem_sz_limits(internal_conf) < 0) {
+				eal_apply_hugepage_mem_sz_limits() < 0) {
 			rte_eal_init_alert("Cannot apply hugepage memory limits.");
 			rte_errno = EINVAL;
 			goto err_out;
lib/eal/freebsd/eal_hugepage_info.c +13 -15
index 29c5d986c1..b4859f9bb0 100644
@@ -57,16 +57,15 @@ eal_hugepage_info_init(void)
 	size_t sysctl_size;
 	int num_buffers, fd, error;
 	int64_t buffer_size = 0;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
 	/* re-use the linux "internal config" structure for our memory data */
-	struct hugepage_info *hpi = &internal_conf->hugepage_info[0];
+	struct hugepage_info *hpi = &platform_info->hugepage_info[0];
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct hugepage_info *tmp_hpi;
 	unsigned int i;
 
-	internal_conf->num_hugepage_sizes = 1;
+	platform_info->num_hugepage_sizes = 1;
 
 	sysctl_size = sizeof(num_buffers);
 	error = sysctlbyname("hw.contigmem.num_buffers", &num_buffers,
@@ -121,23 +120,23 @@ eal_hugepage_info_init(void)
 		return 0;
 
 	tmp_hpi = create_shared_memory(eal_hugepage_info_path(),
-			sizeof(internal_conf->hugepage_info));
+			sizeof(platform_info->hugepage_info));
 	if (tmp_hpi == NULL ) {
 		EAL_LOG(ERR, "Failed to create shared memory!");
 		return -1;
 	}
 
-	memcpy(tmp_hpi, hpi, sizeof(internal_conf->hugepage_info));
+	memcpy(tmp_hpi, hpi, sizeof(platform_info->hugepage_info));
 
 	/* we've copied file descriptors along with everything else, but they
 	 * will be invalid in secondary process, so overwrite them
 	 */
-	for (i = 0; i < RTE_DIM(internal_conf->hugepage_info); i++) {
+	for (i = 0; i < RTE_DIM(platform_info->hugepage_info); i++) {
 		struct hugepage_info *tmp = &tmp_hpi[i];
 		tmp->lock_descriptor = -1;
 	}
 
-	if (munmap(tmp_hpi, sizeof(internal_conf->hugepage_info)) < 0) {
+	if (munmap(tmp_hpi, sizeof(platform_info->hugepage_info)) < 0) {
 		EAL_LOG(ERR, "Failed to unmap shared memory!");
 		return -1;
 	}
@@ -149,24 +148,23 @@ eal_hugepage_info_init(void)
 int
 eal_hugepage_info_read(void)
 {
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
-	struct hugepage_info *hpi = &internal_conf->hugepage_info[0];
+	struct hugepage_info *hpi = &platform_info->hugepage_info[0];
 	struct hugepage_info *tmp_hpi;
 
-	internal_conf->num_hugepage_sizes = 1;
+	platform_info->num_hugepage_sizes = 1;
 
 	tmp_hpi = open_shared_memory(eal_hugepage_info_path(),
-				  sizeof(internal_conf->hugepage_info));
+				  sizeof(platform_info->hugepage_info));
 	if (tmp_hpi == NULL) {
 		EAL_LOG(ERR, "Failed to open shared memory!");
 		return -1;
 	}
 
-	memcpy(hpi, tmp_hpi, sizeof(internal_conf->hugepage_info));
+	memcpy(hpi, tmp_hpi, sizeof(platform_info->hugepage_info));
 
-	if (munmap(tmp_hpi, sizeof(internal_conf->hugepage_info)) < 0) {
+	if (munmap(tmp_hpi, sizeof(platform_info->hugepage_info)) < 0) {
 		EAL_LOG(ERR, "Failed to unmap shared memory!");
 		return -1;
 	}
lib/eal/freebsd/eal_memory.c +9 -12
index 01bec37f3c..98e4313f7a 100644
@@ -71,9 +71,8 @@ rte_eal_hugepage_init(void)
 	uint64_t total_mem = 0;
 	void *addr;
 	unsigned int i, j, seg_idx = 0;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
 	/* get pointer to global configuration */
 	mcfg = rte_eal_get_configuration()->mem_config;
@@ -113,13 +112,13 @@ rte_eal_hugepage_init(void)
 	}
 
 	/* map all hugepages and sort them */
-	for (i = 0; i < internal_conf->num_hugepage_sizes; i++) {
+	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
 		struct hugepage_info *hpi;
 		rte_iova_t prev_end = 0;
 		uint64_t page_sz, mem_needed;
 		unsigned int n_pages, max_pages;
 
-		hpi = &internal_conf->hugepage_info[i];
+		hpi = &platform_info->hugepage_info[i];
 		page_sz = hpi->hugepage_sz;
 		max_pages = hpi->num_pages[0];
 		mem_needed = RTE_ALIGN_CEIL(user_cfg->memory - total_mem,
@@ -289,15 +288,14 @@ attach_segment(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
 int
 rte_eal_hugepage_attach(void)
 {
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	struct hugepage_info *hpi;
 	int fd_hugepage = -1;
 	unsigned int i;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 
-	hpi = &internal_conf->hugepage_info[0];
+	hpi = &platform_info->hugepage_info[0];
 
-	for (i = 0; i < internal_conf->num_hugepage_sizes; i++) {
+	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
 		const struct hugepage_info *cur_hpi = &hpi[i];
 		struct attach_walk_args wa;
 
@@ -357,9 +355,8 @@ memseg_primary_init(void)
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	int hpi_idx, msl_idx = 0;
 	struct rte_memseg_list *msl;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
 	/* no-huge does not need this at all */
 	if (user_cfg->no_hugetlbfs)
@@ -372,13 +369,13 @@ memseg_primary_init(void)
 	 */
 
 	/* create memseg lists */
-	for (hpi_idx = 0; hpi_idx < (int) internal_conf->num_hugepage_sizes;
+	for (hpi_idx = 0; hpi_idx < (int) platform_info->num_hugepage_sizes;
 			hpi_idx++) {
 		struct hugepage_info *hpi;
 		uint64_t hugepage_sz;
 		unsigned int n_segs;
 
-		hpi = &internal_conf->hugepage_info[hpi_idx];
+		hpi = &platform_info->hugepage_info[hpi_idx];
 		hugepage_sz = hpi->hugepage_sz;
 
 		/* no NUMA support on FreeBSD */
lib/eal/linux/eal.c +6 -8
index 51f8149710..d107bd399b 100644
@@ -409,20 +409,18 @@ rte_config_init(void)
 static void
 eal_hugedirs_unlock(void)
 {
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	int i;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
-
 	for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
 	{
 		/* skip uninitialized */
-		if (internal_conf->hugepage_info[i].lock_descriptor < 0)
+		if (platform_info->hugepage_info[i].lock_descriptor < 0)
 			continue;
 		/* unlock hugepage file */
-		flock(internal_conf->hugepage_info[i].lock_descriptor, LOCK_UN);
-		close(internal_conf->hugepage_info[i].lock_descriptor);
+		flock(platform_info->hugepage_info[i].lock_descriptor, LOCK_UN);
+		close(platform_info->hugepage_info[i].lock_descriptor);
 		/* reset the field */
-		internal_conf->hugepage_info[i].lock_descriptor = -1;
+		platform_info->hugepage_info[i].lock_descriptor = -1;
 	}
 }
 
@@ -753,7 +751,7 @@ rte_eal_init(int argc, char **argv)
 			goto err_out;
 		}
 		if (user_cfg->process_type == RTE_PROC_PRIMARY &&
-				eal_apply_hugepage_mem_sz_limits(internal_conf) < 0) {
+				eal_apply_hugepage_mem_sz_limits() < 0) {
 			rte_eal_init_alert("Cannot apply hugepage memory limits.");
 			rte_errno = EINVAL;
 			goto err_out;
lib/eal/linux/eal_hugepage_info.c +17 -20
index 74c55327ff..f35446cdc9 100644
@@ -453,8 +453,7 @@ hugepage_info_init(void)
 	unsigned int reusable_pages;
 	DIR *dir;
 	struct dirent *dirent;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	dir = opendir(sys_dir_path);
@@ -475,7 +474,7 @@ hugepage_info_init(void)
 		if (num_sizes >= MAX_HUGEPAGE_SIZES)
 			break;
 
-		hpi = &internal_conf->hugepage_info[num_sizes];
+		hpi = &platform_info->hugepage_info[num_sizes];
 		hpi->hugepage_sz =
 			rte_str_to_size(&dirent->d_name[dirent_start_len]);
 
@@ -546,17 +545,17 @@ hugepage_info_init(void)
 	if (dirent != NULL)
 		return -1;
 
-	internal_conf->num_hugepage_sizes = num_sizes;
+	platform_info->num_hugepage_sizes = num_sizes;
 
 	/* sort the page directory entries by size, largest to smallest */
-	qsort(&internal_conf->hugepage_info[0], num_sizes,
-	      sizeof(internal_conf->hugepage_info[0]), compare_hpi);
+	qsort(&platform_info->hugepage_info[0], num_sizes,
+	      sizeof(platform_info->hugepage_info[0]), compare_hpi);
 
 	/* now we have all info, check we have at least one valid size */
 	for (i = 0; i < num_sizes; i++) {
 		/* pages may no longer all be on socket 0, so check all */
 		unsigned int j, num_pages = 0;
-		struct hugepage_info *hpi = &internal_conf->hugepage_info[i];
+		struct hugepage_info *hpi = &platform_info->hugepage_info[i];
 
 		for (j = 0; j < RTE_MAX_NUMA_NODES; j++)
 			num_pages += hpi->num_pages[j];
@@ -578,8 +577,7 @@ eal_hugepage_info_init(void)
 {
 	struct hugepage_info *hpi, *tmp_hpi;
 	unsigned int i;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (hugepage_info_init() < 0)
@@ -589,26 +587,26 @@ eal_hugepage_info_init(void)
 	if (user_cfg->no_shconf)
 		return 0;
 
-	hpi = &internal_conf->hugepage_info[0];
+	hpi = &platform_info->hugepage_info[0];
 
 	tmp_hpi = create_shared_memory(eal_hugepage_info_path(),
-			sizeof(internal_conf->hugepage_info));
+			sizeof(platform_info->hugepage_info));
 	if (tmp_hpi == NULL) {
 		EAL_LOG(ERR, "Failed to create shared memory!");
 		return -1;
 	}
 
-	memcpy(tmp_hpi, hpi, sizeof(internal_conf->hugepage_info));
+	memcpy(tmp_hpi, hpi, sizeof(platform_info->hugepage_info));
 
 	/* we've copied file descriptors along with everything else, but they
 	 * will be invalid in secondary process, so overwrite them
 	 */
-	for (i = 0; i < RTE_DIM(internal_conf->hugepage_info); i++) {
+	for (i = 0; i < RTE_DIM(platform_info->hugepage_info); i++) {
 		struct hugepage_info *tmp = &tmp_hpi[i];
 		tmp->lock_descriptor = -1;
 	}
 
-	if (munmap(tmp_hpi, sizeof(internal_conf->hugepage_info)) < 0) {
+	if (munmap(tmp_hpi, sizeof(platform_info->hugepage_info)) < 0) {
 		EAL_LOG(ERR, "Failed to unmap shared memory!");
 		return -1;
 	}
@@ -617,21 +615,20 @@ eal_hugepage_info_init(void)
 
 int eal_hugepage_info_read(void)
 {
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
-	struct hugepage_info *hpi = &internal_conf->hugepage_info[0];
+	struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct hugepage_info *hpi = &platform_info->hugepage_info[0];
 	struct hugepage_info *tmp_hpi;
 
 	tmp_hpi = open_shared_memory(eal_hugepage_info_path(),
-				  sizeof(internal_conf->hugepage_info));
+				  sizeof(platform_info->hugepage_info));
 	if (tmp_hpi == NULL) {
 		EAL_LOG(ERR, "Failed to open shared memory!");
 		return -1;
 	}
 
-	memcpy(hpi, tmp_hpi, sizeof(internal_conf->hugepage_info));
+	memcpy(hpi, tmp_hpi, sizeof(platform_info->hugepage_info));
 
-	if (munmap(tmp_hpi, sizeof(internal_conf->hugepage_info)) < 0) {
+	if (munmap(tmp_hpi, sizeof(platform_info->hugepage_info)) < 0) {
 		EAL_LOG(ERR, "Failed to unmap shared memory!");
 		return -1;
 	}
lib/eal/linux/eal_memalloc.c +12 -15
index 0208c8a266..38e5baec29 100644
@@ -971,9 +971,8 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz,
 #endif
 	struct alloc_walk_param wa;
 	struct hugepage_info *hi = NULL;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
 	memset(&wa, 0, sizeof(wa));
 
@@ -981,10 +980,10 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz,
 	if (user_cfg->legacy_mem)
 		return -1;
 
-	for (i = 0; i < (int) RTE_DIM(internal_conf->hugepage_info); i++) {
+	for (i = 0; i < (int) RTE_DIM(platform_info->hugepage_info); i++) {
 		if (page_sz ==
-				internal_conf->hugepage_info[i].hugepage_sz) {
-			hi = &internal_conf->hugepage_info[i];
+				platform_info->hugepage_info[i].hugepage_sz) {
+			hi = &platform_info->hugepage_info[i];
 			break;
 		}
 	}
@@ -1041,9 +1040,8 @@ int
 eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 {
 	int seg, ret = 0;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
 	/* dynamic free not supported in legacy mode */
 	if (user_cfg->legacy_mem)
@@ -1064,13 +1062,13 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 
 		memset(&wa, 0, sizeof(wa));
 
-		for (i = 0; i < (int)RTE_DIM(internal_conf->hugepage_info);
+		for (i = 0; i < (int)RTE_DIM(platform_info->hugepage_info);
 				i++) {
-			hi = &internal_conf->hugepage_info[i];
+			hi = &platform_info->hugepage_info[i];
 			if (cur->hugepage_sz == hi->hugepage_sz)
 				break;
 		}
-		if (i == (int)RTE_DIM(internal_conf->hugepage_info)) {
+		if (i == (int)RTE_DIM(platform_info->hugepage_info)) {
 			EAL_LOG(ERR, "Can't find relevant hugepage_info entry");
 			ret = -1;
 			continue;
@@ -1334,11 +1332,10 @@ sync_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
 {
 	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	struct rte_memseg_list *primary_msl, *local_msl;
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	struct hugepage_info *hi = NULL;
 	unsigned int i;
 	int msl_idx;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 
 	if (msl->external)
 		return 0;
@@ -1347,12 +1344,12 @@ sync_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
 	primary_msl = &mcfg->memsegs[msl_idx];
 	local_msl = &local_memsegs[msl_idx];
 
-	for (i = 0; i < RTE_DIM(internal_conf->hugepage_info); i++) {
+	for (i = 0; i < RTE_DIM(platform_info->hugepage_info); i++) {
 		uint64_t cur_sz =
-			internal_conf->hugepage_info[i].hugepage_sz;
+			platform_info->hugepage_info[i].hugepage_sz;
 		uint64_t msl_sz = primary_msl->page_sz;
 		if (msl_sz == cur_sz) {
-			hi = &internal_conf->hugepage_info[i];
+			hi = &platform_info->hugepage_info[i];
 			break;
 		}
 	}
lib/eal/linux/eal_memory.c +29 -35

194 lines not on this page · raw message

lib/eal/windows/eal.c +1 -3
index 318504a694..a39b39dc47 100644
@@ -163,8 +163,6 @@ rte_eal_init(int argc, char **argv)
 {
 	int i, fctret, bscan;
 	const struct rte_config *config = rte_eal_get_configuration();
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	bool has_phys_addr;
 	enum rte_iova_mode iova_mode;
@@ -235,7 +233,7 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 	if (!user_cfg->no_hugetlbfs &&
-			eal_apply_hugepage_mem_sz_limits(internal_conf) < 0) {
+			eal_apply_hugepage_mem_sz_limits() < 0) {
 		rte_eal_init_alert("Cannot apply hugepage memory limits");
 		rte_errno = EINVAL;
 		goto err_out;
lib/eal/windows/eal_hugepages.c +3 -4
index ff72b8ee38..4e9e958c65 100644
@@ -62,12 +62,11 @@ hugepage_info_init(void)
 	struct hugepage_info *hpi;
 	unsigned int socket_id;
 	int ret = 0;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 
 	/* Only one hugepage size available on Windows. */
-	internal_conf->num_hugepage_sizes = 1;
-	hpi = &internal_conf->hugepage_info[0];
+	platform_info->num_hugepage_sizes = 1;
+	hpi = &platform_info->hugepage_info[0];
 
 	hpi->hugepage_sz = GetLargePageMinimum();
 	if (hpi->hugepage_sz == 0)
lib/eal/windows/eal_memalloc.c +12 -14
index c68d96c7ec..0163162db2 100644
@@ -33,7 +33,7 @@ eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset)
 
 static int
 alloc_seg(struct rte_memseg *ms, void *requested_addr, int socket_id,
-	struct hugepage_info *hi)
+	const struct hugepage_info *hi)
 {
 	HANDLE current_process;
 	unsigned int numa_node;
@@ -166,7 +166,7 @@ free_seg(struct rte_memseg *ms)
 }
 
 struct alloc_walk_param {
-	struct hugepage_info *hi;
+	const struct hugepage_info *hi;
 	struct rte_memseg **ms;
 	size_t page_sz;
 	unsigned int segs_allocated;
@@ -278,7 +278,7 @@ alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
 }
 
 struct free_walk_param {
-	struct hugepage_info *hi;
+	const struct hugepage_info *hi;
 	struct rte_memseg *ms;
 };
 static int
@@ -318,9 +318,8 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs,
 	unsigned int i;
 	int ret = -1;
 	struct alloc_walk_param wa;
-	struct hugepage_info *hi = NULL;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct hugepage_info *hi = NULL;
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (user_cfg->legacy_mem) {
@@ -328,8 +327,8 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs,
 		return -ENOTSUP;
 	}
 
-	for (i = 0; i < internal_conf->num_hugepage_sizes; i++) {
-		struct hugepage_info *hpi = &internal_conf->hugepage_info[i];
+	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
+		const struct hugepage_info *hpi = &platform_info->hugepage_info[i];
 		if (page_sz == hpi->hugepage_sz) {
 			hi = hpi;
 			break;
@@ -373,8 +372,7 @@ int
 eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 {
 	int seg, ret = 0;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* dynamic free not supported in legacy mode */
@@ -383,7 +381,7 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 
 	for (seg = 0; seg < n_segs; seg++) {
 		struct rte_memseg *cur = ms[seg];
-		struct hugepage_info *hi = NULL;
+		const struct hugepage_info *hi = NULL;
 		struct free_walk_param wa;
 		size_t i;
 		int walk_res;
@@ -397,12 +395,12 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 
 		memset(&wa, 0, sizeof(wa));
 
-		for (i = 0; i < RTE_DIM(internal_conf->hugepage_info); i++) {
-			hi = &internal_conf->hugepage_info[i];
+		for (i = 0; i < RTE_DIM(platform_info->hugepage_info); i++) {
+			hi = &platform_info->hugepage_info[i];
 			if (cur->hugepage_sz == hi->hugepage_sz)
 				break;
 		}
-		if (i == RTE_DIM(internal_conf->hugepage_info)) {
+		if (i == RTE_DIM(platform_info->hugepage_info)) {
 			EAL_LOG(ERR, "Can't find relevant hugepage_info entry");
 			ret = -1;
 			continue;
Signature · 1 line
2.55.0
#105 lore raw

PATCH v3 11/39 eal: move runtime state to appropriate structure

In reply to Bruce Richardson

Remove the last of the fields from the internal config to the runtime state structure, allowing us to remove the general internal_config struct and its reference function.

---
 lib/eal/common/eal_common_config.c  | 10 ----------
 lib/eal/common/eal_common_mcfg.c    |  5 ++---
 lib/eal/common/eal_common_memzone.c |  4 +++-
 lib/eal/common/eal_common_options.c | 18 +++++++++---------
 lib/eal/common/eal_common_proc.c    |  6 +++---
 lib/eal/common/eal_common_thread.c  |  8 ++++----
 lib/eal/common/eal_internal_cfg.h   |  8 +-------
 lib/eal/common/eal_options.h        |  2 +-
 lib/eal/common/eal_private.h        |  9 ---------
 lib/eal/freebsd/eal.c               |  7 +++----
 lib/eal/linux/eal.c                 |  7 +++----
 11 files changed, 29 insertions(+), 55 deletions(-)
lib/eal/common/eal_common_config.c +0 -10
index 50cba4fa1a..f1a5e84aa9 100644
@@ -37,9 +37,6 @@ static struct eal_platform_info eal_platform_info;
 /* internal runtime configuration */
 static struct eal_runtime_state eal_runtime_state;
 
-/* internal configuration */
-static struct internal_config internal_config;
-
 RTE_EXPORT_SYMBOL(rte_eal_get_runtime_dir)
 const char *
 rte_eal_get_runtime_dir(void)
@@ -66,13 +63,6 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
-/* Return a pointer to the internal configuration structure */
-struct internal_config *
-eal_get_internal_configuration(void)
-{
-	return &internal_config;
-}
-
 /* Return a pointer to the user configuration structure */
 struct eal_user_cfg *
 eal_get_user_configuration(void)
lib/eal/common/eal_common_mcfg.c +2 -3
index e060285f51..86dbb0a1fe 100644
@@ -16,14 +16,13 @@ eal_mcfg_complete(void)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
 	struct rte_mem_config *mcfg = cfg->mem_config;
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* ALL shared mem_config related INIT DONE */
 	if (cfg->process_type == RTE_PROC_PRIMARY)
 		mcfg->magic = RTE_MAGIC;
 
-	internal_conf->init_complete = 1;
+	runtime_state->init_complete = 1;
 }
 
 void
lib/eal/common/eal_common_memzone.c +3 -1
index db43af13a8..1207d524c9 100644
@@ -20,6 +20,7 @@
 
 #include "malloc_heap.h"
 #include "malloc_elem.h"
+#include "eal_internal_cfg.h"
 #include "eal_private.h"
 #include "eal_memcfg.h"
 
@@ -30,9 +31,10 @@ RTE_EXPORT_SYMBOL(rte_memzone_max_set)
 int
 rte_memzone_max_set(size_t max)
 {
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct rte_mem_config *mcfg;
 
-	if (eal_get_internal_configuration()->init_complete > 0) {
+	if (runtime_state->init_complete > 0) {
 		EAL_LOG(ERR, "Max memzone cannot be set after EAL init");
 		return -1;
 	}
lib/eal/common/eal_common_options.c +9 -9
index bbdc22d1d6..5d11f90a05 100644
@@ -507,7 +507,7 @@ eal_get_hugefile_prefix(void)
 }
 
 void
-eal_reset_internal_config(struct internal_config *internal_cfg)
+eal_reset_internal_config(void)
 {
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
@@ -563,8 +563,8 @@ eal_reset_internal_config(struct internal_config *internal_cfg)
 	user_cfg->no_telemetry = false;
 	user_cfg->iova_mode = RTE_IOVA_DC;
 	user_cfg->user_mbuf_pool_ops_name = NULL;
-	CPU_ZERO(&internal_cfg->ctrl_cpuset);
-	internal_cfg->init_complete = 0;
+	CPU_ZERO(&runtime_state->ctrl_cpuset);
+	runtime_state->init_complete = 0;
 	user_cfg->max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH;
 	user_cfg->max_simd_bitwidth.forced = 0;
 }
@@ -2075,7 +2075,6 @@ eal_parse_huge_worker_stack(const char *arg)
 int
 eal_parse_args(void)
 {
-	struct internal_config *int_cfg = eal_get_internal_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct rte_config *rte_cfg = rte_eal_get_configuration();
 	bool remap_lcores = (args.remap_lcore_ids != NULL);
@@ -2448,7 +2447,7 @@ eal_parse_args(void)
 	}
 #endif
 
-	if (eal_adjust_config(int_cfg) != 0) {
+	if (eal_adjust_config() != 0) {
 		EAL_LOG(ERR, "Invalid configuration");
 		return -1;
 	}
@@ -2457,9 +2456,10 @@ eal_parse_args(void)
 }
 
 static void
-compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
+compute_ctrl_threads_cpuset(void)
 {
-	rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	rte_cpuset_t *cpuset = &runtime_state->ctrl_cpuset;
 	rte_cpuset_t default_set;
 	unsigned int lcore_id;
 
@@ -2500,7 +2500,7 @@ eal_cleanup_config(const struct eal_user_cfg *user_cfg)
 }
 
 int
-eal_adjust_config(struct internal_config *internal_cfg)
+eal_adjust_config(void)
 {
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	int i;
@@ -2508,7 +2508,7 @@ eal_adjust_config(struct internal_config *internal_cfg)
 	if (user_cfg->process_type == RTE_PROC_AUTO)
 		user_cfg->process_type = eal_proc_type_detect();
 
-	compute_ctrl_threads_cpuset(internal_cfg);
+	compute_ctrl_threads_cpuset();
 
 	/* if no memory amounts were requested, this will result in 0 and
 	 * will be overridden later, right after eal_hugepage_info_init() */
lib/eal/common/eal_common_proc.c +3 -3
index b70e9189a4..1e9a0c3115 100644
@@ -361,8 +361,8 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s)
 	struct action_entry *entry;
 	struct rte_mp_msg *msg = &m->msg;
 	rte_mp_t action = NULL;
-	const struct internal_config *internal_conf =
-		eal_get_internal_configuration();
+	const struct eal_runtime_state *runtime_state =
+		eal_get_runtime_state();
 
 	EAL_LOG(DEBUG, "msg: %s", msg->name);
 
@@ -399,7 +399,7 @@ process_msg(struct mp_msg_internal *m, struct sockaddr_un *s)
 	pthread_mutex_unlock(&mp_mutex_action);
 
 	if (!action) {
-		if (m->type == MP_REQ && !internal_conf->init_complete) {
+		if (m->type == MP_REQ && !runtime_state->init_complete) {
 			/* if this is a request, and init is not yet complete,
 			 * and callback wasn't registered, we should tell the
 			 * requester to ignore our existence because we're not
lib/eal/common/eal_common_thread.c +4 -4
index dcd81f9e32..c2e7315bf4 100644
@@ -234,9 +234,8 @@ struct control_thread_params {
 
 static int control_thread_init(void *arg)
 {
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
-	rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset;
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	rte_cpuset_t *cpuset = &runtime_state->ctrl_cpuset;
 	struct control_thread_params *params = arg;
 
 	__rte_thread_init(rte_lcore_id(), cpuset);
@@ -354,11 +353,12 @@ RTE_EXPORT_SYMBOL(rte_thread_register)
 int
 rte_thread_register(void)
 {
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int lcore_id;
 	rte_cpuset_t cpuset;
 
 	/* EAL init flushes all lcores, we can't register before. */
-	if (eal_get_internal_configuration()->init_complete != 1) {
+	if (runtime_state->init_complete != 1) {
 		EAL_LOG(DEBUG, "Called %s before EAL init.", __func__);
 		rte_errno = EINVAL;
 		return -1;
lib/eal/common/eal_internal_cfg.h +1 -7
index 764aeff954..aa140e074f 100644
@@ -116,12 +116,6 @@ struct eal_platform_info {
 struct eal_runtime_state {
 	uint64_t hugepage_mem_sz_limits[MAX_HUGEPAGE_SIZES];
 	/**< default max memory per hugepage size */
-};
-
-/**
- * internal configuration
- */
-struct internal_config {
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
@@ -130,6 +124,6 @@ struct internal_config {
 struct eal_user_cfg *eal_get_user_configuration(void);
 struct eal_platform_info *eal_get_platform_info(void);
 struct eal_runtime_state *eal_get_runtime_state(void);
-void eal_reset_internal_config(struct internal_config *internal_cfg);
+void eal_reset_internal_config(void);
 
 #endif /* EAL_INTERNAL_CFG_H */
lib/eal/common/eal_options.h +1 -1
index 58a047a532..58fb3085e5 100644
@@ -14,7 +14,7 @@ int eal_parse_log_options(void);
 int eal_parse_args(void);
 int eal_option_device_parse(void);
 int eal_apply_hugepage_mem_sz_limits(void);
-int eal_adjust_config(struct internal_config *internal_cfg);
+int eal_adjust_config(void);
 int eal_cleanup_config(const struct eal_user_cfg *user_cfg);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
lib/eal/common/eal_private.h +0 -9
index 60441ac0f2..7e705c62c8 100644
@@ -712,15 +712,6 @@ eal_mem_set_dump(void *virt, size_t size, bool dump);
 int
 eal_set_runtime_dir(const char *run_dir);
 
-/**
- * Get the internal configuration structure.
- *
- * @return
- *   A pointer to the internal configuration structure.
- */
-struct internal_config *
-eal_get_internal_configuration(void);
-
 /**
  * Get the current value of the rte_application_usage pointer
  *
lib/eal/freebsd/eal.c +3 -4
index 1b633946c7..95f94239b9 100644
@@ -406,9 +406,8 @@ rte_eal_init(int argc, char **argv)
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 	char thread_name[RTE_THREAD_NAME_SIZE];
 	const struct rte_config *config = rte_eal_get_configuration();
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	bool has_phys_addr;
 	enum rte_iova_mode iova_mode;
 
@@ -453,7 +452,7 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	eal_reset_internal_config(internal_conf);
+	eal_reset_internal_config();
 
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
@@ -750,7 +749,7 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY && !user_cfg->no_telemetry) {
 		if (rte_telemetry_init(rte_eal_get_runtime_dir(),
 				rte_version(),
-				&internal_conf->ctrl_cpuset) != 0)
+				&runtime_state->ctrl_cpuset) != 0)
 			goto err_out;
 	}
 
lib/eal/linux/eal.c +3 -4
index d107bd399b..bfade6d57b 100644
@@ -566,9 +566,8 @@ rte_eal_init(int argc, char **argv)
 	char thread_name[RTE_THREAD_NAME_SIZE];
 	bool phys_addrs;
 	const struct rte_config *config = rte_eal_get_configuration();
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* first check if we have been run before */
 	if (!rte_atomic_compare_exchange_strong_explicit(&run_once, &has_run, 1,
@@ -611,7 +610,7 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	eal_reset_internal_config(internal_conf);
+	eal_reset_internal_config();
 
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
@@ -933,7 +932,7 @@ rte_eal_init(int argc, char **argv)
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY && !user_cfg->no_telemetry) {
 		if (rte_telemetry_init(rte_eal_get_runtime_dir(),
 				rte_version(),
-				&internal_conf->ctrl_cpuset) != 0)
+				&runtime_state->ctrl_cpuset) != 0)
 			goto err_out;
 	}
 
Signature · 1 line
2.55.0
#106 lore raw

PATCH v3 12/39 eal: record details of all cpus in platform info

In reply to Bruce Richardson

Populate the platform info structure with details of all the cores on the system.

---
 lib/eal/common/eal_common_lcore.c | 19 ++++++++++++++
 lib/eal/common/eal_internal_cfg.h | 16 ++++++++++--
 lib/eal/common/eal_private.h      |  8 ++++++
 lib/eal/freebsd/eal_lcore.c       | 16 ++++++++----
 lib/eal/linux/eal_lcore.c         | 43 +++++++++++++++++++++++++++++++
 lib/eal/windows/eal_lcore.c       |  6 +++++
 6 files changed, 101 insertions(+), 7 deletions(-)
lib/eal/common/eal_common_lcore.c +19 -0
index 3ddacdb8ce..7277867213 100644
@@ -164,6 +164,7 @@ rte_eal_cpu_init(void)
 {
 	/* pointer to global configuration */
 	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_platform_info *platform_info = eal_get_platform_info();
 	unsigned lcore_id;
 	unsigned count = 0;
 	unsigned int socket_id, prev_socket_id;
@@ -173,6 +174,24 @@ rte_eal_cpu_init(void)
 	int lcore_to_socket_id[RTE_MAX_LCORE] = {0};
 #endif
 
+	/* allocate cpu_info for all CPUs visible to the OS */
+	platform_info->cpu_count = eal_cpu_max();
+	platform_info->cpu_info = calloc(platform_info->cpu_count,
+			sizeof(*platform_info->cpu_info));
+	if (platform_info->cpu_info == NULL) {
+		EAL_LOG(ERR, "Cannot allocate cpu_info array");
+		return -1;
+	}
+
+	/* populate cpu_info with hardware topology for all detected CPUs */
+	for (size_t cpu_id = 0; cpu_id < platform_info->cpu_count; cpu_id++) {
+		if (eal_cpu_detected(cpu_id) == 0)
+			continue;
+		platform_info->cpu_info[cpu_id].detected = true;
+		platform_info->cpu_info[cpu_id].numa_id = eal_cpu_socket_id(cpu_id);
+		platform_info->cpu_info[cpu_id].core_id = eal_cpu_core_id(cpu_id);
+	}
+
 	/*
 	 * Parse the maximum set of logical cores, detect the subset of running
 	 * ones and enable them by default.
lib/eal/common/eal_internal_cfg.h +14 -2
index aa140e074f..3e04f42594 100644
@@ -100,10 +100,22 @@ struct eal_user_cfg {
 };
 
 /**
- * Discovered information about cores, memory, etc. on the system.
- * Immutable after initialization, so no need for atomic types or locks.
+ * Hardware facts about a single physical CPU, populated during CPU discovery.
+ * Indexed by physical CPU ID (not DPDK lcore ID).
+ */
+struct eal_cpu_info {
+	bool detected;         /**< true if this CPU ID is valid and visible to the OS */
+	unsigned int numa_id;  /**< NUMA node this CPU belongs to */
+	unsigned int core_id;  /**< physical core number on its NUMA node */
+};
+
+/**
+ * Discovered information about the system hardware.
+ * Immutable after discovery.
  */
 struct eal_platform_info {
+	size_t cpu_count;                /**< number of entries in cpu_info[] */
+	struct eal_cpu_info *cpu_info;   /**< per-physical-CPU hardware facts */
 	uint8_t num_hugepage_sizes;      /**< how many sizes on this system */
 	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
 };
lib/eal/common/eal_private.h +8 -0
index 7e705c62c8..550dcb6b22 100644
@@ -390,6 +390,14 @@ unsigned eal_cpu_core_id(unsigned lcore_id);
  */
 int eal_cpu_detected(unsigned lcore_id);
 
+/**
+ * Get the number of CPU IDs to allocate for platform CPU info.
+ * Returns max_cpu_id + 1: all valid CPU IDs are in [0, eal_cpu_max()).
+ *
+ * This function is private to the EAL.
+ */
+size_t eal_cpu_max(void);
+
 /**
  * Set TSC frequency from precise value or estimation
  *
lib/eal/freebsd/eal_lcore.c +11 -5
index 1d3d1b67b9..9d7027ceac 100644
@@ -2,7 +2,10 @@
  * Copyright(c) 2010-2014 Intel Corporation
  */
 
+#include <sched.h>
+#include <errno.h>
 #include <unistd.h>
+#include <string.h>
 #include <sys/sysctl.h>
 
 #include <rte_log.h>
@@ -21,18 +24,21 @@ eal_cpu_core_id(__rte_unused unsigned lcore_id)
 	return 0;
 }
 
-static int
-eal_get_ncpus(void)
+size_t
+eal_cpu_max(void)
 {
 	static int ncpu = -1;
 	int mib[2] = {CTL_HW, HW_NCPU};
 	size_t len = sizeof(ncpu);
 
 	if (ncpu < 0) {
-		sysctl(mib, 2, &ncpu, &len, NULL, 0);
+		if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0) {
+			EAL_LOG(ERR, "sysctl failed to get number of CPUs: %s", strerror(errno));
+			return CPU_SETSIZE;  /* fallback to CPU_SETSIZE */
+		}
 		EAL_LOG(INFO, "Sysctl reports %d cpus", ncpu);
 	}
-	return ncpu;
+	return (size_t)ncpu;
 }
 
 unsigned
@@ -47,6 +53,6 @@ eal_cpu_socket_id(__rte_unused unsigned cpu_id)
 int
 eal_cpu_detected(unsigned lcore_id)
 {
-	const unsigned ncpus = eal_get_ncpus();
+	const unsigned int ncpus = eal_cpu_max();
 	return lcore_id < ncpus;
 }
lib/eal/linux/eal_lcore.c +43 -0

62 lines not on this page · raw message

lib/eal/windows/eal_lcore.c +6 -0
index d2a2c2d091..2287337530 100644
@@ -273,6 +273,12 @@ eal_cpu_core_id(unsigned int lcore_id)
 	return cpu_map.lcores[lcore_id].core_id;
 }
 
+size_t
+eal_cpu_max(void)
+{
+	return (size_t)cpu_map.lcore_count;
+}
+
 unsigned int
 eal_socket_numa_node(unsigned int socket_id)
 {
Signature · 1 line
2.55.0
#107 lore raw

PATCH v3 13/39 eal: use platform info for lcore lookups

In reply to Bruce Richardson

Rather than storing the lcore and numa fields in the lcore_config structure - which is a structure indexed by logical core id, rather than physical cpu - use the platform info struct as the one source of truth for cpu topology info.

---
 lib/eal/common/eal_common_lcore.c  | 38 +++++++++++++++++++-----------
 lib/eal/common/eal_common_thread.c | 37 ++++++++++++-----------------
 lib/eal/common/eal_private.h       |  9 +++++--
 3 files changed, 46 insertions(+), 38 deletions(-)
lib/eal/common/eal_common_lcore.c +24 -14
index 7277867213..1042ffabd9 100644
@@ -52,6 +52,9 @@ int rte_lcore_index(int lcore_id)
 RTE_EXPORT_SYMBOL(rte_lcore_to_cpu_id)
 int rte_lcore_to_cpu_id(int lcore_id)
 {
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	unsigned int cpu;
+
 	if (unlikely(lcore_id >= RTE_MAX_LCORE))
 		return -1;
 
@@ -62,7 +65,11 @@ int rte_lcore_to_cpu_id(int lcore_id)
 		lcore_id = (int)rte_lcore_id();
 	}
 
-	return lcore_config[lcore_id].core_id;
+	for (cpu = 0; cpu < CPU_SETSIZE && cpu < platform_info->cpu_count; cpu++) {
+		if (CPU_ISSET(cpu, &lcore_config[lcore_id].cpuset))
+			return (int)platform_info->cpu_info[cpu].core_id;
+	}
+	return -1;
 }
 
 RTE_EXPORT_SYMBOL(rte_lcore_cpuset)
@@ -128,7 +135,10 @@ RTE_EXPORT_SYMBOL(rte_lcore_to_socket_id)
 unsigned int
 rte_lcore_to_socket_id(unsigned int lcore_id)
 {
-	return lcore_config[lcore_id].numa_id;
+	if (unlikely(lcore_id >= RTE_MAX_LCORE))
+		return (unsigned int)SOCKET_ID_ANY;
+
+	return (unsigned int)eal_cpuset_socket_id(&lcore_config[lcore_id].cpuset);
 }
 
 RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_cpu_socket_id, 26.11)
@@ -202,16 +212,16 @@ rte_eal_cpu_init(void)
 		/* init cpuset for per lcore config */
 		CPU_ZERO(&lcore_config[lcore_id].cpuset);
 
-		/* find socket first */
-		socket_id = eal_cpu_socket_id(lcore_id);
-		lcore_to_socket_id[lcore_id] = socket_id;
-
 		if (eal_cpu_detected(lcore_id) == 0) {
 			config->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
 			lcore_config[lcore_id].core_index = -1;
 			continue;
 		}
 
+		/* find socket first */
+		socket_id = platform_info->cpu_info[lcore_id].numa_id;
+		lcore_to_socket_id[lcore_id] = socket_id;
+
 		/* By default, lcore 1:1 map to cpu id */
 		CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset);
 
@@ -221,22 +231,22 @@ rte_eal_cpu_init(void)
 		/* By default, each detected core is enabled */
 		config->lcore_role[lcore_id] = RTE_LCORE_ROLE_RTE;
 		lcore_config[lcore_id].core_role = RTE_LCORE_ROLE_RTE;
-		lcore_config[lcore_id].core_id = eal_cpu_core_id(lcore_id);
-		lcore_config[lcore_id].numa_id = socket_id;
 		EAL_LOG(DEBUG, "Detected lcore %u as "
 				"core %u on NUMA node %u",
-				lcore_id, lcore_config[lcore_id].core_id,
-				lcore_config[lcore_id].numa_id);
+				lcore_id,
+				platform_info->cpu_info[lcore_id].core_id,
+				platform_info->cpu_info[lcore_id].numa_id);
 		count++;
 	}
 	for (; lcore_id < CPU_SETSIZE; lcore_id++) {
 		if (eal_cpu_detected(lcore_id) == 0)
 			continue;
-		socket_id = eal_cpu_socket_id(lcore_id);
-		lcore_to_socket_id[lcore_id] = socket_id;
+		if (unlikely(lcore_id >= platform_info->cpu_count))
+			break;
+		lcore_to_socket_id[lcore_id] = platform_info->cpu_info[lcore_id].numa_id;
 		EAL_LOG(DEBUG, "Skipped lcore %u as core %u on NUMA node %u",
-			lcore_id, eal_cpu_core_id(lcore_id),
-			socket_id);
+			lcore_id, platform_info->cpu_info[lcore_id].core_id,
+			platform_info->cpu_info[lcore_id].numa_id);
 	}
 
 	/* Set the count of enabled logical cores of the EAL configuration */
lib/eal/common/eal_common_thread.c +15 -22
index c2e7315bf4..10e8d84aa7 100644
@@ -37,30 +37,25 @@ unsigned rte_socket_id(void)
 	return RTE_PER_LCORE(_numa_id);
 }
 
-static int
-eal_cpuset_socket_id(rte_cpuset_t *cpusetp)
+int
+eal_cpuset_socket_id(const rte_cpuset_t *cpusetp)
 {
-	unsigned cpu = 0;
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
 	int socket_id = SOCKET_ID_ANY;
-	int sid;
 
 	if (cpusetp == NULL)
 		return SOCKET_ID_ANY;
 
-	do {
+	for (unsigned int cpu = 0; cpu < CPU_SETSIZE && cpu < platform_info->cpu_count; cpu++) {
 		if (!CPU_ISSET(cpu, cpusetp))
 			continue;
 
+		int sid = (int)platform_info->cpu_info[cpu].numa_id;
 		if (socket_id == SOCKET_ID_ANY)
-			socket_id = eal_cpu_socket_id(cpu);
-
-		sid = eal_cpu_socket_id(cpu);
-		if (socket_id != sid) {
-			socket_id = SOCKET_ID_ANY;
-			break;
-		}
-
-	} while (++cpu < CPU_SETSIZE);
+			socket_id = sid;
+		else if (socket_id != sid)
+			return SOCKET_ID_ANY;
+	}
 
 	return socket_id;
 }
@@ -70,19 +65,17 @@ thread_update_affinity(rte_cpuset_t *cpusetp)
 {
 	unsigned int lcore_id = rte_lcore_id();
 
-	/* store numa_id in TLS for quick access */
-	RTE_PER_LCORE(_numa_id) =
-		eal_cpuset_socket_id(cpusetp);
-
 	/* store cpuset in TLS for quick access */
-	memmove(&RTE_PER_LCORE(_cpuset), cpusetp,
-		sizeof(rte_cpuset_t));
+	memmove(&RTE_PER_LCORE(_cpuset), cpusetp, sizeof(rte_cpuset_t));
 
 	if (lcore_id != (unsigned)LCORE_ID_ANY) {
-		/* EAL thread will update lcore_config */
-		lcore_config[lcore_id].numa_id = RTE_PER_LCORE(_numa_id);
+		/* EAL thread: update lcore_config cpuset first then find numa based on that */
 		memmove(&lcore_config[lcore_id].cpuset, cpusetp,
 			sizeof(rte_cpuset_t));
+		RTE_PER_LCORE(_numa_id) = rte_lcore_to_socket_id(lcore_id);
+	} else {
+		/* Non-EAL thread: preserve SOCKET_ID_ANY if cpuset spans NUMA nodes. */
+		RTE_PER_LCORE(_numa_id) = (unsigned int)eal_cpuset_socket_id(cpusetp);
 	}
 }
 
lib/eal/common/eal_private.h +7 -2
index 550dcb6b22..8e7c30fe08 100644
@@ -31,8 +31,6 @@ struct lcore_config {
 	volatile int ret;          /**< return value of function */
 
 	volatile RTE_ATOMIC(enum rte_lcore_state_t) state; /**< lcore state */
-	unsigned int numa_id;      /**< NUMA node ID for this lcore */
-	unsigned int core_id;      /**< core number on socket for this lcore */
 	int core_index;            /**< relative index, starting from 0 */
 	uint8_t core_role;         /**< role of core eg: OFF, RTE, SERVICE */
 
@@ -96,6 +94,13 @@ int eal_collate_args(int argc, char **argv);
  */
 char *eal_cpuset_to_str(const rte_cpuset_t *cpuset);
 
+/**
+ * Resolve a cpuset to a NUMA socket id.
+ *
+ * Returns SOCKET_ID_ANY if cpuset is NULL, empty, or spans multiple sockets.
+ */
+int eal_cpuset_socket_id(const rte_cpuset_t *cpuset);
+
 /**
  * Initialize the memzone subsystem (private to eal).
  *
Signature · 1 line
2.55.0
#108 lore raw

PATCH v3 14/39 eal: add macro for lowest set CPU bit in a set

In reply to Bruce Richardson

FreeBSD supports the CPU_FFS macro as part of the regular cpuset functions. Add this as RTE_CPU_FFS for all OS's.

From "man CPU_FFS" on FreeBSD 15:

The CPU_FFS() macro returns the 1-index of the first (lowest) CPU in cpuset, or zero if cpuset is empty. Like with ffs(3), to use the non- zero result of CPU_FFS() as a cpu_idx index parameter to any other cpuset(9) macro, you must subtract one from the result.

---
 lib/eal/freebsd/include/rte_os.h |  2 ++
 lib/eal/linux/include/rte_os.h   | 10 ++++++++++
 lib/eal/windows/include/rte_os.h |  1 +
 lib/eal/windows/include/sched.h  | 10 ++++++++++
 4 files changed, 23 insertions(+)
lib/eal/freebsd/include/rte_os.h +2 -0
index 94b9275beb..38fd0e7f05 100644
@@ -75,4 +75,6 @@ typedef cpuset_t rte_cpuset_t;
 
 #endif /* RTE_EAL_FREEBSD_CPUSET_LEGACY */
 
+#define RTE_CPU_FFS CPU_FFS
+
 #endif /* _RTE_OS_H_ */
lib/eal/linux/include/rte_os.h +10 -0
index 20eff0409a..85ce56afaa 100644
@@ -41,6 +41,16 @@ typedef cpu_set_t rte_cpuset_t;
 	RTE_CPU_FILL(&tmp); \
 	CPU_XOR(dst, &tmp, src); \
 } while (0)
+
+static inline int
+rte_cpu_ffs(const rte_cpuset_t *s)
+{
+	for (unsigned int _i = 0; _i < CPU_SETSIZE; _i++)
+		if (CPU_ISSET(_i, s))
+			return (int)(_i + 1);
+	return 0;
+}
+#define RTE_CPU_FFS(s) rte_cpu_ffs(s)
 #endif
 
 #endif /* _RTE_OS_H_ */
lib/eal/windows/include/rte_os.h +1 -0
index 2a43cb1f9b..25701c7906 100644
@@ -49,6 +49,7 @@ struct { \
 #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
 #define RTE_CPU_FILL(set) CPU_FILL(set)
 #define RTE_CPU_NOT(dst, src) CPU_NOT(dst, src)
+#define RTE_CPU_FFS(s) CPU_FFS(s)
 
 /* This is an exception without "rte_" prefix, because Windows does have
  * ssize_t, but it's defined in <windows.h> which we avoid to expose.
lib/eal/windows/include/sched.h +10 -0
index 912fed12c2..230de19c76 100644
@@ -86,6 +86,16 @@ do { \
 		(dst)->_bits[_i] = (src)->_bits[_i] ^ -1LL; \
 } while (0)
 
+static inline int
+cpu_ffs(const rte_cpuset_t *s)
+{
+	for (unsigned int _i = 0; _i < CPU_SETSIZE; _i++)
+		if (CPU_ISSET(_i, s))
+			return (int)(_i + 1);
+	return 0;
+}
+#define CPU_FFS(s) cpu_ffs(s)
+
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
2.55.0
#109 lore raw

PATCH v3 15/39 eal: store lcore configuration in runtime data

In reply to Bruce Richardson

Remove the standalone lcore_config array and instead manage the lcore configuration as part of the runtime state.

---
 lib/eal/common/eal_common_launch.c  | 25 +++++++++------
 lib/eal/common/eal_common_lcore.c   | 49 ++++++++++++++++++-----------
 lib/eal/common/eal_common_options.c | 37 ++++++++++++----------
 lib/eal/common/eal_common_thread.c  | 24 ++++++++------
 lib/eal/common/eal_internal_cfg.h   | 19 +++++++++++
 lib/eal/common/eal_private.h        | 21 -------------
 lib/eal/common/rte_service.c        |  8 ++---
 lib/eal/freebsd/eal.c               | 23 ++++++--------
 lib/eal/linux/eal.c                 | 24 +++++++-------
 lib/eal/unix/eal_unix_thread.c      | 11 ++++---
 lib/eal/windows/eal.c               | 22 ++++++-------
 lib/eal/windows/eal_thread.c        | 11 ++++---
 12 files changed, 147 insertions(+), 127 deletions(-)
lib/eal/common/eal_common_launch.c +16 -9
index a7deac6ecd..a0f2a43b2a 100644
@@ -20,11 +20,13 @@ RTE_EXPORT_SYMBOL(rte_eal_wait_lcore)
 int
 rte_eal_wait_lcore(unsigned worker_id)
 {
-	while (rte_atomic_load_explicit(&lcore_config[worker_id].state,
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+
+	while (rte_atomic_load_explicit(&runtime_state->lcore_cfg[worker_id].state,
 			rte_memory_order_acquire) != WAIT)
 		rte_pause();
 
-	return lcore_config[worker_id].ret;
+	return runtime_state->lcore_cfg[worker_id].ret;
 }
 
 /*
@@ -36,21 +38,23 @@ RTE_EXPORT_SYMBOL(rte_eal_remote_launch)
 int
 rte_eal_remote_launch(lcore_function_t *f, void *arg, unsigned int worker_id)
 {
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int rc = -EBUSY;
 
 	/* Check if the worker is in 'WAIT' state. Use acquire order
 	 * since 'state' variable is used as the guard variable.
 	 */
-	if (rte_atomic_load_explicit(&lcore_config[worker_id].state,
+	if (rte_atomic_load_explicit(&runtime_state->lcore_cfg[worker_id].state,
 			rte_memory_order_acquire) != WAIT)
 		goto finish;
 
-	lcore_config[worker_id].arg = arg;
+	runtime_state->lcore_cfg[worker_id].arg = arg;
 	/* Ensure that all the memory operations are completed
 	 * before the worker thread starts running the function.
 	 * Use worker thread function as the guard variable.
 	 */
-	rte_atomic_store_explicit(&lcore_config[worker_id].f, f, rte_memory_order_release);
+	rte_atomic_store_explicit(&runtime_state->lcore_cfg[worker_id].f, f,
+			rte_memory_order_release);
 
 	rc = eal_thread_wake_worker(worker_id);
 
@@ -69,12 +73,13 @@ int
 rte_eal_mp_remote_launch(int (*f)(void *), void *arg,
 			 enum rte_rmt_call_main_t call_main)
 {
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int lcore_id;
 	int main_lcore = rte_get_main_lcore();
 
 	/* check state of lcores */
 	RTE_LCORE_FOREACH_WORKER(lcore_id) {
-		if (lcore_config[lcore_id].state != WAIT)
+		if (runtime_state->lcore_cfg[lcore_id].state != WAIT)
 			return -EBUSY;
 	}
 
@@ -84,8 +89,8 @@ rte_eal_mp_remote_launch(int (*f)(void *), void *arg,
 	}
 
 	if (call_main == CALL_MAIN) {
-		lcore_config[main_lcore].ret = f(arg);
-		lcore_config[main_lcore].state = WAIT;
+		runtime_state->lcore_cfg[main_lcore].ret = f(arg);
+		runtime_state->lcore_cfg[main_lcore].state = WAIT;
 	}
 
 	return 0;
@@ -98,7 +103,9 @@ RTE_EXPORT_SYMBOL(rte_eal_get_lcore_state)
 enum rte_lcore_state_t
 rte_eal_get_lcore_state(unsigned lcore_id)
 {
-	return lcore_config[lcore_id].state;
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+
+	return runtime_state->lcore_cfg[lcore_id].state;
 }
 
 /*
lib/eal/common/eal_common_lcore.c +30 -19

170 lines not on this page · raw message

lib/eal/common/eal_common_options.c +20 -17
index 5d11f90a05..fa1d7763c2 100644
@@ -910,7 +910,7 @@ eal_parse_service_coremask(const char *coremask)
 				if (cfg->lcore_role[idx] == RTE_LCORE_ROLE_RTE)
 					taken_lcore_count++;
 
-				lcore_config[idx].core_role = RTE_LCORE_ROLE_SERVICE;
+				cfg->lcore_role[idx] = RTE_LCORE_ROLE_SERVICE;
 				count++;
 			}
 		}
@@ -921,8 +921,6 @@ eal_parse_service_coremask(const char *coremask)
 			return -1;
 
 	rte_bitset_clear_all(cfg->core_indices, RTE_MAX_LCORE);
-	for (; idx < RTE_MAX_LCORE; idx++)
-		lcore_config[idx].core_index = -1;
 
 	if (count == 0)
 		return -1;
@@ -941,6 +939,7 @@ static int
 update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int lcore_id = remap_base;
 	unsigned int count = 0;
 	unsigned int i;
@@ -950,7 +949,7 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 	rte_bitset_clear_all(cfg->core_indices, RTE_MAX_LCORE);
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
 		cfg->lcore_role[i] = RTE_LCORE_ROLE_OFF;
-		lcore_config[i].core_index = -1;
+		runtime_state->lcore_cfg[i].core_index = -1;
 	}
 
 	/* now go through the cpuset */
@@ -979,9 +978,10 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 
 			rte_bitset_set(cfg->core_indices, count);
 			cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_RTE;
-			lcore_config[lcore_id].core_index = count;
-			CPU_ZERO(&lcore_config[lcore_id].cpuset);
-			CPU_SET(i, &lcore_config[lcore_id].cpuset);
+			runtime_state->lcore_cfg[lcore_id].core_index = count;
+			CPU_ZERO(&runtime_state->lcore_cfg[lcore_id].cpuset);
+			CPU_SET(i, &runtime_state->lcore_cfg[lcore_id].cpuset);
+			runtime_state->lcore_cfg[lcore_id].first_cpu = i;
 			EAL_LOG(DEBUG, "lcore %u mapped to physical core %u", lcore_id, i);
 			lcore_id++;
 			count++;
@@ -1154,8 +1154,7 @@ eal_parse_service_corelist(const char *corelist)
 					if (cfg->lcore_role[idx] == RTE_LCORE_ROLE_RTE)
 						taken_lcore_count++;
 
-					lcore_config[idx].core_role =
-							RTE_LCORE_ROLE_SERVICE;
+					cfg->lcore_role[idx] = RTE_LCORE_ROLE_SERVICE;
 					count++;
 				}
 			}
@@ -1178,7 +1177,7 @@ eal_parse_service_corelist(const char *corelist)
 	rte_cpuset_t service_cpuset;
 	CPU_ZERO(&service_cpuset);
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (lcore_config[i].core_role == RTE_LCORE_ROLE_SERVICE)
+		if (cfg->lcore_role[i] == RTE_LCORE_ROLE_SERVICE)
 			CPU_SET(i, &service_cpuset);
 	}
 	if (CPU_COUNT(&service_cpuset) > 0) {
@@ -1207,7 +1206,7 @@ eal_parse_main_lcore(const char *arg)
 		return -1;
 
 	/* ensure main core is not used as service core */
-	if (lcore_config[cfg->main_lcore].core_role == RTE_LCORE_ROLE_SERVICE) {
+	if (cfg->lcore_role[cfg->main_lcore] == RTE_LCORE_ROLE_SERVICE) {
 		EAL_LOG(ERR, "Error: Main lcore is used as a service core");
 		return -1;
 	}
@@ -1379,6 +1378,7 @@ static int
 eal_parse_lcores(const char *lcores)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	rte_cpuset_t lcore_set;
 	unsigned int set_count;
 	unsigned idx = 0;
@@ -1403,8 +1403,9 @@ eal_parse_lcores(const char *lcores)
 	rte_bitset_clear_all(cfg->core_indices, RTE_MAX_LCORE);
 	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
 		cfg->lcore_role[idx] = RTE_LCORE_ROLE_OFF;
-		lcore_config[idx].core_index = -1;
-		CPU_ZERO(&lcore_config[idx].cpuset);
+		runtime_state->lcore_cfg[idx].core_index = -1;
+		CPU_ZERO(&runtime_state->lcore_cfg[idx].cpuset);
+		runtime_state->lcore_cfg[idx].first_cpu = UINT16_MAX;
 	}
 
 	/* Get list of cores */
@@ -1466,7 +1467,7 @@ eal_parse_lcores(const char *lcores)
 
 			if (cfg->lcore_role[idx] != RTE_LCORE_ROLE_RTE) {
 				rte_bitset_set(cfg->core_indices, count);
-				lcore_config[idx].core_index = count;
+				runtime_state->lcore_cfg[idx].core_index = count;
 				cfg->lcore_role[idx] = RTE_LCORE_ROLE_RTE;
 				count++;
 			}
@@ -1478,8 +1479,10 @@ eal_parse_lcores(const char *lcores)
 
 			if (check_cpuset(&cpuset) < 0)
 				goto err;
-			rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
+			rte_memcpy(&runtime_state->lcore_cfg[idx].cpuset, &cpuset,
 				   sizeof(rte_cpuset_t));
+			runtime_state->lcore_cfg[idx].first_cpu =
+					(uint16_t)(RTE_CPU_FFS(&cpuset) - 1);
 		}
 
 		/* some cores from the lcore_set can't be handled by EAL */
@@ -2466,7 +2469,7 @@ compute_ctrl_threads_cpuset(void)
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
 		if (rte_lcore_has_role(lcore_id, RTE_LCORE_ROLE_OFF))
 			continue;
-		RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
+		RTE_CPU_OR(cpuset, cpuset, &runtime_state->lcore_cfg[lcore_id].cpuset);
 	}
 	RTE_CPU_NOT(cpuset, cpuset);
 
@@ -2477,7 +2480,7 @@ compute_ctrl_threads_cpuset(void)
 
 	/* if no remaining cpu, use main lcore cpu affinity */
 	if (!CPU_COUNT(cpuset)) {
-		memcpy(cpuset, &lcore_config[rte_get_main_lcore()].cpuset,
+		memcpy(cpuset, &runtime_state->lcore_cfg[rte_get_main_lcore()].cpuset,
 			sizeof(*cpuset));
 	}
 
lib/eal/common/eal_common_thread.c +14 -10
index 10e8d84aa7..a2e08242bd 100644
@@ -69,9 +69,12 @@ thread_update_affinity(rte_cpuset_t *cpusetp)
 	memmove(&RTE_PER_LCORE(_cpuset), cpusetp, sizeof(rte_cpuset_t));
 
 	if (lcore_id != (unsigned)LCORE_ID_ANY) {
-		/* EAL thread: update lcore_config cpuset first then find numa based on that */
-		memmove(&lcore_config[lcore_id].cpuset, cpusetp,
+		struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+
+		/* EAL thread: update lcore_runtime cpuset first then find numa based on that */
+		memmove(&runtime_state->lcore_cfg[lcore_id].cpuset, cpusetp,
 			sizeof(rte_cpuset_t));
+		runtime_state->lcore_cfg[lcore_id].first_cpu = (uint16_t)(RTE_CPU_FFS(cpusetp) - 1);
 		RTE_PER_LCORE(_numa_id) = rte_lcore_to_socket_id(lcore_id);
 	} else {
 		/* Non-EAL thread: preserve SOCKET_ID_ANY if cpuset spans NUMA nodes. */
@@ -149,10 +152,11 @@ __rte_noreturn uint32_t
 eal_thread_loop(void *arg)
 {
 	unsigned int lcore_id = (uintptr_t)arg;
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 	int ret;
 
-	__rte_thread_init(lcore_id, &lcore_config[lcore_id].cpuset);
+	__rte_thread_init(lcore_id, &runtime_state->lcore_cfg[lcore_id].cpuset);
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 	EAL_LOG(DEBUG, "lcore %u is ready (tid=%zx;cpuset=[%s%s])",
@@ -171,7 +175,7 @@ eal_thread_loop(void *arg)
 		/* Set the state to 'RUNNING'. Use release order
 		 * since 'state' variable is used as the guard variable.
 		 */
-		rte_atomic_store_explicit(&lcore_config[lcore_id].state, RUNNING,
+		rte_atomic_store_explicit(&runtime_state->lcore_cfg[lcore_id].state, RUNNING,
 			rte_memory_order_release);
 
 		eal_thread_ack_command();
@@ -181,25 +185,25 @@ eal_thread_loop(void *arg)
 		 * are accessed only after update to 'f' is visible.
 		 * Wait till the update to 'f' is visible to the worker.
 		 */
-		while ((f = rte_atomic_load_explicit(&lcore_config[lcore_id].f,
+		while ((f = rte_atomic_load_explicit(&runtime_state->lcore_cfg[lcore_id].f,
 				rte_memory_order_acquire)) == NULL)
 			rte_pause();
 
 		rte_eal_trace_thread_lcore_running(lcore_id, f);
 
 		/* call the function and store the return value */
-		fct_arg = lcore_config[lcore_id].arg;
+		fct_arg = runtime_state->lcore_cfg[lcore_id].arg;
 		ret = f(fct_arg);
-		lcore_config[lcore_id].ret = ret;
-		lcore_config[lcore_id].f = NULL;
-		lcore_config[lcore_id].arg = NULL;
+		runtime_state->lcore_cfg[lcore_id].ret = ret;
+		runtime_state->lcore_cfg[lcore_id].f = NULL;
+		runtime_state->lcore_cfg[lcore_id].arg = NULL;
 
 		/* Store the state with release order to ensure that
 		 * the memory operations from the worker thread
 		 * are completed before the state is updated.
 		 * Use 'state' as the guard variable.
 		 */
-		rte_atomic_store_explicit(&lcore_config[lcore_id].state, WAIT,
+		rte_atomic_store_explicit(&runtime_state->lcore_cfg[lcore_id].state, WAIT,
 			rte_memory_order_release);
 
 		rte_eal_trace_thread_lcore_stopped(lcore_id);
lib/eal/common/eal_internal_cfg.h +19 -0
index 3e04f42594..28388793a1 100644
@@ -16,6 +16,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+#include <rte_stdatomic.h>
 #include "eal_thread.h"
 
 #if defined(RTE_ARCH_ARM)
@@ -120,6 +121,23 @@ struct eal_platform_info {
 	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
 };
 
+/**
+ * Per-lcore runtime state, owned by EAL.
+ */
+struct lcore_cfg {
+	int core_index;                   /**< relative index, starting from 0 */
+	rte_cpuset_t cpuset;              /**< cpu set which the lcore affinity to */
+	uint16_t first_cpu;               /**< lowest CPU set in cpuset, UINT16_MAX if none */
+	/* Fields for executing code on a remote lcore */
+	rte_thread_t thread_id;          /**< thread identifier */
+	int pipe_main2worker[2];         /**< communication pipe with main */
+	int pipe_worker2main[2];         /**< communication pipe with main */
+	RTE_ATOMIC(lcore_function_t *) volatile f; /**< function to call */
+	void * volatile arg;             /**< argument of function */
+	volatile int ret;                /**< return value of function */
+	volatile RTE_ATOMIC(enum rte_lcore_state_t) state; /**< lcore state */
+};
+
 /**
  * Internal EAL runtime state
  * May be modified at runtime, so access must be protected by locks or atomic types
@@ -131,6 +149,7 @@ struct eal_runtime_state {
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
+	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
 };
 
 struct eal_user_cfg *eal_get_user_configuration(void);
lib/eal/common/eal_private.h +0 -21
index 8e7c30fe08..e146be3adb 100644
@@ -18,27 +18,6 @@
 
 #include "eal_internal_cfg.h"
 
-/**
- * Structure storing internal configuration (per-lcore)
- */
-struct lcore_config {
-	rte_thread_t thread_id;    /**< thread identifier */
-	int pipe_main2worker[2];   /**< communication pipe with main */
-	int pipe_worker2main[2];   /**< communication pipe with main */
-
-	RTE_ATOMIC(lcore_function_t *) volatile f; /**< function to call */
-	void * volatile arg;       /**< argument of function */
-	volatile int ret;          /**< return value of function */
-
-	volatile RTE_ATOMIC(enum rte_lcore_state_t) state; /**< lcore state */
-	int core_index;            /**< relative index, starting from 0 */
-	uint8_t core_role;         /**< role of core eg: OFF, RTE, SERVICE */
-
-	rte_cpuset_t cpuset;       /**< cpu set which the lcore affinity to */
-};
-
-extern struct lcore_config lcore_config[RTE_MAX_LCORE];
-
 /**
  * The global RTE configuration structure.
  */
lib/eal/common/rte_service.c +3 -5
index cb07ce83fe..05bcdbb3dd 100644
@@ -107,7 +107,7 @@ rte_service_init(void)
 	int i;
 	struct rte_config *cfg = rte_eal_get_configuration();
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (lcore_config[i].core_role == RTE_LCORE_ROLE_SERVICE) {
+		if (cfg->lcore_role[i] == RTE_LCORE_ROLE_SERVICE) {
 			if ((unsigned int)i == cfg->main_lcore)
 				continue;
 			rte_service_lcore_add(i);
@@ -714,9 +714,6 @@ set_lcore_state(uint32_t lcore, int32_t state)
 	struct core_state *cs =	RTE_LCORE_VAR_LCORE(lcore, lcore_states);
 	cfg->lcore_role[lcore] = state;
 
-	/* mark state in process local lcore_config */
-	lcore_config[lcore].core_role = state;
-
 	/* update per-lcore optimized state tracking */
 	cs->is_service_core = (state == RTE_LCORE_ROLE_SERVICE);
 
@@ -1103,6 +1100,7 @@ RTE_EXPORT_SYMBOL(rte_service_dump)
 int32_t
 rte_service_dump(FILE *f, uint32_t id)
 {
+	struct rte_config *cfg = rte_eal_get_configuration();
 	uint32_t i;
 	int print_one = (id != UINT32_MAX);
 
@@ -1125,7 +1123,7 @@ rte_service_dump(FILE *f, uint32_t id)
 
 	fprintf(f, "Service Cores Summary\n");
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (lcore_config[i].core_role != RTE_LCORE_ROLE_SERVICE)
+		if (cfg->lcore_role[i] != RTE_LCORE_ROLE_SERVICE)
 			continue;
 
 		service_dump_calls_per_lcore(f, i);
lib/eal/freebsd/eal.c +10 -13
index 95f94239b9..89b43c450d 100644
@@ -69,9 +69,6 @@ static struct flock wr_lock = {
 		.l_len = RTE_SIZEOF_FIELD(struct rte_mem_config, memsegs),
 };
 
-/* internal configuration (per-core) */
-struct lcore_config lcore_config[RTE_MAX_LCORE];
-
 /* used by rte_rdtsc() */
 RTE_EXPORT_SYMBOL(rte_cycles_vmware_tsc_map)
 int rte_cycles_vmware_tsc_map;
@@ -407,7 +404,7 @@ rte_eal_init(int argc, char **argv)
 	char thread_name[RTE_THREAD_NAME_SIZE];
 	const struct rte_config *config = rte_eal_get_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	bool has_phys_addr;
 	enum rte_iova_mode iova_mode;
 
@@ -655,13 +652,13 @@ rte_eal_init(int argc, char **argv)
 	eal_check_mem_on_local_socket();
 
 	if (rte_thread_set_affinity_by_id(rte_thread_self(),
-			&lcore_config[config->main_lcore].cpuset) != 0) {
+			&runtime_state->lcore_cfg[config->main_lcore].cpuset) != 0) {
 		rte_eal_init_alert("Cannot set affinity");
 		rte_errno = EINVAL;
 		goto err_out;
 	}
 	__rte_thread_init(config->main_lcore,
-		&lcore_config[config->main_lcore].cpuset);
+		&runtime_state->lcore_cfg[config->main_lcore].cpuset);
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 
@@ -675,15 +672,15 @@ rte_eal_init(int argc, char **argv)
 		 * create communication pipes between main thread
 		 * and children
 		 */
-		if (pipe(lcore_config[i].pipe_main2worker) < 0)
+		if (pipe(runtime_state->lcore_cfg[i].pipe_main2worker) < 0)
 			rte_panic("Cannot create pipe\n");
-		if (pipe(lcore_config[i].pipe_worker2main) < 0)
+		if (pipe(runtime_state->lcore_cfg[i].pipe_worker2main) < 0)
 			rte_panic("Cannot create pipe\n");
 
-		lcore_config[i].state = WAIT;
+		runtime_state->lcore_cfg[i].state = WAIT;
 
 		/* create a thread for each lcore */
-		ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
+		ret = rte_thread_create(&runtime_state->lcore_cfg[i].thread_id, NULL,
 				     eal_thread_loop, (void *)(uintptr_t)i);
 		if (ret != 0)
 			rte_panic("Cannot create thread\n");
@@ -693,10 +690,10 @@ rte_eal_init(int argc, char **argv)
 		if (ret >= RTE_THREAD_NAME_SIZE)
 			EAL_LOG(INFO, "Worker thread name %s truncated", thread_name);
 
-		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
+		rte_thread_set_name(runtime_state->lcore_cfg[i].thread_id, thread_name);
 
-		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
-			&lcore_config[i].cpuset);
+		ret = rte_thread_set_affinity_by_id(runtime_state->lcore_cfg[i].thread_id,
+			&runtime_state->lcore_cfg[i].cpuset);
 		if (ret != 0)
 			rte_panic("Cannot set affinity\n");
 	}
lib/eal/linux/eal.c +11 -13
index bfade6d57b..330a245cd7 100644
@@ -69,9 +69,6 @@ static struct flock wr_lock = {
 		.l_len = RTE_SIZEOF_FIELD(struct rte_mem_config, memsegs),
 };
 
-/* internal configuration (per-core) */
-struct lcore_config lcore_config[RTE_MAX_LCORE];
-
 /* used by rte_rdtsc() */
 RTE_EXPORT_SYMBOL(rte_cycles_vmware_tsc_map)
 int rte_cycles_vmware_tsc_map;
@@ -516,6 +513,7 @@ eal_worker_thread_create(unsigned int lcore_id)
 	size_t stack_size;
 	int ret = -1;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	stack_size = user_cfg->huge_worker_stack_size;
 	if (stack_size != 0) {
@@ -542,7 +540,7 @@ eal_worker_thread_create(unsigned int lcore_id)
 		}
 	}
 
-	if (pthread_create((pthread_t *)&lcore_config[lcore_id].thread_id.opaque_id,
+	if (pthread_create((pthread_t *)&runtime_state->lcore_cfg[lcore_id].thread_id.opaque_id,
 			attrp, eal_worker_thread_loop, (void *)(uintptr_t)lcore_id) == 0)
 		ret = 0;
 
@@ -567,7 +565,7 @@ rte_eal_init(int argc, char **argv)
 	bool phys_addrs;
 	const struct rte_config *config = rte_eal_get_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* first check if we have been run before */
 	if (!rte_atomic_compare_exchange_strong_explicit(&run_once, &has_run, 1,
@@ -840,13 +838,13 @@ rte_eal_init(int argc, char **argv)
 	eal_check_mem_on_local_socket();
 
 	if (rte_thread_set_affinity_by_id(rte_thread_self(),
-			&lcore_config[config->main_lcore].cpuset) != 0) {
+			&runtime_state->lcore_cfg[config->main_lcore].cpuset) != 0) {
 		rte_eal_init_alert("Cannot set affinity");
 		rte_errno = EINVAL;
 		goto err_out;
 	}
 	__rte_thread_init(config->main_lcore,
-		&lcore_config[config->main_lcore].cpuset);
+		&runtime_state->lcore_cfg[config->main_lcore].cpuset);
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 	EAL_LOG(DEBUG, "Main lcore %u is ready (tid=%zx;cpuset=[%s%s])",
@@ -859,12 +857,12 @@ rte_eal_init(int argc, char **argv)
 		 * create communication pipes between main thread
 		 * and children
 		 */
-		if (pipe(lcore_config[i].pipe_main2worker) < 0)
+		if (pipe(runtime_state->lcore_cfg[i].pipe_main2worker) < 0)
 			rte_panic("Cannot create pipe\n");
-		if (pipe(lcore_config[i].pipe_worker2main) < 0)
+		if (pipe(runtime_state->lcore_cfg[i].pipe_worker2main) < 0)
 			rte_panic("Cannot create pipe\n");
 
-		lcore_config[i].state = WAIT;
+		runtime_state->lcore_cfg[i].state = WAIT;
 
 		/* create a thread for each lcore */
 		ret = eal_worker_thread_create(i);
@@ -876,10 +874,10 @@ rte_eal_init(int argc, char **argv)
 		if (ret >= RTE_THREAD_NAME_SIZE)
 			EAL_LOG(INFO, "Worker thread name %s truncated", thread_name);
 
-		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
+		rte_thread_set_name(runtime_state->lcore_cfg[i].thread_id, thread_name);
 
-		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
-			&lcore_config[i].cpuset);
+		ret = rte_thread_set_affinity_by_id(runtime_state->lcore_cfg[i].thread_id,
+			&runtime_state->lcore_cfg[i].cpuset);
 		if (ret != 0)
 			rte_panic("Cannot set affinity\n");
 	}
lib/eal/unix/eal_unix_thread.c +7 -4
index ef6cbff0ee..1555078f96 100644
@@ -12,8 +12,9 @@
 int
 eal_thread_wake_worker(unsigned int worker_id)
 {
-	int m2w = lcore_config[worker_id].pipe_main2worker[1];
-	int w2m = lcore_config[worker_id].pipe_worker2main[0];
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	int m2w = runtime_state->lcore_cfg[worker_id].pipe_main2worker[1];
+	int w2m = runtime_state->lcore_cfg[worker_id].pipe_worker2main[0];
 	char c = 0;
 	int n;
 
@@ -35,11 +36,12 @@ void
 eal_thread_wait_command(void)
 {
 	unsigned int lcore_id = rte_lcore_id();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int m2w;
 	char c;
 	int n;
 
-	m2w = lcore_config[lcore_id].pipe_main2worker[0];
+	m2w = runtime_state->lcore_cfg[lcore_id].pipe_main2worker[0];
 	do {
 		n = read(m2w, &c, 1);
 	} while (n < 0 && errno == EINTR);
@@ -51,11 +53,12 @@ void
 eal_thread_ack_command(void)
 {
 	unsigned int lcore_id = rte_lcore_id();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	char c = 0;
 	int w2m;
 	int n;
 
-	w2m = lcore_config[lcore_id].pipe_worker2main[1];
+	w2m = runtime_state->lcore_cfg[lcore_id].pipe_worker2main[1];
 	do {
 		n = write(w2m, &c, 1);
 	} while (n == 0 || (n < 0 && errno == EINTR));
lib/eal/windows/eal.c +10 -12
index a39b39dc47..2f8f6200ba 100644
@@ -38,9 +38,6 @@
  */
 static int mem_cfg_fd = -1;
 
-/* internal configuration (per-core) */
-struct lcore_config lcore_config[RTE_MAX_LCORE];
-
 /* Detect if we are a primary or a secondary process */
 enum rte_proc_type_t
 eal_proc_type_detect(void)
@@ -164,6 +161,7 @@ rte_eal_init(int argc, char **argv)
 	int i, fctret, bscan;
 	const struct rte_config *config = rte_eal_get_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	bool has_phys_addr;
 	enum rte_iova_mode iova_mode;
 	int ret;
@@ -353,13 +351,13 @@ rte_eal_init(int argc, char **argv)
 	eal_rand_init();
 
 	if (rte_thread_set_affinity_by_id(rte_thread_self(),
-			&lcore_config[config->main_lcore].cpuset) != 0) {
+			&runtime_state->lcore_cfg[config->main_lcore].cpuset) != 0) {
 		rte_eal_init_alert("Cannot set affinity");
 		rte_errno = EINVAL;
 		goto err_out;
 	}
 	__rte_thread_init(config->main_lcore,
-		&lcore_config[config->main_lcore].cpuset);
+		&runtime_state->lcore_cfg[config->main_lcore].cpuset);
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 	EAL_LOG(DEBUG, "Main lcore %u is ready (tid=%zx;cpuset=[%s%s])",
@@ -372,17 +370,17 @@ rte_eal_init(int argc, char **argv)
 		 * create communication pipes between main thread
 		 * and children
 		 */
-		if (_pipe(lcore_config[i].pipe_main2worker,
+		if (_pipe(runtime_state->lcore_cfg[i].pipe_main2worker,
 			sizeof(char), _O_BINARY) < 0)
 			rte_panic("Cannot create pipe\n");
-		if (_pipe(lcore_config[i].pipe_worker2main,
+		if (_pipe(runtime_state->lcore_cfg[i].pipe_worker2main,
 			sizeof(char), _O_BINARY) < 0)
 			rte_panic("Cannot create pipe\n");
 
-		lcore_config[i].state = WAIT;
+		runtime_state->lcore_cfg[i].state = WAIT;
 
 		/* create a thread for each lcore */
-		if (rte_thread_create(&lcore_config[i].thread_id, NULL,
+		if (rte_thread_create(&runtime_state->lcore_cfg[i].thread_id, NULL,
 				eal_thread_loop, (void *)(uintptr_t)i) != 0)
 			rte_panic("Cannot create thread\n");
 
@@ -391,10 +389,10 @@ rte_eal_init(int argc, char **argv)
 		if (ret >= RTE_THREAD_NAME_SIZE)
 			EAL_LOG(INFO, "Worker thread name %s truncated", thread_name);
 
-		rte_thread_set_name(lcore_config[i].thread_id, thread_name);
+		rte_thread_set_name(runtime_state->lcore_cfg[i].thread_id, thread_name);
 
-		ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
-			&lcore_config[i].cpuset);
+		ret = rte_thread_set_affinity_by_id(runtime_state->lcore_cfg[i].thread_id,
+			&runtime_state->lcore_cfg[i].cpuset);
 		if (ret != 0)
 			EAL_LOG(DEBUG, "Cannot set affinity");
 	}
lib/eal/windows/eal_thread.c +7 -4
index 3eeb94a589..7dbba48ecb 100644
@@ -20,8 +20,9 @@
 int
 eal_thread_wake_worker(unsigned int worker_id)
 {
-	int m2w = lcore_config[worker_id].pipe_main2worker[1];
-	int w2m = lcore_config[worker_id].pipe_worker2main[0];
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	int m2w = runtime_state->lcore_cfg[worker_id].pipe_main2worker[1];
+	int w2m = runtime_state->lcore_cfg[worker_id].pipe_worker2main[0];
 	char c = 0;
 	int n;
 
@@ -43,11 +44,12 @@ void
 eal_thread_wait_command(void)
 {
 	unsigned int lcore_id = rte_lcore_id();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int m2w;
 	char c;
 	int n;
 
-	m2w = lcore_config[lcore_id].pipe_main2worker[0];
+	m2w = runtime_state->lcore_cfg[lcore_id].pipe_main2worker[0];
 	do {
 		n = _read(m2w, &c, 1);
 	} while (n < 0 && errno == EINTR);
@@ -59,11 +61,12 @@ void
 eal_thread_ack_command(void)
 {
 	unsigned int lcore_id = rte_lcore_id();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	char c = 0;
 	int w2m;
 	int n;
 
-	w2m = lcore_config[lcore_id].pipe_worker2main[1];
+	w2m = runtime_state->lcore_cfg[lcore_id].pipe_worker2main[1];
 	do {
 		n = _write(w2m, &c, 1);
 	} while (n == 0 || (n < 0 && errno == EINTR));
Signature · 1 line
2.55.0
#110 lore raw

PATCH v3 16/39 eal: move core indices bitset to runtime state

In reply to Bruce Richardson

Move the bitset for tracking allocated lcore ids to the runtime configuration struct, to co-exist with the other lcore data.

---
 lib/eal/common/eal_common_lcore.c   | 12 +++++++-----
 lib/eal/common/eal_common_options.c | 11 ++++++-----
 lib/eal/common/eal_internal_cfg.h   |  2 ++
 lib/eal/common/eal_private.h        |  3 ---
 4 files changed, 15 insertions(+), 13 deletions(-)
lib/eal/common/eal_common_lcore.c +7 -5
index e207697900..eab60d548a 100644
@@ -234,7 +234,7 @@ rte_eal_cpu_init(void)
 		runtime_state->lcore_cfg[lcore_id].first_cpu = lcore_id;
 
 		/* This is the first time we discover the lcores, so the bitset should be zeroed */
-		rte_bitset_set(config->core_indices, count);
+		rte_bitset_set(runtime_state->core_indices, count);
 
 		/* By default, each detected core is enabled */
 		config->lcore_role[lcore_id] = RTE_LCORE_ROLE_RTE;
@@ -428,7 +428,7 @@ eal_lcore_non_eal_allocate(void)
 	int core_index = -1;
 
 	rte_rwlock_write_lock(&lcore_lock);
-	core_index = rte_bitset_find_first_clear(cfg->core_indices, RTE_MAX_LCORE);
+	core_index = rte_bitset_find_first_clear(runtime_state->core_indices, RTE_MAX_LCORE);
 	if (core_index == -1) {
 		EAL_LOG(DEBUG, "No core_index available.");
 		lcore_id = RTE_MAX_LCORE;
@@ -437,7 +437,7 @@ eal_lcore_non_eal_allocate(void)
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
 		if (cfg->lcore_role[lcore_id] != RTE_LCORE_ROLE_OFF)
 			continue;
-		rte_bitset_set(cfg->core_indices, core_index);
+		rte_bitset_set(runtime_state->core_indices, core_index);
 		runtime_state->lcore_cfg[lcore_id].core_index = core_index;
 		cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_NON_EAL;
 		cfg->lcore_count++;
@@ -460,7 +460,8 @@ eal_lcore_non_eal_allocate(void)
 		}
 		EAL_LOG(DEBUG, "Initialization refused for lcore %u.",
 			lcore_id);
-		rte_bitset_clear(cfg->core_indices, runtime_state->lcore_cfg[lcore_id].core_index);
+		rte_bitset_clear(runtime_state->core_indices,
+				runtime_state->lcore_cfg[lcore_id].core_index);
 		runtime_state->lcore_cfg[lcore_id].core_index = -1;
 		cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
 		cfg->lcore_count--;
@@ -484,7 +485,8 @@ eal_lcore_non_eal_release(unsigned int lcore_id)
 		goto out;
 	TAILQ_FOREACH(callback, &lcore_callbacks, next)
 		callback_uninit(callback, lcore_id);
-	rte_bitset_clear(cfg->core_indices, runtime_state->lcore_cfg[lcore_id].core_index);
+	rte_bitset_clear(runtime_state->core_indices,
+			runtime_state->lcore_cfg[lcore_id].core_index);
 	runtime_state->lcore_cfg[lcore_id].core_index = -1;
 	cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
 	cfg->lcore_count--;
lib/eal/common/eal_common_options.c +6 -5
index fa1d7763c2..4477969a1f 100644
@@ -864,6 +864,7 @@ static int
 eal_parse_service_coremask(const char *coremask)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int i, j, idx = 0;
 	unsigned int count = 0;
 	char c;
@@ -920,7 +921,7 @@ eal_parse_service_coremask(const char *coremask)
 		if (coremask[i] != '0')
 			return -1;
 
-	rte_bitset_clear_all(cfg->core_indices, RTE_MAX_LCORE);
+	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
 
 	if (count == 0)
 		return -1;
@@ -946,7 +947,7 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 	int ret = 0;
 
 	/* set everything to disabled first, then set up values */
-	rte_bitset_clear_all(cfg->core_indices, RTE_MAX_LCORE);
+	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
 		cfg->lcore_role[i] = RTE_LCORE_ROLE_OFF;
 		runtime_state->lcore_cfg[i].core_index = -1;
@@ -976,7 +977,7 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 				continue;
 			}
 
-			rte_bitset_set(cfg->core_indices, count);
+			rte_bitset_set(runtime_state->core_indices, count);
 			cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_RTE;
 			runtime_state->lcore_cfg[lcore_id].core_index = count;
 			CPU_ZERO(&runtime_state->lcore_cfg[lcore_id].cpuset);
@@ -1400,7 +1401,7 @@ eal_parse_lcores(const char *lcores)
 	CPU_ZERO(&cpuset);
 
 	/* Reset lcore config */
-	rte_bitset_clear_all(cfg->core_indices, RTE_MAX_LCORE);
+	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
 	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
 		cfg->lcore_role[idx] = RTE_LCORE_ROLE_OFF;
 		runtime_state->lcore_cfg[idx].core_index = -1;
@@ -1466,7 +1467,7 @@ eal_parse_lcores(const char *lcores)
 			set_count--;
 
 			if (cfg->lcore_role[idx] != RTE_LCORE_ROLE_RTE) {
-				rte_bitset_set(cfg->core_indices, count);
+				rte_bitset_set(runtime_state->core_indices, count);
 				runtime_state->lcore_cfg[idx].core_index = count;
 				cfg->lcore_role[idx] = RTE_LCORE_ROLE_RTE;
 				count++;
lib/eal/common/eal_internal_cfg.h +2 -0
index 28388793a1..e0a3c8dec5 100644
@@ -16,6 +16,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 
+#include <rte_bitset.h>
 #include <rte_stdatomic.h>
 #include "eal_thread.h"
 
@@ -150,6 +151,7 @@ struct eal_runtime_state {
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
 	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
+	RTE_BITSET_DECLARE(core_indices, RTE_MAX_LCORE); /**< currently allocated core_indices */
 };
 
 struct eal_user_cfg *eal_get_user_configuration(void);
lib/eal/common/eal_private.h +0 -3
index e146be3adb..d2b99582c9 100644
@@ -11,7 +11,6 @@
 #include <sys/queue.h>
 
 #include <dev_driver.h>
-#include <rte_bitset.h>
 #include <rte_lcore.h>
 #include <rte_log.h>
 #include <rte_memory.h>
@@ -22,8 +21,6 @@
  * The global RTE configuration structure.
  */
 struct rte_config {
-	RTE_BITSET_DECLARE(core_indices,
-			   RTE_MAX_LCORE); /**< bitset of currently allocated core_indices */
 	uint32_t main_lcore;         /**< Id of the main lcore */
 	uint32_t lcore_count;        /**< Number of available logical cores. */
 	uint32_t numa_node_count;    /**< Number of detected NUMA nodes. */
Signature · 1 line
2.55.0
#111 lore raw

PATCH v3 17/39 eal: cleanup CPU init function

In reply to Bruce Richardson

The CPU init function did extra work in zeroing the runtime config for lcores, something that was being done a second time in configuring the argparsing stage when preparing to set up the correct cpu affinities for each lcore. Therefore we can remove that unnecessary initialization, and have the function not make any changes to "runtime_state" but only the "platform_info".

In the process we can make some other cleanups too:
* remove the limit on the lcore_to_socket_id array, and dynamically allocate it to the correct number of present cores.
* with the runtime lcore init gone, we can move the assignment to the lcore_to_socket_id into the first loop, allowing us to remove the second loop entirely.
* the log message about "skipping" lcores was incorrect for modern DPDK, since we no longer have a hard-link between physical core numbers and lcore ids. Therefore just report what cores are detected on what sockets.

---
 lib/eal/common/eal_common_lcore.c | 92 +++++++++----------------------
 1 file changed, 25 insertions(+), 67 deletions(-)
lib/eal/common/eal_common_lcore.c +25 -67
index eab60d548a..02fbadb0ba 100644
@@ -177,18 +177,10 @@ socket_id_cmp(const void *a, const void *b)
 int
 rte_eal_cpu_init(void)
 {
-	/* pointer to global configuration */
 	struct rte_config *config = rte_eal_get_configuration();
 	struct eal_platform_info *platform_info = eal_get_platform_info();
-	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
-	unsigned lcore_id;
-	unsigned count = 0;
-	unsigned int socket_id, prev_socket_id;
-#if CPU_SETSIZE > RTE_MAX_LCORE
-	int lcore_to_socket_id[CPU_SETSIZE] = {0};
-#else
-	int lcore_to_socket_id[RTE_MAX_LCORE] = {0};
-#endif
+	int *lcore_to_socket_id;
+	size_t nb_detected_cpus = 0;
 
 	/* allocate cpu_info for all CPUs visible to the OS */
 	platform_info->cpu_count = eal_cpu_max();
@@ -198,6 +190,12 @@ rte_eal_cpu_init(void)
 		EAL_LOG(ERR, "Cannot allocate cpu_info array");
 		return -1;
 	}
+	lcore_to_socket_id = calloc(platform_info->cpu_count, sizeof(*lcore_to_socket_id));
+	if (lcore_to_socket_id == NULL) {
+		EAL_LOG(ERR, "Cannot allocate lcore_to_socket_id array");
+		free(platform_info->cpu_info);
+		return -1;
+	}
 
 	/* populate cpu_info with hardware topology for all detected CPUs */
 	for (size_t cpu_id = 0; cpu_id < platform_info->cpu_count; cpu_id++) {
@@ -206,71 +204,30 @@ rte_eal_cpu_init(void)
 		platform_info->cpu_info[cpu_id].detected = true;
 		platform_info->cpu_info[cpu_id].numa_id = eal_cpu_socket_id(cpu_id);
 		platform_info->cpu_info[cpu_id].core_id = eal_cpu_core_id(cpu_id);
-	}
-
-	/*
-	 * Parse the maximum set of logical cores, detect the subset of running
-	 * ones and enable them by default.
-	 */
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		runtime_state->lcore_cfg[lcore_id].core_index = count;
-
-		/* init cpuset for per lcore config */
-		CPU_ZERO(&runtime_state->lcore_cfg[lcore_id].cpuset);
-		runtime_state->lcore_cfg[lcore_id].first_cpu = UINT16_MAX;
+		/* store numa id for later processing to determine all unique numa nodes */
+		lcore_to_socket_id[nb_detected_cpus++] = platform_info->cpu_info[cpu_id].numa_id;
 
-		if (eal_cpu_detected(lcore_id) == 0) {
-			config->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
-			runtime_state->lcore_cfg[lcore_id].core_index = -1;
-			continue;
-		}
-
-		/* find socket first */
-		socket_id = platform_info->cpu_info[lcore_id].numa_id;
-		lcore_to_socket_id[lcore_id] = socket_id;
-
-		/* By default, lcore 1:1 map to cpu id */
-		CPU_SET(lcore_id, &runtime_state->lcore_cfg[lcore_id].cpuset);
-		runtime_state->lcore_cfg[lcore_id].first_cpu = lcore_id;
-
-		/* This is the first time we discover the lcores, so the bitset should be zeroed */
-		rte_bitset_set(runtime_state->core_indices, count);
-
-		/* By default, each detected core is enabled */
-		config->lcore_role[lcore_id] = RTE_LCORE_ROLE_RTE;
-		EAL_LOG(DEBUG, "Detected lcore %u as "
-				"core %u on NUMA node %u",
-				lcore_id,
-				platform_info->cpu_info[lcore_id].core_id,
-				platform_info->cpu_info[lcore_id].numa_id);
-		count++;
-	}
-	for (; lcore_id < CPU_SETSIZE; lcore_id++) {
-		if (eal_cpu_detected(lcore_id) == 0)
-			continue;
-		if (unlikely(lcore_id >= platform_info->cpu_count))
-			break;
-		lcore_to_socket_id[lcore_id] = platform_info->cpu_info[lcore_id].numa_id;
-		EAL_LOG(DEBUG, "Skipped lcore %u as core %u on NUMA node %u",
-			lcore_id, platform_info->cpu_info[lcore_id].core_id,
-			platform_info->cpu_info[lcore_id].numa_id);
+		EAL_LOG(DEBUG, "Detected CPU %zu as core %u on NUMA node %u",
+				cpu_id,
+				platform_info->cpu_info[cpu_id].core_id,
+				platform_info->cpu_info[cpu_id].numa_id);
 	}
 
-	/* Set the count of enabled logical cores of the EAL configuration */
-	config->lcore_count = count;
-	EAL_LOG(DEBUG,
-			"Maximum logical cores by configuration: %u",
-			RTE_MAX_LCORE);
-	EAL_LOG(INFO, "Detected CPU lcores: %u", config->lcore_count);
+	if (nb_detected_cpus == 0) {
+		EAL_LOG(ERR, "No CPUs detected for platform topology");
+		free(platform_info->cpu_info);
+		free(lcore_to_socket_id);
+		return -1;
+	}
 
 	/* sort all socket id's in ascending order */
-	qsort(lcore_to_socket_id, RTE_DIM(lcore_to_socket_id),
+	qsort(lcore_to_socket_id, nb_detected_cpus,
 			sizeof(lcore_to_socket_id[0]), socket_id_cmp);
 
-	prev_socket_id = -1;
+	int prev_socket_id = -1;
 	config->numa_node_count = 0;
-	for (lcore_id = 0; lcore_id < RTE_DIM(lcore_to_socket_id); lcore_id++) {
-		socket_id = lcore_to_socket_id[lcore_id];
+	for (size_t i = 0; i < nb_detected_cpus; i++) {
+		int socket_id = lcore_to_socket_id[i];
 		if (socket_id != prev_socket_id)
 			config->numa_nodes[config->numa_node_count++] =	socket_id;
 		prev_socket_id = socket_id;
@@ -279,6 +236,7 @@ rte_eal_cpu_init(void)
 	}
 	EAL_LOG(INFO, "Detected NUMA nodes: %u", config->numa_node_count);
 
+	free(lcore_to_socket_id);
 	return 0;
 }
 
Signature · 1 line
2.55.0
#112 lore raw

PATCH v3 18/39 eal: move NUMA node information to platform info struct

In reply to Bruce Richardson

The numa node information for the platform is stored in rte_config but belongs more in platform info struct. Move the data to that location. In the process remove the hard-coded limit for RTE_MAX_NUMA_NODES for the array. At least for platform info, we can record details about all numa nodes, whatever the number.

---
 lib/eal/common/eal_common_lcore.c | 59 ++++++++++++++++++++++---------
 lib/eal/common/eal_internal_cfg.h |  2 ++
 lib/eal/common/eal_private.h      |  2 --
 3 files changed, 45 insertions(+), 18 deletions(-)
lib/eal/common/eal_common_lcore.c +43 -16
index 02fbadb0ba..e208ee7437 100644
@@ -177,7 +177,6 @@ socket_id_cmp(const void *a, const void *b)
 int
 rte_eal_cpu_init(void)
 {
-	struct rte_config *config = rte_eal_get_configuration();
 	struct eal_platform_info *platform_info = eal_get_platform_info();
 	int *lcore_to_socket_id;
 	size_t nb_detected_cpus = 0;
@@ -224,19 +223,47 @@ rte_eal_cpu_init(void)
 	qsort(lcore_to_socket_id, nb_detected_cpus,
 			sizeof(lcore_to_socket_id[0]), socket_id_cmp);
 
-	int prev_socket_id = -1;
-	config->numa_node_count = 0;
-	for (size_t i = 0; i < nb_detected_cpus; i++) {
-		int socket_id = lcore_to_socket_id[i];
-		if (socket_id != prev_socket_id)
-			config->numa_nodes[config->numa_node_count++] =	socket_id;
-		prev_socket_id = socket_id;
-		if (config->numa_node_count >= RTE_MAX_NUMA_NODES)
-			break;
+	/* allocate worst-case (one NUMA node per CPU), then dedup and shrink */
+	platform_info->numa_nodes = calloc(platform_info->cpu_count,
+			sizeof(*platform_info->numa_nodes));
+	if (platform_info->numa_nodes == NULL) {
+		EAL_LOG(ERR, "Cannot allocate numa_nodes array");
+		free(lcore_to_socket_id);
+		free(platform_info->cpu_info);
+		return -1;
 	}
-	EAL_LOG(INFO, "Detected NUMA nodes: %u", config->numa_node_count);
 
+	uint32_t numa_node_count = 0;
+	int prev_socket_id = -1;
+	for (size_t cpu_id = 0; cpu_id < nb_detected_cpus; cpu_id++) {
+		int socket_id = lcore_to_socket_id[cpu_id];
+		if (socket_id != prev_socket_id) {
+			platform_info->numa_nodes[numa_node_count++] = socket_id;
+			prev_socket_id = socket_id;
+		}
+	}
 	free(lcore_to_socket_id);
+
+	if (numa_node_count > RTE_MAX_NUMA_NODES) {
+		EAL_LOG(ERR, "Detected %u NUMA nodes, but only RTE_MAX_NUMA_NODES (%u) are supported",
+				numa_node_count, RTE_MAX_NUMA_NODES);
+		free(platform_info->numa_nodes);
+		platform_info->numa_nodes = NULL;
+		free(platform_info->cpu_info);
+		platform_info->cpu_info = NULL;
+		return -1;
+	}
+	platform_info->numa_node_count = numa_node_count;
+
+	/* shrink to the actual number of unique NUMA nodes found,
+	 * realloc may fail, in that case we keep the original allocation
+	 */
+	uint32_t *tmp = realloc(platform_info->numa_nodes,
+			numa_node_count * sizeof(*platform_info->numa_nodes));
+	if (tmp != NULL)
+		platform_info->numa_nodes = tmp;
+	EAL_LOG(INFO, "Detected NUMA nodes: %u", platform_info->numa_node_count);
+
 	return 0;
 }
 
@@ -244,20 +271,20 @@ RTE_EXPORT_SYMBOL(rte_socket_count)
 unsigned int
 rte_socket_count(void)
 {
-	const struct rte_config *config = rte_eal_get_configuration();
-	return config->numa_node_count;
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	return platform_info->numa_node_count;
 }
 
 RTE_EXPORT_SYMBOL(rte_socket_id_by_idx)
 int
 rte_socket_id_by_idx(unsigned int idx)
 {
-	const struct rte_config *config = rte_eal_get_configuration();
-	if (idx >= config->numa_node_count) {
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	if (idx >= platform_info->numa_node_count) {
 		rte_errno = EINVAL;
 		return -1;
 	}
-	return config->numa_nodes[idx];
+	return platform_info->numa_nodes[idx];
 }
 
 static rte_rwlock_t lcore_lock = RTE_RWLOCK_INITIALIZER;
lib/eal/common/eal_internal_cfg.h +2 -0
index e0a3c8dec5..feb7baf71f 100644
@@ -118,6 +118,8 @@ struct eal_cpu_info {
 struct eal_platform_info {
 	size_t cpu_count;                /**< number of entries in cpu_info[] */
 	struct eal_cpu_info *cpu_info;   /**< per-physical-CPU hardware facts */
+	uint32_t numa_node_count;        /**< number of detected NUMA nodes */
+	uint32_t *numa_nodes;            /**< sorted list of detected NUMA node IDs */
 	uint8_t num_hugepage_sizes;      /**< how many sizes on this system */
 	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
 };
lib/eal/common/eal_private.h +0 -2
index d2b99582c9..4d1a28762e 100644
@@ -23,8 +23,6 @@
 struct rte_config {
 	uint32_t main_lcore;         /**< Id of the main lcore */
 	uint32_t lcore_count;        /**< Number of available logical cores. */
-	uint32_t numa_node_count;    /**< Number of detected NUMA nodes. */
-	uint32_t numa_nodes[RTE_MAX_NUMA_NODES]; /**< List of detected NUMA nodes. */
 	uint32_t service_lcore_count;/**< Number of available service cores. */
 	enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
 
Signature · 1 line
2.55.0
#113 lore raw

PATCH v3 19/39 eal: move lcore role and count to runtime state

In reply to Bruce Richardson

Move the lcore role and lcore count values from rte_config struct to the runtime state struct. Update all call sites. The service_lcore_count value was set but never actually used, so just remove it from rte_config rather than moving it to the new structure.

---
 lib/eal/common/eal_common_lcore.c   | 53 ++++++++++++++---------------
 lib/eal/common/eal_common_options.c | 37 +++++++++-----------
 lib/eal/common/eal_internal_cfg.h   |  2 ++
 lib/eal/common/eal_private.h        |  3 --
 lib/eal/common/rte_service.c        | 14 ++++----
 5 files changed, 51 insertions(+), 58 deletions(-)
lib/eal/common/eal_common_lcore.c +25 -28
index e208ee7437..24c8872765 100644
@@ -30,7 +30,7 @@ unsigned int rte_get_main_lcore(void)
 RTE_EXPORT_SYMBOL(rte_lcore_count)
 unsigned int rte_lcore_count(void)
 {
-	return rte_eal_get_configuration()->lcore_count;
+	return eal_get_runtime_state()->lcore_count;
 }
 
 RTE_EXPORT_SYMBOL(rte_lcore_index)
@@ -86,33 +86,33 @@ RTE_EXPORT_SYMBOL(rte_eal_lcore_role)
 enum rte_lcore_role_t
 rte_eal_lcore_role(unsigned int lcore_id)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	if (lcore_id >= RTE_MAX_LCORE)
 		return RTE_LCORE_ROLE_OFF;
-	return cfg->lcore_role[lcore_id];
+	return runtime_state->lcore_role[lcore_id];
 }
 
 RTE_EXPORT_SYMBOL(rte_lcore_has_role)
 int
 rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	if (lcore_id >= RTE_MAX_LCORE)
 		return 0;
 
-	return cfg->lcore_role[lcore_id] == role;
+	return runtime_state->lcore_role[lcore_id] == role;
 }
 
 RTE_EXPORT_SYMBOL(rte_lcore_is_enabled)
 int rte_lcore_is_enabled(unsigned int lcore_id)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	if (lcore_id >= RTE_MAX_LCORE)
 		return 0;
-	return cfg->lcore_role[lcore_id] == RTE_LCORE_ROLE_RTE;
+	return runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_RTE;
 }
 
 RTE_EXPORT_SYMBOL(rte_get_next_lcore)
@@ -330,7 +330,7 @@ void *
 rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
 	rte_lcore_uninit_cb uninit, void *arg)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct lcore_callback *callback;
 	unsigned int lcore_id;
 
@@ -350,7 +350,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
 	if (callback->init == NULL)
 		goto no_init;
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (cfg->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
+		if (runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
 			continue;
 		if (callback_init(callback, lcore_id) == 0)
 			continue;
@@ -358,7 +358,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
 		 * previous lcore.
 		 */
 		while (lcore_id-- != 0) {
-			if (cfg->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
+			if (runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
 				continue;
 			callback_uninit(callback, lcore_id);
 		}
@@ -380,7 +380,7 @@ RTE_EXPORT_SYMBOL(rte_lcore_callback_unregister)
 void
 rte_lcore_callback_unregister(void *handle)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct lcore_callback *callback = handle;
 	unsigned int lcore_id;
 
@@ -390,7 +390,7 @@ rte_lcore_callback_unregister(void *handle)
 	if (callback->uninit == NULL)
 		goto no_uninit;
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (cfg->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
+		if (runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
 			continue;
 		callback_uninit(callback, lcore_id);
 	}
@@ -405,7 +405,6 @@ rte_lcore_callback_unregister(void *handle)
 unsigned int
 eal_lcore_non_eal_allocate(void)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct lcore_callback *callback;
 	struct lcore_callback *prev;
@@ -420,12 +419,12 @@ eal_lcore_non_eal_allocate(void)
 		goto out;
 	}
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (cfg->lcore_role[lcore_id] != RTE_LCORE_ROLE_OFF)
+		if (runtime_state->lcore_role[lcore_id] != RTE_LCORE_ROLE_OFF)
 			continue;
 		rte_bitset_set(runtime_state->core_indices, core_index);
 		runtime_state->lcore_cfg[lcore_id].core_index = core_index;
-		cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_NON_EAL;
-		cfg->lcore_count++;
+		runtime_state->lcore_role[lcore_id] =RTE_LCORE_ROLE_NON_EAL;
+		runtime_state->lcore_count++;
 		break;
 	}
 	if (lcore_id == RTE_MAX_LCORE) {
@@ -448,8 +447,8 @@ eal_lcore_non_eal_allocate(void)
 		rte_bitset_clear(runtime_state->core_indices,
 				runtime_state->lcore_cfg[lcore_id].core_index);
 		runtime_state->lcore_cfg[lcore_id].core_index = -1;
-		cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
-		cfg->lcore_count--;
+		runtime_state->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
+		runtime_state->lcore_count--;
 		lcore_id = RTE_MAX_LCORE;
 		goto out;
 	}
@@ -461,20 +460,19 @@ eal_lcore_non_eal_allocate(void)
 void
 eal_lcore_non_eal_release(unsigned int lcore_id)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct lcore_callback *callback;
 
 	rte_rwlock_write_lock(&lcore_lock);
-	if (cfg->lcore_role[lcore_id] != RTE_LCORE_ROLE_NON_EAL)
+	if (runtime_state->lcore_role[lcore_id] != RTE_LCORE_ROLE_NON_EAL)
 		goto out;
 	TAILQ_FOREACH(callback, &lcore_callbacks, next)
 		callback_uninit(callback, lcore_id);
 	rte_bitset_clear(runtime_state->core_indices,
 			runtime_state->lcore_cfg[lcore_id].core_index);
 	runtime_state->lcore_cfg[lcore_id].core_index = -1;
-	cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
-	cfg->lcore_count--;
+	runtime_state->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
+	runtime_state->lcore_count--;
 out:
 	rte_rwlock_write_unlock(&lcore_lock);
 }
@@ -483,13 +481,13 @@ RTE_EXPORT_SYMBOL(rte_lcore_iterate)
 int
 rte_lcore_iterate(rte_lcore_iterate_cb cb, void *arg)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int lcore_id;
 	int ret = 0;
 
 	rte_rwlock_read_lock(&lcore_lock);
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (cfg->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
+		if (runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
 			continue;
 		ret = cb(lcore_id, arg);
 		if (ret != 0)
@@ -534,7 +532,6 @@ static int
 lcore_dump_cb(unsigned int lcore_id, void *arg)
 {
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
-	struct rte_config *cfg = rte_eal_get_configuration();
 	char *cpuset;
 	struct rte_lcore_usage usage;
 	rte_lcore_usage_cb usage_cb;
@@ -555,7 +552,7 @@ lcore_dump_cb(unsigned int lcore_id, void *arg)
 	cpuset = eal_cpuset_to_str(&runtime_state->lcore_cfg[lcore_id].cpuset);
 	fprintf(f, "lcore %u, socket %u, role %s, cpuset %s\n", lcore_id,
 		rte_lcore_to_socket_id(lcore_id),
-		lcore_role_str(cfg->lcore_role[lcore_id]),
+		lcore_role_str(runtime_state->lcore_role[lcore_id]),
 		cpuset != NULL ? cpuset : "<unknown>");
 	free(cpuset);
 	free(usage_str);
@@ -608,7 +605,6 @@ static int
 lcore_telemetry_info_cb(unsigned int lcore_id, void *arg)
 {
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
-	struct rte_config *cfg = rte_eal_get_configuration();
 	struct lcore_telemetry_info *info = arg;
 	char ratio_str[RTE_TEL_MAX_STRING_LEN];
 	struct rte_lcore_usage usage;
@@ -622,7 +618,8 @@ lcore_telemetry_info_cb(unsigned int lcore_id, void *arg)
 	rte_tel_data_start_dict(info->d);
 	rte_tel_data_add_dict_int(info->d, "lcore_id", lcore_id);
 	rte_tel_data_add_dict_int(info->d, "socket", rte_lcore_to_socket_id(lcore_id));
-	rte_tel_data_add_dict_string(info->d, "role", lcore_role_str(cfg->lcore_role[lcore_id]));
+	rte_tel_data_add_dict_string(info->d, "role",
+			lcore_role_str(runtime_state->lcore_role[lcore_id]));
 	cpuset = rte_tel_data_alloc();
 	if (cpuset == NULL)
 		return -ENOMEM;
lib/eal/common/eal_common_options.c +17 -20
index 4477969a1f..6a7da51dac 100644
@@ -863,7 +863,6 @@ static int xdigit2val(unsigned char c)
 static int
 eal_parse_service_coremask(const char *coremask)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int i, j, idx = 0;
 	unsigned int count = 0;
@@ -908,10 +907,10 @@ eal_parse_service_coremask(const char *coremask)
 					return -1;
 				}
 
-				if (cfg->lcore_role[idx] == RTE_LCORE_ROLE_RTE)
+				if (runtime_state->lcore_role[idx] == RTE_LCORE_ROLE_RTE)
 					taken_lcore_count++;
 
-				cfg->lcore_role[idx] = RTE_LCORE_ROLE_SERVICE;
+				runtime_state->lcore_role[idx] = RTE_LCORE_ROLE_SERVICE;
 				count++;
 			}
 		}
@@ -932,14 +931,12 @@ eal_parse_service_coremask(const char *coremask)
 			"Please ensure -c or -l includes service cores");
 	}
 
-	cfg->service_lcore_count = count;
 	return 0;
 }
 
 static int
 update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int lcore_id = remap_base;
 	unsigned int count = 0;
@@ -949,7 +946,7 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 	/* set everything to disabled first, then set up values */
 	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		cfg->lcore_role[i] = RTE_LCORE_ROLE_OFF;
+		runtime_state->lcore_role[i] = RTE_LCORE_ROLE_OFF;
 		runtime_state->lcore_cfg[i].core_index = -1;
 	}
 
@@ -978,7 +975,7 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 			}
 
 			rte_bitset_set(runtime_state->core_indices, count);
-			cfg->lcore_role[lcore_id] = RTE_LCORE_ROLE_RTE;
+			runtime_state->lcore_role[lcore_id] = RTE_LCORE_ROLE_RTE;
 			runtime_state->lcore_cfg[lcore_id].core_index = count;
 			CPU_ZERO(&runtime_state->lcore_cfg[lcore_id].cpuset);
 			CPU_SET(i, &runtime_state->lcore_cfg[lcore_id].cpuset);
@@ -993,7 +990,7 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 		ret = -1;
 	}
 	if (!ret)
-		cfg->lcore_count = count;
+		runtime_state->lcore_count = count;
 	return ret;
 }
 
@@ -1112,7 +1109,7 @@ rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_ra
 static int
 eal_parse_service_corelist(const char *corelist)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int i;
 	unsigned count = 0;
 	char *end = NULL;
@@ -1151,11 +1148,11 @@ eal_parse_service_corelist(const char *corelist)
 			if (min == RTE_MAX_LCORE)
 				min = idx;
 			for (idx = min; idx <= max; idx++) {
-				if (cfg->lcore_role[idx] != RTE_LCORE_ROLE_SERVICE) {
-					if (cfg->lcore_role[idx] == RTE_LCORE_ROLE_RTE)
+				if (runtime_state->lcore_role[idx] != RTE_LCORE_ROLE_SERVICE) {
+					if (runtime_state->lcore_role[idx] == RTE_LCORE_ROLE_RTE)
 						taken_lcore_count++;
 
-					cfg->lcore_role[idx] = RTE_LCORE_ROLE_SERVICE;
+					runtime_state->lcore_role[idx] = RTE_LCORE_ROLE_SERVICE;
 					count++;
 				}
 			}
@@ -1178,7 +1175,7 @@ eal_parse_service_corelist(const char *corelist)
 	rte_cpuset_t service_cpuset;
 	CPU_ZERO(&service_cpuset);
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (cfg->lcore_role[i] == RTE_LCORE_ROLE_SERVICE)
+		if (runtime_state->lcore_role[i] == RTE_LCORE_ROLE_SERVICE)
 			CPU_SET(i, &service_cpuset);
 	}
 	if (CPU_COUNT(&service_cpuset) > 0) {
@@ -1198,6 +1195,7 @@ eal_parse_main_lcore(const char *arg)
 {
 	char *parsing_end;
 	struct rte_config *cfg = rte_eal_get_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	errno = 0;
 	cfg->main_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
@@ -1207,12 +1205,12 @@ eal_parse_main_lcore(const char *arg)
 		return -1;
 
 	/* ensure main core is not used as service core */
-	if (cfg->lcore_role[cfg->main_lcore] == RTE_LCORE_ROLE_SERVICE) {
+	if (runtime_state->lcore_role[cfg->main_lcore] == RTE_LCORE_ROLE_SERVICE) {
 		EAL_LOG(ERR, "Error: Main lcore is used as a service core");
 		return -1;
 	}
 	/* check that we have the core recorded in the core list */
-	if (cfg->lcore_role[cfg->main_lcore] != RTE_LCORE_ROLE_RTE) {
+	if (runtime_state->lcore_role[cfg->main_lcore] != RTE_LCORE_ROLE_RTE) {
 		EAL_LOG(ERR, "Error: Main lcore is not enabled for DPDK");
 		return -1;
 	}
@@ -1378,7 +1376,6 @@ check_cpuset(rte_cpuset_t *set)
 static int
 eal_parse_lcores(const char *lcores)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	rte_cpuset_t lcore_set;
 	unsigned int set_count;
@@ -1403,7 +1400,7 @@ eal_parse_lcores(const char *lcores)
 	/* Reset lcore config */
 	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
 	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-		cfg->lcore_role[idx] = RTE_LCORE_ROLE_OFF;
+		runtime_state->lcore_role[idx] = RTE_LCORE_ROLE_OFF;
 		runtime_state->lcore_cfg[idx].core_index = -1;
 		CPU_ZERO(&runtime_state->lcore_cfg[idx].cpuset);
 		runtime_state->lcore_cfg[idx].first_cpu = UINT16_MAX;
@@ -1466,10 +1463,10 @@ eal_parse_lcores(const char *lcores)
 				continue;
 			set_count--;
 
-			if (cfg->lcore_role[idx] != RTE_LCORE_ROLE_RTE) {
+			if (runtime_state->lcore_role[idx] != RTE_LCORE_ROLE_RTE) {
 				rte_bitset_set(runtime_state->core_indices, count);
 				runtime_state->lcore_cfg[idx].core_index = count;
-				cfg->lcore_role[idx] = RTE_LCORE_ROLE_RTE;
+				runtime_state->lcore_role[idx] = RTE_LCORE_ROLE_RTE;
 				count++;
 			}
 
@@ -1496,7 +1493,7 @@ eal_parse_lcores(const char *lcores)
 	if (count == 0)
 		goto err;
 
-	cfg->lcore_count = count;
+	runtime_state->lcore_count = count;
 	ret = 0;
 
 err:
lib/eal/common/eal_internal_cfg.h +2 -0
index feb7baf71f..c5737d070c 100644
@@ -152,6 +152,8 @@ struct eal_runtime_state {
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
+	uint32_t lcore_count;         /**< Number of active lcore IDs (role != ROLE_OFF). */
+	enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
 	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
 	RTE_BITSET_DECLARE(core_indices, RTE_MAX_LCORE); /**< currently allocated core_indices */
 };
lib/eal/common/eal_private.h +0 -3
index 4d1a28762e..7a236c5788 100644
@@ -22,9 +22,6 @@
  */
 struct rte_config {
 	uint32_t main_lcore;         /**< Id of the main lcore */
-	uint32_t lcore_count;        /**< Number of available logical cores. */
-	uint32_t service_lcore_count;/**< Number of available service cores. */
-	enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
 
 	/** Primary or secondary configuration */
 	enum rte_proc_type_t process_type;
lib/eal/common/rte_service.c +7 -7
index 05bcdbb3dd..c4908ae4be 100644
@@ -105,9 +105,10 @@ rte_service_init(void)
 		RTE_LCORE_VAR_ALLOC(lcore_states);
 
 	int i;
-	struct rte_config *cfg = rte_eal_get_configuration();
+	const struct rte_config *cfg = rte_eal_get_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (cfg->lcore_role[i] == RTE_LCORE_ROLE_SERVICE) {
+		if (runtime_state->lcore_role[i] == RTE_LCORE_ROLE_SERVICE) {
 			if ((unsigned int)i == cfg->main_lcore)
 				continue;
 			rte_service_lcore_add(i);
@@ -709,10 +710,9 @@ rte_service_map_lcore_get(uint32_t id, uint32_t lcore)
 static void
 set_lcore_state(uint32_t lcore, int32_t state)
 {
-	/* mark core state in hugepage backed config */
-	struct rte_config *cfg = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct core_state *cs =	RTE_LCORE_VAR_LCORE(lcore, lcore_states);
-	cfg->lcore_role[lcore] = state;
+	runtime_state->lcore_role[lcore] = state;
 
 	/* update per-lcore optimized state tracking */
 	cs->is_service_core = (state == RTE_LCORE_ROLE_SERVICE);
@@ -1100,7 +1100,7 @@ RTE_EXPORT_SYMBOL(rte_service_dump)
 int32_t
 rte_service_dump(FILE *f, uint32_t id)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	uint32_t i;
 	int print_one = (id != UINT32_MAX);
 
@@ -1123,7 +1123,7 @@ rte_service_dump(FILE *f, uint32_t id)
 
 	fprintf(f, "Service Cores Summary\n");
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (cfg->lcore_role[i] != RTE_LCORE_ROLE_SERVICE)
+		if (runtime_state->lcore_role[i] != RTE_LCORE_ROLE_SERVICE)
 			continue;
 
 		service_dump_calls_per_lcore(f, i);
Signature · 1 line
2.55.0
#114 lore raw

PATCH v3 20/39 eal: make lcore role a field in lcore config struct

In reply to Bruce Richardson

Rather than having a separate array for lcore role, just make the role a field in the lcore_cfg struct.

---
 lib/eal/common/eal_common_lcore.c   | 28 ++++++++++++++--------------
 lib/eal/common/eal_common_options.c | 26 +++++++++++++-------------
 lib/eal/common/eal_internal_cfg.h   |  2 +-
 lib/eal/common/rte_service.c        |  6 +++---
 4 files changed, 31 insertions(+), 31 deletions(-)
lib/eal/common/eal_common_lcore.c +14 -14
index 24c8872765..3a4cc70c7e 100644
@@ -90,7 +90,7 @@ rte_eal_lcore_role(unsigned int lcore_id)
 
 	if (lcore_id >= RTE_MAX_LCORE)
 		return RTE_LCORE_ROLE_OFF;
-	return runtime_state->lcore_role[lcore_id];
+	return runtime_state->lcore_cfg[lcore_id].role;
 }
 
 RTE_EXPORT_SYMBOL(rte_lcore_has_role)
@@ -102,7 +102,7 @@ rte_lcore_has_role(unsigned int lcore_id, enum rte_lcore_role_t role)
 	if (lcore_id >= RTE_MAX_LCORE)
 		return 0;
 
-	return runtime_state->lcore_role[lcore_id] == role;
+	return runtime_state->lcore_cfg[lcore_id].role == role;
 }
 
 RTE_EXPORT_SYMBOL(rte_lcore_is_enabled)
@@ -112,7 +112,7 @@ int rte_lcore_is_enabled(unsigned int lcore_id)
 
 	if (lcore_id >= RTE_MAX_LCORE)
 		return 0;
-	return runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_RTE;
+	return runtime_state->lcore_cfg[lcore_id].role == RTE_LCORE_ROLE_RTE;
 }
 
 RTE_EXPORT_SYMBOL(rte_get_next_lcore)
@@ -350,7 +350,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
 	if (callback->init == NULL)
 		goto no_init;
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
+		if (runtime_state->lcore_cfg[lcore_id].role == RTE_LCORE_ROLE_OFF)
 			continue;
 		if (callback_init(callback, lcore_id) == 0)
 			continue;
@@ -358,7 +358,7 @@ rte_lcore_callback_register(const char *name, rte_lcore_init_cb init,
 		 * previous lcore.
 		 */
 		while (lcore_id-- != 0) {
-			if (runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
+			if (runtime_state->lcore_cfg[lcore_id].role == RTE_LCORE_ROLE_OFF)
 				continue;
 			callback_uninit(callback, lcore_id);
 		}
@@ -390,7 +390,7 @@ rte_lcore_callback_unregister(void *handle)
 	if (callback->uninit == NULL)
 		goto no_uninit;
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
+		if (runtime_state->lcore_cfg[lcore_id].role == RTE_LCORE_ROLE_OFF)
 			continue;
 		callback_uninit(callback, lcore_id);
 	}
@@ -419,11 +419,11 @@ eal_lcore_non_eal_allocate(void)
 		goto out;
 	}
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (runtime_state->lcore_role[lcore_id] != RTE_LCORE_ROLE_OFF)
+		if (runtime_state->lcore_cfg[lcore_id].role != RTE_LCORE_ROLE_OFF)
 			continue;
 		rte_bitset_set(runtime_state->core_indices, core_index);
 		runtime_state->lcore_cfg[lcore_id].core_index = core_index;
-		runtime_state->lcore_role[lcore_id] =RTE_LCORE_ROLE_NON_EAL;
+		runtime_state->lcore_cfg[lcore_id].role = RTE_LCORE_ROLE_NON_EAL;
 		runtime_state->lcore_count++;
 		break;
 	}
@@ -447,7 +447,7 @@ eal_lcore_non_eal_allocate(void)
 		rte_bitset_clear(runtime_state->core_indices,
 				runtime_state->lcore_cfg[lcore_id].core_index);
 		runtime_state->lcore_cfg[lcore_id].core_index = -1;
-		runtime_state->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
+		runtime_state->lcore_cfg[lcore_id].role = RTE_LCORE_ROLE_OFF;
 		runtime_state->lcore_count--;
 		lcore_id = RTE_MAX_LCORE;
 		goto out;
@@ -464,14 +464,14 @@ eal_lcore_non_eal_release(unsigned int lcore_id)
 	struct lcore_callback *callback;
 
 	rte_rwlock_write_lock(&lcore_lock);
-	if (runtime_state->lcore_role[lcore_id] != RTE_LCORE_ROLE_NON_EAL)
+	if (runtime_state->lcore_cfg[lcore_id].role != RTE_LCORE_ROLE_NON_EAL)
 		goto out;
 	TAILQ_FOREACH(callback, &lcore_callbacks, next)
 		callback_uninit(callback, lcore_id);
 	rte_bitset_clear(runtime_state->core_indices,
 			runtime_state->lcore_cfg[lcore_id].core_index);
 	runtime_state->lcore_cfg[lcore_id].core_index = -1;
-	runtime_state->lcore_role[lcore_id] = RTE_LCORE_ROLE_OFF;
+	runtime_state->lcore_cfg[lcore_id].role = RTE_LCORE_ROLE_OFF;
 	runtime_state->lcore_count--;
 out:
 	rte_rwlock_write_unlock(&lcore_lock);
@@ -487,7 +487,7 @@ rte_lcore_iterate(rte_lcore_iterate_cb cb, void *arg)
 
 	rte_rwlock_read_lock(&lcore_lock);
 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (runtime_state->lcore_role[lcore_id] == RTE_LCORE_ROLE_OFF)
+		if (runtime_state->lcore_cfg[lcore_id].role == RTE_LCORE_ROLE_OFF)
 			continue;
 		ret = cb(lcore_id, arg);
 		if (ret != 0)
@@ -552,7 +552,7 @@ lcore_dump_cb(unsigned int lcore_id, void *arg)
 	cpuset = eal_cpuset_to_str(&runtime_state->lcore_cfg[lcore_id].cpuset);
 	fprintf(f, "lcore %u, socket %u, role %s, cpuset %s\n", lcore_id,
 		rte_lcore_to_socket_id(lcore_id),
-		lcore_role_str(runtime_state->lcore_role[lcore_id]),
+		lcore_role_str(runtime_state->lcore_cfg[lcore_id].role),
 		cpuset != NULL ? cpuset : "<unknown>");
 	free(cpuset);
 	free(usage_str);
@@ -619,7 +619,7 @@ lcore_telemetry_info_cb(unsigned int lcore_id, void *arg)
 	rte_tel_data_add_dict_int(info->d, "lcore_id", lcore_id);
 	rte_tel_data_add_dict_int(info->d, "socket", rte_lcore_to_socket_id(lcore_id));
 	rte_tel_data_add_dict_string(info->d, "role",
-			lcore_role_str(runtime_state->lcore_role[lcore_id]));
+			lcore_role_str(runtime_state->lcore_cfg[lcore_id].role));
 	cpuset = rte_tel_data_alloc();
 	if (cpuset == NULL)
 		return -ENOMEM;
lib/eal/common/eal_common_options.c +13 -13
index 6a7da51dac..e8109b94c0 100644
@@ -907,10 +907,10 @@ eal_parse_service_coremask(const char *coremask)
 					return -1;
 				}
 
-				if (runtime_state->lcore_role[idx] == RTE_LCORE_ROLE_RTE)
+				if (runtime_state->lcore_cfg[idx].role == RTE_LCORE_ROLE_RTE)
 					taken_lcore_count++;
 
-				runtime_state->lcore_role[idx] = RTE_LCORE_ROLE_SERVICE;
+				runtime_state->lcore_cfg[idx].role = RTE_LCORE_ROLE_SERVICE;
 				count++;
 			}
 		}
@@ -946,7 +946,7 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 	/* set everything to disabled first, then set up values */
 	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		runtime_state->lcore_role[i] = RTE_LCORE_ROLE_OFF;
+		runtime_state->lcore_cfg[i].role = RTE_LCORE_ROLE_OFF;
 		runtime_state->lcore_cfg[i].core_index = -1;
 	}
 
@@ -975,7 +975,7 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 			}
 
 			rte_bitset_set(runtime_state->core_indices, count);
-			runtime_state->lcore_role[lcore_id] = RTE_LCORE_ROLE_RTE;
+			runtime_state->lcore_cfg[lcore_id].role = RTE_LCORE_ROLE_RTE;
 			runtime_state->lcore_cfg[lcore_id].core_index = count;
 			CPU_ZERO(&runtime_state->lcore_cfg[lcore_id].cpuset);
 			CPU_SET(i, &runtime_state->lcore_cfg[lcore_id].cpuset);
@@ -1148,11 +1148,11 @@ eal_parse_service_corelist(const char *corelist)
 			if (min == RTE_MAX_LCORE)
 				min = idx;
 			for (idx = min; idx <= max; idx++) {
-				if (runtime_state->lcore_role[idx] != RTE_LCORE_ROLE_SERVICE) {
-					if (runtime_state->lcore_role[idx] == RTE_LCORE_ROLE_RTE)
+				if (runtime_state->lcore_cfg[idx].role != RTE_LCORE_ROLE_SERVICE) {
+					if (runtime_state->lcore_cfg[idx].role == RTE_LCORE_ROLE_RTE)
 						taken_lcore_count++;
 
-					runtime_state->lcore_role[idx] = RTE_LCORE_ROLE_SERVICE;
+					runtime_state->lcore_cfg[idx].role = RTE_LCORE_ROLE_SERVICE;
 					count++;
 				}
 			}
@@ -1175,7 +1175,7 @@ eal_parse_service_corelist(const char *corelist)
 	rte_cpuset_t service_cpuset;
 	CPU_ZERO(&service_cpuset);
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (runtime_state->lcore_role[i] == RTE_LCORE_ROLE_SERVICE)
+		if (runtime_state->lcore_cfg[i].role == RTE_LCORE_ROLE_SERVICE)
 			CPU_SET(i, &service_cpuset);
 	}
 	if (CPU_COUNT(&service_cpuset) > 0) {
@@ -1205,12 +1205,12 @@ eal_parse_main_lcore(const char *arg)
 		return -1;
 
 	/* ensure main core is not used as service core */
-	if (runtime_state->lcore_role[cfg->main_lcore] == RTE_LCORE_ROLE_SERVICE) {
+	if (runtime_state->lcore_cfg[cfg->main_lcore].role == RTE_LCORE_ROLE_SERVICE) {
 		EAL_LOG(ERR, "Error: Main lcore is used as a service core");
 		return -1;
 	}
 	/* check that we have the core recorded in the core list */
-	if (runtime_state->lcore_role[cfg->main_lcore] != RTE_LCORE_ROLE_RTE) {
+	if (runtime_state->lcore_cfg[cfg->main_lcore].role != RTE_LCORE_ROLE_RTE) {
 		EAL_LOG(ERR, "Error: Main lcore is not enabled for DPDK");
 		return -1;
 	}
@@ -1400,7 +1400,7 @@ eal_parse_lcores(const char *lcores)
 	/* Reset lcore config */
 	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
 	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-		runtime_state->lcore_role[idx] = RTE_LCORE_ROLE_OFF;
+		runtime_state->lcore_cfg[idx].role = RTE_LCORE_ROLE_OFF;
 		runtime_state->lcore_cfg[idx].core_index = -1;
 		CPU_ZERO(&runtime_state->lcore_cfg[idx].cpuset);
 		runtime_state->lcore_cfg[idx].first_cpu = UINT16_MAX;
@@ -1463,10 +1463,10 @@ eal_parse_lcores(const char *lcores)
 				continue;
 			set_count--;
 
-			if (runtime_state->lcore_role[idx] != RTE_LCORE_ROLE_RTE) {
+			if (runtime_state->lcore_cfg[idx].role != RTE_LCORE_ROLE_RTE) {
 				rte_bitset_set(runtime_state->core_indices, count);
 				runtime_state->lcore_cfg[idx].core_index = count;
-				runtime_state->lcore_role[idx] = RTE_LCORE_ROLE_RTE;
+				runtime_state->lcore_cfg[idx].role = RTE_LCORE_ROLE_RTE;
 				count++;
 			}
 
lib/eal/common/eal_internal_cfg.h +1 -1
index c5737d070c..83944c5951 100644
@@ -129,6 +129,7 @@ struct eal_platform_info {
  */
 struct lcore_cfg {
 	int core_index;                   /**< relative index, starting from 0 */
+	enum rte_lcore_role_t role;       /**< role assigned to this lcore */
 	rte_cpuset_t cpuset;              /**< cpu set which the lcore affinity to */
 	uint16_t first_cpu;               /**< lowest CPU set in cpuset, UINT16_MAX if none */
 	/* Fields for executing code on a remote lcore */
@@ -153,7 +154,6 @@ struct eal_runtime_state {
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
 	uint32_t lcore_count;         /**< Number of active lcore IDs (role != ROLE_OFF). */
-	enum rte_lcore_role_t lcore_role[RTE_MAX_LCORE]; /**< State of cores. */
 	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
 	RTE_BITSET_DECLARE(core_indices, RTE_MAX_LCORE); /**< currently allocated core_indices */
 };
lib/eal/common/rte_service.c +3 -3
index c4908ae4be..954b5503b4 100644
@@ -108,7 +108,7 @@ rte_service_init(void)
 	const struct rte_config *cfg = rte_eal_get_configuration();
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (runtime_state->lcore_role[i] == RTE_LCORE_ROLE_SERVICE) {
+		if (runtime_state->lcore_cfg[i].role == RTE_LCORE_ROLE_SERVICE) {
 			if ((unsigned int)i == cfg->main_lcore)
 				continue;
 			rte_service_lcore_add(i);
@@ -712,7 +712,7 @@ set_lcore_state(uint32_t lcore, int32_t state)
 {
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct core_state *cs =	RTE_LCORE_VAR_LCORE(lcore, lcore_states);
-	runtime_state->lcore_role[lcore] = state;
+	runtime_state->lcore_cfg[lcore].role = state;
 
 	/* update per-lcore optimized state tracking */
 	cs->is_service_core = (state == RTE_LCORE_ROLE_SERVICE);
@@ -1123,7 +1123,7 @@ rte_service_dump(FILE *f, uint32_t id)
 
 	fprintf(f, "Service Cores Summary\n");
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (runtime_state->lcore_role[i] != RTE_LCORE_ROLE_SERVICE)
+		if (runtime_state->lcore_cfg[i].role != RTE_LCORE_ROLE_SERVICE)
 			continue;
 
 		service_dump_calls_per_lcore(f, i);
Signature · 1 line
2.55.0
#115 lore raw

PATCH v3 21/39 eal: move main lcore setting to runtime config struct

In reply to Bruce Richardson

Move the main lcore setting from the rte_config struct to the new runtime structure. One additional wrinkle here is that this is an optional user setting, so it also needs to be stored in eal_user_cfg if specified. The difference is that the eal_user_cfg value is the raw value and can be "-1" if unspecified, while the runtime config value has to have a valid lcore id.

---
 lib/eal/common/eal_common_dynmem.c  |  4 +---
 lib/eal/common/eal_common_lcore.c   |  2 +-
 lib/eal/common/eal_common_options.c | 32 ++++++++++++++++-------------
 lib/eal/common/eal_internal_cfg.h   |  2 ++
 lib/eal/common/eal_private.h        |  1 -
 lib/eal/common/rte_service.c        |  3 +--
 lib/eal/freebsd/eal.c               | 12 +++++------
 lib/eal/linux/eal.c                 | 12 +++++------
 lib/eal/linux/eal_memory.c          |  3 +--
 lib/eal/windows/eal.c               |  9 ++++----
 10 files changed, 38 insertions(+), 42 deletions(-)
lib/eal/common/eal_common_dynmem.c +1 -3
index d5c1c62879..e431ddf03d 100644
@@ -440,11 +440,9 @@ eal_dynmem_calc_num_pages_per_socket(
 		total_size = user_cfg->memory;
 		for (socket = 0; socket < RTE_MAX_NUMA_NODES && total_size != 0;
 				socket++) {
-			struct rte_config *cfg = rte_eal_get_configuration();
 			unsigned int main_lcore_socket;
 
-			main_lcore_socket =
-				rte_lcore_to_socket_id(cfg->main_lcore);
+			main_lcore_socket = rte_lcore_to_socket_id(rte_get_main_lcore());
 
 			if (main_lcore_socket != socket)
 				continue;
lib/eal/common/eal_common_lcore.c +1 -1
index 3a4cc70c7e..de603b2ff3 100644
@@ -24,7 +24,7 @@
 RTE_EXPORT_SYMBOL(rte_get_main_lcore)
 unsigned int rte_get_main_lcore(void)
 {
-	return rte_eal_get_configuration()->main_lcore;
+	return eal_get_runtime_state()->main_lcore;
 }
 
 RTE_EXPORT_SYMBOL(rte_lcore_count)
lib/eal/common/eal_common_options.c +18 -14
index e8109b94c0..b2aba99f12 100644
@@ -1194,23 +1194,24 @@ static int
 eal_parse_main_lcore(const char *arg)
 {
 	char *parsing_end;
-	struct rte_config *cfg = rte_eal_get_configuration();
-	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	long main_lcore;
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	errno = 0;
-	cfg->main_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
-	if (errno || parsing_end[0] != 0)
-		return -1;
-	if (cfg->main_lcore >= RTE_MAX_LCORE)
+	main_lcore = strtol(arg, &parsing_end, 0);
+	if (errno || parsing_end[0] != 0 || main_lcore < 0 ||
+			main_lcore >= RTE_MAX_LCORE)
 		return -1;
+	user_cfg->main_lcore = (int)main_lcore;
 
 	/* ensure main core is not used as service core */
-	if (runtime_state->lcore_cfg[cfg->main_lcore].role == RTE_LCORE_ROLE_SERVICE) {
+	if (runtime_state->lcore_cfg[user_cfg->main_lcore].role == RTE_LCORE_ROLE_SERVICE) {
 		EAL_LOG(ERR, "Error: Main lcore is used as a service core");
 		return -1;
 	}
 	/* check that we have the core recorded in the core list */
-	if (runtime_state->lcore_cfg[cfg->main_lcore].role != RTE_LCORE_ROLE_RTE) {
+	if (runtime_state->lcore_cfg[user_cfg->main_lcore].role != RTE_LCORE_ROLE_RTE) {
 		EAL_LOG(ERR, "Error: Main lcore is not enabled for DPDK");
 		return -1;
 	}
@@ -2077,7 +2078,7 @@ int
 eal_parse_args(void)
 {
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct rte_config *rte_cfg = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	bool remap_lcores = (args.remap_lcore_ids != NULL);
 	struct arg_list_elem *arg;
 	uint16_t lcore_id_base = 0;
@@ -2201,13 +2202,16 @@ eal_parse_args(void)
 			return -1;
 		}
 	}
-	if (args.main_lcore != NULL) {
-		if (eal_parse_main_lcore(args.main_lcore) < 0)
-			return -1;
+	user_cfg->main_lcore = -1;
+	if (args.main_lcore != NULL && eal_parse_main_lcore(args.main_lcore) < 0)
+		return -1;
+
+	if (user_cfg->main_lcore != -1) {
+		runtime_state->main_lcore = user_cfg->main_lcore;
 	} else {
 		/* default main lcore is the first one */
-		rte_cfg->main_lcore = rte_get_next_lcore(-1, 0, 0);
-		if (rte_cfg->main_lcore >= RTE_MAX_LCORE) {
+		runtime_state->main_lcore = rte_get_next_lcore(-1, 0, 0);
+		if (runtime_state->main_lcore >= RTE_MAX_LCORE) {
 			EAL_LOG(ERR, "Main lcore is not enabled for DPDK");
 			return -1;
 		}
lib/eal/common/eal_internal_cfg.h +2 -0
index 83944c5951..52822e4c2d 100644
@@ -99,6 +99,7 @@ struct eal_user_cfg {
 		uint64_t limit;    /**< memory limit in bytes */
 	} pagesz_mem_overrides[MAX_HUGEPAGE_SIZES];
 	unsigned int num_pagesz_mem_overrides;  /**< number of stored overrides */
+	int main_lcore;          /**< ID of the main lcore */
 };
 
 /**
@@ -153,6 +154,7 @@ struct eal_runtime_state {
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
+	uint32_t main_lcore;          /**< ID of the main lcore */
 	uint32_t lcore_count;         /**< Number of active lcore IDs (role != ROLE_OFF). */
 	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
 	RTE_BITSET_DECLARE(core_indices, RTE_MAX_LCORE); /**< currently allocated core_indices */
lib/eal/common/eal_private.h +0 -1
index 7a236c5788..b146bd7f50 100644
@@ -21,7 +21,6 @@
  * The global RTE configuration structure.
  */
 struct rte_config {
-	uint32_t main_lcore;         /**< Id of the main lcore */
 
 	/** Primary or secondary configuration */
 	enum rte_proc_type_t process_type;
lib/eal/common/rte_service.c +1 -2
index 954b5503b4..6813c22ddd 100644
@@ -105,11 +105,10 @@ rte_service_init(void)
 		RTE_LCORE_VAR_ALLOC(lcore_states);
 
 	int i;
-	const struct rte_config *cfg = rte_eal_get_configuration();
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
 		if (runtime_state->lcore_cfg[i].role == RTE_LCORE_ROLE_SERVICE) {
-			if ((unsigned int)i == cfg->main_lcore)
+			if ((unsigned int)i == runtime_state->main_lcore)
 				continue;
 			rte_service_lcore_add(i);
 		}
lib/eal/freebsd/eal.c +5 -7
index 89b43c450d..2cda49ea2d 100644
@@ -357,9 +357,8 @@ static void
 eal_check_mem_on_local_socket(void)
 {
 	int socket_id;
-	const struct rte_config *config = rte_eal_get_configuration();
 
-	socket_id = rte_lcore_to_socket_id(config->main_lcore);
+	socket_id = rte_lcore_to_socket_id(rte_get_main_lcore());
 
 	if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
 		EAL_LOG(WARNING, "WARNING: Main core has no memory on local socket!");
@@ -402,7 +401,6 @@ rte_eal_init(int argc, char **argv)
 	uint32_t has_run = 0;
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 	char thread_name[RTE_THREAD_NAME_SIZE];
-	const struct rte_config *config = rte_eal_get_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	bool has_phys_addr;
@@ -652,18 +650,18 @@ rte_eal_init(int argc, char **argv)
 	eal_check_mem_on_local_socket();
 
 	if (rte_thread_set_affinity_by_id(rte_thread_self(),
-			&runtime_state->lcore_cfg[config->main_lcore].cpuset) != 0) {
+			&runtime_state->lcore_cfg[rte_get_main_lcore()].cpuset) != 0) {
 		rte_eal_init_alert("Cannot set affinity");
 		rte_errno = EINVAL;
 		goto err_out;
 	}
-	__rte_thread_init(config->main_lcore,
-		&runtime_state->lcore_cfg[config->main_lcore].cpuset);
+	__rte_thread_init(rte_get_main_lcore(),
+		&runtime_state->lcore_cfg[rte_get_main_lcore()].cpuset);
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 
 	EAL_LOG(DEBUG, "Main lcore %u is ready (tid=%zx;cpuset=[%s%s])",
-		config->main_lcore, (uintptr_t)pthread_self(), cpuset,
+		rte_get_main_lcore(), (uintptr_t)pthread_self(), cpuset,
 		ret == 0 ? "" : "...");
 
 	RTE_LCORE_FOREACH_WORKER(i) {
lib/eal/linux/eal.c +5 -7
index 330a245cd7..cdb8fbb363 100644
@@ -436,9 +436,8 @@ static void
 eal_check_mem_on_local_socket(void)
 {
 	int socket_id;
-	const struct rte_config *config = rte_eal_get_configuration();
 
-	socket_id = rte_lcore_to_socket_id(config->main_lcore);
+	socket_id = rte_lcore_to_socket_id(rte_get_main_lcore());
 
 	if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
 		EAL_LOG(WARNING, "WARNING: Main core has no memory on local socket!");
@@ -563,7 +562,6 @@ rte_eal_init(int argc, char **argv)
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 	char thread_name[RTE_THREAD_NAME_SIZE];
 	bool phys_addrs;
-	const struct rte_config *config = rte_eal_get_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
@@ -838,17 +836,17 @@ rte_eal_init(int argc, char **argv)
 	eal_check_mem_on_local_socket();
 
 	if (rte_thread_set_affinity_by_id(rte_thread_self(),
-			&runtime_state->lcore_cfg[config->main_lcore].cpuset) != 0) {
+			&runtime_state->lcore_cfg[rte_get_main_lcore()].cpuset) != 0) {
 		rte_eal_init_alert("Cannot set affinity");
 		rte_errno = EINVAL;
 		goto err_out;
 	}
-	__rte_thread_init(config->main_lcore,
-		&runtime_state->lcore_cfg[config->main_lcore].cpuset);
+	__rte_thread_init(rte_get_main_lcore(),
+		&runtime_state->lcore_cfg[rte_get_main_lcore()].cpuset);
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 	EAL_LOG(DEBUG, "Main lcore %u is ready (tid=%zx;cpuset=[%s%s])",
-		config->main_lcore, (uintptr_t)pthread_self(), cpuset,
+		rte_get_main_lcore(), (uintptr_t)pthread_self(), cpuset,
 		ret == 0 ? "" : "...");
 
 	RTE_LCORE_FOREACH_WORKER(i) {
lib/eal/linux/eal_memory.c +1 -2
index a7d1575a60..3cd100ce56 100644
@@ -1771,7 +1771,6 @@ memseg_primary_init_32(void)
 		int hp_sizes = (int) platform_info->num_hugepage_sizes;
 		uint64_t max_socket_mem, cur_socket_mem;
 		unsigned int main_lcore_socket;
-		struct rte_config *cfg = rte_eal_get_configuration();
 		bool skip;
 		int ret;
 
@@ -1794,7 +1793,7 @@ memseg_primary_init_32(void)
 		/* ...or if we didn't specifically request memory on *any*
 		 * socket, and this is not main lcore
 		 */
-		main_lcore_socket = rte_lcore_to_socket_id(cfg->main_lcore);
+		main_lcore_socket = rte_lcore_to_socket_id(rte_get_main_lcore());
 		skip |= active_sockets == 0 && socket_id != main_lcore_socket;
 
 		if (skip) {
lib/eal/windows/eal.c +4 -5
index 2f8f6200ba..ddbf39dbc4 100644
@@ -159,7 +159,6 @@ int
 rte_eal_init(int argc, char **argv)
 {
 	int i, fctret, bscan;
-	const struct rte_config *config = rte_eal_get_configuration();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	bool has_phys_addr;
@@ -351,17 +350,17 @@ rte_eal_init(int argc, char **argv)
 	eal_rand_init();
 
 	if (rte_thread_set_affinity_by_id(rte_thread_self(),
-			&runtime_state->lcore_cfg[config->main_lcore].cpuset) != 0) {
+			&runtime_state->lcore_cfg[rte_get_main_lcore()].cpuset) != 0) {
 		rte_eal_init_alert("Cannot set affinity");
 		rte_errno = EINVAL;
 		goto err_out;
 	}
-	__rte_thread_init(config->main_lcore,
-		&runtime_state->lcore_cfg[config->main_lcore].cpuset);
+	__rte_thread_init(rte_get_main_lcore(),
+		&runtime_state->lcore_cfg[rte_get_main_lcore()].cpuset);
 
 	ret = eal_thread_dump_current_affinity(cpuset, sizeof(cpuset));
 	EAL_LOG(DEBUG, "Main lcore %u is ready (tid=%zx;cpuset=[%s%s])",
-		config->main_lcore, rte_thread_self().opaque_id, cpuset,
+		rte_get_main_lcore(), rte_thread_self().opaque_id, cpuset,
 		ret == 0 ? "" : "...");
 
 	RTE_LCORE_FOREACH_WORKER(i) {
Signature · 1 line
2.55.0
#116 lore raw

PATCH v3 22/39 eal: move IOVA mode and process type to runtime cfg

In reply to Bruce Richardson

Move two more fields, iova_mode and process_type from old rte_config to eal_runtime_state struct.

---
 lib/eal/common/eal_common_config.c |  4 ++--
 lib/eal/common/eal_common_mcfg.c   |  2 +-
 lib/eal/common/eal_internal_cfg.h  |  2 ++
 lib/eal/common/eal_private.h       |  7 -------
 lib/eal/freebsd/eal.c              | 11 +++++------
 lib/eal/linux/eal.c                | 13 ++++++-------
 lib/eal/windows/eal.c              |  2 +-
 7 files changed, 17 insertions(+), 24 deletions(-)
lib/eal/common/eal_common_config.c +2 -2
index f1a5e84aa9..7e6704a32d 100644
@@ -88,7 +88,7 @@ RTE_EXPORT_SYMBOL(rte_eal_iova_mode)
 enum rte_iova_mode
 rte_eal_iova_mode(void)
 {
-	return rte_eal_get_configuration()->iova_mode;
+	return eal_get_runtime_state()->iova_mode;
 }
 
 /* Get the EAL base address */
@@ -105,7 +105,7 @@ RTE_EXPORT_SYMBOL(rte_eal_process_type)
 enum rte_proc_type_t
 rte_eal_process_type(void)
 {
-	return rte_config.process_type;
+	return eal_get_runtime_state()->process_type;
 }
 
 /* Return user provided mbuf pool ops name */
lib/eal/common/eal_common_mcfg.c +1 -1
index 86dbb0a1fe..5739939933 100644
@@ -19,7 +19,7 @@ eal_mcfg_complete(void)
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* ALL shared mem_config related INIT DONE */
-	if (cfg->process_type == RTE_PROC_PRIMARY)
+	if (runtime_state->process_type == RTE_PROC_PRIMARY)
 		mcfg->magic = RTE_MAGIC;
 
 	runtime_state->init_complete = 1;
lib/eal/common/eal_internal_cfg.h +2 -0
index 52822e4c2d..ad232a5b30 100644
@@ -154,6 +154,8 @@ struct eal_runtime_state {
 	rte_cpuset_t ctrl_cpuset;         /**< cpuset for ctrl threads */
 	volatile unsigned int init_complete;
 	/**< indicates whether EAL has completed initialization */
+	enum rte_proc_type_t process_type; /**< primary or secondary process */
+	enum rte_iova_mode iova_mode; /**< PA or VA IOVA mapping mode */
 	uint32_t main_lcore;          /**< ID of the main lcore */
 	uint32_t lcore_count;         /**< Number of active lcore IDs (role != ROLE_OFF). */
 	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
lib/eal/common/eal_private.h +0 -7
index b146bd7f50..50b8e1653b 100644
@@ -21,13 +21,6 @@
  * The global RTE configuration structure.
  */
 struct rte_config {
-
-	/** Primary or secondary configuration */
-	enum rte_proc_type_t process_type;
-
-	/** PA or VA mapping mode */
-	enum rte_iova_mode iova_mode;
-
 	/**
 	 * Pointer to memory configuration, which may be shared across multiple
 	 * DPDK instances
lib/eal/freebsd/eal.c +5 -6
index 2cda49ea2d..782514eb09 100644
@@ -283,12 +283,12 @@ eal_proc_type_detect(void)
 static int
 rte_config_init(void)
 {
-	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	config->process_type = user_cfg->process_type;
+	runtime_state->process_type = user_cfg->process_type;
 
-	switch (config->process_type) {
+	switch (runtime_state->process_type) {
 	case RTE_PROC_PRIMARY:
 		if (rte_eal_config_create() < 0)
 			return -1;
@@ -312,8 +312,7 @@ rte_config_init(void)
 		break;
 	case RTE_PROC_AUTO:
 	case RTE_PROC_INVALID:
-		EAL_LOG(ERR, "Invalid process type %d",
-			config->process_type);
+		EAL_LOG(ERR, "Invalid process type %d", runtime_state->process_type);
 		return -1;
 	}
 
@@ -559,7 +558,7 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	rte_eal_get_configuration()->iova_mode = iova_mode;
+	runtime_state->iova_mode = iova_mode;
 	EAL_LOG(INFO, "Selected IOVA mode '%s'",
 		rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
 
lib/eal/linux/eal.c +6 -7
index cdb8fbb363..b44097d9bf 100644
@@ -365,12 +365,12 @@ eal_proc_type_detect(void)
 static int
 rte_config_init(void)
 {
-	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
-	config->process_type = user_cfg->process_type;
+	runtime_state->process_type = user_cfg->process_type;
 
-	switch (config->process_type) {
+	switch (runtime_state->process_type) {
 	case RTE_PROC_PRIMARY:
 		if (rte_eal_config_create() < 0)
 			return -1;
@@ -395,7 +395,7 @@ rte_config_init(void)
 	case RTE_PROC_AUTO:
 	case RTE_PROC_INVALID:
 		EAL_LOG(ERR, "Invalid process type %d",
-			config->process_type);
+			runtime_state->process_type);
 		return -1;
 	}
 
@@ -714,10 +714,9 @@ rte_eal_init(int argc, char **argv)
 				EAL_LOG(DEBUG, "IOMMU is not available, selecting IOVA as PA mode.");
 			}
 		}
-		rte_eal_get_configuration()->iova_mode = iova_mode;
+		runtime_state->iova_mode = iova_mode;
 	} else {
-		rte_eal_get_configuration()->iova_mode =
-			user_cfg->iova_mode;
+		runtime_state->iova_mode = user_cfg->iova_mode;
 	}
 
 	if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) {
lib/eal/windows/eal.c +1 -1
index ddbf39dbc4..9ff6fbec7a 100644
@@ -309,7 +309,7 @@ rte_eal_init(int argc, char **argv)
 
 	EAL_LOG(DEBUG, "Selected IOVA mode '%s'",
 		iova_mode == RTE_IOVA_PA ? "PA" : "VA");
-	rte_eal_get_configuration()->iova_mode = iova_mode;
+	runtime_state->iova_mode = iova_mode;
 
 	if (rte_eal_memzone_init() < 0) {
 		rte_eal_init_alert("Cannot init memzone");
Signature · 1 line
2.55.0
#117 lore raw

PATCH v3 23/39 eal: move memory config pointer to runtime state struct

In reply to Bruce Richardson

Remove the final field from the rte_config struct - the mem_config pointer - and put it in the runtime state structure instead. The rte_config struct is now unused and ready for removal in a later commit.

---
 lib/eal/common/eal_common_config.c  | 15 ++++++---
 lib/eal/common/eal_common_dynmem.c  |  2 +-
 lib/eal/common/eal_common_mcfg.c    | 23 ++++++-------
 lib/eal/common/eal_common_memory.c  | 52 ++++++++++++++---------------
 lib/eal/common/eal_common_memzone.c | 20 +++++------
 lib/eal/common/eal_common_proc.c    |  4 +--
 lib/eal/common/eal_common_tailqs.c  |  6 ++--
 lib/eal/common/eal_common_timer.c   |  2 +-
 lib/eal/common/eal_internal_cfg.h   |  4 +++
 lib/eal/common/eal_memcfg.h         |  3 ++
 lib/eal/common/eal_private.h        |  6 +---
 lib/eal/common/malloc_heap.c        | 22 ++++++------
 lib/eal/common/malloc_mp.c          |  2 +-
 lib/eal/common/rte_malloc.c         | 14 ++++----
 lib/eal/freebsd/eal.c               | 22 ++++++------
 lib/eal/freebsd/eal_memory.c        |  6 ++--
 lib/eal/linux/eal.c                 | 24 ++++++-------
 lib/eal/linux/eal_memalloc.c        | 18 +++++-----
 lib/eal/linux/eal_memory.c          | 14 ++++----
 lib/eal/windows/eal.c               |  6 ++--
 lib/eal/windows/eal_memalloc.c      |  4 +--
 lib/eal/windows/eal_memory.c        |  2 +-
 22 files changed, 139 insertions(+), 132 deletions(-)
lib/eal/common/eal_common_config.c +11 -4
index 7e6704a32d..ebb7c222d9 100644
@@ -21,9 +21,7 @@ static struct rte_mem_config early_mem_config = {
 };
 
 /* Address of global and public configuration */
-static struct rte_config rte_config = {
-	.mem_config = &early_mem_config,
-};
+static struct rte_config rte_config;
 
 /* platform-specific runtime dir */
 static char runtime_dir[UNIX_PATH_MAX];
@@ -35,7 +33,9 @@ static struct eal_user_cfg eal_user_cfg;
 static struct eal_platform_info eal_platform_info;
 
 /* internal runtime configuration */
-static struct eal_runtime_state eal_runtime_state;
+static struct eal_runtime_state eal_runtime_state = {
+	.mem_config = &early_mem_config,
+};
 
 RTE_EXPORT_SYMBOL(rte_eal_get_runtime_dir)
 const char *
@@ -63,6 +63,13 @@ rte_eal_get_configuration(void)
 	return &rte_config;
 }
 
+/* Return a pointer to the memory config structure */
+struct rte_mem_config *
+eal_get_mcfg(void)
+{
+	return eal_get_runtime_state()->mem_config;
+}
+
 /* Return a pointer to the user configuration structure */
 struct eal_user_cfg *
 eal_get_user_configuration(void)
lib/eal/common/eal_common_dynmem.c +1 -1
index e431ddf03d..f9b275dbeb 100644
@@ -20,7 +20,7 @@
 int
 eal_dynmem_memseg_lists_init(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct memtype {
 		uint64_t page_sz;
 		int socket_id;
lib/eal/common/eal_common_mcfg.c +11 -12
index 5739939933..6f8dc34062 100644
@@ -14,8 +14,7 @@
 void
 eal_mcfg_complete(void)
 {
-	struct rte_config *cfg = rte_eal_get_configuration();
-	struct rte_mem_config *mcfg = cfg->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* ALL shared mem_config related INIT DONE */
@@ -28,7 +27,7 @@ eal_mcfg_complete(void)
 void
 eal_mcfg_wait_complete(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 
 	/* wait until shared mem_config finish initialising */
 	rte_wait_until_equal_32(&mcfg->magic, RTE_MAGIC, rte_memory_order_relaxed);
@@ -37,7 +36,7 @@ eal_mcfg_wait_complete(void)
 int
 eal_mcfg_check_version(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 
 	/* check if version from memconfig matches compiled in macro */
 	if (mcfg->version != RTE_VERSION)
@@ -49,7 +48,7 @@ eal_mcfg_check_version(void)
 void
 eal_mcfg_update_internal(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	user_cfg->legacy_mem = mcfg->legacy_mem;
@@ -60,7 +59,7 @@ void
 eal_mcfg_update_from_internal(void)
 {
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 
 	mcfg->legacy_mem = user_cfg->legacy_mem;
 	mcfg->single_file_segments = user_cfg->single_file_segments;
@@ -74,7 +73,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_mcfg_mem_get_lock)
 rte_rwlock_t *
 rte_mcfg_mem_get_lock(void)
 {
-	return &rte_eal_get_configuration()->mem_config->memory_hotplug_lock;
+	return &eal_get_mcfg()->memory_hotplug_lock;
 }
 
 RTE_EXPORT_SYMBOL(rte_mcfg_mem_read_lock)
@@ -109,7 +108,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_mcfg_tailq_get_lock)
 rte_rwlock_t *
 rte_mcfg_tailq_get_lock(void)
 {
-	return &rte_eal_get_configuration()->mem_config->qlock;
+	return &eal_get_mcfg()->qlock;
 }
 
 RTE_EXPORT_SYMBOL(rte_mcfg_tailq_read_lock)
@@ -144,7 +143,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_mcfg_mempool_get_lock)
 rte_rwlock_t *
 rte_mcfg_mempool_get_lock(void)
 {
-	return &rte_eal_get_configuration()->mem_config->mplock;
+	return &eal_get_mcfg()->mplock;
 }
 
 RTE_EXPORT_SYMBOL(rte_mcfg_mempool_read_lock)
@@ -179,7 +178,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_mcfg_timer_get_lock)
 rte_spinlock_t *
 rte_mcfg_timer_get_lock(void)
 {
-	return &rte_eal_get_configuration()->mem_config->tlock;
+	return &eal_get_mcfg()->tlock;
 }
 
 RTE_EXPORT_SYMBOL(rte_mcfg_timer_lock)
@@ -200,13 +199,13 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_mcfg_ethdev_get_lock)
 rte_spinlock_t *
 rte_mcfg_ethdev_get_lock(void)
 {
-	return &rte_eal_get_configuration()->mem_config->ethdev_lock;
+	return &eal_get_mcfg()->ethdev_lock;
 }
 
 RTE_EXPORT_SYMBOL(rte_mcfg_get_single_file_segments)
 bool
 rte_mcfg_get_single_file_segments(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	return (bool)mcfg->single_file_segments;
 }
lib/eal/common/eal_common_memory.c +25 -27

201 lines not on this page · raw message

lib/eal/common/eal_common_memzone.c +10 -10
index 1207d524c9..570cb60757 100644
@@ -39,7 +39,7 @@ rte_memzone_max_set(size_t max)
 		return -1;
 	}
 
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 	if (mcfg == NULL) {
 		EAL_LOG(ERR, "Failed to set max memzone count");
 		return -1;
@@ -56,7 +56,7 @@ rte_memzone_max_get(void)
 {
 	struct rte_mem_config *mcfg;
 
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 	if (mcfg == NULL || mcfg->max_memzone == 0)
 		return DEFAULT_MAX_MEMZONE_COUNT;
 
@@ -72,7 +72,7 @@ memzone_lookup_thread_unsafe(const char *name)
 	int i = 0;
 
 	/* get pointer to global configuration */
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 	arr = &mcfg->memzones;
 
 	/*
@@ -116,7 +116,7 @@ memzone_reserve_aligned_thread_unsafe(const char *name, size_t len,
 	bool contig;
 
 	/* get pointer to global configuration */
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 	arr = &mcfg->memzones;
 
 	/* no more room in config */
@@ -248,7 +248,7 @@ rte_memzone_reserve_thread_safe(const char *name, size_t len, int socket_id,
 	const struct rte_memzone *mz = NULL;
 
 	/* get pointer to global configuration */
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 
 	rte_rwlock_write_lock(&mcfg->mlock);
 
@@ -319,7 +319,7 @@ rte_memzone_free(const struct rte_memzone *mz)
 		return -EINVAL;
 
 	rte_strlcpy(name, mz->name, RTE_MEMZONE_NAMESIZE);
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 	arr = &mcfg->memzones;
 
 	rte_rwlock_write_lock(&mcfg->mlock);
@@ -357,7 +357,7 @@ rte_memzone_lookup(const char *name)
 	struct rte_mem_config *mcfg;
 	const struct rte_memzone *memzone = NULL;
 
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 
 	rte_rwlock_read_lock(&mcfg->mlock);
 
@@ -377,7 +377,7 @@ struct memzone_info {
 static void
 dump_memzone(const struct rte_memzone *mz, void *arg)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *msl = NULL;
 	struct memzone_info *info = arg;
 	void *cur_addr, *mz_end;
@@ -448,7 +448,7 @@ rte_eal_memzone_init(void)
 	int ret = 0;
 
 	/* get pointer to global configuration */
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 
 	rte_rwlock_write_lock(&mcfg->mlock);
 
@@ -477,7 +477,7 @@ void rte_memzone_walk(void (*func)(const struct rte_memzone *, void *),
 	struct rte_fbarray *arr;
 	int i;
 
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 	arr = &mcfg->memzones;
 
 	rte_rwlock_read_lock(&mcfg->mlock);
lib/eal/common/eal_common_proc.c +2 -2
index 1e9a0c3115..26e7a59cd2 100644
@@ -1390,7 +1390,7 @@ enum mp_status {
 static bool
 set_mp_status(enum mp_status status)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	uint8_t expected;
 	uint8_t desired;
 
@@ -1419,7 +1419,7 @@ __rte_mp_enable(void)
 bool
 eal_mp_is_disabled(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 
 	return rte_atomic_load_explicit(&mcfg->mp_status,
 			rte_memory_order_relaxed) == MP_STATUS_DISABLED;
lib/eal/common/eal_common_tailqs.c +3 -3
index fe3ced21c7..a90c0c8932 100644
@@ -29,7 +29,7 @@ struct rte_tailq_head *
 rte_eal_tailq_lookup(const char *name)
 {
 	unsigned i;
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 
 	if (name == NULL) {
 		rte_errno = EINVAL;
@@ -53,7 +53,7 @@ rte_dump_tailq(FILE *f)
 	struct rte_mem_config *mcfg;
 	unsigned i = 0;
 
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 
 	rte_mcfg_tailq_read_lock();
 	for (i = 0; i < RTE_MAX_TAILQ; i++) {
@@ -81,7 +81,7 @@ rte_eal_tailq_create(const char *name)
 	    (rte_tailqs_count + 1 < RTE_MAX_TAILQ)) {
 		struct rte_mem_config *mcfg;
 
-		mcfg = rte_eal_get_configuration()->mem_config;
+		mcfg = eal_get_mcfg();
 		head = &mcfg->tailq_head[rte_tailqs_count];
 		strlcpy(head->name, name, sizeof(head->name));
 		TAILQ_INIT(&head->tailq_head);
lib/eal/common/eal_common_timer.c +1 -1
index 67ede70c62..b55bb21d63 100644
@@ -55,7 +55,7 @@ estimate_tsc_freq(void)
 int
 init_tsc_freq(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	uint64_t freq;
 
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
lib/eal/common/eal_internal_cfg.h +4 -0
index ad232a5b30..550489829f 100644
@@ -20,6 +20,9 @@
 #include <rte_stdatomic.h>
 #include "eal_thread.h"
 
+/* Forward declaration — full definition is in eal_memcfg.h */
+struct rte_mem_config;
+
 #if defined(RTE_ARCH_ARM)
 #define MAX_HUGEPAGE_SIZES 4  /**< support up to 4 page sizes */
 #else
@@ -160,6 +163,7 @@ struct eal_runtime_state {
 	uint32_t lcore_count;         /**< Number of active lcore IDs (role != ROLE_OFF). */
 	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
 	RTE_BITSET_DECLARE(core_indices, RTE_MAX_LCORE); /**< currently allocated core_indices */
+	struct rte_mem_config *mem_config; /**< pointer to memory config (in shared memory) */
 };
 
 struct eal_user_cfg *eal_get_user_configuration(void);
lib/eal/common/eal_memcfg.h +3 -0
index 2b3b3b62ba..51dddbf525 100644
@@ -86,6 +86,9 @@ struct rte_mem_config {
 	size_t max_memzone; /**< Maximum number of allocated memzones. */
 };
 
+/* Return a pointer to the shared memory config */
+struct rte_mem_config *eal_get_mcfg(void);
+
 /* update internal config from shared mem config */
 void
 eal_mcfg_update_internal(void);
lib/eal/common/eal_private.h +1 -5
index 50b8e1653b..c7c600fa13 100644
@@ -21,11 +21,7 @@
  * The global RTE configuration structure.
  */
 struct rte_config {
-	/**
-	 * Pointer to memory configuration, which may be shared across multiple
-	 * DPDK instances
-	 */
-	struct rte_mem_config *mem_config;
+	int _unused; /**< dummy field to prevent empty struct */
 };
 
 /**
lib/eal/common/malloc_heap.c +11 -11
index bd25496275..90534c9cbc 100644
@@ -71,7 +71,7 @@ check_hugepage_sz(unsigned flags, uint64_t hugepage_sz)
 int
 malloc_socket_to_heap_id(unsigned int socket_id)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int i;
 
 	for (i = 0; i < RTE_MAX_HEAPS; i++) {
@@ -107,7 +107,7 @@ static int
 malloc_add_seg(const struct rte_memseg_list *msl,
 		const struct rte_memseg *ms, size_t len, void *arg __rte_unused)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *found_msl;
 	struct malloc_heap *heap;
 	int msl_idx, heap_idx;
@@ -294,7 +294,7 @@ alloc_pages_on_heap(struct malloc_heap *heap, uint64_t pg_sz, size_t elt_size,
 		int socket, unsigned int flags, size_t align, size_t bound,
 		bool contig, struct rte_memseg **ms, int n_segs)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *msl;
 	struct malloc_elem *elem = NULL;
 	size_t alloc_sz;
@@ -465,7 +465,7 @@ try_expand_heap_secondary(struct malloc_heap *heap, uint64_t pg_sz,
 		size_t elt_size, int socket, unsigned int flags, size_t align,
 		size_t bound, bool contig)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct malloc_mp_req req;
 	int req_result;
 
@@ -534,7 +534,7 @@ static int
 alloc_more_mem_on_socket(struct malloc_heap *heap, size_t size, int socket,
 		unsigned int flags, size_t align, size_t bound, bool contig)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *requested_msls[RTE_MAX_MEMSEG_LISTS];
 	struct rte_memseg_list *other_msls[RTE_MAX_MEMSEG_LISTS];
 	uint64_t requested_pg_sz[RTE_MAX_MEMSEG_LISTS];
@@ -642,7 +642,7 @@ static void *
 malloc_heap_alloc_on_heap_id(size_t size, unsigned int heap_id, unsigned int flags, size_t align,
 		size_t bound, bool contig)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct malloc_heap *heap = &mcfg->malloc_heaps[heap_id];
 	unsigned int size_flags = flags & ~RTE_MEMZONE_SIZE_HINT_ONLY;
 	int socket_id;
@@ -773,7 +773,7 @@ static void *
 heap_alloc_biggest_on_heap_id(unsigned int heap_id,
 		unsigned int flags, size_t align, bool contig)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct malloc_heap *heap = &mcfg->malloc_heaps[heap_id];
 	void *ret;
 
@@ -1175,7 +1175,7 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 		unsigned int n_pages, size_t page_sz, const char *seg_name,
 		unsigned int socket_id)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	char fbarray_name[RTE_FBARRAY_NAME_LEN];
 	struct rte_memseg_list *msl = NULL;
 	struct rte_fbarray *arr;
@@ -1242,7 +1242,7 @@ struct extseg_walk_arg {
 static int
 extseg_walk(const struct rte_memseg_list *msl, void *arg)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct extseg_walk_arg *wa = arg;
 
 	if (msl->base_va == wa->va_addr && msl->len == wa->len) {
@@ -1343,7 +1343,7 @@ malloc_heap_remove_external_memory(struct malloc_heap *heap, void *va_addr,
 int
 malloc_heap_create(struct malloc_heap *heap, const char *heap_name)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	uint32_t next_socket_id = mcfg->next_socket_id;
 
 	/* prevent overflow. did you really create 2 billion heaps??? */
@@ -1397,7 +1397,7 @@ malloc_heap_destroy(struct malloc_heap *heap)
 int
 rte_eal_malloc_heap_init(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	unsigned int i;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
lib/eal/common/malloc_mp.c +1 -1
index 9765277f5d..d225b22bfd 100644
@@ -217,7 +217,7 @@ static int
 handle_alloc_request(const struct malloc_mp_req *m,
 		struct mp_request *req)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	const struct malloc_req_alloc *ar = &m->alloc_req;
 	struct malloc_heap *heap;
 	struct malloc_elem *elem;
lib/eal/common/rte_malloc.c +7 -7
index 388e5a63b6..9e1c7adfed 100644
@@ -265,7 +265,7 @@ int
 rte_malloc_get_socket_stats(int socket,
 		struct rte_malloc_socket_stats *socket_stats)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int heap_idx;
 
 	heap_idx = malloc_socket_to_heap_id(socket);
@@ -283,7 +283,7 @@ RTE_EXPORT_SYMBOL(rte_malloc_dump_heaps)
 void
 rte_malloc_dump_heaps(FILE *f)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	unsigned int idx;
 
 	for (idx = 0; idx < RTE_MAX_HEAPS; idx++) {
@@ -296,7 +296,7 @@ RTE_EXPORT_SYMBOL(rte_malloc_heap_get_socket)
 int
 rte_malloc_heap_get_socket(const char *name)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct malloc_heap *heap = NULL;
 	unsigned int idx;
 	int ret;
@@ -333,7 +333,7 @@ RTE_EXPORT_SYMBOL(rte_malloc_heap_socket_is_external)
 int
 rte_malloc_heap_socket_is_external(int socket_id)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	unsigned int idx;
 	int ret = -1;
 
@@ -362,7 +362,7 @@ RTE_EXPORT_SYMBOL(rte_malloc_dump_stats)
 void
 rte_malloc_dump_stats(FILE *f, __rte_unused const char *type)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	unsigned int heap_id;
 	struct rte_malloc_socket_stats sock_stats;
 
@@ -414,7 +414,7 @@ rte_malloc_virt2iova(const void *addr)
 static struct malloc_heap *
 find_named_heap(const char *name)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	unsigned int i;
 
 	for (i = 0; i < RTE_MAX_HEAPS; i++) {
@@ -616,7 +616,7 @@ RTE_EXPORT_SYMBOL(rte_malloc_heap_create)
 int
 rte_malloc_heap_create(const char *heap_name)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct malloc_heap *heap = NULL;
 	int i, ret;
 
lib/eal/freebsd/eal.c +11 -11
index 782514eb09..6714699828 100644
@@ -92,7 +92,7 @@ eal_clean_runtime_dir(void)
 static int
 rte_eal_config_create(void)
 {
-	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	size_t page_sz = rte_mem_page_size();
 	size_t cfg_len = sizeof(struct rte_mem_config);
@@ -162,13 +162,13 @@ rte_eal_config_create(void)
 		return -1;
 	}
 
-	memcpy(rte_mem_cfg_addr, config->mem_config, sizeof(struct rte_mem_config));
-	config->mem_config = rte_mem_cfg_addr;
+	memcpy(rte_mem_cfg_addr, runtime_state->mem_config, sizeof(struct rte_mem_config));
+	runtime_state->mem_config = rte_mem_cfg_addr;
 
 	/* store address of the config in the config itself so that secondary
 	 * processes could later map the config into this exact location
 	 */
-	config->mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
+	runtime_state->mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
 	return 0;
 }
 
@@ -178,7 +178,7 @@ rte_eal_config_attach(void)
 {
 	void *rte_mem_cfg_addr;
 	const char *pathname = eal_runtime_config_path();
-	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 
@@ -194,7 +194,7 @@ rte_eal_config_attach(void)
 		}
 	}
 
-	rte_mem_cfg_addr = mmap(NULL, sizeof(*config->mem_config),
+	rte_mem_cfg_addr = mmap(NULL, sizeof(*runtime_state->mem_config),
 				PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
 	/* don't close the fd here, it will be closed on reattach */
 	if (rte_mem_cfg_addr == MAP_FAILED) {
@@ -205,7 +205,7 @@ rte_eal_config_attach(void)
 		return -1;
 	}
 
-	config->mem_config = rte_mem_cfg_addr;
+	runtime_state->mem_config = rte_mem_cfg_addr;
 
 	return 0;
 }
@@ -216,7 +216,7 @@ rte_eal_config_reattach(void)
 {
 	struct rte_mem_config *mem_config;
 	void *rte_mem_cfg_addr;
-	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (user_cfg->no_shconf)
@@ -224,10 +224,10 @@ rte_eal_config_reattach(void)
 
 	/* save the address primary process has mapped shared config to */
 	rte_mem_cfg_addr =
-			(void *)(uintptr_t)config->mem_config->mem_cfg_addr;
+			(void *)(uintptr_t)runtime_state->mem_config->mem_cfg_addr;
 
 	/* unmap original config */
-	munmap(config->mem_config, sizeof(struct rte_mem_config));
+	munmap(runtime_state->mem_config, sizeof(struct rte_mem_config));
 
 	/* remap the config at proper address */
 	mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
@@ -248,7 +248,7 @@ rte_eal_config_reattach(void)
 		return -1;
 	}
 
-	config->mem_config = mem_config;
+	runtime_state->mem_config = mem_config;
 
 	return 0;
 }
lib/eal/freebsd/eal_memory.c +3 -3
index 98e4313f7a..2466987e03 100644
@@ -75,7 +75,7 @@ rte_eal_hugepage_init(void)
 	struct eal_platform_info *platform_info = eal_get_platform_info();
 
 	/* get pointer to global configuration */
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 
 	/* for debug purposes, hugetlbfs can be disabled */
 	if (user_cfg->no_hugetlbfs) {
@@ -352,7 +352,7 @@ memseg_list_alloc(struct rte_memseg_list *msl)
 static int
 memseg_primary_init(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int hpi_idx, msl_idx = 0;
 	struct rte_memseg_list *msl;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
@@ -416,7 +416,7 @@ memseg_primary_init(void)
 static int
 memseg_secondary_init(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int msl_idx = 0;
 	struct rte_memseg_list *msl;
 
lib/eal/linux/eal.c +12 -12
index b44097d9bf..2b02d984e9 100644
@@ -170,9 +170,9 @@ eal_clean_runtime_dir(void)
 static int
 rte_eal_config_create(void)
 {
-	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	size_t page_sz = rte_mem_page_size();
-	size_t cfg_len = sizeof(*config->mem_config);
+	size_t cfg_len = sizeof(*runtime_state->mem_config);
 	size_t cfg_len_aligned = RTE_ALIGN(cfg_len, page_sz);
 	void *rte_mem_cfg_addr, *mapped_mem_cfg_addr;
 	int retval;
@@ -240,14 +240,14 @@ rte_eal_config_create(void)
 		return -1;
 	}
 
-	memcpy(rte_mem_cfg_addr, config->mem_config, sizeof(struct rte_mem_config));
-	config->mem_config = rte_mem_cfg_addr;
+	memcpy(rte_mem_cfg_addr, runtime_state->mem_config, sizeof(struct rte_mem_config));
+	runtime_state->mem_config = rte_mem_cfg_addr;
 
 	/* store address of the config in the config itself so that secondary
 	 * processes could later map the config into this exact location
 	 */
-	config->mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
-	config->mem_config->dma_maskbits = 0;
+	runtime_state->mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
+	runtime_state->mem_config->dma_maskbits = 0;
 
 	return 0;
 }
@@ -256,7 +256,7 @@ rte_eal_config_create(void)
 static int
 rte_eal_config_attach(void)
 {
-	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct rte_mem_config *mem_config;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
@@ -285,7 +285,7 @@ rte_eal_config_attach(void)
 		return -1;
 	}
 
-	config->mem_config = mem_config;
+	runtime_state->mem_config = mem_config;
 
 	return 0;
 }
@@ -294,7 +294,7 @@ rte_eal_config_attach(void)
 static int
 rte_eal_config_reattach(void)
 {
-	struct rte_config *config = rte_eal_get_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct rte_mem_config *mem_config;
 	void *rte_mem_cfg_addr;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
@@ -304,10 +304,10 @@ rte_eal_config_reattach(void)
 
 	/* save the address primary process has mapped shared config to */
 	rte_mem_cfg_addr =
-		(void *) (uintptr_t) config->mem_config->mem_cfg_addr;
+		(void *) (uintptr_t) runtime_state->mem_config->mem_cfg_addr;
 
 	/* unmap original config */
-	munmap(config->mem_config, sizeof(struct rte_mem_config));
+	munmap(runtime_state->mem_config, sizeof(struct rte_mem_config));
 
 	/* remap the config at proper address */
 	mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
@@ -330,7 +330,7 @@ rte_eal_config_reattach(void)
 		return -1;
 	}
 
-	config->mem_config = mem_config;
+	runtime_state->mem_config = mem_config;
 
 	return 0;
 }
lib/eal/linux/eal_memalloc.c +9 -9
index 38e5baec29..3e693d4705 100644
@@ -761,7 +761,7 @@ struct alloc_walk_param {
 static int
 alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct alloc_walk_param *wa = arg;
 	struct rte_memseg_list *cur_msl;
 	size_t page_sz;
@@ -900,7 +900,7 @@ struct free_walk_param {
 static int
 free_seg_walk(const struct rte_memseg_list *msl, void *arg)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *found_msl;
 	struct free_walk_param *wa = arg;
 	uintptr_t start_addr, end_addr;
@@ -1330,7 +1330,7 @@ sync_existing(struct rte_memseg_list *primary_msl,
 static int
 sync_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *primary_msl, *local_msl;
 	struct eal_platform_info *platform_info = eal_get_platform_info();
 	struct hugepage_info *hi = NULL;
@@ -1383,7 +1383,7 @@ static int
 secondary_msl_create_walk(const struct rte_memseg_list *msl,
 		void *arg __rte_unused)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *primary_msl, *local_msl;
 	char name[RTE_FBARRAY_NAME_LEN];
 	int msl_idx, ret;
@@ -1432,7 +1432,7 @@ static int
 secondary_msl_destroy_walk(const struct rte_memseg_list *msl,
 		void *arg __rte_unused)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *local_msl;
 	int msl_idx, ret;
 
@@ -1515,7 +1515,7 @@ static int
 fd_list_create_walk(const struct rte_memseg_list *msl,
 		void *arg __rte_unused)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	unsigned int len;
 	int msl_idx;
 
@@ -1531,7 +1531,7 @@ fd_list_create_walk(const struct rte_memseg_list *msl,
 static int
 fd_list_destroy_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int msl_idx;
 
 	if (msl->external)
@@ -1545,7 +1545,7 @@ fd_list_destroy_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
 int
 eal_memalloc_set_seg_fd(int list_idx, int seg_idx, int fd)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* single file segments mode doesn't support individual segment fd's */
@@ -1600,7 +1600,7 @@ eal_memalloc_get_seg_fd(int list_idx, int seg_idx)
 int
 eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (user_cfg->single_file_segments) {
lib/eal/linux/eal_memory.c +7 -7
index 3cd100ce56..41d0cf79c0 100644
@@ -679,8 +679,8 @@ unmap_unneeded_hugepages(struct hugepage_file *hugepg_tbl,
 static int
 remap_segment(struct hugepage_file *hugepages, int seg_start, int seg_end)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *msl;
 	struct rte_fbarray *arr;
 	int cur_page, seg_len;
@@ -848,7 +848,7 @@ static int __rte_unused
 prealloc_segments(struct hugepage_file *hugepages, int n_pages)
 {
 	const struct eal_platform_info *platform_info = eal_get_platform_info();
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int cur_page, seg_start_page, end_seg, new_memseg;
 	unsigned int hpi_idx, socket, i;
 	int n_contig_segs, n_segs;
@@ -1146,7 +1146,7 @@ eal_legacy_hugepage_init(void)
 	memset(used_hp, 0, sizeof(used_hp));
 
 	/* get pointer to global configuration */
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 
 	/* hugetlbfs can be disabled */
 	if (user_cfg->no_hugetlbfs) {
@@ -1523,7 +1523,7 @@ getFileSize(int fd)
 static int
 eal_legacy_hugepage_attach(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct hugepage_file *hp = NULL;
 	unsigned int num_hp = 0;
 	unsigned int i = 0;
@@ -1696,7 +1696,7 @@ memseg_primary_init_32(void)
 {
 	/* limit total amount of memory on 32-bit */
 	const uint64_t mem32_max_mem = 2ULL << 30;
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int active_sockets, hpi_idx, msl_idx = 0;
 	unsigned int socket_id, i;
 	struct rte_memseg_list *msl;
@@ -1898,7 +1898,7 @@ memseg_primary_init(void)
 static int __rte_unused
 memseg_secondary_init_dynmem(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int msl_idx = 0;
 	struct rte_memseg_list *msl;
 	void *mem_va_addr;
@@ -1949,7 +1949,7 @@ memseg_secondary_init_dynmem(void)
 static int
 memseg_secondary_init_legacy(void)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	int msl_idx = 0;
 	struct rte_memseg_list *msl;
 
lib/eal/windows/eal.c +3 -3
index 9ff6fbec7a..51b149828b 100644
@@ -44,7 +44,7 @@ eal_proc_type_detect(void)
 {
 	enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
 	const char *pathname = eal_runtime_config_path();
-	const struct rte_config *config = rte_eal_get_configuration();
+	const struct rte_mem_config *config = eal_get_mcfg();
 
 	/* if we can open the file but not get a write-lock we are a secondary
 	 * process. NOTE: if we get a file handle back, we keep that open
@@ -54,14 +54,14 @@ eal_proc_type_detect(void)
 		_O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
 	if (err == 0) {
 		OVERLAPPED soverlapped = { 0 };
-		soverlapped.Offset = sizeof(*config->mem_config);
+		soverlapped.Offset = sizeof(*config);
 		soverlapped.OffsetHigh = 0;
 
 		HANDLE hwinfilehandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
 
 		if (!LockFileEx(hwinfilehandle,
 			LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
-			sizeof(*config->mem_config), 0, &soverlapped))
+			sizeof(*config), 0, &soverlapped))
 			ptype = RTE_PROC_SECONDARY;
 	}
 
lib/eal/windows/eal_memalloc.c +2 -2
index 0163162db2..b45002621b 100644
@@ -178,7 +178,7 @@ struct alloc_walk_param {
 static int
 alloc_seg_walk(const struct rte_memseg_list *msl, void *arg)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct alloc_walk_param *wa = arg;
 	struct rte_memseg_list *cur_msl;
 	size_t page_sz;
@@ -284,7 +284,7 @@ struct free_walk_param {
 static int
 free_seg_walk(const struct rte_memseg_list *msl, void *arg)
 {
-	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *found_msl;
 	struct free_walk_param *wa = arg;
 	uintptr_t start_addr, end_addr;
lib/eal/windows/eal_memory.c +1 -1
index 8fcd636a3a..8a267a9215 100644
@@ -677,7 +677,7 @@ eal_nohuge_init(void)
 	uint64_t mem_sz, page_sz;
 	void *addr;
 
-	mcfg = rte_eal_get_configuration()->mem_config;
+	mcfg = eal_get_mcfg();
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* nohuge mode is legacy mode */
Signature · 1 line
2.55.0
#118 lore raw

PATCH v3 24/39 eal: remove rte_config structure

In reply to Bruce Richardson

The rte_config structure is no longer used, so remove it, and the function returning a pointer to it.

In the process, as a general cleanup, remove references to rte_config in error or info messages where it no longer makes sense to do so. For example, messages around creating or attaching to the shared memory config were referencing "rte_config", even though rte_config itself hasn't been in shared memory.

---
 lib/eal/common/eal_common_config.c | 10 ----------
 lib/eal/common/eal_private.h       | 15 ---------------
 lib/eal/freebsd/eal.c              | 18 +++++++++---------
 lib/eal/include/rte_memzone.h      | 10 +++++-----
 lib/eal/include/rte_tailq.h        |  2 +-
 lib/eal/linux/eal.c                | 18 +++++++++---------
 6 files changed, 24 insertions(+), 49 deletions(-)
lib/eal/common/eal_common_config.c +0 -10
index ebb7c222d9..35654cc71f 100644
@@ -20,9 +20,6 @@ static struct rte_mem_config early_mem_config = {
 	.memory_hotplug_lock = RTE_RWLOCK_INITIALIZER,
 };
 
-/* Address of global and public configuration */
-static struct rte_config rte_config;
-
 /* platform-specific runtime dir */
 static char runtime_dir[UNIX_PATH_MAX];
 
@@ -56,13 +53,6 @@ eal_set_runtime_dir(const char *run_dir)
 	return 0;
 }
 
-/* Return a pointer to the configuration structure */
-struct rte_config *
-rte_eal_get_configuration(void)
-{
-	return &rte_config;
-}
-
 /* Return a pointer to the memory config structure */
 struct rte_mem_config *
 eal_get_mcfg(void)
lib/eal/common/eal_private.h +0 -15
index c7c600fa13..798e60a359 100644
@@ -17,21 +17,6 @@
 
 #include "eal_internal_cfg.h"
 
-/**
- * The global RTE configuration structure.
- */
-struct rte_config {
-	int _unused; /**< dummy field to prevent empty struct */
-};
-
-/**
- * Get the global configuration structure.
- *
- * @return
- *   A pointer to the global configuration structure.
- */
-struct rte_config *rte_eal_get_configuration(void);
-
 /**
  * Put the argument list into a structure.
  *
lib/eal/freebsd/eal.c +9 -9
index 6714699828..18333071de 100644
@@ -144,7 +144,7 @@ rte_eal_config_create(void)
 	rte_mem_cfg_addr = eal_get_virtual_area(rte_mem_cfg_addr,
 			&cfg_len_aligned, page_sz, 0, 0);
 	if (rte_mem_cfg_addr == NULL) {
-		EAL_LOG(ERR, "Cannot mmap memory for rte_config");
+		EAL_LOG(ERR, "Cannot mmap shared memory config");
 		close(mem_cfg_fd);
 		mem_cfg_fd = -1;
 		return -1;
@@ -155,7 +155,7 @@ rte_eal_config_create(void)
 			cfg_len_aligned, PROT_READ | PROT_WRITE,
 			MAP_SHARED | MAP_FIXED, mem_cfg_fd, 0);
 	if (mapped_mem_cfg_addr == MAP_FAILED) {
-		EAL_LOG(ERR, "Cannot remap memory for rte_config: %s", strerror(errno));
+		EAL_LOG(ERR, "Cannot remap shared memory config: %s", strerror(errno));
 		munmap(rte_mem_cfg_addr, cfg_len);
 		close(mem_cfg_fd);
 		mem_cfg_fd = -1;
@@ -200,7 +200,7 @@ rte_eal_config_attach(void)
 	if (rte_mem_cfg_addr == MAP_FAILED) {
 		close(mem_cfg_fd);
 		mem_cfg_fd = -1;
-		EAL_LOG(ERR, "Cannot mmap memory for rte_config! error %i (%s)",
+		EAL_LOG(ERR, "Cannot mmap shared memory config! error %i (%s)",
 			errno, strerror(errno));
 		return -1;
 	}
@@ -238,12 +238,12 @@ rte_eal_config_reattach(void)
 
 	if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
 		if (mem_config != MAP_FAILED) {
-			EAL_LOG(ERR, "Cannot mmap memory for rte_config at [%p], got [%p] - please use '--base-virtaddr' option",
+			EAL_LOG(ERR, "Cannot mmap shared memory config at [%p], got [%p] - please use '--base-virtaddr' option",
 					rte_mem_cfg_addr, mem_config);
 			munmap(mem_config, sizeof(struct rte_mem_config));
 			return -1;
 		}
-		EAL_LOG(ERR, "Cannot mmap memory for rte_config! error %i (%s)",
+		EAL_LOG(ERR, "Cannot mmap shared memory config! error %i (%s)",
 			errno, strerror(errno));
 		return -1;
 	}
@@ -279,9 +279,9 @@ eal_proc_type_detect(void)
 	return ptype;
 }
 
-/* Sets up rte_config structure with the pointer to shared memory config.*/
+/* Attaches to or creates the shared memory config for this process. */
 static int
-rte_config_init(void)
+eal_mem_config_init(void)
 {
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
@@ -484,7 +484,7 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	if (rte_config_init() < 0) {
+	if (eal_mem_config_init() < 0) {
 		rte_eal_init_alert("Cannot init config");
 		goto err_out;
 	}
@@ -563,7 +563,7 @@ rte_eal_init(int argc, char **argv)
 		rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
 
 	if (!user_cfg->no_hugetlbfs) {
-		/* rte_config isn't initialized yet */
+		/* shared mem config not yet attached */
 		ret = user_cfg->process_type == RTE_PROC_PRIMARY ?
 			eal_hugepage_info_init() :
 			eal_hugepage_info_read();
lib/eal/include/rte_memzone.h +5 -5
index 5a0e1b8a15..7f94b6ff71 100644
@@ -13,8 +13,8 @@
  * portions of physical memory. These zones are identified by a name.
  *
  * The memzone descriptors are shared by all partitions and are
- * located in a known place of physical memory. This zone is accessed
- * using rte_eal_get_configuration(). The lookup (by name) of a
+ * located in a known place of physical memory accessible via the
+ * shared memory config. The lookup (by name) of a
  * memory zone can be done in any partition and returns the same
  * physical address.
  *
@@ -137,7 +137,7 @@ size_t rte_memzone_max_get(void);
  *   A pointer to a correctly-filled read-only memzone descriptor, or NULL
  *   on error.
  *   On error case, rte_errno will be set appropriately:
- *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
+ *    - E_RTE_NO_CONFIG - function could not get pointer to shared memory config
  *    - ENOSPC - the maximum number of memzones has already been allocated
  *    - EEXIST - a memzone with the same name already exists
  *    - ENOMEM - no appropriate memory area found in which to create memzone
@@ -202,7 +202,7 @@ const struct rte_memzone *rte_memzone_reserve(const char *name,
  *   A pointer to a correctly-filled read-only memzone descriptor, or NULL
  *   on error.
  *   On error case, rte_errno will be set appropriately:
- *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
+ *    - E_RTE_NO_CONFIG - function could not get pointer to shared memory config
  *    - ENOSPC - the maximum number of memzones has already been allocated
  *    - EEXIST - a memzone with the same name already exists
  *    - ENOMEM - no appropriate memory area found in which to create memzone
@@ -273,7 +273,7 @@ const struct rte_memzone *rte_memzone_reserve_aligned(const char *name,
  *   A pointer to a correctly-filled read-only memzone descriptor, or NULL
  *   on error.
  *   On error case, rte_errno will be set appropriately:
- *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
+ *    - E_RTE_NO_CONFIG - function could not get pointer to shared memory config
  *    - ENOSPC - the maximum number of memzones has already been allocated
  *    - EEXIST - a memzone with the same name already exists
  *    - ENOMEM - no appropriate memory area found in which to create memzone
lib/eal/include/rte_tailq.h +1 -1
index e7caed6812..dced107368 100644
@@ -29,7 +29,7 @@ RTE_TAILQ_HEAD(rte_tailq_entry_head, rte_tailq_entry);
 
 /**
  * The structure defining a tailq header entry for storing
- * in the rte_config structure in shared memory. Each tailq
+ * in shared memory. Each tailq
  * is identified by name.
  * Any library storing a set of objects e.g. rings, mempools, hash-tables,
  * is recommended to use an entry here, so as to make it easy for
lib/eal/linux/eal.c +9 -9
index 2b02d984e9..7f8010b61d 100644
@@ -222,7 +222,7 @@ rte_eal_config_create(void)
 	rte_mem_cfg_addr = eal_get_virtual_area(rte_mem_cfg_addr,
 			&cfg_len_aligned, page_sz, 0, 0);
 	if (rte_mem_cfg_addr == NULL) {
-		EAL_LOG(ERR, "Cannot mmap memory for rte_config");
+		EAL_LOG(ERR, "Cannot mmap shared memory config");
 		close(mem_cfg_fd);
 		mem_cfg_fd = -1;
 		return -1;
@@ -236,7 +236,7 @@ rte_eal_config_create(void)
 		munmap(rte_mem_cfg_addr, cfg_len);
 		close(mem_cfg_fd);
 		mem_cfg_fd = -1;
-		EAL_LOG(ERR, "Cannot remap memory for rte_config");
+		EAL_LOG(ERR, "Cannot remap shared memory config");
 		return -1;
 	}
 
@@ -280,7 +280,7 @@ rte_eal_config_attach(void)
 	if (mem_config == MAP_FAILED) {
 		close(mem_cfg_fd);
 		mem_cfg_fd = -1;
-		EAL_LOG(ERR, "Cannot mmap memory for rte_config! error %i (%s)",
+		EAL_LOG(ERR, "Cannot mmap shared memory config! error %i (%s)",
 			errno, strerror(errno));
 		return -1;
 	}
@@ -320,12 +320,12 @@ rte_eal_config_reattach(void)
 	if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
 		if (mem_config != MAP_FAILED) {
 			/* errno is stale, don't use */
-			EAL_LOG(ERR, "Cannot mmap memory for rte_config at [%p], got [%p] - please use '--base-virtaddr' option",
+			EAL_LOG(ERR, "Cannot mmap shared memory config at [%p], got [%p] - please use '--base-virtaddr' option",
 				 rte_mem_cfg_addr, mem_config);
 			munmap(mem_config, sizeof(struct rte_mem_config));
 			return -1;
 		}
-		EAL_LOG(ERR, "Cannot mmap memory for rte_config! error %i (%s)",
+		EAL_LOG(ERR, "Cannot mmap shared memory config! error %i (%s)",
 			errno, strerror(errno));
 		return -1;
 	}
@@ -361,9 +361,9 @@ eal_proc_type_detect(void)
 	return ptype;
 }
 
-/* Sets up rte_config structure with the pointer to shared memory config.*/
+/* Attaches to or creates the shared memory config for this process. */
 static int
-rte_config_init(void)
+eal_mem_config_init(void)
 {
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
@@ -637,7 +637,7 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	if (rte_config_init() < 0) {
+	if (eal_mem_config_init() < 0) {
 		rte_eal_init_alert("Cannot init config");
 		goto err_out;
 	}
@@ -735,7 +735,7 @@ rte_eal_init(int argc, char **argv)
 		rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
 
 	if (!user_cfg->no_hugetlbfs) {
-		/* rte_config isn't initialized yet */
+		/* shared mem config not yet attached */
 		ret = user_cfg->process_type == RTE_PROC_PRIMARY ?
 				eal_hugepage_info_init() :
 				eal_hugepage_info_read();
Signature · 1 line
2.55.0
#119 lore raw

PATCH v3 25/39 eal: separate runtime state update from arg parsing

In reply to Bruce Richardson

The eal_parse_args function was performing several updates to the runtime state that do not logically belong in a parse_args function. Move these to the "eal_adjust_config()" function, which is now renamed to the more accurate "eal_apply_runtime_state()". Ensure too, that all queries for the multi process mode use the runtime state rather than the original user provided value, which needs resolution if it's AUTO.

---
 lib/eal/common/eal_common_options.c | 68 +++++++++++++----------------
 lib/eal/common/eal_options.h        |  2 +-
 lib/eal/freebsd/eal.c               |  7 +--
 lib/eal/linux/eal.c                 |  7 +--
 4 files changed, 36 insertions(+), 48 deletions(-)
lib/eal/common/eal_common_options.c +31 -37
index b2aba99f12..ea49a44218 100644
@@ -2078,7 +2078,6 @@ int
 eal_parse_args(void)
 {
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	bool remap_lcores = (args.remap_lcore_ids != NULL);
 	struct arg_list_elem *arg;
 	uint16_t lcore_id_base = 0;
@@ -2206,17 +2205,6 @@ eal_parse_args(void)
 	if (args.main_lcore != NULL && eal_parse_main_lcore(args.main_lcore) < 0)
 		return -1;
 
-	if (user_cfg->main_lcore != -1) {
-		runtime_state->main_lcore = user_cfg->main_lcore;
-	} else {
-		/* default main lcore is the first one */
-		runtime_state->main_lcore = rte_get_next_lcore(-1, 0, 0);
-		if (runtime_state->main_lcore >= RTE_MAX_LCORE) {
-			EAL_LOG(ERR, "Main lcore is not enabled for DPDK");
-			return -1;
-		}
-	}
-
 	/* memory options */
 	if (args.memory_size != NULL) {
 		char *end = NULL;
@@ -2441,23 +2429,11 @@ eal_parse_args(void)
 		}
 	}
 
-#ifndef RTE_EXEC_ENV_WINDOWS
-	/* create runtime data directory. In no_shconf mode, skip any errors */
-	if (eal_create_runtime_dir() < 0) {
-		if (!user_cfg->no_shconf) {
-			EAL_LOG(ERR, "Cannot create runtime directory");
-			return -1;
-		}
-		EAL_LOG(WARNING, "No DPDK runtime directory created");
-	}
-#endif
-
-	if (eal_adjust_config() != 0) {
-		EAL_LOG(ERR, "Invalid configuration");
-		return -1;
-	}
+	/* sum per-NUMA memory requests into user_cfg->memory */
+	for (int i = 0; i < RTE_MAX_NUMA_NODES; i++)
+		user_cfg->memory += user_cfg->numa_mem[i];
 
-	return 0;
+	return eal_apply_runtime_state();
 }
 
 static void
@@ -2505,20 +2481,38 @@ eal_cleanup_config(const struct eal_user_cfg *user_cfg)
 }
 
 int
-eal_adjust_config(void)
+eal_apply_runtime_state(void)
 {
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	int i;
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
-	if (user_cfg->process_type == RTE_PROC_AUTO)
-		user_cfg->process_type = eal_proc_type_detect();
+	/* set the main lcore */
+	if (user_cfg->main_lcore != -1) {
+		runtime_state->main_lcore = user_cfg->main_lcore;
+	} else {
+		/* default main lcore is the first one */
+		runtime_state->main_lcore = rte_get_next_lcore(-1, 0, 0);
+		if (runtime_state->main_lcore >= RTE_MAX_LCORE) {
+			EAL_LOG(ERR, "Main lcore is not enabled for DPDK");
+			return -1;
+		}
+	}
 
-	compute_ctrl_threads_cpuset();
+#ifndef RTE_EXEC_ENV_WINDOWS
+	/* create runtime data directory. In no_shconf mode, skip any errors */
+	if (eal_create_runtime_dir() < 0) {
+		if (!user_cfg->no_shconf) {
+			EAL_LOG(ERR, "Cannot create runtime directory");
+			return -1;
+		}
+		EAL_LOG(WARNING, "No DPDK runtime directory created");
+	}
+#endif
 
-	/* if no memory amounts were requested, this will result in 0 and
-	 * will be overridden later, right after eal_hugepage_info_init() */
-	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
-		user_cfg->memory += user_cfg->numa_mem[i];
+	runtime_state->process_type = (user_cfg->process_type == RTE_PROC_AUTO) ?
+			eal_proc_type_detect() : user_cfg->process_type;
+
+	compute_ctrl_threads_cpuset();
 
 	return 0;
 }
lib/eal/common/eal_options.h +1 -1
index 58fb3085e5..eee7339e90 100644
@@ -14,7 +14,7 @@ int eal_parse_log_options(void);
 int eal_parse_args(void);
 int eal_option_device_parse(void);
 int eal_apply_hugepage_mem_sz_limits(void);
-int eal_adjust_config(void);
+int eal_apply_runtime_state(void);
 int eal_cleanup_config(const struct eal_user_cfg *user_cfg);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
lib/eal/freebsd/eal.c +2 -5
index 18333071de..acb650031b 100644
@@ -284,9 +284,6 @@ static int
 eal_mem_config_init(void)
 {
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
-	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-
-	runtime_state->process_type = user_cfg->process_type;
 
 	switch (runtime_state->process_type) {
 	case RTE_PROC_PRIMARY:
@@ -564,7 +561,7 @@ rte_eal_init(int argc, char **argv)
 
 	if (!user_cfg->no_hugetlbfs) {
 		/* shared mem config not yet attached */
-		ret = user_cfg->process_type == RTE_PROC_PRIMARY ?
+		ret = rte_eal_process_type() == RTE_PROC_PRIMARY ?
 			eal_hugepage_info_init() :
 			eal_hugepage_info_read();
 		if (ret < 0) {
@@ -572,7 +569,7 @@ rte_eal_init(int argc, char **argv)
 			rte_errno = EACCES;
 			goto err_out;
 		}
-		if (user_cfg->process_type == RTE_PROC_PRIMARY &&
+		if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
 				eal_apply_hugepage_mem_sz_limits() < 0) {
 			rte_eal_init_alert("Cannot apply hugepage memory limits.");
 			rte_errno = EINVAL;
lib/eal/linux/eal.c +2 -5
index 7f8010b61d..32b7206f63 100644
@@ -366,9 +366,6 @@ static int
 eal_mem_config_init(void)
 {
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
-	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-
-	runtime_state->process_type = user_cfg->process_type;
 
 	switch (runtime_state->process_type) {
 	case RTE_PROC_PRIMARY:
@@ -736,7 +733,7 @@ rte_eal_init(int argc, char **argv)
 
 	if (!user_cfg->no_hugetlbfs) {
 		/* shared mem config not yet attached */
-		ret = user_cfg->process_type == RTE_PROC_PRIMARY ?
+		ret = rte_eal_process_type() == RTE_PROC_PRIMARY ?
 				eal_hugepage_info_init() :
 				eal_hugepage_info_read();
 		if (ret < 0) {
@@ -744,7 +741,7 @@ rte_eal_init(int argc, char **argv)
 			rte_errno = EACCES;
 			goto err_out;
 		}
-		if (user_cfg->process_type == RTE_PROC_PRIMARY &&
+		if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
 				eal_apply_hugepage_mem_sz_limits() < 0) {
 			rte_eal_init_alert("Cannot apply hugepage memory limits.");
 			rte_errno = EINVAL;
Signature · 1 line
2.55.0
#120 lore raw

PATCH v3 26/39 eal: move device options staging list into user cfg

In reply to Bruce Richardson

The file-static devopt_list in eal_common_options.c holds device options (-a/-b/--vdev) staged during arg parsing for later consumption by eal_option_device_parse(). Rather than holding this as file local static data, store it in the user_cfg struct.

---
 lib/eal/common/eal_common_options.c | 21 ++++++---------------
 lib/eal/common/eal_internal_cfg.h   | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 15 deletions(-)
lib/eal/common/eal_common_options.c +6 -15
index ea49a44218..1369f75be7 100644
@@ -305,18 +305,6 @@ static const char *default_solib_dir = RTE_EAL_PMD_PATH;
 RTE_PMD_EXPORT_SYMBOL(const char, dpdk_solib_path)[] =
 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
 
-TAILQ_HEAD(device_option_list, device_option);
-
-struct device_option {
-	TAILQ_ENTRY(device_option) next;
-
-	enum rte_devtype type;
-	char arg[];
-};
-
-static struct device_option_list devopt_list =
-TAILQ_HEAD_INITIALIZER(devopt_list);
-
 /* Returns rte_usage_hook_t */
 rte_usage_hook_t
 eal_get_application_usage_hook(void)
@@ -454,6 +442,7 @@ eal_clean_saved_args(void)
 static int
 eal_option_device_add(enum rte_devtype type, const char *arg)
 {
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct device_option *devopt;
 	size_t arglen;
 	int ret;
@@ -472,25 +461,26 @@ eal_option_device_add(enum rte_devtype type, const char *arg)
 		free(devopt);
 		return -EINVAL;
 	}
-	TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
+	TAILQ_INSERT_TAIL(&user_cfg->devopt_list, devopt, next);
 	return 0;
 }
 
 int
 eal_option_device_parse(void)
 {
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct device_option *devopt;
 	void *tmp;
 	int ret = 0;
 
-	RTE_TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
+	RTE_TAILQ_FOREACH_SAFE(devopt, &user_cfg->devopt_list, next, tmp) {
 		if (ret == 0) {
 			ret = rte_devargs_add(devopt->type, devopt->arg);
 			if (ret)
 				EAL_LOG(ERR, "Unable to parse device '%s'",
 					devopt->arg);
 		}
-		TAILQ_REMOVE(&devopt_list, devopt, next);
+		TAILQ_REMOVE(&user_cfg->devopt_list, devopt, next);
 		free(devopt);
 	}
 	return ret;
@@ -514,6 +504,7 @@ eal_reset_internal_config(void)
 	struct eal_platform_info *platform_info = eal_get_platform_info();
 	int i;
 
+	TAILQ_INIT(&user_cfg->devopt_list);
 	user_cfg->memory = 0;
 	user_cfg->force_nrank = 0;
 	user_cfg->force_nchannel = 0;
lib/eal/common/eal_internal_cfg.h +15 -0
index 550489829f..578de5184f 100644
@@ -10,6 +10,9 @@
 #ifndef EAL_INTERNAL_CFG_H
 #define EAL_INTERNAL_CFG_H
 
+#include <sys/queue.h>
+
+#include <rte_devargs.h>
 #include <rte_eal.h>
 #include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
@@ -61,11 +64,23 @@ struct hugepage_file_discipline {
 	bool unlink_existing;
 };
 
+/**
+ * A single device option (-a/-b/--vdev) staged during arg parsing.
+ * Lives in user_cfg->devopt_list; drained by eal_option_device_parse().
+ */
+struct device_option {
+	TAILQ_ENTRY(device_option) next;
+	enum rte_devtype type;
+	char arg[];
+};
+TAILQ_HEAD(eal_devopt_list, device_option);
+
 /**
  * User-provided EAL initialization configuration.
  * Immutable after initialization, so no need for atomic types or locks.
  */
 struct eal_user_cfg {
+	struct eal_devopt_list devopt_list; /**< staged device options (-a/-b/--vdev) */
 	size_t memory;           /**< amount of asked memory */
 	size_t huge_worker_stack_size; /**< worker thread stack size */
 	enum rte_proc_type_t process_type; /**< requested process type */
Signature · 1 line
2.55.0
#121 lore raw

PATCH v3 27/39 eal: separate plugin paths from loaded plugin objects

In reply to Bruce Richardson

The one data structure in eal managed both the loaded plugins and the list of plugin paths provided by the user, separating the two rather awkwardly by using a flag value. Since we have separate user_cfg and runtime_state structures, separate the plugin info between the two structs - user provided directory and file paths in one, and actual loaded .so paths and pointers in the other.

---
 lib/eal/common/eal_common_options.c | 248 +++++++++++++++-------------
 lib/eal/common/eal_internal_cfg.h   |  22 +++
 2 files changed, 158 insertions(+), 112 deletions(-)
lib/eal/common/eal_common_options.c +136 -112
index 1369f75be7..1d24f52e5c 100644
@@ -277,21 +277,6 @@ eal_collate_args(int argc, char **argv)
 	return retval - 1;
 }
 
-TAILQ_HEAD(shared_driver_list, shared_driver);
-
-/* Definition for shared object drivers. */
-struct shared_driver {
-	TAILQ_ENTRY(shared_driver) next;
-
-	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 */
-static struct shared_driver_list solib_list =
-TAILQ_HEAD_INITIALIZER(solib_list);
-
 #ifndef RTE_EXEC_ENV_WINDOWS
 /* Default path of external loadable drivers */
 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
@@ -505,6 +490,8 @@ eal_reset_internal_config(void)
 	int i;
 
 	TAILQ_INIT(&user_cfg->devopt_list);
+	TAILQ_INIT(&user_cfg->plugin_list);
+	TAILQ_INIT(&runtime_state->loaded_plugins);
 	user_cfg->memory = 0;
 	user_cfg->force_nrank = 0;
 	user_cfg->force_nchannel = 0;
@@ -561,19 +548,18 @@ eal_reset_internal_config(void)
 }
 
 static int
-eal_plugin_add(const char *path, bool from_cmdline)
+eal_plugin_path_add(const char *path)
 {
-	struct shared_driver *solib;
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_plugin_path *p;
 
-	solib = malloc(sizeof(*solib));
-	if (solib == NULL) {
-		EAL_LOG(ERR, "malloc(solib) failed");
+	p = malloc(sizeof(*p));
+	if (p == NULL) {
+		EAL_LOG(ERR, "malloc(plugin_path) failed");
 		return -1;
 	}
-	memset(solib, 0, sizeof(*solib));
-	strlcpy(solib->name, path, PATH_MAX);
-	solib->from_cmdline = from_cmdline;
-	TAILQ_INSERT_TAIL(&solib_list, solib, next);
+	strlcpy(p->name, path, PATH_MAX);
+	TAILQ_INSERT_TAIL(&user_cfg->plugin_list, p, next);
 
 	return 0;
 }
@@ -595,53 +581,6 @@ ends_with(const char *str, const char *tail)
 	return str_len >= tail_len && strcmp(&str[str_len - tail_len], tail) == 0;
 }
 
-static int
-eal_plugindir_init(const char *path)
-{
-	struct dirent *dent = NULL;
-	DIR *d = NULL;
-
-	if (path == NULL || *path == '\0')
-		return 0;
-
-	d = opendir(path);
-	if (d == NULL) {
-		EAL_LOG(ERR, "failed to open directory %s: %s",
-			path, strerror(errno));
-		return -1;
-	}
-
-	while ((dent = readdir(d)) != NULL) {
-		char *sopath = NULL;
-		struct stat sb;
-
-		if (!ends_with(dent->d_name, ".so") && !ends_with(dent->d_name, ".so."ABI_VERSION))
-			continue;
-
-		if (asprintf(&sopath, "%s/%s", path, dent->d_name) < 0) {
-			EAL_LOG(ERR, "failed to create full path %s/%s",
-				path, dent->d_name);
-			continue;
-		}
-
-		/* if a regular file, add to list to load */
-		if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode))) {
-			free(sopath);
-			continue;
-		}
-
-		if (eal_plugin_add(sopath, false) == -1) {
-			free(sopath);
-			break;
-		}
-		free(sopath);
-	}
-
-	closedir(d);
-	/* XXX this ignores failures from readdir() itself */
-	return (dent == NULL) ? 0 : -1;
-}
-
 static int
 verify_perms(const char *dirpath)
 {
@@ -713,6 +652,65 @@ eal_dlopen(const char *pathname)
 	return retval;
 }
 
+static int
+eal_plugindir_init(const char *path)
+{
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	struct dirent *dent = NULL;
+	DIR *d = NULL;
+
+	if (path == NULL || *path == '\0')
+		return 0;
+
+	d = opendir(path);
+	if (d == NULL) {
+		EAL_LOG(ERR, "failed to open directory %s: %s",
+			path, strerror(errno));
+		return -1;
+	}
+
+	while ((dent = readdir(d)) != NULL) {
+		char *sopath = NULL;
+		struct shared_driver *solib;
+		struct stat sb;
+
+		if (!ends_with(dent->d_name, ".so") && !ends_with(dent->d_name, ".so."ABI_VERSION))
+			continue;
+
+		if (asprintf(&sopath, "%s/%s", path, dent->d_name) < 0) {
+			EAL_LOG(ERR, "failed to create full path %s/%s",
+				path, dent->d_name);
+			continue;
+		}
+
+		/* if not a regular file, skip */
+		if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode))) {
+			free(sopath);
+			continue;
+		}
+
+		solib = calloc(1, sizeof(*solib));
+		if (solib == NULL) {
+			free(sopath);
+			break;
+		}
+		strlcpy(solib->name, sopath, PATH_MAX);
+		free(sopath);
+
+		EAL_LOG(DEBUG, "open shared lib %s", solib->name);
+		solib->lib_handle = eal_dlopen(solib->name);
+		if (solib->lib_handle == NULL) {
+			free(solib);
+			break;
+		}
+		TAILQ_INSERT_TAIL(&runtime_state->loaded_plugins, solib, next);
+	}
+
+	closedir(d);
+	/* XXX this ignores failures from readdir() itself */
+	return (dent == NULL) ? 0 : -1;
+}
+
 static int
 is_shared_build(void)
 {
@@ -753,37 +751,45 @@ is_shared_build(void)
 int
 eal_plugins_init(void)
 {
-	struct shared_driver *solib = NULL;
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	struct eal_plugin_path *p;
 	struct stat sb;
 
-	/* If we are not statically linked, add default driver loading
-	 * path if it exists as a directory.
-	 * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL
-	 * shared library is not already loaded i.e. it's statically linked.)
-	 */
+	TAILQ_INIT(&runtime_state->loaded_plugins);
+
+	/* If we are not statically linked, scan the default driver directory. */
 	if (is_shared_build() &&
 			*default_solib_dir != '\0' &&
 			stat(default_solib_dir, &sb) == 0 &&
-			S_ISDIR(sb.st_mode))
-		eal_plugin_add(default_solib_dir, false);
-
-	TAILQ_FOREACH(solib, &solib_list, next) {
+			S_ISDIR(sb.st_mode)) {
+		if (eal_plugindir_init(default_solib_dir) == -1) {
+			EAL_LOG(ERR, "Cannot init plugin directory %s",
+				default_solib_dir);
+			return -1;
+		}
+	}
 
-		if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
-			if (eal_plugindir_init(solib->name) == -1) {
-				EAL_LOG(ERR,
-					"Cannot init plugin directory %s",
-					solib->name);
+	TAILQ_FOREACH(p, &user_cfg->plugin_list, next) {
+		if (stat(p->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
+			if (eal_plugindir_init(p->name) == -1) {
+				EAL_LOG(ERR, "Cannot init plugin directory %s",
+					p->name);
 				return -1;
 			}
 		} else {
-			EAL_LOG(DEBUG, "open shared lib %s",
-				solib->name);
+			struct shared_driver *solib = calloc(1, sizeof(*solib));
+			if (solib == NULL)
+				return -1;
+			strlcpy(solib->name, p->name, PATH_MAX);
+			EAL_LOG(DEBUG, "open shared lib %s", solib->name);
 			solib->lib_handle = eal_dlopen(solib->name);
-			if (solib->lib_handle == NULL)
+			if (solib->lib_handle == NULL) {
+				free(solib);
 				return -1;
+			}
+			TAILQ_INSERT_TAIL(&runtime_state->loaded_plugins, solib, next);
 		}
-
 	}
 	return 0;
 }
@@ -793,40 +799,58 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_eal_driver_path_next)
 const char *
 rte_eal_driver_path_next(const char *start, bool cmdline_only)
 {
-	struct shared_driver *solib;
+	if (cmdline_only) {
+		const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+		struct eal_plugin_path *p;
 
-	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 (start == NULL) {
+			p = TAILQ_FIRST(&user_cfg->plugin_list);
+		} else {
+			TAILQ_FOREACH(p, &user_cfg->plugin_list, next) {
+				if (start == p->name) {
+					p = TAILQ_NEXT(p, next);
+					break;
+				}
 			}
+			if (p == NULL)
+				return NULL;
 		}
-		if (solib == NULL)
-			return NULL;
-	}
+		return p ? p->name : NULL;
+	} else {
+		const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+		struct shared_driver *solib;
 
-	/* 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);
+		if (start == NULL) {
+			solib = TAILQ_FIRST(&runtime_state->loaded_plugins);
+		} else {
+			TAILQ_FOREACH(solib, &runtime_state->loaded_plugins, next) {
+				if (start == solib->name) {
+					solib = TAILQ_NEXT(solib, next);
+					break;
+				}
+			}
+			if (solib == NULL)
+				return NULL;
+		}
+		return solib ? solib->name : NULL;
 	}
-
-	return solib ? solib->name : NULL;
 }
 
 RTE_EXPORT_INTERNAL_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)
+	if (cmdline_only) {
+		const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+		struct eal_plugin_path *p;
+		TAILQ_FOREACH(p, &user_cfg->plugin_list, next)
+			count++;
+	} else {
+		const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+		struct shared_driver *solib;
+		TAILQ_FOREACH(solib, &runtime_state->loaded_plugins, next)
 			count++;
 	}
 
@@ -2105,7 +2129,7 @@ eal_parse_args(void)
 			return -1;
 	/* driver loading options */
 	TAILQ_FOREACH(arg, &args.driver_path, next)
-		if (eal_plugin_add(arg->arg, true) < 0)
+		if (eal_plugin_path_add(arg->arg) < 0)
 			return -1;
 
 	if (remap_lcores && args.remap_lcore_ids != (void *)1) {
lib/eal/common/eal_internal_cfg.h +22 -0
index 578de5184f..55900f87bf 100644
@@ -64,6 +64,16 @@ struct hugepage_file_discipline {
 	bool unlink_existing;
 };
 
+/**
+ * A plugin path provided by the user via -d, staged during arg parsing.
+ * Lives in user_cfg->plugin_list; consumed by eal_plugins_init().
+ */
+struct eal_plugin_path {
+	TAILQ_ENTRY(eal_plugin_path) next;
+	char name[PATH_MAX];
+};
+TAILQ_HEAD(eal_plugin_path_list, eal_plugin_path);
+
 /**
  * A single device option (-a/-b/--vdev) staged during arg parsing.
  * Lives in user_cfg->devopt_list; drained by eal_option_device_parse().
@@ -81,6 +91,7 @@ TAILQ_HEAD(eal_devopt_list, device_option);
  */
 struct eal_user_cfg {
 	struct eal_devopt_list devopt_list; /**< staged device options (-a/-b/--vdev) */
+	struct eal_plugin_path_list plugin_list; /**< user-provided plugin paths (-d) */
 	size_t memory;           /**< amount of asked memory */
 	size_t huge_worker_stack_size; /**< worker thread stack size */
 	enum rte_proc_type_t process_type; /**< requested process type */
@@ -161,6 +172,16 @@ struct lcore_cfg {
 	volatile RTE_ATOMIC(enum rte_lcore_state_t) state; /**< lcore state */
 };
 
+/**
+ * A plugin loaded by EAL, including directory-expanded entries.
+ */
+struct shared_driver {
+	TAILQ_ENTRY(shared_driver) next;
+	char name[PATH_MAX];
+	void *lib_handle;
+};
+TAILQ_HEAD(eal_solib_list, shared_driver);
+
 /**
  * Internal EAL runtime state
  * May be modified at runtime, so access must be protected by locks or atomic types
@@ -179,6 +200,7 @@ struct eal_runtime_state {
 	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
 	RTE_BITSET_DECLARE(core_indices, RTE_MAX_LCORE); /**< currently allocated core_indices */
 	struct rte_mem_config *mem_config; /**< pointer to memory config (in shared memory) */
+	struct eal_solib_list loaded_plugins; /**< all plugins loaded by eal_plugins_init() */
 };
 
 struct eal_user_cfg *eal_get_user_configuration(void);
Signature · 1 line
2.55.0
#122 lore raw

PATCH v3 28/39 eal: simplify internal driver path iteration APIs

In reply to Bruce Richardson

The APIs for counting and iterating the driver paths originally iterated the mixed list of both user-provided paths and loaded .so paths. However, in practice only the user-provided paths were ever queried.

Since supporting both types of iteration is duplicating the work in code (because we now have two different lists of different types to iterate) just drop the unused iteration support and update the API to only iterate the user-provided list. This simplifies the API (dropping a parameter), the implementation (removing iteration of the runtime_cfg list), and has no ABI impacts since the APIs are explicitly marked as internal. The iteration macro is updated to match the APIs too.

---
 app/test/process.c                  |  4 +-
 lib/eal/common/eal_common_options.c | 60 ++++++++---------------------
 lib/eal/include/rte_eal.h           | 35 ++++++-----------
 3 files changed, 31 insertions(+), 68 deletions(-)
app/test/process.c +2 -2
index 92c8af702b..599d6ee780 100644
@@ -63,7 +63,7 @@ add_parameter_driver_path(char **argv, int max_capacity)
 	const char *driver_path;
 	int count = 0;
 
-	RTE_EAL_DRIVER_PATH_FOREACH(driver_path, true) {
+	RTE_EAL_DRIVER_PATH_FOREACH(driver_path) {
 		if (asprintf(&argv[count], PREFIX_DRIVER_PATH"%s", driver_path) < 0)
 			break;
 
@@ -95,7 +95,7 @@ process_dup(const char *const argv[], int numargs, const char *env_value)
 		return -1;
 	else if (pid == 0) {
 		allow_num = rte_devargs_type_count(RTE_DEVTYPE_ALLOWED);
-		driver_path_num = rte_eal_driver_path_count(true);
+		driver_path_num = rte_eal_driver_path_count();
 		argv_num = numargs + allow_num + driver_path_num + 1;
 		argv_cpy = calloc(argv_num, sizeof(char *));
 		if (!argv_cpy)
lib/eal/common/eal_common_options.c +17 -43

79 lines not on this page · raw message

lib/eal/include/rte_eal.h +12 -23
index 7241f3be5d..6711ee4440 100644
@@ -493,57 +493,46 @@ rte_eal_get_runtime_dir(void);
 
 /**
  * @internal
- * Iterate to the next driver path.
+ * Iterate to the next user-provided 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.
+ * This function iterates through the 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.
  */
 __rte_internal
 const char *
-rte_eal_driver_path_next(const char *start, bool cmdline_only);
+rte_eal_driver_path_next(const char *start);
 
 /**
  * @internal
- * Iterate over all driver paths.
+ * Iterate over all user-provided driver paths.
  *
  * This macro provides a convenient way to iterate through all driver paths
- * that were loaded via -d flags during EAL initialization.
+ * that were specified 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); \
+#define RTE_EAL_DRIVER_PATH_FOREACH(path) \
+	for (path = rte_eal_driver_path_next(NULL); \
 	     path != NULL; \
-	     path = rte_eal_driver_path_next(path, cmdline_only))
+	     path = rte_eal_driver_path_next(path))
 
 /**
  * @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.
+ * Get count of user-provided driver paths.
  *
  * @return
- *   Number of driver paths.
+ *   Number of driver paths specified via -d flags during EAL initialization.
  */
 __rte_internal
 unsigned int
-rte_eal_driver_path_count(bool cmdline_only);
+rte_eal_driver_path_count(void);
 
 #ifdef __cplusplus
 }
Signature · 1 line
2.55.0
#123 lore raw

PATCH v3 29/39 eal: move trace config into user config struct

In reply to Bruce Richardson

The trace settings (pattern list, directory, buffer size, mode) were previously stored directly in the internal struct trace singleton during arg parsing, via helper functions. Move these setting into eal_user_cfg and drop the helper functions.

NOTE: after these changes, eal_cleanup_config needs a non-const user config pointer to cleanup. Rather than making the pointer in rte_eal_cleanup non-const, make eal_cleanup_config like all the other functions in the cleanup chain in taking no parameters. Then it can define its own non-const user config pointer internally.

---
 lib/eal/common/eal_common_options.c     |  53 ++++++++++--
 lib/eal/common/eal_common_trace.c       |  30 +++++--
 lib/eal/common/eal_common_trace_utils.c | 104 ------------------------
 lib/eal/common/eal_internal_cfg.h       |  15 ++++
 lib/eal/common/eal_options.h            |   2 +-
 lib/eal/common/eal_trace.h              |  11 ---
 lib/eal/freebsd/eal.c                   |   3 +-
 lib/eal/linux/eal.c                     |   2 +-
 lib/eal/windows/eal.c                   |   4 +-
 9 files changed, 87 insertions(+), 137 deletions(-)
lib/eal/common/eal_common_options.c +47 -6
index 5014eb6209..dd25c3274b 100644
@@ -14,6 +14,7 @@
 #include <sys/queue.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <dlfcn.h>
+#include <fnmatch.h>
 #include <libgen.h>
 #endif
 #include <sys/stat.h>
@@ -491,6 +492,7 @@ eal_reset_internal_config(void)
 
 	TAILQ_INIT(&user_cfg->devopt_list);
 	TAILQ_INIT(&user_cfg->plugin_list);
+	STAILQ_INIT(&user_cfg->trace_patterns);
 	TAILQ_INIT(&runtime_state->loaded_plugins);
 	user_cfg->memory = 0;
 	user_cfg->force_nrank = 0;
@@ -2320,28 +2322,56 @@ eal_parse_args(void)
 		EAL_LOG(WARNING, "Tracing is not supported on Windows, ignoring tracing parameters");
 #else
 	TAILQ_FOREACH(arg, &args.trace, next) {
-		if (eal_trace_args_save(arg->arg) < 0) {
-			EAL_LOG(ERR, "invalid trace parameter, '%s'", arg->arg);
+		struct eal_trace_arg *ta = malloc(sizeof(*ta));
+		if (ta == NULL) {
+			EAL_LOG(ERR, "failed to allocate trace arg for '%s'", arg->arg);
 			return -1;
 		}
+		ta->val = strdup(arg->arg);
+		if (ta->val == NULL) {
+			EAL_LOG(ERR, "failed to allocate trace arg for '%s'", arg->arg);
+			free(ta);
+			return -1;
+		}
+		STAILQ_INSERT_TAIL(&user_cfg->trace_patterns, ta, next);
 	}
 	if (args.trace_dir != NULL) {
-		if (eal_trace_dir_args_save(args.trace_dir) < 0) {
+		if (asprintf(&user_cfg->trace_dir, "%s/", args.trace_dir) == -1) {
 			EAL_LOG(ERR, "invalid trace directory, '%s'", args.trace_dir);
 			return -1;
 		}
 	}
 	if (args.trace_bufsz != NULL) {
-		if (eal_trace_bufsz_args_save(args.trace_bufsz) < 0) {
+		uint64_t bufsz = rte_str_to_size(args.trace_bufsz);
+		if (bufsz == 0) {
 			EAL_LOG(ERR, "invalid trace buffer size, '%s'", args.trace_bufsz);
 			return -1;
 		}
+		user_cfg->trace_bufsz = bufsz;
 	}
 	if (args.trace_mode != NULL) {
-		if (eal_trace_mode_args_save(args.trace_mode) < 0) {
+		size_t len = strlen(args.trace_mode);
+		char *pattern;
+		if (len == 0) {
+			EAL_LOG(ERR, "trace mode value is empty");
+			return -1;
+		}
+		pattern = calloc(1, len + 2);
+		if (pattern == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for trace mode");
+			return -1;
+		}
+		sprintf(pattern, "%s*", args.trace_mode);
+		if (fnmatch(pattern, "overwrite", 0) == 0)
+			user_cfg->trace_mode = RTE_TRACE_MODE_OVERWRITE;
+		else if (fnmatch(pattern, "discard", 0) == 0)
+			user_cfg->trace_mode = RTE_TRACE_MODE_DISCARD;
+		else {
 			EAL_LOG(ERR, "invalid trace mode, '%s'", args.trace_mode);
+			free(pattern);
 			return -1;
 		}
+		free(pattern);
 	}
 #endif
 
@@ -2460,8 +2490,19 @@ compute_ctrl_threads_cpuset(void)
 }
 
 int
-eal_cleanup_config(const struct eal_user_cfg *user_cfg)
+eal_cleanup_config(void)
 {
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_trace_arg *ta;
+
+	/* free trace patterns list */
+	while (!STAILQ_EMPTY(&user_cfg->trace_patterns)) {
+		ta = STAILQ_FIRST(&user_cfg->trace_patterns);
+		STAILQ_REMOVE_HEAD(&user_cfg->trace_patterns, next);
+		free(ta->val);
+		free(ta);
+	}
+	free(user_cfg->trace_dir);
 	free(user_cfg->hugefile_prefix);
 	free(user_cfg->hugepage_dir);
 	free(user_cfg->user_mbuf_pool_ops_name);
lib/eal/common/eal_common_trace.c +21 -9
index a76dff0017..3d984ac8b1 100644
@@ -24,7 +24,7 @@ RTE_DEFINE_PER_LCORE(void *, trace_mem);
 static RTE_DEFINE_PER_LCORE(char *, ctf_field);
 
 static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list);
-static struct trace trace = { .args = STAILQ_HEAD_INITIALIZER(trace.args), };
+static struct trace trace;
 
 struct trace *
 trace_obj_get(void)
@@ -41,7 +41,8 @@ trace_list_head_get(void)
 int
 eal_trace_init(void)
 {
-	struct trace_arg *arg;
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	const struct eal_trace_arg *arg;
 
 	/* Trace memory should start with 8B aligned for natural alignment */
 	RTE_BUILD_BUG_ON((offsetof(struct __rte_trace_header, mem) % 8) != 0);
@@ -58,14 +59,24 @@ eal_trace_init(void)
 	if (trace_has_duplicate_entry())
 		goto fail;
 
+	/* Copy trace directory from user config (trace.dir may be reallocated later) */
+	if (user_cfg->trace_dir != NULL) {
+		trace.dir = strdup(user_cfg->trace_dir);
+		if (trace.dir == NULL) {
+			rte_errno = ENOMEM;
+			goto fail;
+		}
+	}
+
+	/* Apply buffer size from user config, then fill in default if still 0 */
+	trace.buff_len = user_cfg->trace_bufsz;
+	trace_bufsz_args_apply();
+
 	/* Generate UUID ver 4 with total size of events and number of
 	 * events
 	 */
 	trace_uuid_generate();
 
-	/* Apply buffer size configuration for trace output */
-	trace_bufsz_args_apply();
-
 	/* Generate CTF TDSL metadata */
 	if (trace_metadata_create() < 0)
 		goto fail;
@@ -74,11 +85,11 @@ eal_trace_init(void)
 	if (trace_epoch_time_save() < 0)
 		goto free_meta;
 
-	/* Apply global configurations */
-	STAILQ_FOREACH(arg, &trace.args, next)
+	/* Apply trace pattern filters from user config */
+	STAILQ_FOREACH(arg, &user_cfg->trace_patterns, next)
 		trace_args_apply(arg->val);
 
-	rte_trace_mode_set(trace.mode);
+	rte_trace_mode_set(user_cfg->trace_mode);
 
 	return 0;
 
@@ -94,7 +105,8 @@ eal_trace_fini(void)
 {
 	trace_mem_free();
 	trace_metadata_destroy();
-	eal_trace_args_free();
+	free(trace.dir);
+	trace.dir = NULL;
 }
 
 RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_trace_is_enabled, 20.05)
lib/eal/common/eal_common_trace_utils.c +0 -104

128 lines not on this page · raw message

lib/eal/common/eal_internal_cfg.h +15 -0
index 55900f87bf..2415ac238f 100644
@@ -16,6 +16,7 @@
 #include <rte_eal.h>
 #include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
+#include <rte_trace.h>
 #include <stdint.h>
 #include <stdbool.h>
 
@@ -64,6 +65,16 @@ struct hugepage_file_discipline {
 	bool unlink_existing;
 };
 
+/**
+ * A saved trace pattern string from --trace, staged during arg parsing.
+ * Lives in user_cfg->trace_patterns; applied during eal_trace_init().
+ */
+struct eal_trace_arg {
+	STAILQ_ENTRY(eal_trace_arg) next;
+	char *val;
+};
+STAILQ_HEAD(eal_trace_arg_list, eal_trace_arg);
+
 /**
  * A plugin path provided by the user via -d, staged during arg parsing.
  * Lives in user_cfg->plugin_list; consumed by eal_plugins_init().
@@ -92,6 +103,10 @@ TAILQ_HEAD(eal_devopt_list, device_option);
 struct eal_user_cfg {
 	struct eal_devopt_list devopt_list; /**< staged device options (-a/-b/--vdev) */
 	struct eal_plugin_path_list plugin_list; /**< user-provided plugin paths (-d) */
+	struct eal_trace_arg_list trace_patterns; /**< saved --trace patterns */
+	char *trace_dir;        /**< trace output directory (NULL = use default) */
+	uint64_t trace_bufsz;   /**< trace buffer size in bytes (0 = use default 1 MB) */
+	enum rte_trace_mode trace_mode; /**< trace mode (default RTE_TRACE_MODE_OVERWRITE) */
 	size_t memory;           /**< amount of asked memory */
 	size_t huge_worker_stack_size; /**< worker thread stack size */
 	enum rte_proc_type_t process_type; /**< requested process type */
lib/eal/common/eal_options.h +1 -1
index eee7339e90..1ff9291170 100644
@@ -15,7 +15,7 @@ int eal_parse_args(void);
 int eal_option_device_parse(void);
 int eal_apply_hugepage_mem_sz_limits(void);
 int eal_apply_runtime_state(void);
-int eal_cleanup_config(const struct eal_user_cfg *user_cfg);
+int eal_cleanup_config(void);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
lib/eal/common/eal_trace.h +0 -11
index 55262677e0..c7ef7d12f7 100644
@@ -42,11 +42,6 @@ struct thread_mem_meta {
 	enum trace_area_e area;
 };
 
-struct trace_arg {
-	STAILQ_ENTRY(trace_arg) next;
-	char *val;
-};
-
 struct trace {
 	char *dir;
 	int register_errno;
@@ -54,7 +49,6 @@ struct trace {
 	enum rte_trace_mode mode;
 	rte_uuid_t uuid;
 	uint32_t buff_len;
-	STAILQ_HEAD(, trace_arg) args;
 	uint32_t nb_trace_points;
 	uint32_t nb_trace_mem_list;
 	struct thread_mem_meta *lcore_meta;
@@ -107,10 +101,5 @@ void trace_mem_per_thread_free(void);
 /* EAL interface */
 int eal_trace_init(void);
 void eal_trace_fini(void);
-int eal_trace_args_save(const char *val);
-void eal_trace_args_free(void);
-int eal_trace_dir_args_save(const char *val);
-int eal_trace_mode_args_save(const char *val);
-int eal_trace_bufsz_args_save(const char *val);
 
 #endif /* __EAL_TRACE_H */
lib/eal/freebsd/eal.c +1 -2
index acb650031b..9c8243fa4b 100644
@@ -767,7 +767,6 @@ rte_eal_cleanup(void)
 		return -1;
 	}
 
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	rte_service_finalize();
 	eal_bus_cleanup();
 	rte_mp_channel_cleanup();
@@ -776,7 +775,7 @@ rte_eal_cleanup(void)
 	eal_trace_fini();
 	/* after this point, any DPDK pointers will become dangling */
 	rte_eal_memory_detach();
-	eal_cleanup_config(user_cfg);
+	eal_cleanup_config();
 	eal_lcore_var_cleanup();
 	return 0;
 }
lib/eal/linux/eal.c +1 -1
index 32b7206f63..8372f838e1 100644
@@ -989,7 +989,7 @@ rte_eal_cleanup(void)
 	/* after this point, any DPDK pointers will become dangling */
 	rte_eal_memory_detach();
 	rte_eal_malloc_heap_cleanup();
-	eal_cleanup_config(user_cfg);
+	eal_cleanup_config();
 	eal_lcore_var_cleanup();
 	rte_eal_log_cleanup();
 	return 0;
lib/eal/windows/eal.c +1 -3
index 51b149828b..5e3be25ed7 100644
@@ -141,14 +141,12 @@ RTE_EXPORT_SYMBOL(rte_eal_cleanup)
 int
 rte_eal_cleanup(void)
 {
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-
 	eal_intr_thread_cancel();
 	eal_mem_virt2iova_cleanup();
 	eal_bus_cleanup();
 	/* after this point, any DPDK pointers will become dangling */
 	rte_eal_memory_detach();
-	eal_cleanup_config(user_cfg);
+	eal_cleanup_config();
 	eal_lcore_var_cleanup();
 	return 0;
 }
Signature · 1 line
2.55.0
#124 lore raw

PATCH v3 30/39 eal: record service cores in user config struct

In reply to Bruce Richardson

The user provided service coremask or service corelist needs to be recorded in the user config struct, so store it there as a cpuset.

---
 lib/eal/common/eal_common_options.c | 157 ++++++++--------------------
 lib/eal/common/eal_internal_cfg.h   |   1 +
 2 files changed, 46 insertions(+), 112 deletions(-)
lib/eal/common/eal_common_options.c +45 -112
index dd25c3274b..90497d9825 100644
@@ -545,6 +545,7 @@ eal_reset_internal_config(void)
 	user_cfg->user_mbuf_pool_ops_name = NULL;
 	CPU_ZERO(&runtime_state->ctrl_cpuset);
 	runtime_state->init_complete = 0;
+	CPU_ZERO(&user_cfg->service_cpuset);
 	user_cfg->max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH;
 	user_cfg->max_simd_bitwidth.forced = 0;
 }
@@ -852,21 +853,20 @@ static int xdigit2val(unsigned char c)
 }
 
 static int
-eal_parse_service_coremask(const char *coremask)
+eal_parse_service_coremask(const char *coremask, rte_cpuset_t *cpuset)
 {
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int i, j, idx = 0;
 	unsigned int count = 0;
 	char c;
 	int val;
-	uint32_t taken_lcore_count = 0;
 
 	EAL_LOG(WARNING, "'-s <service-coremask>' is deprecated, and will be removed in a future release.");
 	EAL_LOG(WARNING, "\tUse '-S <service-corelist>' option instead.");
 
 	if (coremask == NULL)
 		return -1;
-	/* Remove all blank characters ahead and after .
+	/* Remove all blank characters ahead and after.
 	 * Remove 0x/0X if exists.
 	 */
 	while (isblank(*coremask))
@@ -888,20 +888,9 @@ eal_parse_service_coremask(const char *coremask)
 			return -1;
 		}
 		val = xdigit2val(c);
-		for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
-				j++, idx++) {
+		for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++) {
 			if ((1 << j) & val) {
-
-				if (eal_cpu_detected(idx) == 0) {
-					EAL_LOG(ERR,
-						"lcore %u unavailable", idx);
-					return -1;
-				}
-
-				if (runtime_state->lcore_cfg[idx].role == RTE_LCORE_ROLE_RTE)
-					taken_lcore_count++;
-
-				runtime_state->lcore_cfg[idx].role = RTE_LCORE_ROLE_SERVICE;
+				CPU_SET(idx, cpuset);
 				count++;
 			}
 		}
@@ -913,16 +902,15 @@ eal_parse_service_coremask(const char *coremask)
 
 	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
 
-	if (count == 0)
-		return -1;
-
-	if (taken_lcore_count != count) {
-		EAL_LOG(WARNING,
-			"Not all service cores are in the coremask. "
-			"Please ensure -c or -l includes service cores");
-	}
+	return count > 0 ? 0 : -1;
+}
 
-	return 0;
+static int
+eal_parse_service_corelist(const char *corelist, rte_cpuset_t *cpuset)
+{
+	if (rte_argparse_parse_type(corelist, RTE_ARGPARSE_VALUE_TYPE_CORELIST, cpuset) != 0)
+		return -1;
+	return CPU_COUNT(cpuset) > 0 ? 0 : -1;
 }
 
 static int
@@ -1097,89 +1085,6 @@ rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_ra
 	return 0;
 }
 
-static int
-eal_parse_service_corelist(const char *corelist)
-{
-	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
-	int i;
-	unsigned count = 0;
-	char *end = NULL;
-	uint32_t min, max, idx;
-	uint32_t taken_lcore_count = 0;
-
-	if (corelist == NULL)
-		return -1;
-
-	/* Remove all blank characters ahead and after */
-	while (isblank(*corelist))
-		corelist++;
-	i = strlen(corelist);
-	while ((i > 0) && isblank(corelist[i - 1]))
-		i--;
-
-	/* Get list of cores */
-	min = RTE_MAX_LCORE;
-	do {
-		while (isblank(*corelist))
-			corelist++;
-		if (*corelist == '\0')
-			return -1;
-		errno = 0;
-		idx = strtoul(corelist, &end, 10);
-		if (errno || end == NULL)
-			return -1;
-		if (idx >= RTE_MAX_LCORE)
-			return -1;
-		while (isblank(*end))
-			end++;
-		if (*end == '-') {
-			min = idx;
-		} else if ((*end == ',') || (*end == '\0')) {
-			max = idx;
-			if (min == RTE_MAX_LCORE)
-				min = idx;
-			for (idx = min; idx <= max; idx++) {
-				if (runtime_state->lcore_cfg[idx].role != RTE_LCORE_ROLE_SERVICE) {
-					if (runtime_state->lcore_cfg[idx].role == RTE_LCORE_ROLE_RTE)
-						taken_lcore_count++;
-
-					runtime_state->lcore_cfg[idx].role = RTE_LCORE_ROLE_SERVICE;
-					count++;
-				}
-			}
-			min = RTE_MAX_LCORE;
-		} else
-			return -1;
-		corelist = end + 1;
-	} while (*end != '\0');
-
-	if (count == 0)
-		return -1;
-
-	if (taken_lcore_count != count) {
-		EAL_LOG(WARNING,
-			"Not all service cores were in the coremask. "
-			"Please ensure -c or -l includes service cores");
-	}
-
-	/* log the configured service cores for debugging */
-	rte_cpuset_t service_cpuset;
-	CPU_ZERO(&service_cpuset);
-	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		if (runtime_state->lcore_cfg[i].role == RTE_LCORE_ROLE_SERVICE)
-			CPU_SET(i, &service_cpuset);
-	}
-	if (CPU_COUNT(&service_cpuset) > 0) {
-		char *cpuset_str = eal_cpuset_to_str(&service_cpuset);
-		if (cpuset_str != NULL) {
-			EAL_LOG(DEBUG, "Service cores configured: %s", cpuset_str);
-			free(cpuset_str);
-		}
-	}
-
-	return 0;
-}
-
 /* Changes the lcore id of the main thread */
 static int
 eal_parse_main_lcore(const char *arg)
@@ -1196,8 +1101,8 @@ eal_parse_main_lcore(const char *arg)
 		return -1;
 	user_cfg->main_lcore = (int)main_lcore;
 
-	/* ensure main core is not used as service core */
-	if (runtime_state->lcore_cfg[user_cfg->main_lcore].role == RTE_LCORE_ROLE_SERVICE) {
+	/* check main core is not already down as a service core */
+	if (CPU_ISSET(user_cfg->main_lcore, &user_cfg->service_cpuset)) {
 		EAL_LOG(ERR, "Error: Main lcore is used as a service core");
 		return -1;
 	}
@@ -2180,13 +2085,15 @@ eal_parse_args(void)
 
 	/* service core options */
 	if (args.service_coremask != NULL) {
-		if (eal_parse_service_coremask(args.service_coremask) < 0) {
+		if (eal_parse_service_coremask(args.service_coremask,
+				&user_cfg->service_cpuset) < 0) {
 			EAL_LOG(ERR, "invalid service coremask: '%s'",
 					args.service_coremask);
 			return -1;
 		}
 	} else if (args.service_corelist != NULL) {
-		if (eal_parse_service_corelist(args.service_corelist) < 0) {
+		if (eal_parse_service_corelist(args.service_corelist,
+				&user_cfg->service_cpuset) < 0) {
 			EAL_LOG(ERR, "invalid service core list: '%s'",
 					args.service_corelist);
 			return -1;
@@ -2516,6 +2423,32 @@ eal_apply_runtime_state(void)
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
+	/* Apply service core roles: service_cpuset bits are lcore IDs */
+	if (CPU_COUNT(&user_cfg->service_cpuset) > 0) {
+		unsigned int i;
+		char *cpuset_str;
+
+		for (i = 0; i < RTE_MAX_LCORE; i++) {
+			if (!CPU_ISSET(i, &user_cfg->service_cpuset))
+				continue;
+			if (eal_cpu_detected(i) == 0) {
+				EAL_LOG(ERR, "Requested service lcore %u unavailable", i);
+				return -1;
+			}
+			if (runtime_state->lcore_cfg[i].role != ROLE_RTE) {
+				EAL_LOG(WARNING,
+					"service lcore %u is not in the enabled lcore set; please ensure -c or -l includes service cores",
+					i);
+			}
+			runtime_state->lcore_cfg[i].role = ROLE_SERVICE;
+		}
+		cpuset_str = eal_cpuset_to_str(&user_cfg->service_cpuset);
+		if (cpuset_str != NULL) {
+			EAL_LOG(DEBUG, "Service cores configured: %s", cpuset_str);
+			free(cpuset_str);
+		}
+	}
+
 	/* set the main lcore */
 	if (user_cfg->main_lcore != -1) {
 		runtime_state->main_lcore = user_cfg->main_lcore;
lib/eal/common/eal_internal_cfg.h +1 -0
index 2415ac238f..998985018f 100644
@@ -143,6 +143,7 @@ struct eal_user_cfg {
 		uint64_t limit;    /**< memory limit in bytes */
 	} pagesz_mem_overrides[MAX_HUGEPAGE_SIZES];
 	unsigned int num_pagesz_mem_overrides;  /**< number of stored overrides */
+	rte_cpuset_t service_cpuset; /**<  each bit set is one lcore ID to use as service core */
 	int main_lcore;          /**< ID of the main lcore */
 };
 
Signature · 1 line
2.55.0
#125 lore raw

PATCH v3 31/39 eal: store user-provided lcore info in user config struct

In reply to Bruce Richardson

The user provides details of what lcores are to run on what cpus in a variety of ways. Map all those to a single array of cpusets in the user_cfg struct, such that each lcore id has a cpuset of physical lcore ids if it is to be used. Then post-parse of args, we can use that to appropriately populate the runtime configuration.

---
 lib/eal/common/eal_common_options.c | 151 ++++++++++++++++++----------
 lib/eal/common/eal_internal_cfg.h   |   9 +-
 lib/eal/freebsd/eal.c               |   1 +
 lib/eal/linux/eal.c                 |   1 +
 lib/eal/windows/eal.c               |   1 +
 5 files changed, 109 insertions(+), 54 deletions(-)
lib/eal/common/eal_common_options.c +98 -53
index 90497d9825..50ae345299 100644
@@ -546,6 +546,10 @@ eal_reset_internal_config(void)
 	CPU_ZERO(&runtime_state->ctrl_cpuset);
 	runtime_state->init_complete = 0;
 	CPU_ZERO(&user_cfg->service_cpuset);
+	for (i = 0; i < RTE_MAX_LCORE; i++) {
+		free(user_cfg->lcore_cpusets[i]);
+		user_cfg->lcore_cpusets[i] = NULL;
+	}
 	user_cfg->max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH;
 	user_cfg->max_simd_bitwidth.forced = 0;
 }
@@ -913,23 +917,20 @@ eal_parse_service_corelist(const char *corelist, rte_cpuset_t *cpuset)
 	return CPU_COUNT(cpuset) > 0 ? 0 : -1;
 }
 
+/* Expand a flat cpuset into lcore_cpusets[], assigning lcore IDs.
+ * If remap is false:  lcore_id == physical CPU id (identity mapping).
+ * If remap is true:   lcore IDs are assigned sequentially from remap_base.
+ * Returns the number of lcores configured, or -1 on error.
+ */
 static int
-update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
+eal_expand_cpuset_to_map(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base,
+		rte_cpuset_t **lcore_cpusets)
 {
-	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int lcore_id = remap_base;
 	unsigned int count = 0;
 	unsigned int i;
 	int ret = 0;
 
-	/* set everything to disabled first, then set up values */
-	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
-	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		runtime_state->lcore_cfg[i].role = RTE_LCORE_ROLE_OFF;
-		runtime_state->lcore_cfg[i].core_index = -1;
-	}
-
-	/* now go through the cpuset */
 	for (i = 0; i < CPU_SETSIZE; i++) {
 		if (CPU_ISSET(i, cpuset)) {
 			if (eal_cpu_detected(i) == 0) {
@@ -953,12 +954,17 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 				continue;
 			}
 
-			rte_bitset_set(runtime_state->core_indices, count);
-			runtime_state->lcore_cfg[lcore_id].role = RTE_LCORE_ROLE_RTE;
-			runtime_state->lcore_cfg[lcore_id].core_index = count;
-			CPU_ZERO(&runtime_state->lcore_cfg[lcore_id].cpuset);
-			CPU_SET(i, &runtime_state->lcore_cfg[lcore_id].cpuset);
-			runtime_state->lcore_cfg[lcore_id].first_cpu = i;
+			lcore_cpusets[lcore_id] = malloc(sizeof(rte_cpuset_t));
+			if (lcore_cpusets[lcore_id] == NULL) {
+				EAL_LOG(ERR, "failed to allocate cpuset for lcore %u", lcore_id);
+				for (unsigned int j = 0; j < lcore_id; j++) {
+					free(lcore_cpusets[j]);
+					lcore_cpusets[j] = NULL;
+				}
+				return -1;
+			}
+			CPU_ZERO(lcore_cpusets[lcore_id]);
+			CPU_SET(i, lcore_cpusets[lcore_id]);
 			EAL_LOG(DEBUG, "lcore %u mapped to physical core %u", lcore_id, i);
 			lcore_id++;
 			count++;
@@ -968,9 +974,9 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 		EAL_LOG(ERR, "No valid lcores in core list");
 		ret = -1;
 	}
-	if (!ret)
-		runtime_state->lcore_count = count;
-	return ret;
+	if (ret == -1)
+		return -1;
+	return (int)count;
 }
 
 static int
@@ -1092,7 +1098,6 @@ eal_parse_main_lcore(const char *arg)
 	char *parsing_end;
 	long main_lcore;
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	errno = 0;
 	main_lcore = strtol(arg, &parsing_end, 0);
@@ -1106,8 +1111,9 @@ eal_parse_main_lcore(const char *arg)
 		EAL_LOG(ERR, "Error: Main lcore is used as a service core");
 		return -1;
 	}
-	/* check that we have the core recorded in the core list */
-	if (runtime_state->lcore_cfg[user_cfg->main_lcore].role != RTE_LCORE_ROLE_RTE) {
+
+	/* lcore_cpusets is always populated before eal_parse_main_lcore is called */
+	if (user_cfg->lcore_cpusets[user_cfg->main_lcore] == NULL) {
 		EAL_LOG(ERR, "Error: Main lcore is not enabled for DPDK");
 		return -1;
 	}
@@ -1269,15 +1275,18 @@ check_cpuset(rte_cpuset_t *set)
  *   lcore 6 runs on cpuset 0x41 (cpu 0,6)
  *   lcore 7 runs on cpuset 0x80 (cpu 7)
  *   lcore 8 runs on cpuset 0x100 (cpu 8)
+ *
+ * Writes the physical-CPU affinity for each mentioned lcore_id into
+ * cpusets[lcore_id].  Slots not mentioned are left as NULL.
+ * Returns the number of distinct lcore IDs configured, or -1 on error.
  */
 static int
-eal_parse_lcores(const char *lcores)
+eal_parse_lcores_to_map(const char *lcores, rte_cpuset_t **cpusets)
 {
-	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	rte_cpuset_t lcore_set;
 	unsigned int set_count;
-	unsigned idx = 0;
-	unsigned count = 0;
+	unsigned int idx;
+	int count = 0;
 	const char *lcore_start = NULL;
 	const char *end = NULL;
 	int offset;
@@ -1294,15 +1303,6 @@ eal_parse_lcores(const char *lcores)
 
 	CPU_ZERO(&cpuset);
 
-	/* Reset lcore config */
-	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
-	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-		runtime_state->lcore_cfg[idx].role = RTE_LCORE_ROLE_OFF;
-		runtime_state->lcore_cfg[idx].core_index = -1;
-		CPU_ZERO(&runtime_state->lcore_cfg[idx].cpuset);
-		runtime_state->lcore_cfg[idx].first_cpu = UINT16_MAX;
-	}
-
 	/* Get list of cores */
 	do {
 		while (isblank(*lcores))
@@ -1351,7 +1351,7 @@ eal_parse_lcores(const char *lcores)
 
 		/* without '@', by default using lcore_set as cpuset */
 		if (*lcores != '@')
-			rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
+			memcpy(&cpuset, &lcore_set, sizeof(cpuset));
 
 		set_count = CPU_COUNT(&lcore_set);
 		/* start to update lcore_set */
@@ -1360,13 +1360,6 @@ eal_parse_lcores(const char *lcores)
 				continue;
 			set_count--;
 
-			if (runtime_state->lcore_cfg[idx].role != RTE_LCORE_ROLE_RTE) {
-				rte_bitset_set(runtime_state->core_indices, count);
-				runtime_state->lcore_cfg[idx].core_index = count;
-				runtime_state->lcore_cfg[idx].role = RTE_LCORE_ROLE_RTE;
-				count++;
-			}
-
 			if (lflags) {
 				CPU_ZERO(&cpuset);
 				CPU_SET(idx, &cpuset);
@@ -1374,10 +1367,16 @@ eal_parse_lcores(const char *lcores)
 
 			if (check_cpuset(&cpuset) < 0)
 				goto err;
-			rte_memcpy(&runtime_state->lcore_cfg[idx].cpuset, &cpuset,
-				   sizeof(rte_cpuset_t));
-			runtime_state->lcore_cfg[idx].first_cpu =
-					(uint16_t)(RTE_CPU_FFS(&cpuset) - 1);
+			if (cpusets[idx] == NULL) {
+				cpusets[idx] = malloc(sizeof(rte_cpuset_t));
+				if (cpusets[idx] == NULL) {
+					EAL_LOG(ERR, "failed to allocate cpuset for lcore %u", idx);
+					ret = -1;
+					goto err;
+				}
+				count++;
+			}
+			memcpy(cpusets[idx], &cpuset, sizeof(rte_cpuset_t));
 		}
 
 		/* some cores from the lcore_set can't be handled by EAL */
@@ -1390,11 +1389,14 @@ eal_parse_lcores(const char *lcores)
 	if (count == 0)
 		goto err;
 
-	runtime_state->lcore_count = count;
-	ret = 0;
-
+	ret = count;
 err:
-
+	if (ret == -1) {
+		for (unsigned int j = 0; j < RTE_MAX_LCORE; j++) {
+			free(cpusets[j]);
+			cpusets[j] = NULL;
+		}
+	}
 	return ret;
 }
 
@@ -2035,7 +2037,7 @@ eal_parse_args(void)
 
 	/* First handle the special case where we have explicit core mapping/remapping */
 	if (manual_lcore_mapping) {
-		if (eal_parse_lcores(args.lcores) < 0) {
+		if (eal_parse_lcores_to_map(args.lcores, user_cfg->lcore_cpusets) < 0) {
 			EAL_LOG(ERR, "invalid lcore mapping list: '%s'", args.lcores);
 			return -1;
 		}
@@ -2073,7 +2075,8 @@ eal_parse_args(void)
 			EAL_LOG(DEBUG, "Cores selected by %s: %s", cpuset_source, cpuset_str);
 			free(cpuset_str);
 		}
-		if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
+		if (eal_expand_cpuset_to_map(&cpuset, remap_lcores, lcore_id_base,
+				user_cfg->lcore_cpusets) < 0) {
 			char *available = available_cores();
 
 			EAL_LOG(ERR, "invalid coremask or core-list parameter, please check specified cores are part of %s",
@@ -2413,7 +2416,46 @@ eal_cleanup_config(void)
 	free(user_cfg->hugefile_prefix);
 	free(user_cfg->hugepage_dir);
 	free(user_cfg->user_mbuf_pool_ops_name);
+	for (unsigned int i = 0; i < RTE_MAX_LCORE; i++) {
+		free(user_cfg->lcore_cpusets[i]);
+		user_cfg->lcore_cpusets[i] = NULL;
+	}
+
+	return 0;
+}
+
+static int
+eal_apply_lcore_config(void)
+{
+	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+
+	/* lcore_cpusets[] is always populated at parse time for all input forms */
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	unsigned int i;
+	unsigned int count = 0;
 
+	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
+	for (i = 0; i < RTE_MAX_LCORE; i++) {
+		if (user_cfg->lcore_cpusets[i] == NULL) {
+			runtime_state->lcore_cfg[i].role = ROLE_OFF;
+			runtime_state->lcore_cfg[i].core_index = -1;
+			CPU_ZERO(&runtime_state->lcore_cfg[i].cpuset);
+			runtime_state->lcore_cfg[i].first_cpu = UINT16_MAX;
+			continue;
+		}
+		rte_bitset_set(runtime_state->core_indices, count);
+		runtime_state->lcore_cfg[i].role = ROLE_RTE;
+		runtime_state->lcore_cfg[i].core_index = count++;
+		memcpy(&runtime_state->lcore_cfg[i].cpuset,
+			user_cfg->lcore_cpusets[i], sizeof(rte_cpuset_t));
+		runtime_state->lcore_cfg[i].first_cpu =
+			(uint16_t)(RTE_CPU_FFS(&runtime_state->lcore_cfg[i].cpuset) - 1);
+	}
+	if (count == 0) {
+		EAL_LOG(ERR, "No valid lcores in core list");
+		return -1;
+	}
+	runtime_state->lcore_count = count;
 	return 0;
 }
 
@@ -2423,6 +2465,9 @@ eal_apply_runtime_state(void)
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
+	if (eal_apply_lcore_config() < 0)
+		return -1;
+
 	/* Apply service core roles: service_cpuset bits are lcore IDs */
 	if (CPU_COUNT(&user_cfg->service_cpuset) > 0) {
 		unsigned int i;
lib/eal/common/eal_internal_cfg.h +8 -1
index 998985018f..130ff0f3b3 100644
@@ -144,7 +144,14 @@ struct eal_user_cfg {
 	} pagesz_mem_overrides[MAX_HUGEPAGE_SIZES];
 	unsigned int num_pagesz_mem_overrides;  /**< number of stored overrides */
 	rte_cpuset_t service_cpuset; /**<  each bit set is one lcore ID to use as service core */
-	int main_lcore;          /**< ID of the main lcore */
+
+	/** Per-lcore cpuset array, always populated at arg-parse time for all input forms
+	 * (-c coremask, -l corelist, --lcores with or without '@'/'()').
+	 * Each non-NULL slot is an individually heap-allocated rte_cpuset_t.
+	 * NULL means the corresponding lcore ID is not configured.
+	 */
+	rte_cpuset_t *lcore_cpusets[RTE_MAX_LCORE];
+	int            main_lcore;    /**< ID of the main lcore */
 };
 
 /**
lib/eal/freebsd/eal.c +1 -0
index 9c8243fa4b..78d1aebddc 100644
@@ -749,6 +749,7 @@ rte_eal_init(int argc, char **argv)
 	return fctret;
 err_out:
 	rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed);
+	eal_cleanup_config();
 	eal_clean_saved_args();
 	return -1;
 }
lib/eal/linux/eal.c +1 -0
index 8372f838e1..3d1060962b 100644
@@ -934,6 +934,7 @@ rte_eal_init(int argc, char **argv)
 
 err_out:
 	rte_atomic_store_explicit(&run_once, 0, rte_memory_order_relaxed);
+	eal_cleanup_config();
 	eal_clean_saved_args();
 	return -1;
 }
lib/eal/windows/eal.c +1 -0
index 5e3be25ed7..d8ebcd866b 100644
@@ -419,6 +419,7 @@ rte_eal_init(int argc, char **argv)
 
 	return fctret;
 err_out:
+	eal_cleanup_config();
 	eal_clean_saved_args();
 	return -1;
 }
Signature · 1 line
2.55.0
#126 lore raw

PATCH v3 32/39 eal: clarify docs on params taking lcore IDs

In reply to Bruce Richardson

The documentation doesn't make clear how the parameters to service core and main lcore EAL flags relate to the regular --lcores parameter when mapping lcores to physical CPU ids.

For example, when looking to add service cores to process run using the command "/path/to/app -R -l 40-50", it's not clear whether the service cores list parameter should be "-S 49-50" i.e. physical CPU ids, or "-S 9-10" i.e. logical lcore IDs. Update the docs to make it clear its the latter.

---
 doc/guides/linux_gsg/eal_args.include.rst | 38 +++++++++++++++++++++--
 lib/eal/common/eal_option_list.h          |  6 ++--
 2 files changed, 38 insertions(+), 6 deletions(-)
doc/guides/linux_gsg/eal_args.include.rst +35 -3
index 32c24c8e41..33281ecec3 100644
@@ -89,13 +89,45 @@ Lcore-related options
     and the use of ``()`` for core groupings,
     are not allowed when ``-R`` or ``--remap-lcore-ids`` is also used.
 
-*   ``--main-lcore <core ID>``
+*   ``--main-lcore <lcore ID>``
 
-    Core ID that is used as main.
+    Set the lcore ID to use for the main thread.
+    The value is a DPDK lcore ID, not a physical CPU ID,
+    and must be present in the enabled lcore set (as configured by ``-l``/``--lcores``).
+
+    In the simple case, without any explicit lcore-to-CPU mapping,
+    lcore IDs equal physical CPU IDs so the distinction does not matter.
+    The two differ when ``-R``/``--remap-lcore-ids`` assigns sequential lcore IDs to higher-numbered physical CPUs,
+    or when the ``@`` mapping syntax in ``--lcores`` is used.
+    In those cases the lcore ID must be specified here, not the physical CPU ID.
+
+    Example using ``--lcores`` explicit mapping:
+    ``--lcores=1@31,2@32,3@33 --main-lcore 2`` selects the thread with lcore ID 2,
+    running on physical CPU 32, as the main thread.
+
+    Example using ``-R`` remapping:
+    ``-l 31-33 -R --main-lcore 1`` starts three threads on physical CPUs 31, 32 and 33, remapped to lcore IDs 0, 1 and 2.
+    ``--main-lcore 1`` selects the thread remapped to lcore ID 1, which runs on physical CPU 32.
 
 *   ``-S, --service-corelist <service core list>``
 
-    List of cores to be used as service cores.
+    List of lcore IDs to be used as service cores.
+    The list format is the same as for ``-l``/``--lcores``:
+    a comma-separated set of lcore IDs or ranges (e.g. ``2,3`` or ``2-5``).
+    Each specified lcore ID must be present in the enabled lcore set.
+
+    The values are lcore IDs, not physical CPU IDs.
+    In the simple case, without any explicit lcore-to-CPU mapping, the two are equal so the distinction does not matter.
+    When using ``-R``/``--remap-lcore-ids`` or the ``@`` mapping syntax in ``--lcores``, lcore IDs and physical CPU IDs differ,
+    and the lcore IDs must be used here.
+
+    Example using ``--lcores`` explicit mapping:
+    ``--lcores=1@31,2@32,3@33 -S 2,3`` assigns the threads with
+    lcore IDs 2 and 3 (running on physical CPUs 32 and 33) as service cores.
+
+    Example using ``-R`` remapping:
+    ``-l 31-33 -R -S 1,2`` starts three threads on physical CPUs 31, 32 and 33, remapped to lcore IDs 0, 1 and 2.
+    ``-S 1,2`` assigns the threads with lcore IDs 1 and 2 (running on physical CPUs 32 and 33) as service cores.
 
 
 Device-related options
lib/eal/common/eal_option_list.h +3 -3
index b72f243cc6..2b94e4f22f 100644
@@ -47,7 +47,7 @@ BOOL_ARG("--legacy-mem", NULL, "Enable legacy memory behavior", legacy_mem)
 OPT_STR_ARG("--log-color", NULL, "Enable/disable color in log output", log_color)
 LIST_ARG("--log-level", NULL, "Log level for loggers; use log-level=help for list of log types and levels", log_level)
 OPT_STR_ARG("--log-timestamp", NULL, "Enable/disable timestamp in log output", log_timestamp)
-STR_ARG("--main-lcore", NULL, "Select which core to use for the main thread", main_lcore)
+STR_ARG("--main-lcore", NULL, "Lcore ID to use for the main thread", main_lcore)
 STR_ARG("--mbuf-pool-ops-name", NULL, "User defined mbuf default pool ops name", mbuf_pool_ops_name)
 STR_ARG("--memory-channels", "-n", "Number of memory channels per socket", memory_channels)
 STR_ARG("--memory-ranks", "-r", "Force number of memory ranks (don't detect)", memory_ranks)
@@ -61,8 +61,8 @@ BOOL_ARG("--no-telemetry", NULL, "Disable telemetry", no_telemetry)
 LIST_ARG("--pagesz-mem", NULL, "Memory allocation per hugepage size (format: <pagesz>:<limit>, e.g. 2M:32G). Repeat option for multiple page sizes.", pagesz_mem)
 STR_ARG("--proc-type", NULL, "Type of process (primary|secondary|auto)", proc_type)
 OPT_STR_ARG("--remap-lcore-ids", "-R", "Remap lcore IDs to be contiguous starting from 0, or supplied value", remap_lcore_ids)
-STR_ARG("--service-corelist", "-S", "List of cores to use for service threads", service_corelist)
-STR_ARG("--service-coremask", "-s", "[Deprecated] Bitmask of cores to use for service threads", service_coremask)
+STR_ARG("--service-corelist", "-S", "List of lcore IDs to use for service threads", service_corelist)
+STR_ARG("--service-coremask", "-s", "[Deprecated] Bitmask of lcore IDs to use for service threads", service_coremask)
 BOOL_ARG("--single-file-segments", NULL, "Store all pages within single files (per-page-size, per-node)", single_file_segments)
 BOOL_ARG("--telemetry", NULL, "Enable telemetry", telemetry)
 LIST_ARG("--vdev", NULL, "Add a virtual device to the system; format=<driver><id>[,key=val,...]", vdev)
Signature · 1 line
2.55.0
#127 lore raw

PATCH v3 33/39 eal: remove internal config reset function

In reply to Bruce Richardson

Rather than having a single function which attempts to reset multiple internal config structures, just init each structure in the function which configures it. Use structure assignment for initialization rather than a series of assignment statements.

---
 lib/eal/common/eal_common_config.c  |  8 ++-
 lib/eal/common/eal_common_options.c | 92 ++++++-----------------------
 lib/eal/common/eal_internal_cfg.h   |  1 -
 lib/eal/freebsd/eal.c               |  2 -
 lib/eal/linux/eal.c                 |  2 -
 5 files changed, 26 insertions(+), 79 deletions(-)
lib/eal/common/eal_common_config.c +7 -1
index 35654cc71f..6f131f3a3c 100644
@@ -27,7 +27,13 @@ static char runtime_dir[UNIX_PATH_MAX];
 static struct eal_user_cfg eal_user_cfg;
 
 /* platform-discovered and runtime EAL state */
-static struct eal_platform_info eal_platform_info;
+static struct eal_platform_info eal_platform_info = {
+	.hugepage_info = {
+		[0] = {.lock_descriptor = -1 },
+		[1] = {.lock_descriptor = -1 },
+		[2] = {.lock_descriptor = -1 }
+	}
+};
 
 /* internal runtime configuration */
 static struct eal_runtime_state eal_runtime_state = {
lib/eal/common/eal_common_options.c +19 -73

116 lines not on this page · raw message

lib/eal/common/eal_internal_cfg.h +0 -1
index 130ff0f3b3..d101a60413 100644
@@ -229,6 +229,5 @@ struct eal_runtime_state {
 struct eal_user_cfg *eal_get_user_configuration(void);
 struct eal_platform_info *eal_get_platform_info(void);
 struct eal_runtime_state *eal_get_runtime_state(void);
-void eal_reset_internal_config(void);
 
 #endif /* EAL_INTERNAL_CFG_H */
lib/eal/freebsd/eal.c +0 -2
index 78d1aebddc..cb82fc7619 100644
@@ -443,8 +443,6 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	eal_reset_internal_config();
-
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
 		rte_errno = ENOTSUP;
lib/eal/linux/eal.c +0 -2
index 3d1060962b..708c89122f 100644
@@ -603,8 +603,6 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	eal_reset_internal_config();
-
 	if (rte_eal_cpu_init() < 0) {
 		rte_eal_init_alert("Cannot detect lcores.");
 		rte_errno = ENOTSUP;
Signature · 1 line
2.55.0
#128 lore raw

PATCH v3 34/39 eal: move functions setting runtime state

In reply to Bruce Richardson

The functions to configure some of the runtime state based on the user-provided options no longer belong in eal_common_options.c, which should instead be more focused on processing the user-provided options. Move the functions to eal_common_config instead, and explicitly have the runtime state setup function called from eal_init directly, rather than hidden as a last step in arg parsing.

---
 lib/eal/common/eal_common_config.c  | 170 +++++++++++++++++++++++++++-
 lib/eal/common/eal_common_options.c | 167 +--------------------------
 lib/eal/common/eal_options.h        |   3 -
 lib/eal/common/eal_private.h        |  33 ++++++
 lib/eal/freebsd/eal.c               |   6 +
 lib/eal/linux/eal.c                 |   6 +
 lib/eal/windows/eal.c               |   6 +
 7 files changed, 221 insertions(+), 170 deletions(-)
lib/eal/common/eal_common_config.c +169 -1
index 6f131f3a3c..2eb7646e90 100644
@@ -2,8 +2,10 @@
  * Copyright(c) 2020 Mellanox Technologies, Ltd
  */
 
-#include <rte_string_fns.h>
+#include <pthread.h>
 
+#include <rte_string_fns.h>
+#include <rte_thread.h>
 #include <eal_export.h>
 #include "eal_internal_cfg.h"
 #include "eal_private.h"
@@ -133,3 +135,169 @@ rte_eal_has_pci(void)
 {
 	return !eal_user_cfg.no_pci;
 }
+
+static void
+compute_ctrl_threads_cpuset(void)
+{
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	rte_cpuset_t *cpuset = &runtime_state->ctrl_cpuset;
+	rte_cpuset_t default_set;
+	unsigned int lcore_id;
+
+	CPU_ZERO(cpuset);
+	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
+		if (rte_lcore_has_role(lcore_id, ROLE_OFF))
+			continue;
+		RTE_CPU_OR(cpuset, cpuset, &runtime_state->lcore_cfg[lcore_id].cpuset);
+	}
+	RTE_CPU_NOT(cpuset, cpuset);
+
+	if (rte_thread_get_affinity_by_id(rte_thread_self(), &default_set) != 0)
+		CPU_ZERO(&default_set);
+
+	RTE_CPU_AND(cpuset, cpuset, &default_set);
+
+	/* if no remaining cpu, use main lcore cpu affinity */
+	if (!CPU_COUNT(cpuset)) {
+		memcpy(cpuset, &runtime_state->lcore_cfg[rte_get_main_lcore()].cpuset,
+			sizeof(*cpuset));
+	}
+
+	/* log the computed control thread cpuset for debugging */
+	char *cpuset_str = eal_cpuset_to_str(cpuset);
+	if (cpuset_str != NULL) {
+		EAL_LOG(DEBUG, "Control threads will use cores: %s", cpuset_str);
+		free(cpuset_str);
+	}
+}
+
+static int
+eal_apply_lcore_config(void)
+{
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+
+	/* lcore_cpusets[] is always populated at parse time for all input forms */
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	unsigned int i;
+	unsigned int count = 0;
+
+	rte_bitset_clear_all(runtime_state->core_indices, RTE_MAX_LCORE);
+	for (i = 0; i < RTE_MAX_LCORE; i++) {
+		if (user_cfg->lcore_cpusets[i] == NULL) {
+			runtime_state->lcore_cfg[i].role = ROLE_OFF;
+			runtime_state->lcore_cfg[i].core_index = -1;
+			CPU_ZERO(&runtime_state->lcore_cfg[i].cpuset);
+			runtime_state->lcore_cfg[i].first_cpu = UINT16_MAX;
+			continue;
+		}
+		rte_bitset_set(runtime_state->core_indices, count);
+		runtime_state->lcore_cfg[i].role = ROLE_RTE;
+		runtime_state->lcore_cfg[i].core_index = count++;
+		memcpy(&runtime_state->lcore_cfg[i].cpuset,
+			user_cfg->lcore_cpusets[i], sizeof(rte_cpuset_t));
+		runtime_state->lcore_cfg[i].first_cpu =
+			(uint16_t)(RTE_CPU_FFS(&runtime_state->lcore_cfg[i].cpuset) - 1);
+	}
+	if (count == 0) {
+		EAL_LOG(ERR, "No valid lcores in core list");
+		return -1;
+	}
+	runtime_state->lcore_count = count;
+	return 0;
+}
+
+int
+eal_apply_runtime_state(void)
+{
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+
+	if (eal_apply_lcore_config() < 0)
+		return -1;
+
+	/* Apply service core roles: service_cpuset bits are lcore IDs */
+	if (CPU_COUNT(&user_cfg->service_cpuset) > 0) {
+		unsigned int i;
+		char *cpuset_str;
+
+		for (i = 0; i < RTE_MAX_LCORE; i++) {
+			if (!CPU_ISSET(i, &user_cfg->service_cpuset))
+				continue;
+			if (eal_cpu_detected(i) == 0) {
+				EAL_LOG(ERR, "Requested service lcore %u unavailable", i);
+				return -1;
+			}
+			if (runtime_state->lcore_cfg[i].role != ROLE_RTE) {
+				EAL_LOG(WARNING,
+					"service lcore %u is not in the enabled lcore set; please ensure -c or -l includes service cores",
+					i);
+			}
+			runtime_state->lcore_cfg[i].role = ROLE_SERVICE;
+		}
+		cpuset_str = eal_cpuset_to_str(&user_cfg->service_cpuset);
+		if (cpuset_str != NULL) {
+			EAL_LOG(DEBUG, "Service cores configured: %s", cpuset_str);
+			free(cpuset_str);
+		}
+	}
+
+	/* set the main lcore */
+	if (user_cfg->main_lcore != -1) {
+		runtime_state->main_lcore = user_cfg->main_lcore;
+	} else {
+		/* default main lcore is the first one */
+		runtime_state->main_lcore = rte_get_next_lcore(-1, 0, 0);
+		if (runtime_state->main_lcore >= RTE_MAX_LCORE) {
+			EAL_LOG(ERR, "Main lcore is not enabled for DPDK");
+			return -1;
+		}
+	}
+
+#ifndef RTE_EXEC_ENV_WINDOWS
+	/* create runtime data directory. In no_shconf mode, skip any errors */
+	if (eal_create_runtime_dir() < 0) {
+		if (!user_cfg->no_shconf) {
+			EAL_LOG(ERR, "Cannot create runtime directory");
+			return -1;
+		}
+		EAL_LOG(WARNING, "No DPDK runtime directory created");
+	}
+#endif
+
+	runtime_state->process_type = (user_cfg->process_type == RTE_PROC_AUTO) ?
+			eal_proc_type_detect() :
+			user_cfg->process_type;
+
+	compute_ctrl_threads_cpuset();
+
+	return 0;
+}
+
+int
+eal_apply_hugepage_mem_sz_limits(void)
+{
+	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
+	unsigned int i;
+
+	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
+		unsigned int j;
+		const uint64_t pagesz = platform_info->hugepage_info[i].hugepage_sz;
+		uint64_t limit;
+
+		/* assign default limits */
+		limit = RTE_MIN((uint64_t)RTE_MAX_MEM_MB_PER_TYPE << 20,
+				(uint64_t)RTE_MAX_MEMSEG_PER_TYPE * pagesz);
+
+		/* override with user value for matching page size */
+		for (j = 0; j < user_cfg->num_pagesz_mem_overrides; j++) {
+			if (user_cfg->pagesz_mem_overrides[j].pagesz == pagesz)
+				limit = user_cfg->pagesz_mem_overrides[j].limit;
+		}
+
+		runtime_state->hugepage_mem_sz_limits[i] = limit;
+	}
+
+	return 0;
+}
lib/eal/common/eal_common_options.c +1 -166

179 lines not on this page · raw message

lib/eal/common/eal_options.h +0 -3
index 1ff9291170..77a6a4405f 100644
@@ -13,10 +13,7 @@ struct eal_user_cfg;
 int eal_parse_log_options(void);
 int eal_parse_args(void);
 int eal_option_device_parse(void);
-int eal_apply_hugepage_mem_sz_limits(void);
-int eal_apply_runtime_state(void);
 int eal_cleanup_config(void);
-enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
 void eal_clean_saved_args(void);
lib/eal/common/eal_private.h +33 -0
index 798e60a359..edda0289fa 100644
@@ -28,6 +28,39 @@
  */
 int eal_collate_args(int argc, char **argv);
 
+/**
+ * Apply user configuration to runtime state.
+ *
+ * Translates the populated eal_user_cfg into the eal_runtime_state,
+ * including lcore roles, main lcore, service cores, process type
+ * detection, and the runtime directory.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
+int eal_apply_runtime_state(void);
+
+/**
+ * Detect the process type.
+ *
+ * Used to detect process type when the user requests process type auto-detection,
+ * rather than manually specifying primary or secondary.
+ * @return
+ *   The detected process type.
+ */
+enum rte_proc_type_t eal_proc_type_detect(void);
+
+/**
+ * Apply user-provided hugepage memory size overrides to the runtime state.
+ *
+ * Computes the per-hugepage-size memory limits, applying any user-supplied
+ * overrides on top of the default limits.
+ *
+ * @return
+ *   0 on success, negative on error
+ */
+int eal_apply_hugepage_mem_sz_limits(void);
+
 /**
  * Convert an rte_cpuset_t to string form suitable for parsing by argparse.
  *
lib/eal/freebsd/eal.c +6 -0
index cb82fc7619..47efe2f4b4 100644
@@ -462,6 +462,12 @@ rte_eal_init(int argc, char **argv)
 		user_cfg->in_memory = false;
 	}
 
+	if (eal_apply_runtime_state() < 0) {
+		rte_eal_init_alert("Cannot apply runtime state.");
+		rte_errno = EINVAL;
+		goto err_out;
+	}
+
 	if (eal_plugins_init() < 0) {
 		rte_eal_init_alert("Cannot init plugins");
 		rte_errno = EINVAL;
lib/eal/linux/eal.c +6 -0
index 708c89122f..03e26584d6 100644
@@ -615,6 +615,12 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
+	if (eal_apply_runtime_state() < 0) {
+		rte_eal_init_alert("Cannot apply runtime state.");
+		rte_errno = EINVAL;
+		goto err_out;
+	}
+
 	if (eal_plugins_init() < 0) {
 		rte_eal_init_alert("Cannot init plugins");
 		rte_errno = EINVAL;
lib/eal/windows/eal.c +6 -0
index d8ebcd866b..37e43c9a62 100644
@@ -222,6 +222,12 @@ rte_eal_init(int argc, char **argv)
 		user_cfg->no_shconf = true;
 	}
 
+	if (eal_apply_runtime_state() < 0) {
+		rte_eal_init_alert("Cannot apply runtime state.");
+		rte_errno = EINVAL;
+		goto err_out;
+	}
+
 	if (!user_cfg->no_hugetlbfs && (eal_hugepage_info_init() < 0)) {
 		rte_eal_init_alert("Cannot get hugepage information");
 		rte_errno = EACCES;
Signature · 1 line
2.55.0
#129 lore raw

PATCH v3 35/39 eal: initialize platform info on first use

In reply to Bruce Richardson

The platform information should be made available as early in the init process as possible, since it should be fixed and not depend on any application or user provided data. Therefore, rework the hugepage info so that the basic HP info only is stored in the platform info struct, and things like lock fd's are found in the runtime state struct.

Then start enhancing the get_platform_info structure so that it is initialized on first use, rather than having it initialized as part of the normal flow of rte_eal_init(). The objective is to have the platform info, both cpu and memory, fully available when processing the user configuration parameters, in order to properly validate them. Note that this may defer some error conditions to later, because hugepage scanning failures, for example, need not be an error when scanning the platform info, if we later discover the app is being run with --no-huge flag.

---
 lib/eal/common/eal_common_config.c  |  50 +++++++++---
 lib/eal/common/eal_common_dynmem.c  |  27 ++++---
 lib/eal/common/eal_common_lcore.c   |  13 +++-
 lib/eal/common/eal_hugepages.h      |   8 ++
 lib/eal/common/eal_internal_cfg.h   |  15 +++-
 lib/eal/common/eal_private.h        |  18 ++++-
 lib/eal/freebsd/eal.c               |  23 ++++--
 lib/eal/freebsd/eal_hugepage_info.c |  60 ++++++++++----
 lib/eal/freebsd/eal_memory.c        |  15 ++--
 lib/eal/linux/eal.c                 |  28 ++++---
 lib/eal/linux/eal_hugepage_info.c   | 117 ++++++++++++++++++++++++----
 lib/eal/linux/eal_memalloc.c        |  24 +++---
 lib/eal/linux/eal_memory.c          |  59 +++++++-------
 lib/eal/windows/eal.c               |  24 +++---
 lib/eal/windows/eal_hugepages.c     |  35 ++++++++-
 lib/eal/windows/eal_memalloc.c      |  11 +--
 lib/eal/windows/eal_windows.h       |   8 --
 17 files changed, 377 insertions(+), 158 deletions(-)
lib/eal/common/eal_common_config.c +39 -11
index 2eb7646e90..110921ae93 100644
@@ -10,6 +10,7 @@
 #include "eal_internal_cfg.h"
 #include "eal_private.h"
 #include "eal_filesystem.h"
+#include "eal_hugepages.h"
 #include "eal_memcfg.h"
 
 /* early configuration structure, when memory config is not mmapped */
@@ -28,15 +29,6 @@ static char runtime_dir[UNIX_PATH_MAX];
 /* user-provided EAL configuration */
 static struct eal_user_cfg eal_user_cfg;
 
-/* platform-discovered and runtime EAL state */
-static struct eal_platform_info eal_platform_info = {
-	.hugepage_info = {
-		[0] = {.lock_descriptor = -1 },
-		[1] = {.lock_descriptor = -1 },
-		[2] = {.lock_descriptor = -1 }
-	}
-};
-
 /* internal runtime configuration */
 static struct eal_runtime_state eal_runtime_state = {
 	.mem_config = &early_mem_config,
@@ -76,9 +68,42 @@ eal_get_user_configuration(void)
 }
 
 /* Return a pointer to the platform state structure */
-struct eal_platform_info *
+const struct eal_platform_info *
 eal_get_platform_info(void)
 {
+	/* platform-discovered and runtime EAL state */
+	static struct eal_platform_info eal_platform_info;
+	static rte_spinlock_t init_lock = RTE_SPINLOCK_INITIALIZER;
+	static RTE_ATOMIC(bool) initialized;
+
+	if (unlikely(!rte_atomic_load_explicit(&initialized, rte_memory_order_acquire))) {
+		struct eal_platform_info discovered_info = { 0 };
+
+		rte_spinlock_lock(&init_lock);
+		if (rte_atomic_load_explicit(&initialized, rte_memory_order_relaxed)) {
+			rte_spinlock_unlock(&init_lock);
+			return &eal_platform_info;
+		}
+		if (rte_eal_cpu_init(&discovered_info) < 0) {
+			EAL_LOG(ERR, "Failed to initialise CPU information");
+			goto fail;
+		}
+		if (eal_get_platform_hp_info(&discovered_info) < 0) {
+			EAL_LOG(ERR, "Failed to get platform hugepage information");
+			goto fail;
+		}
+		eal_platform_info = discovered_info;
+		rte_atomic_store_explicit(&initialized, true, rte_memory_order_release);
+		rte_spinlock_unlock(&init_lock);
+		return &eal_platform_info;
+
+fail:
+		free(discovered_info.cpu_info);
+		free(discovered_info.numa_nodes);
+		rte_spinlock_unlock(&init_lock);
+		return NULL;
+	}
+
 	return &eal_platform_info;
 }
 
@@ -212,6 +237,9 @@ eal_apply_runtime_state(void)
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
+	for (unsigned int i = 0; i < MAX_HUGEPAGE_SIZES; i++)
+		runtime_state->hugepage_info[i].lock_descriptor = -1;
+
 	if (eal_apply_lcore_config() < 0)
 		return -1;
 
@@ -283,7 +311,7 @@ eal_apply_hugepage_mem_sz_limits(void)
 
 	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
 		unsigned int j;
-		const uint64_t pagesz = platform_info->hugepage_info[i].hugepage_sz;
+		const uint64_t pagesz = platform_info->hugepage_sizes[i].size;
 		uint64_t limit;
 
 		/* assign default limits */
lib/eal/common/eal_common_dynmem.c +13 -14
index f9b275dbeb..229cd8201e 100644
@@ -34,7 +34,6 @@ eal_dynmem_memseg_lists_init(void)
 	size_t mem_va_len, mem_va_page_sz;
 	unsigned int n_memtypes, cur_type;
 	void *mem_va_addr = NULL;
-	struct eal_platform_info *platform_info = eal_get_platform_info();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
@@ -58,7 +57,7 @@ eal_dynmem_memseg_lists_init(void)
 	 */
 
 	/* maximum number of memtypes we're ever going to get */
-	n_memtypes = platform_info->num_hugepage_sizes * rte_socket_count();
+	n_memtypes = runtime_state->num_hugepage_sizes * rte_socket_count();
 
 	/* can we fit all memtypes into the memseg lists? */
 	if (n_memtypes > RTE_MAX_MEMSEG_LISTS) {
@@ -69,12 +68,12 @@ eal_dynmem_memseg_lists_init(void)
 
 	/* populate mem types */
 	cur_type = 0;
-	for (hpi_idx = 0; hpi_idx < (int) platform_info->num_hugepage_sizes;
+	for (hpi_idx = 0; hpi_idx < (int) runtime_state->num_hugepage_sizes;
 			hpi_idx++) {
-		struct hugepage_info *hpi;
+		const struct hugepage_info *hpi;
 		uint64_t hugepage_sz;
 
-		hpi = &platform_info->hugepage_info[hpi_idx];
+		hpi = &runtime_state->hugepage_info[hpi_idx];
 		hugepage_sz = hpi->hugepage_sz;
 
 		for (i = 0; i < (int) rte_socket_count(); i++, cur_type++) {
@@ -231,13 +230,13 @@ eal_dynmem_hugepage_init(void)
 	struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
 	uint64_t memory[RTE_MAX_NUMA_NODES];
 	int hp_sz_idx, socket_id;
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	memset(used_hp, 0, sizeof(used_hp));
 
 	for (hp_sz_idx = 0;
-			hp_sz_idx < (int) platform_info->num_hugepage_sizes;
+			hp_sz_idx < (int) runtime_state->num_hugepage_sizes;
 			hp_sz_idx++) {
 #ifndef RTE_ARCH_64
 		struct hugepage_info dummy;
@@ -245,7 +244,7 @@ eal_dynmem_hugepage_init(void)
 #endif
 		/* also initialize used_hp hugepage sizes in used_hp */
 		struct hugepage_info *hpi;
-		hpi = &platform_info->hugepage_info[hp_sz_idx];
+		hpi = &runtime_state->hugepage_info[hp_sz_idx];
 		used_hp[hp_sz_idx].hugepage_sz = hpi->hugepage_sz;
 
 #ifndef RTE_ARCH_64
@@ -273,12 +272,12 @@ eal_dynmem_hugepage_init(void)
 
 	/* calculate final number of pages */
 	if (eal_dynmem_calc_num_pages_per_socket(memory,
-			platform_info->hugepage_info, used_hp,
-			platform_info->num_hugepage_sizes) < 0)
+			runtime_state->hugepage_info, used_hp,
+			runtime_state->num_hugepage_sizes) < 0)
 		return -1;
 
 	for (hp_sz_idx = 0;
-			hp_sz_idx < (int)platform_info->num_hugepage_sizes;
+			hp_sz_idx < (int)runtime_state->num_hugepage_sizes;
 			hp_sz_idx++) {
 		for (socket_id = 0; socket_id < RTE_MAX_NUMA_NODES;
 				socket_id++) {
@@ -357,10 +356,10 @@ get_socket_mem_size(int socket)
 {
 	uint64_t size = 0;
 	unsigned int i;
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
-	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
-		struct hugepage_info *hpi = &platform_info->hugepage_info[i];
+	for (i = 0; i < runtime_state->num_hugepage_sizes; i++) {
+		struct hugepage_info *hpi = &runtime_state->hugepage_info[i];
 		size += hpi->hugepage_sz * hpi->num_pages[socket];
 	}
 
lib/eal/common/eal_common_lcore.c +10 -3
index de603b2ff3..842230e729 100644
@@ -175,12 +175,16 @@ socket_id_cmp(const void *a, const void *b)
  * structure.
  */
 int
-rte_eal_cpu_init(void)
+rte_eal_cpu_init(struct eal_platform_info *platform_info)
 {
-	struct eal_platform_info *platform_info = eal_get_platform_info();
 	int *lcore_to_socket_id;
 	size_t nb_detected_cpus = 0;
 
+	if (eal_create_cpu_map() < 0) {
+		EAL_LOG(ERR, "Failed to create CPU map");
+		return -1;
+	}
+
 	/* allocate cpu_info for all CPUs visible to the OS */
 	platform_info->cpu_count = eal_cpu_max();
 	platform_info->cpu_info = calloc(platform_info->cpu_count,
@@ -193,6 +197,7 @@ rte_eal_cpu_init(void)
 	if (lcore_to_socket_id == NULL) {
 		EAL_LOG(ERR, "Cannot allocate lcore_to_socket_id array");
 		free(platform_info->cpu_info);
+		platform_info->cpu_info = NULL;
 		return -1;
 	}
 
@@ -214,8 +219,9 @@ rte_eal_cpu_init(void)
 
 	if (nb_detected_cpus == 0) {
 		EAL_LOG(ERR, "No CPUs detected for platform topology");
-		free(platform_info->cpu_info);
 		free(lcore_to_socket_id);
+		free(platform_info->cpu_info);
+		platform_info->cpu_info = NULL;
 		return -1;
 	}
 
@@ -230,6 +236,7 @@ rte_eal_cpu_init(void)
 		EAL_LOG(ERR, "Cannot allocate numa_nodes array");
 		free(lcore_to_socket_id);
 		free(platform_info->cpu_info);
+		platform_info->cpu_info = NULL;
 		return -1;
 	}
 
lib/eal/common/eal_hugepages.h +8 -0
index 1b560d3379..b30ff12f2d 100644
@@ -11,6 +11,8 @@
 
 #define MAX_HUGEPAGE_PATH PATH_MAX
 
+struct eal_platform_info;
+
 /**
  * Structure used to store information about hugepages that we mapped
  * through the files in hugetlbfs.
@@ -25,6 +27,12 @@ struct hugepage_file {
 	char filepath[MAX_HUGEPAGE_PATH]; /**< path to backing file on filesystem */
 };
 
+/**
+ * Discover hugepage sizes and mounts available on this platform and populate
+ * the hugepage_sizes[] fields of the provided platform_info struct.
+ */
+int eal_get_platform_hp_info(struct eal_platform_info *platform_info);
+
 /**
  * Read the information on what hugepages are available for the EAL to use,
  * clearing out any unused ones.
lib/eal/common/eal_internal_cfg.h +13 -2
index d101a60413..7d23568d7b 100644
@@ -164,6 +164,14 @@ struct eal_cpu_info {
 	unsigned int core_id;  /**< physical core number on its NUMA node */
 };
 
+struct hp_sizes {
+	uint64_t size;         /**< hugepage size in bytes */
+	char dir[PATH_MAX];    /**< dir where hugetlbfs is mounted for this size */
+	uint32_t total_pages;  /**< total hugepages of this size across all NUMA nodes */
+	uint32_t max_pages[RTE_MAX_NUMA_NODES];
+	/**< maximum hugepages of this size available on each NUMA node */
+};
+
 /**
  * Discovered information about the system hardware.
  * Immutable after discovery.
@@ -174,7 +182,7 @@ struct eal_platform_info {
 	uint32_t numa_node_count;        /**< number of detected NUMA nodes */
 	uint32_t *numa_nodes;            /**< sorted list of detected NUMA node IDs */
 	uint8_t num_hugepage_sizes;      /**< how many sizes on this system */
-	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
+	struct hp_sizes hugepage_sizes[MAX_HUGEPAGE_SIZES];
 };
 
 /**
@@ -222,12 +230,15 @@ struct eal_runtime_state {
 	uint32_t lcore_count;         /**< Number of active lcore IDs (role != ROLE_OFF). */
 	struct lcore_cfg lcore_cfg[RTE_MAX_LCORE];
 	RTE_BITSET_DECLARE(core_indices, RTE_MAX_LCORE); /**< currently allocated core_indices */
+
+	uint32_t num_hugepage_sizes;       /**< how many sizes stored in hugepage_info[] */
+	struct hugepage_info hugepage_info[MAX_HUGEPAGE_SIZES];
 	struct rte_mem_config *mem_config; /**< pointer to memory config (in shared memory) */
 	struct eal_solib_list loaded_plugins; /**< all plugins loaded by eal_plugins_init() */
 };
 
+const struct eal_platform_info *eal_get_platform_info(void);
 struct eal_user_cfg *eal_get_user_configuration(void);
-struct eal_platform_info *eal_get_platform_info(void);
 struct eal_runtime_state *eal_get_runtime_state(void);
 
 #endif /* EAL_INTERNAL_CFG_H */
lib/eal/common/eal_private.h +17 -1
index edda0289fa..7de94cc300 100644
@@ -95,10 +95,12 @@ int rte_eal_memzone_init(void);
  * Parse /proc/cpuinfo to get the number of physical and logical
  * processors on the machine.
  *
+ * @param platform_info
+ *   Platform info struct to populate with CPU topology.
  * @return
  *   0 on success, negative on error
  */
-int rte_eal_cpu_init(void);
+int rte_eal_cpu_init(struct eal_platform_info *platform_info);
 
 /**
  * Check for architecture supported MMU.
@@ -753,6 +755,20 @@ int eal_asprintf(char **buffer, const char *format, ...);
 		eal_asprintf(buffer, format, ##__VA_ARGS__)
 #endif
 
+/**
+ * Create a map of processors and cores on the system.
+ *
+ * @return
+ *  0 on success, (-1) on failure and rte_errno is set.
+ */
+#ifdef RTE_EXEC_ENV_WINDOWS
+int eal_create_cpu_map(void);
+#else
+/* non-Windows platforms do not require CPU map creation, define stub fn */
+static inline int
+eal_create_cpu_map(void) { return 0; }
+#endif
+
 #define EAL_LOG(level, ...) \
 	RTE_LOG_LINE(level, EAL, "" __VA_ARGS__)
 
lib/eal/freebsd/eal.c +15 -8
index 47efe2f4b4..e4a69e4edf 100644
@@ -321,10 +321,11 @@ eal_get_hugepage_mem_size(void)
 {
 	uint64_t size = 0;
 	unsigned i, j;
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
-		struct hugepage_info *hpi = &platform_info->hugepage_info[i];
+		struct hugepage_info *hpi = &runtime_state->hugepage_info[i];
 		if (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) {
 			for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
 				size += hpi->hugepage_sz * hpi->num_pages[j];
@@ -402,6 +403,18 @@ rte_eal_init(int argc, char **argv)
 	bool has_phys_addr;
 	enum rte_iova_mode iova_mode;
 
+	/*
+	 * platform_info is lazily initialized on first use, and that
+	 * initialization can fail (CPU/NUMA/hugepage detection). Almost
+	 * everything below depends on a valid platform_info, so confirm it
+	 * is available before doing anything else.
+	 */
+	if (eal_get_platform_info() == NULL) {
+		rte_eal_init_alert("Cannot get platform information.");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	/* first check if we have been run before */
 	if (!rte_atomic_compare_exchange_strong_explicit(&run_once, &has_run, 1,
 					rte_memory_order_relaxed, rte_memory_order_relaxed)) {
@@ -443,12 +456,6 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	if (rte_eal_cpu_init() < 0) {
-		rte_eal_init_alert("Cannot detect lcores.");
-		rte_errno = ENOTSUP;
-		goto err_out;
-	}
-
 	if (eal_parse_args() < 0) {
 		rte_eal_init_alert("Error parsing command-line arguments.");
 		rte_errno = EINVAL;
lib/eal/freebsd/eal_hugepage_info.c +46 -14

120 lines not on this page · raw message

lib/eal/freebsd/eal_memory.c +9 -6
index 2466987e03..b8d23a1dc8 100644
@@ -72,7 +72,8 @@ rte_eal_hugepage_init(void)
 	void *addr;
 	unsigned int i, j, seg_idx = 0;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* get pointer to global configuration */
 	mcfg = eal_get_mcfg();
@@ -118,7 +119,7 @@ rte_eal_hugepage_init(void)
 		uint64_t page_sz, mem_needed;
 		unsigned int n_pages, max_pages;
 
-		hpi = &platform_info->hugepage_info[i];
+		hpi = &runtime_state->hugepage_info[i];
 		page_sz = hpi->hugepage_sz;
 		max_pages = hpi->num_pages[0];
 		mem_needed = RTE_ALIGN_CEIL(user_cfg->memory - total_mem,
@@ -288,12 +289,13 @@ attach_segment(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
 int
 rte_eal_hugepage_attach(void)
 {
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct hugepage_info *hpi;
 	int fd_hugepage = -1;
 	unsigned int i;
 
-	hpi = &platform_info->hugepage_info[0];
+	hpi = &runtime_state->hugepage_info[0];
 
 	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
 		const struct hugepage_info *cur_hpi = &hpi[i];
@@ -356,7 +358,8 @@ memseg_primary_init(void)
 	int hpi_idx, msl_idx = 0;
 	struct rte_memseg_list *msl;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* no-huge does not need this at all */
 	if (user_cfg->no_hugetlbfs)
@@ -375,7 +378,7 @@ memseg_primary_init(void)
 		uint64_t hugepage_sz;
 		unsigned int n_segs;
 
-		hpi = &platform_info->hugepage_info[hpi_idx];
+		hpi = &runtime_state->hugepage_info[hpi_idx];
 		hugepage_sz = hpi->hugepage_sz;
 
 		/* no NUMA support on FreeBSD */
lib/eal/linux/eal.c +17 -11
index 03e26584d6..6824e0f06b 100644
@@ -403,18 +403,18 @@ eal_mem_config_init(void)
 static void
 eal_hugedirs_unlock(void)
 {
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	int i;
 	for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
 	{
 		/* skip uninitialized */
-		if (platform_info->hugepage_info[i].lock_descriptor < 0)
+		if (runtime_state->hugepage_info[i].lock_descriptor < 0)
 			continue;
 		/* unlock hugepage file */
-		flock(platform_info->hugepage_info[i].lock_descriptor, LOCK_UN);
-		close(platform_info->hugepage_info[i].lock_descriptor);
+		flock(runtime_state->hugepage_info[i].lock_descriptor, LOCK_UN);
+		close(runtime_state->hugepage_info[i].lock_descriptor);
 		/* reset the field */
-		platform_info->hugepage_info[i].lock_descriptor = -1;
+		runtime_state->hugepage_info[i].lock_descriptor = -1;
 	}
 }
 
@@ -562,6 +562,18 @@ rte_eal_init(int argc, char **argv)
 	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
+	/*
+	 * platform_info is lazily initialized on first use, and that
+	 * initialization can fail (CPU/NUMA/hugepage detection). Almost
+	 * everything below depends on a valid platform_info, so confirm it
+	 * is available before doing anything else.
+	 */
+	if (eal_get_platform_info() == NULL) {
+		rte_eal_init_alert("Cannot get platform information.");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	/* first check if we have been run before */
 	if (!rte_atomic_compare_exchange_strong_explicit(&run_once, &has_run, 1,
 					rte_memory_order_relaxed, rte_memory_order_relaxed)) {
@@ -603,12 +615,6 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	if (rte_eal_cpu_init() < 0) {
-		rte_eal_init_alert("Cannot detect lcores.");
-		rte_errno = ENOTSUP;
-		goto err_out;
-	}
-
 	if (eal_parse_args() < 0) {
 		rte_eal_init_alert("Error parsing command line arguments.");
 		rte_errno = EINVAL;
lib/eal/linux/eal_hugepage_info.c +100 -17

192 lines not on this page · raw message

lib/eal/linux/eal_memalloc.c +12 -12
index 3e693d4705..3819d12d71 100644
@@ -972,7 +972,7 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz,
 	struct alloc_walk_param wa;
 	struct hugepage_info *hi = NULL;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	memset(&wa, 0, sizeof(wa));
 
@@ -980,10 +980,10 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs, size_t page_sz,
 	if (user_cfg->legacy_mem)
 		return -1;
 
-	for (i = 0; i < (int) RTE_DIM(platform_info->hugepage_info); i++) {
+	for (i = 0; i < (int) RTE_DIM(runtime_state->hugepage_info); i++) {
 		if (page_sz ==
-				platform_info->hugepage_info[i].hugepage_sz) {
-			hi = &platform_info->hugepage_info[i];
+				runtime_state->hugepage_info[i].hugepage_sz) {
+			hi = &runtime_state->hugepage_info[i];
 			break;
 		}
 	}
@@ -1041,7 +1041,7 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 {
 	int seg, ret = 0;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* dynamic free not supported in legacy mode */
 	if (user_cfg->legacy_mem)
@@ -1062,13 +1062,13 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 
 		memset(&wa, 0, sizeof(wa));
 
-		for (i = 0; i < (int)RTE_DIM(platform_info->hugepage_info);
+		for (i = 0; i < (int)RTE_DIM(runtime_state->hugepage_info);
 				i++) {
-			hi = &platform_info->hugepage_info[i];
+			hi = &runtime_state->hugepage_info[i];
 			if (cur->hugepage_sz == hi->hugepage_sz)
 				break;
 		}
-		if (i == (int)RTE_DIM(platform_info->hugepage_info)) {
+		if (i == (int)RTE_DIM(runtime_state->hugepage_info)) {
 			EAL_LOG(ERR, "Can't find relevant hugepage_info entry");
 			ret = -1;
 			continue;
@@ -1332,7 +1332,7 @@ sync_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
 {
 	struct rte_mem_config *mcfg = eal_get_mcfg();
 	struct rte_memseg_list *primary_msl, *local_msl;
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct hugepage_info *hi = NULL;
 	unsigned int i;
 	int msl_idx;
@@ -1344,12 +1344,12 @@ sync_walk(const struct rte_memseg_list *msl, void *arg __rte_unused)
 	primary_msl = &mcfg->memsegs[msl_idx];
 	local_msl = &local_memsegs[msl_idx];
 
-	for (i = 0; i < RTE_DIM(platform_info->hugepage_info); i++) {
+	for (i = 0; i < RTE_DIM(runtime_state->hugepage_info); i++) {
 		uint64_t cur_sz =
-			platform_info->hugepage_info[i].hugepage_sz;
+			runtime_state->hugepage_info[i].hugepage_sz;
 		uint64_t msl_sz = primary_msl->page_sz;
 		if (msl_sz == cur_sz) {
-			hi = &platform_info->hugepage_info[i];
+			hi = &runtime_state->hugepage_info[i];
 			break;
 		}
 	}
lib/eal/linux/eal_memory.c +29 -30

185 lines not on this page · raw message

lib/eal/windows/eal.c +12 -12
index 37e43c9a62..f1a159bf48 100644
@@ -165,6 +165,18 @@ rte_eal_init(int argc, char **argv)
 	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
 	char thread_name[RTE_THREAD_NAME_SIZE];
 
+	/*
+	 * platform_info is lazily initialized on first use, and that
+	 * initialization can fail (CPU/NUMA/hugepage detection). Almost
+	 * everything below depends on a valid platform_info, so confirm it
+	 * is available before doing anything else.
+	 */
+	if (eal_get_platform_info() == NULL) {
+		rte_eal_init_alert("Cannot get platform information.");
+		rte_errno = ENOTSUP;
+		return -1;
+	}
+
 	/* clone argv to report out later in telemetry */
 	eal_save_args(argc, argv);
 
@@ -184,12 +196,6 @@ rte_eal_init(int argc, char **argv)
 
 	eal_log_init(NULL);
 
-	if (eal_create_cpu_map() < 0) {
-		rte_eal_init_alert("Cannot discover CPU and NUMA.");
-		/* rte_errno is set */
-		goto err_out;
-	}
-
 	/* verify if DPDK supported on architecture MMU */
 	if (!eal_mmu_supported()) {
 		rte_eal_init_alert("Unsupported MMU type.");
@@ -197,12 +203,6 @@ rte_eal_init(int argc, char **argv)
 		goto err_out;
 	}
 
-	if (rte_eal_cpu_init() < 0) {
-		rte_eal_init_alert("Cannot detect lcores.");
-		rte_errno = ENOTSUP;
-		goto err_out;
-	}
-
 	if (eal_parse_args() < 0) {
 		rte_eal_init_alert("Invalid command line arguments.");
 		rte_errno = EINVAL;
lib/eal/windows/eal_hugepages.c +31 -4
index 4e9e958c65..fa19b7b77c 100644
@@ -62,11 +62,9 @@ hugepage_info_init(void)
 	struct hugepage_info *hpi;
 	unsigned int socket_id;
 	int ret = 0;
-	struct eal_platform_info *platform_info = eal_get_platform_info();
+	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
-	/* Only one hugepage size available on Windows. */
-	platform_info->num_hugepage_sizes = 1;
-	hpi = &platform_info->hugepage_info[0];
+	hpi = &runtime_state->hugepage_info[0];
 
 	hpi->hugepage_sz = GetLargePageMinimum();
 	if (hpi->hugepage_sz == 0)
@@ -96,10 +94,39 @@ hugepage_info_init(void)
 	/* No hugepage filesystem on Windows. */
 	hpi->lock_descriptor = -1;
 	memset(hpi->hugedir, 0, sizeof(hpi->hugedir));
+	runtime_state->num_hugepage_sizes = 1;
 
 	return ret;
 }
 
+int
+eal_get_platform_hp_info(struct eal_platform_info *platform_info)
+{
+	size_t hp_sz;
+	unsigned int socket_id;
+
+	hp_sz = GetLargePageMinimum();
+	if (hp_sz == 0)
+		return -ENOTSUP;
+
+	for (socket_id = 0; socket_id < platform_info->numa_node_count; socket_id++) {
+		ULONGLONG bytes;
+		unsigned int numa_node;
+
+		numa_node = eal_socket_numa_node(socket_id);
+		if (GetNumaAvailableMemoryNodeEx(numa_node, &bytes)) {
+			platform_info->hugepage_sizes[0].max_pages[socket_id] = bytes / hp_sz;
+			platform_info->hugepage_sizes[0].total_pages += bytes / hp_sz;
+		}
+	}
+
+	platform_info->num_hugepage_sizes = 1;
+	platform_info->hugepage_sizes[0].size = hp_sz;
+	platform_info->hugepage_sizes[0].dir[0] = '\0'; /* no hugetlbfs on Windows */
+
+	return 0;
+}
+
 int
 eal_hugepage_info_init(void)
 {
lib/eal/windows/eal_memalloc.c +6 -5
index b45002621b..8a2d3966ba 100644
@@ -320,6 +320,7 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs,
 	struct alloc_walk_param wa;
 	const struct hugepage_info *hi = NULL;
 	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (user_cfg->legacy_mem) {
@@ -328,7 +329,7 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs,
 	}
 
 	for (i = 0; i < platform_info->num_hugepage_sizes; i++) {
-		const struct hugepage_info *hpi = &platform_info->hugepage_info[i];
+		const struct hugepage_info *hpi = &runtime_state->hugepage_info[i];
 		if (page_sz == hpi->hugepage_sz) {
 			hi = hpi;
 			break;
@@ -372,7 +373,7 @@ int
 eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 {
 	int seg, ret = 0;
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	/* dynamic free not supported in legacy mode */
@@ -395,12 +396,12 @@ eal_memalloc_free_seg_bulk(struct rte_memseg **ms, int n_segs)
 
 		memset(&wa, 0, sizeof(wa));
 
-		for (i = 0; i < RTE_DIM(platform_info->hugepage_info); i++) {
-			hi = &platform_info->hugepage_info[i];
+		for (i = 0; i < RTE_DIM(runtime_state->hugepage_info); i++) {
+			hi = &runtime_state->hugepage_info[i];
 			if (cur->hugepage_sz == hi->hugepage_sz)
 				break;
 		}
-		if (i == RTE_DIM(platform_info->hugepage_info)) {
+		if (i == RTE_DIM(runtime_state->hugepage_info)) {
 			EAL_LOG(ERR, "Can't find relevant hugepage_info entry");
 			ret = -1;
 			continue;
lib/eal/windows/eal_windows.h +0 -8
index 91cf15eaaa..64662e957a 100644
@@ -29,14 +29,6 @@
 #define EAL_LOG_STUB() \
 	EAL_LOG(DEBUG, "Windows: %s() is a stub", __func__)
 
-/**
- * Create a map of processors and cores on the system.
- *
- * @return
- *  0 on success, (-1) on failure and rte_errno is set.
- */
-int eal_create_cpu_map(void);
-
 /**
  * Get system NUMA node number for a socket ID.
  *
Signature · 1 line
2.55.0
#130 lore raw

PATCH v3 36/39 eal: remove duplicated scan of sysfs for hugepage details

In reply to Bruce Richardson

Since the platform_info struct does the hugepage scanning, we can reuse those details in the hugepage init functions rather than rescanning sysfs.

---
 lib/eal/common/eal_internal_cfg.h   |   1 +
 lib/eal/freebsd/eal_hugepage_info.c |  29 ++------
 lib/eal/linux/eal_hugepage_info.c   | 103 ++++++++++------------------
 lib/eal/windows/eal_hugepages.c     |  26 ++-----
 4 files changed, 51 insertions(+), 108 deletions(-)
lib/eal/common/eal_internal_cfg.h +1 -0
index 7d23568d7b..6dcf2c55a7 100644
@@ -167,6 +167,7 @@ struct eal_cpu_info {
 struct hp_sizes {
 	uint64_t size;         /**< hugepage size in bytes */
 	char dir[PATH_MAX];    /**< dir where hugetlbfs is mounted for this size */
+	char subdir[32];       /**< sysfs subdir name for this size, e.g. "hugepages-2048kB" */
 	uint32_t total_pages;  /**< total hugepages of this size across all NUMA nodes */
 	uint32_t max_pages[RTE_MAX_NUMA_NODES];
 	/**< maximum hugepages of this size available on each NUMA node */
lib/eal/freebsd/eal_hugepage_info.c +7 -22
index 2b731f2b3c..9c97897cc3 100644
@@ -87,9 +87,9 @@ eal_get_platform_hp_info(struct eal_platform_info *platform_info)
 int
 eal_hugepage_info_init(void)
 {
-	size_t sysctl_size;
-	int num_buffers, fd, error;
-	int64_t buffer_size = 0;
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	int num_buffers, fd;
+	int64_t buffer_size;
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* re-use the linux "internal config" structure for our memory data */
@@ -98,28 +98,13 @@ eal_hugepage_info_init(void)
 	struct hugepage_info *tmp_hpi;
 	unsigned int i;
 
-	sysctl_size = sizeof(num_buffers);
-	error = sysctlbyname("hw.contigmem.num_buffers", &num_buffers,
-			&sysctl_size, NULL, 0);
-
-	if (error != 0) {
-		EAL_LOG(ERR, "could not read sysctl hw.contigmem.num_buffers");
+	if (platform_info->num_hugepage_sizes == 0) {
+		EAL_LOG(ERR, "could not read hugepage info from platform");
 		return -1;
 	}
 
-	sysctl_size = sizeof(buffer_size);
-	error = sysctlbyname("hw.contigmem.buffer_size", &buffer_size,
-			&sysctl_size, NULL, 0);
-
-	if (error != 0) {
-		error = sysctlbyname("hw.contigmem.buffer_size_MB", &buffer_size,
-				&sysctl_size, NULL, 0);
-		buffer_size *= 1024 * 1024;  /* convert to bytes, harmless to multiple on error*/
-	}
-	if (error != 0) {
-		EAL_LOG(ERR, "could not read sysctl hw.contigmem.buffer_size");
-		return -1;
-	}
+	buffer_size = (int64_t)platform_info->hugepage_sizes[0].size;
+	num_buffers = (int)platform_info->hugepage_sizes[0].max_pages[0];
 
 	fd = open(CONTIGMEM_DEV, O_RDWR);
 	if (fd < 0) {
lib/eal/linux/eal_hugepage_info.c +36 -67

198 lines not on this page · raw message

lib/eal/windows/eal_hugepages.c +7 -19
index fa19b7b77c..0c62f5ff48 100644
@@ -59,33 +59,21 @@ hugepage_claim_privilege(void)
 static int
 hugepage_info_init(void)
 {
+	const struct eal_platform_info *platform_info = eal_get_platform_info();
 	struct hugepage_info *hpi;
 	unsigned int socket_id;
 	int ret = 0;
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
-	hpi = &runtime_state->hugepage_info[0];
-
-	hpi->hugepage_sz = GetLargePageMinimum();
-	if (hpi->hugepage_sz == 0)
+	if (platform_info->num_hugepage_sizes == 0)
 		return -ENOTSUP;
 
-	/* Assume all memory on each NUMA node available for hugepages,
-	 * because Windows neither advertises additional limits,
-	 * nor provides an API to query them.
-	 */
-	for (socket_id = 0; socket_id < rte_socket_count(); socket_id++) {
-		ULONGLONG bytes;
-		unsigned int numa_node;
-
-		numa_node = eal_socket_numa_node(socket_id);
-		if (!GetNumaAvailableMemoryNodeEx(numa_node, &bytes)) {
-			RTE_LOG_WIN32_ERR("GetNumaAvailableMemoryNodeEx(%u)",
-				numa_node);
-			continue;
-		}
+	hpi = &runtime_state->hugepage_info[0];
+	hpi->hugepage_sz = platform_info->hugepage_sizes[0].size;
 
-		hpi->num_pages[socket_id] = bytes / hpi->hugepage_sz;
+	for (socket_id = 0; socket_id < rte_socket_count(); socket_id++) {
+		hpi->num_pages[socket_id] =
+			platform_info->hugepage_sizes[0].max_pages[socket_id];
 		EAL_LOG(DEBUG,
 			"Found %u hugepages of %zu bytes on socket %u",
 			hpi->num_pages[socket_id], hpi->hugepage_sz, socket_id);
Signature · 1 line
2.55.0
#131 lore raw

PATCH v3 37/39 eal: add utilities for working with user config struct

In reply to Bruce Richardson

Since the user-config struct has tailqs elements, string elements and variable length arrays it cannot be initialized via a simple "= {0}" and copy and cleanup requires looping through the various non-basic elements. Add functions below the struct definitions to handle these tasks correctly, adding a comment on the struct to remind any future editors to also adjust the functions if necessary.

---
 lib/eal/common/eal_common_options.c |  12 +--
 lib/eal/common/eal_internal_cfg.h   | 152 ++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 11 deletions(-)
lib/eal/common/eal_common_options.c +1 -11
index bdf5a8b03d..7590ad9c8c 100644
@@ -1910,17 +1910,7 @@ eal_parse_args(void)
 	 * false or NULL, which is the correct default (RTE_PROC_PRIMARY,
 	 * RTE_INTR_MODE_NONE, RTE_IOVA_DC, etc. are all defined as 0).
 	 */
-	*user_cfg = (struct eal_user_cfg){
-		.devopt_list = TAILQ_HEAD_INITIALIZER(user_cfg->devopt_list),
-		.plugin_list = TAILQ_HEAD_INITIALIZER(user_cfg->plugin_list),
-		.trace_patterns = STAILQ_HEAD_INITIALIZER(user_cfg->trace_patterns),
-		.hugepage_file.unlink_existing = true,
-		.main_lcore = -1,
-#ifndef RTE_LIBEAL_USE_HPET
-		.no_hpet = true,
-#endif
-		.max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH,
-	};
+	*user_cfg = EAL_USER_CFG_INITIALIZER(*user_cfg);
 
 	bool remap_lcores = (args.remap_lcore_ids != NULL);
 	struct arg_list_elem *arg;
lib/eal/common/eal_internal_cfg.h +152 -0

176 lines not on this page · raw message

Signature · 1 line
2.55.0
#132 lore raw

PATCH v3 38/39 eal: split EAL init into two stages

In reply to Bruce Richardson

Split the rte_eal_init function into two parts, where the first part is handling the argument parsing and then calling the second part which does the actual subsystem initialization.

---
 lib/eal/common/eal_common_options.c | 69 +++++++++--------------------
 lib/eal/common/eal_options.h        |  2 +-
 lib/eal/freebsd/eal.c               | 56 +++++++++++++++++------
 lib/eal/linux/eal.c                 | 54 +++++++++++++++++-----
 lib/eal/windows/eal.c               | 55 +++++++++++++++++------
 5 files changed, 149 insertions(+), 87 deletions(-)
lib/eal/common/eal_common_options.c +21 -48
index 7590ad9c8c..d0bea404fe 100644
@@ -426,9 +426,8 @@ eal_clean_saved_args(void)
 #endif /* !RTE_EXEC_ENV_WINDOWS */
 
 static int
-eal_option_device_add(enum rte_devtype type, const char *arg)
+eal_option_device_add(struct eal_user_cfg *user_cfg, enum rte_devtype type, const char *arg)
 {
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct device_option *devopt;
 	size_t arglen;
 	int ret;
@@ -483,9 +482,8 @@ eal_get_hugefile_prefix(void)
 }
 
 static int
-eal_plugin_path_add(const char *path)
+eal_plugin_path_add(struct eal_user_cfg *user_cfg, const char *path)
 {
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	struct eal_plugin_path *p;
 
 	p = malloc(sizeof(*p));
@@ -1021,11 +1019,10 @@ rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_ra
 
 /* Changes the lcore id of the main thread */
 static int
-eal_parse_main_lcore(const char *arg)
+eal_parse_main_lcore(struct eal_user_cfg *user_cfg, const char *arg)
 {
 	char *parsing_end;
 	long main_lcore;
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	errno = 0;
 	main_lcore = strtol(arg, &parsing_end, 0);
@@ -1459,10 +1456,9 @@ eal_parse_proc_type(const char *arg)
 }
 
 static int
-eal_parse_iova_mode(const char *name)
+eal_parse_iova_mode(struct eal_user_cfg *user_cfg, const char *name)
 {
 	int mode;
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (name == NULL)
 		return -1;
@@ -1506,11 +1502,10 @@ eal_parse_simd_bitwidth(const char *arg)
 }
 
 static int
-eal_parse_base_virtaddr(const char *arg)
+eal_parse_base_virtaddr(struct eal_user_cfg *user_cfg, const char *arg)
 {
 	char *end;
 	uint64_t addr;
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	errno = 0;
 	addr = strtoull(arg, &end, 16);
@@ -1822,9 +1817,8 @@ eal_parse_pagesz_mem(char *strval, struct eal_user_cfg *user_cfg)
 }
 
 static int
-eal_parse_vfio_intr(const char *mode)
+eal_parse_vfio_intr(struct eal_user_cfg *user_cfg, const char *mode)
 {
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	static struct {
 		const char *name;
 		enum rte_intr_mode value;
@@ -1844,9 +1838,8 @@ eal_parse_vfio_intr(const char *mode)
 }
 
 static int
-eal_parse_vfio_vf_token(const char *vf_token)
+eal_parse_vfio_vf_token(struct eal_user_cfg *user_cfg, const char *vf_token)
 {
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 	rte_uuid_t uuid;
 
 	if (!rte_uuid_parse(vf_token, uuid)) {
@@ -1858,13 +1851,13 @@ eal_parse_vfio_vf_token(const char *vf_token)
 }
 
 static int
-eal_parse_huge_worker_stack(const char *arg)
+eal_parse_huge_worker_stack(struct eal_user_cfg *user_cfg, const char *arg)
 {
 #ifdef RTE_EXEC_ENV_WINDOWS
 	EAL_LOG(WARNING, "Cannot set worker stack size on Windows, parameter ignored");
+	RTE_SET_USED(user_cfg);
 	RTE_SET_USED(arg);
 #else
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
 	if (arg == NULL || arg[0] == '\0') {
 		pthread_attr_t attr;
@@ -1901,10 +1894,8 @@ eal_parse_huge_worker_stack(const char *arg)
 
 /* Parse the arguments given in the command line of the application */
 int
-eal_parse_args(void)
+eal_parse_args(struct eal_user_cfg *user_cfg)
 {
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-
 	/*
 	 * Initialise user_cfg to defaults. Fields not listed here are zero,
 	 * false or NULL, which is the correct default (RTE_PROC_PRIMARY,
@@ -1938,17 +1929,17 @@ eal_parse_args(void)
 
 	/* device -a/-b/-vdev options*/
 	TAILQ_FOREACH(arg, &args.allow, next)
-		if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, arg->arg) < 0)
+		if (eal_option_device_add(user_cfg, RTE_DEVTYPE_ALLOWED, arg->arg) < 0)
 			return -1;
 	TAILQ_FOREACH(arg, &args.block, next)
-		if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, arg->arg) < 0)
+		if (eal_option_device_add(user_cfg, RTE_DEVTYPE_BLOCKED, arg->arg) < 0)
 			return -1;
 	TAILQ_FOREACH(arg, &args.vdev, next)
-		if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL, arg->arg) < 0)
+		if (eal_option_device_add(user_cfg, RTE_DEVTYPE_VIRTUAL, arg->arg) < 0)
 			return -1;
 	/* driver loading options */
 	TAILQ_FOREACH(arg, &args.driver_path, next)
-		if (eal_plugin_path_add(arg->arg) < 0)
+		if (eal_plugin_path_add(user_cfg, arg->arg) < 0)
 			return -1;
 
 	if (remap_lcores && args.remap_lcore_ids != (void *)1) {
@@ -2038,7 +2029,7 @@ eal_parse_args(void)
 			return -1;
 		}
 	}
-	if (args.main_lcore != NULL && eal_parse_main_lcore(args.main_lcore) < 0)
+	if (args.main_lcore != NULL && eal_parse_main_lcore(user_cfg, args.main_lcore) < 0)
 		return -1;
 
 	/* memory options */
@@ -2241,13 +2232,13 @@ eal_parse_args(void)
 
 	/* other misc settings */
 	if (args.iova_mode != NULL) {
-		if (eal_parse_iova_mode(args.iova_mode) < 0) {
+		if (eal_parse_iova_mode(user_cfg, args.iova_mode) < 0) {
 			EAL_LOG(ERR, "invalid iova mode parameter '%s'", args.iova_mode);
 			return -1;
 		}
 	};
 	if (args.base_virtaddr != NULL) {
-		if (eal_parse_base_virtaddr(args.base_virtaddr) < 0) {
+		if (eal_parse_base_virtaddr(user_cfg, args.base_virtaddr) < 0) {
 			EAL_LOG(ERR, "invalid base virtaddr '%s'", args.base_virtaddr);
 			return -1;
 		}
@@ -2260,13 +2251,13 @@ eal_parse_args(void)
 		}
 	}
 	if (args.vfio_intr != NULL) {
-		if (eal_parse_vfio_intr(args.vfio_intr) < 0) {
+		if (eal_parse_vfio_intr(user_cfg, args.vfio_intr) < 0) {
 			EAL_LOG(ERR, "invalid vfio interrupt parameter: '%s'", args.vfio_intr);
 			return -1;
 		}
 	}
 	if (args.vfio_vf_token != NULL) {
-		if (eal_parse_vfio_vf_token(args.vfio_vf_token) < 0) {
+		if (eal_parse_vfio_vf_token(user_cfg, args.vfio_vf_token) < 0) {
 			EAL_LOG(ERR, "invalid vfio vf token parameter: '%s'", args.vfio_vf_token);
 			return -1;
 		}
@@ -2275,7 +2266,7 @@ eal_parse_args(void)
 	if (args.huge_worker_stack != NULL) {
 		if (args.huge_worker_stack == (void *)1)
 			args.huge_worker_stack = NULL;
-		if (eal_parse_huge_worker_stack(args.huge_worker_stack) < 0) {
+		if (eal_parse_huge_worker_stack(user_cfg, args.huge_worker_stack) < 0) {
 			EAL_LOG(ERR, "invalid huge worker stack parameter");
 			return -1;
 		}
@@ -2303,25 +2294,7 @@ eal_parse_args(void)
 int
 eal_cleanup_config(void)
 {
-	struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	struct eal_trace_arg *ta;
-
-	/* free trace patterns list */
-	while (!STAILQ_EMPTY(&user_cfg->trace_patterns)) {
-		ta = STAILQ_FIRST(&user_cfg->trace_patterns);
-		STAILQ_REMOVE_HEAD(&user_cfg->trace_patterns, next);
-		free(ta->val);
-		free(ta);
-	}
-	free(user_cfg->trace_dir);
-	free(user_cfg->hugefile_prefix);
-	free(user_cfg->hugepage_dir);
-	free(user_cfg->user_mbuf_pool_ops_name);
-	for (unsigned int i = 0; i < RTE_MAX_LCORE; i++) {
-		free(user_cfg->lcore_cpusets[i]);
-		user_cfg->lcore_cpusets[i] = NULL;
-	}
-
+	eal_user_cfg_cleanup(eal_get_user_configuration());
 	return 0;
 }
 
lib/eal/common/eal_options.h +1 -1
index 77a6a4405f..afa8449ee7 100644
@@ -11,7 +11,7 @@ struct rte_tel_data;
 struct eal_user_cfg;
 
 int eal_parse_log_options(void);
-int eal_parse_args(void);
+int eal_parse_args(struct eal_user_cfg *user_cfg);
 int eal_option_device_parse(void);
 int eal_cleanup_config(void);
 int eal_plugins_init(void);
lib/eal/freebsd/eal.c +43 -13

95 lines not on this page · raw message

lib/eal/linux/eal.c +42 -12

94 lines not on this page · raw message

lib/eal/windows/eal.c +42 -13

92 lines not on this page · raw message

Signature · 1 line
2.55.0
#133 lore raw

PATCH v3 39/39 eal: provide hooks for init with externally supplied config

In reply to Bruce Richardson

Now that we have a split EAL init, where most work is done on a configured eal_user_cfg structure, add in hooks to allow other libraries to init EAL by passing in that structure pre-configured.

We export an internal function that wraps the second stage init, while taking care of the run_once flag, before calling the main initialization function with a prepopulated config.

Also, export internally the platform info function so that any callers of this new function can do any necessary validation of parameters as part of their setup.

---
 lib/eal/common/eal_common_config.c  |  5 ++-
 lib/eal/common/eal_common_lcore.c   |  6 +--
 lib/eal/common/eal_common_thread.c  |  2 +-
 lib/eal/common/eal_internal_cfg.h   |  8 +++-
 lib/eal/freebsd/eal.c               | 57 ++++++++++++++++++++++++---
 lib/eal/freebsd/eal_hugepage_info.c |  2 +-
 lib/eal/freebsd/eal_memory.c        |  6 +--
 lib/eal/linux/eal.c                 | 55 ++++++++++++++++++++++++--
 lib/eal/linux/eal_hugepage_info.c   |  2 +-
 lib/eal/windows/eal.c               | 60 ++++++++++++++++++++++++++++-
 lib/eal/windows/eal_hugepages.c     |  2 +-
 lib/eal/windows/eal_memalloc.c      |  2 +-
 12 files changed, 183 insertions(+), 24 deletions(-)
lib/eal/common/eal_common_config.c +3 -2
index 110921ae93..73074f2520 100644
@@ -68,8 +68,9 @@ eal_get_user_configuration(void)
 }
 
 /* Return a pointer to the platform state structure */
+RTE_EXPORT_INTERNAL_SYMBOL(rte_eal_get_platform_info)
 const struct eal_platform_info *
-eal_get_platform_info(void)
+rte_eal_get_platform_info(void)
 {
 	/* platform-discovered and runtime EAL state */
 	static struct eal_platform_info eal_platform_info;
@@ -305,7 +306,7 @@ int
 eal_apply_hugepage_mem_sz_limits(void)
 {
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	unsigned int i;
 
lib/eal/common/eal_common_lcore.c +3 -3
index 842230e729..47a754a990 100644
@@ -55,7 +55,7 @@ RTE_EXPORT_SYMBOL(rte_lcore_to_cpu_id)
 int rte_lcore_to_cpu_id(int lcore_id)
 {
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	unsigned int cpu;
 
 	if (unlikely(lcore_id >= RTE_MAX_LCORE))
@@ -278,7 +278,7 @@ RTE_EXPORT_SYMBOL(rte_socket_count)
 unsigned int
 rte_socket_count(void)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	return platform_info->numa_node_count;
 }
 
@@ -286,7 +286,7 @@ RTE_EXPORT_SYMBOL(rte_socket_id_by_idx)
 int
 rte_socket_id_by_idx(unsigned int idx)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	if (idx >= platform_info->numa_node_count) {
 		rte_errno = EINVAL;
 		return -1;
lib/eal/common/eal_common_thread.c +1 -1
index a2e08242bd..b56dd4f2b6 100644
@@ -40,7 +40,7 @@ unsigned rte_socket_id(void)
 int
 eal_cpuset_socket_id(const rte_cpuset_t *cpusetp)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	int socket_id = SOCKET_ID_ANY;
 
 	if (cpusetp == NULL)
lib/eal/common/eal_internal_cfg.h +7 -1
index 935d322345..ecc17e94e1 100644
@@ -25,6 +25,7 @@
 #include <rte_bitset.h>
 #include <rte_stdatomic.h>
 #include "eal_thread.h"
+#include "rte_compat.h"
 
 /* Forward declaration — full definition is in eal_memcfg.h */
 struct rte_mem_config;
@@ -390,8 +391,13 @@ struct eal_runtime_state {
 	struct eal_solib_list loaded_plugins; /**< all plugins loaded by eal_plugins_init() */
 };
 
-const struct eal_platform_info *eal_get_platform_info(void);
+__rte_internal
+const struct eal_platform_info *rte_eal_get_platform_info(void);
 struct eal_user_cfg *eal_get_user_configuration(void);
 struct eal_runtime_state *eal_get_runtime_state(void);
 
+__rte_internal
+int
+rte_eal_runtime_init(const char *progname, const struct eal_user_cfg *user_provided_cfg);
+
 #endif /* EAL_INTERNAL_CFG_H */
lib/eal/freebsd/eal.c +52 -5

99 lines not on this page · raw message

lib/eal/freebsd/eal_hugepage_info.c +1 -1
index 9c97897cc3..28e1a04528 100644
@@ -87,7 +87,7 @@ eal_get_platform_hp_info(struct eal_platform_info *platform_info)
 int
 eal_hugepage_info_init(void)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	int num_buffers, fd;
 	int64_t buffer_size;
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
lib/eal/freebsd/eal_memory.c +3 -3
index b8d23a1dc8..4579da20b9 100644
@@ -72,7 +72,7 @@ rte_eal_hugepage_init(void)
 	void *addr;
 	unsigned int i, j, seg_idx = 0;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* get pointer to global configuration */
@@ -289,7 +289,7 @@ attach_segment(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
 int
 rte_eal_hugepage_attach(void)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	struct hugepage_info *hpi;
 	int fd_hugepage = -1;
@@ -358,7 +358,7 @@ memseg_primary_init(void)
 	int hpi_idx, msl_idx = 0;
 	struct rte_memseg_list *msl;
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 
 	/* no-huge does not need this at all */
lib/eal/linux/eal.c +51 -4

91 lines not on this page · raw message

lib/eal/linux/eal_hugepage_info.c +1 -1
index a6bf807f90..7be3fe3b65 100644
@@ -518,7 +518,7 @@ hugepage_info_init(void)
 	unsigned int reusable_pages;
 	struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	int failed = 0;
 
 	/* platform_info->hugepage_sizes[] is already sorted largest to smallest */
lib/eal/windows/eal.c +59 -1

95 lines not on this page · raw message

lib/eal/windows/eal_hugepages.c +1 -1
index 0c62f5ff48..0870495c78 100644
@@ -59,7 +59,7 @@ hugepage_claim_privilege(void)
 static int
 hugepage_info_init(void)
 {
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	struct hugepage_info *hpi;
 	unsigned int socket_id;
 	int ret = 0;
lib/eal/windows/eal_memalloc.c +1 -1
index 8a2d3966ba..97947d1bc4 100644
@@ -319,7 +319,7 @@ eal_memalloc_alloc_seg_bulk(struct rte_memseg **ms, int n_segs,
 	int ret = -1;
 	struct alloc_walk_param wa;
 	const struct hugepage_info *hi = NULL;
-	const struct eal_platform_info *platform_info = eal_get_platform_info();
+	const struct eal_platform_info *platform_info = rte_eal_get_platform_info();
 	const struct eal_runtime_state *runtime_state = eal_get_runtime_state();
 	const struct eal_user_cfg *user_cfg = eal_get_user_configuration();
 
Signature · 1 line
2.55.0
#134 lore raw

v2 cover Rework EAL configuration

In reply to Bruce Richardson

This patchset reworks how configuration is stored and managed in EAL. The existing "internal_config", "rte_config", "lcore_config" structures, which sometimes have arbitrary separation between them (especially the first two) are replaced by three new structures with clearly defined roles:

- eal_platform_info - contains the raw HW info for the system, details of CPUs and hugepage mounts. This is initialized on first use - even before EAL init is called - and is then immutable, since our HW should not change much underneath us. Its early availability means that it can be used to sanity check the contents of the other structs as they are being built up.

- eal_user_cfg - contains the config settings passed in by the user. For existing rte_eal_init, this is built up in the arg parse stage, and it's contents verified against the platform info, e.g. to check core masks are valid etc. Once argument parsing is completed, is also immutable.

- runtime_cfg - basically all the runtime settings that need to be there for DPDK to run, or which change over time. Largely combined content of the old rte_config, internal_config and lcore_config structs. This is initialized from the other two structs by eal initialization and can be modified by EAL at any time.

Once that is done, we have a clean separation between user provided configuration and the rest of EAL, we can split EAL init into two parts, the first of which parses cmdline arguments and then calls the second which takes the eal_user_cfg struct result of that parse and does the actual initialization. The longer-term objective is to have other first-stage functions that prepare the user_cfg struct for initialization, so that we can move away from argc/argv as the only method of configuring DPDK initialization.

v2: minor rework following AI review.

Bruce Richardson (39):
telemetry: make cpuset init parameter const
argparse: check for range overflow in CPU lists
eal: define new functionally distinct config structs
eal: move memory request fields to user config
eal: move NUMA request fields to user config
eal: move hugepage policy fields to user config
eal: move process policy fields to user config
eal: move hugepage limit fields to new config structs
eal: move advanced user config options to user cfg struct
eal: move hugepage size info to platform info struct
eal: move runtime state to appropriate structure
eal: record details of all cpus in platform info
eal: use platform info for lcore lookups
eal: add macro for lowest set CPU bit in a set
eal: store lcore configuration in runtime data
eal: move core indices bitset to runtime state
eal: cleanup CPU init function
eal: move NUMA node information to platform info struct
eal: move lcore role and count to runtime state
eal: make lcore role a field in lcore config struct
eal: move main lcore setting to runtime config struct
eal: move IOVA mode and process type to runtime cfg
eal: move memory config pointer to runtime state struct
eal: remove rte_config structure
eal: separate runtime state update from arg parsing
eal: move device options staging list into user cfg
eal: separate plugin paths from loaded plugin objects
eal: simplify internal driver path iteration APIs
eal: move trace config into user config struct
eal: record service cores in user config struct
eal: store user-provided lcore info in user config struct
eal: clarify docs on params taking lcore IDs
eal: remove internal config reset function
eal: move functions setting runtime state
eal: initialize platform info on first use
eal: remove duplicated scan of sysfs for hugepage details
eal: add utilities for working with user config struct
eal: split EAL init into two stages
eal: provide hooks for init with externally supplied config

 app/test/process.h                        |   4 +-
 app/test/test_argparse.c                  |  10 +
 doc/guides/linux_gsg/eal_args.include.rst |  38 +-
 lib/argparse/rte_argparse.c               |   5 +
 lib/eal/common/eal_common_bus.c           |   4 +-
 lib/eal/common/eal_common_config.c        | 267 ++++++-
 lib/eal/common/eal_common_dev.c           |  10 +-
 lib/eal/common/eal_common_dynmem.c        |  70 +-
 lib/eal/common/eal_common_fbarray.c       |  10 +-
 lib/eal/common/eal_common_launch.c        |  25 +-
 lib/eal/common/eal_common_lcore.c         | 267 ++++---
 lib/eal/common/eal_common_mcfg.c          |  44 +-
 lib/eal/common/eal_common_memalloc.c      |   5 +-
 lib/eal/common/eal_common_memory.c        | 104 ++-
 lib/eal/common/eal_common_memzone.c       |  24 +-
 lib/eal/common/eal_common_options.c       | 899 ++++++++--------------
 lib/eal/common/eal_common_proc.c          |  43 +-
 lib/eal/common/eal_common_tailqs.c        |   6 +-
 lib/eal/common/eal_common_thread.c        |  67 +-
 lib/eal/common/eal_common_timer.c         |   2 +-
 lib/eal/common/eal_common_trace.c         |  30 +-
 lib/eal/common/eal_common_trace_utils.c   | 104 ---
 lib/eal/common/eal_hugepages.h            |   8 +
 lib/eal/common/eal_internal_cfg.h         | 385 +++++++--
 lib/eal/common/eal_memcfg.h               |   3 +
 lib/eal/common/eal_option_list.h          |   6 +-
 lib/eal/common/eal_options.h              |   8 +-
 lib/eal/common/eal_private.h              | 121 ++-
 lib/eal/common/eal_trace.h                |  11 -
 lib/eal/common/malloc_elem.c              |  15 +-
 lib/eal/common/malloc_heap.c              |  41 +-
 lib/eal/common/malloc_mp.c                |   2 +-
 lib/eal/common/rte_malloc.c               |  14 +-
 lib/eal/common/rte_service.c              |  17 +-
 lib/eal/freebsd/eal.c                     | 291 ++++---
 lib/eal/freebsd/eal_hugepage_info.c       |  78 +-
 lib/eal/freebsd/eal_lcore.c               |  16 +-
 lib/eal/freebsd/eal_memory.c              |  46 +-
 lib/eal/freebsd/include/rte_os.h          |   2 +
 lib/eal/include/rte_eal.h                 |  35 +-
 lib/eal/include/rte_memzone.h             |  10 +-
 lib/eal/include/rte_tailq.h               |   2 +-
 lib/eal/linux/eal.c                       | 297 ++++---
 lib/eal/linux/eal_hugepage_info.c         | 231 +++---
 lib/eal/linux/eal_lcore.c                 |  43 ++
 lib/eal/linux/eal_memalloc.c              | 168 ++--
 lib/eal/linux/eal_memory.c                | 168 ++--
 lib/eal/linux/eal_timer_hpet.c            |  21 +-
 lib/eal/linux/eal_vfio.c                  |  11 +-
 lib/eal/linux/include/rte_os.h            |  10 +
 lib/eal/unix/eal_unix_thread.c            |  11 +-
 lib/eal/windows/eal.c                     | 197 +++--
 lib/eal/windows/eal_hugepages.c           |  60 +-
 lib/eal/windows/eal_lcore.c               |   6 +
 lib/eal/windows/eal_memalloc.c            |  37 +-
 lib/eal/windows/eal_memory.c              |  14 +-
 lib/eal/windows/eal_thread.c              |  11 +-
 lib/eal/windows/eal_windows.h             |   8 -
 lib/eal/windows/include/rte_os.h          |   1 +
 lib/eal/windows/include/sched.h           |  10 +
 lib/telemetry/telemetry.c                 |   4 +-
 lib/telemetry/telemetry_internal.h        |   2 +-
 62 files changed, 2511 insertions(+), 1948 deletions(-)

--
2.53.0

#135 lore raw

PATCH v2 1/39 telemetry: make cpuset init parameter const

The cpuset parameter to telemetry_init is not modified so can be marked as const. This can allow callers to pass the parameter from a const structure rather than a modifiable one.

---
 lib/telemetry/telemetry.c          | 4 ++--
 lib/telemetry/telemetry_internal.h | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
lib/telemetry/telemetry.c +2 -2
index e591c1e283..956a261c13 100644
@@ -56,7 +56,7 @@ static struct socket v1_socket; /* socket for v1 telemetry */
 
 static const char *telemetry_version; /* save rte_version */
 static const char *socket_dir;        /* runtime directory */
-static rte_cpuset_t *thread_cpuset;
+static const rte_cpuset_t *thread_cpuset;
 
 RTE_LOG_REGISTER_DEFAULT(logtype, WARNING);
 #define RTE_LOGTYPE_TELEMETRY logtype
@@ -658,7 +658,7 @@ telemetry_v2_init(void)
 
 RTE_EXPORT_INTERNAL_SYMBOL(rte_telemetry_init)
 int32_t
-rte_telemetry_init(const char *runtime_dir, const char *rte_version, rte_cpuset_t *cpuset)
+rte_telemetry_init(const char *runtime_dir, const char *rte_version, const rte_cpuset_t *cpuset)
 {
 	telemetry_version = rte_version;
 	socket_dir = runtime_dir;
lib/telemetry/telemetry_internal.h +1 -1
index 2fd9fbd7c1..4a6b2e9838 100644
@@ -119,6 +119,6 @@ typedef int (*rte_log_fn)(uint32_t level, uint32_t logtype, const char *format,
  */
 __rte_internal
 int
-rte_telemetry_init(const char *runtime_dir, const char *rte_version, rte_cpuset_t *cpuset);
+rte_telemetry_init(const char *runtime_dir, const char *rte_version, const rte_cpuset_t *cpuset);
 
 #endif
Signature · 1 line
2.53.0
#136 lore raw

PATCH v2 2/39 argparse: check for range overflow in CPU lists

In reply to Bruce Richardson

The rte_cpuset_t type cannot handle core ids greater than CPU_SETSIZE Add an explicit check for out of range values when processes a corelist.

Fixes d78103fb9488 ("argparse: support core lists")
---
 app/test/test_argparse.c    | 10 ++++++++++
 lib/argparse/rte_argparse.c |  5 +++++
 2 files changed, 15 insertions(+)
app/test/test_argparse.c +10 -0
index fdc6dd113c..318f8df9fb 100644
@@ -834,9 +834,13 @@ test_argparse_parse_type_corelist(void)
 	char *corelist_invalid_special_chars = test_strdup("1,2@3");
 	char *corelist_invalid_comma_only = test_strdup(",");
 	char *corelist_invalid_out_of_range = test_strdup("70000");
+	char corelist_invalid_cpu_set[32];
 	rte_cpuset_t val_cpuset;
 	int ret;
 
+	snprintf(corelist_invalid_cpu_set, sizeof(corelist_invalid_cpu_set),
+		"0-%d", CPU_SETSIZE);
+
 	/* test valid single core */
 	CPU_ZERO(&val_cpuset);
 	ret = rte_argparse_parse_type(corelist_valid_single,
@@ -966,6 +970,12 @@ test_argparse_parse_type_corelist(void)
 			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
 	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (out of range) should have failed!");
 
+	/* test invalid corelist that exceeds the destination CPU set */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_cpu_set,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist outside CPU set should have failed!");
+
 	return 0;
 }
 
lib/argparse/rte_argparse.c +5 -0
index 88c3e7740c..158c413bdc 100644
@@ -623,6 +623,11 @@ parse_arg_corelist(const struct rte_argparse_arg *arg, const char *value)
 				/* range from low to high */
 				max = idx;
 			}
+			if (max >= CPU_SETSIZE) {
+				ARGPARSE_LOG(ERR, "argument %s contains a core outside the CPU set range!",
+					arg->name_long);
+				return -EINVAL;
+			}
 
 			for (; min <= max; min++)
 				CPU_SET(min, cpuset);
Signature · 1 line
2.53.0
#137 lore raw

PATCH v2 3/39 eal: define new functionally distinct config structs

In reply to Bruce Richardson

Rather than having a generic internal_config structure which mixes system configuration, memory configuration, and user options in one struct, create separate structures for the platform info, system runtime state and the user provided config. Later patches will complete these with data moved from the current location.

---
 lib/eal/common/eal_common_config.c | 31 ++++++++++++++++++++++++++++++
 lib/eal/common/eal_internal_cfg.h  | 28 +++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
lib/eal/common/eal_common_config.c +31 -0
index e2e69a75fb..5427b30659 100644
@@ -5,6 +5,7 @@
 #include <rte_string_fns.h>
 
 #include <eal_export.h>
+#include "eal_internal_cfg.h"
 #include "eal_private.h"
 #include "eal_filesystem.h"
 #include "eal_memcfg.h"
@@ -27,6 +28,15 @@ static struct rte_config rte_config = {
 /* platform-specific runtime dir */
 static char runtime_dir[UNIX_PATH_MAX];
 
+/* user-provided EAL configuration */
+static struct eal_user_cfg eal_user_cfg;
+
+/* platform-discovered and runtime EAL state */
+static struct eal_platform_info eal_platform_info;
+
+/* internal runtime configuration */
+static struct eal_runtime_state eal_runtime_state;
+
 /* internal configuration */
 static struct internal_config internal_config;
 
@@ -63,6 +73,27 @@ eal_get_internal_configuration(void)
 	return &internal_config;
 }
 
+/* Return a pointer to the user configuration structure */
+struct eal_user_cfg *
+eal_get_user_configuration(void)
+{
+	return &eal_user_cfg;
+}
+
+/* Return a pointer to the platform state structure */
+struct eal_platform_info *
+eal_get_platform_info(void)
+{
+	return &eal_platform_info;
+}
+
+/* Return a pointer to the runtime state structure */
+struct eal_runtime_state *
+eal_get_runtime_state(void)
+{
+	return &eal_runtime_state;
+}
+
 RTE_EXPORT_SYMBOL(rte_eal_iova_mode)
 enum rte_iova_mode
 rte_eal_iova_mode(void)
lib/eal/common/eal_internal_cfg.h +28 -0
index 07cd35167d..66224e7c75 100644
@@ -48,6 +48,31 @@ struct hugepage_file_discipline {
 	bool unlink_existing;
 };
 
+/**
+ * User-provided EAL initialization configuration.
+ * Immutable after initialization, so no need for atomic types or locks.
+ */
+struct eal_user_cfg {
+	uint8_t reserved;
+};
+
+/**
+ * Discovered information about cores, memory, etc. on the system.
+ * Immutable after initialization, so no need for atomic types or locks.
+ */
+struct eal_platform_info {
+	uint8_t reserved;
+};
+
+/**
+ * Internal EAL runtime state
+ * May be modified at runtime, so access must be protected by locks or atomic types
+ * as appropriate.
+ */
+struct eal_runtime_state {
+	uint8_t reserved;
+};
+
 /**
  * internal configuration
  */
@@ -115,6 +140,9 @@ struct internal_config {
 	unsigned int no_auto_probing; /**< true to switch from block-listing to allow-listing */
 };
 
+struct eal_user_cfg *eal_get_user_configuration(void);
+struct eal_platform_info *eal_get_platform_info(void);
+struct eal_runtime_state *eal_get_runtime_state(void);
 void eal_reset_internal_config(struct internal_config *internal_cfg);
 
 #endif /* EAL_INTERNAL_CFG_H */
Signature · 1 line
2.53.0