Skip to content

Commit

Permalink
init: defer component init in EAL init
Browse files Browse the repository at this point in the history
Signed-off-by: David Marchand <[email protected]>
  • Loading branch information
david-marchand committed Dec 4, 2024
1 parent 58aec28 commit 8f0a286
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/eal/linux/eal.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,8 @@ rte_eal_init(int argc, char **argv)
struct internal_config *internal_conf =
eal_get_internal_configuration();

eal_init_early();

/* setup log as early as possible */
if (eal_parse_log_options(argc, argv) < 0) {
rte_eal_init_alert("invalid log arguments.");
Expand Down
2 changes: 2 additions & 0 deletions lib/init/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Red Hat, Inc.

includes += global_inc
sources = files('rte_init.c')
headers = files('rte_init.h')
50 changes: 50 additions & 0 deletions lib/init/rte_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2024 Red Hat, Inc.
*/

#include <stdbool.h>
#include <sys/queue.h>

#include <rte_os.h>

#include <rte_common.h>
#include <rte_init.h>

static bool init_called;

static TAILQ_HEAD(, rte_init) init_list = TAILQ_HEAD_INITIALIZER(init_list);

void
rte_init_register(struct rte_init *i)
{
struct rte_init *p;

/*
* This code has been invoked after rte_eal_init() (common case is with drivers loaded
* as shared libraries).
*/
if (init_called) {
i->callback();
return;
}

TAILQ_FOREACH(p, &init_list, next) {
if (i->priority >= p->priority)
continue;
TAILQ_INSERT_BEFORE(p, i, next);
return;
}

TAILQ_INSERT_TAIL(&init_list, i, next);
}

void
eal_init_early(void)
{
struct rte_init *i;

init_called = true;

TAILQ_FOREACH(i, &init_list, next)
i->callback();
}
29 changes: 28 additions & 1 deletion lib/init/rte_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
#ifndef RTE_INIT_H
#define RTE_INIT_H

#include <sys/queue.h>

#include <rte_os.h>

#include <rte_compat.h>

struct rte_init {
TAILQ_ENTRY(rte_init) next;
unsigned int priority;
void (*callback)(void);
};
void
rte_init_register(struct rte_init *i);

__rte_internal
void
eal_init_early(void);

#define RTE_PRIORITY_LOG 101
#define RTE_PRIORITY_BUS 110
#define RTE_PRIORITY_CLASS 120
Expand All @@ -25,7 +43,16 @@
#ifndef RTE_INIT_PRIO /* Allow to override from EAL */
#ifndef RTE_TOOLCHAIN_MSVC
#define RTE_INIT_PRIO(func, prio) \
static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void)
static void func(void); \
static struct rte_init init_obj_ ## func; \
static void __attribute__((constructor(RTE_PRIO(prio)), used)) init_ ## func(void) \
{ \
struct rte_init *i = &init_obj_ ## func; \
i->callback = func; \
i->priority = RTE_PRIO(prio); \
rte_init_register(i); \
} \
static void func(void)
#else
/* definition from the Microsoft CRT */
typedef int(__cdecl *_PIFV)(void);
Expand Down
10 changes: 10 additions & 0 deletions lib/init/version.map
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
DPDK_25 {
global:

rte_init_register;

local: *;
};

INTERNAL {
global:

eal_init_early;
};

0 comments on commit 8f0a286

Please sign in to comment.