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 d9a7bfb
Show file tree
Hide file tree
Showing 5 changed files with 94 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')
63 changes: 63 additions & 0 deletions lib/init/rte_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (c) 2024 Red Hat, Inc.
*/

#include <stdbool.h>
#include <stdlib.h>

#include <rte_common.h>
#include <rte_tailq.h>

static bool init_called;

static RTE_TAILQ_HEAD(, rte_init) init_list = TAILQ_HEAD_INITIALIZER(init_list);
struct rte_init {
RTE_TAILQ_ENTRY(rte_init) next;
unsigned int priority;
const char *func;
void (*init)(void);
};

void
rte_init_register(const char *func, void (*init)(void), unsigned int priority)
{
struct rte_init *p;
struct rte_init *i;

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

i = malloc(sizeof(*i));
if (i == NULL)
return;

i->priority = priority;
i->func = func;
i->init = init;

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->init();
}
18 changes: 17 additions & 1 deletion lib/init/rte_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
#ifndef RTE_INIT_H
#define RTE_INIT_H

#include <rte_os.h>

#include <rte_compat.h>

void
rte_init_register(const char *func, void (*init)(void), unsigned int prio);

__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 +36,12 @@
#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 void __attribute__((constructor(RTE_PRIO(prio)), used)) init_ ## func(void) \
{ \
rte_init_register(#func, func, RTE_PRIO(prio)); \
} \
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 d9a7bfb

Please sign in to comment.