forked from DPDK/dpdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Marchand <[email protected]>
- Loading branch information
1 parent
1b3bf11
commit c07a1bd
Showing
8 changed files
with
217 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
*/ | ||
|
||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
#include <rte_common.h> | ||
|
||
static bool init_called; | ||
|
||
RTE_TAILQ_HEAD(, rte_init) rte_init_list; | ||
struct rte_init { | ||
RTE_TAILQ_ENTRY(rte_init) next; | ||
unsigned int priority; | ||
const char *file; | ||
int line; | ||
void (*init)(void); | ||
}; | ||
|
||
void | ||
rte_init_register(const char *file, int line, 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) { | ||
printf("Late init for %s:%d, priority %u\n", file, line, priority); | ||
init(); | ||
return; | ||
} | ||
|
||
i = malloc(sizeof(*i)); | ||
if (i == NULL) | ||
return; | ||
|
||
i->priority = priority; | ||
i->file = file; | ||
i->line = line; | ||
i->init = init; | ||
|
||
TAILQ_FOREACH(p, &rte_init_list, next) { | ||
if (i->priority >= p->priority) | ||
continue; | ||
TAILQ_INSERT_BEFORE(p, i, next); | ||
} | ||
|
||
TAILQ_INSERT_HEAD(&rte_init_list, i, next); | ||
} | ||
|
||
void | ||
eal_init_early(void) | ||
{ | ||
struct rte_init *i; | ||
|
||
init_called = true; | ||
|
||
TAILQ_FOREACH(i, &rte_init_list, next) { | ||
printf("Init for %s:%d, priority %u\n", i->file, i->line, i->priority); | ||
i->init(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* SPDX-License-Identifier: BSD-3-Clause | ||
* Copyright(c) 2010-2019 Intel Corporation | ||
*/ | ||
|
||
#ifndef RTE_INIT_H | ||
#define RTE_INIT_H | ||
|
||
#include <rte_compat.h> | ||
|
||
__rte_experimental | ||
void | ||
rte_init_register(const char *file, int line, 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 | ||
#define RTE_PRIORITY_LAST 65535 | ||
|
||
#define RTE_PRIO(prio) \ | ||
RTE_PRIORITY_ ## prio | ||
|
||
/** | ||
* Run function before main() with high priority. | ||
* | ||
* @param func | ||
* Constructor function. | ||
* @param prio | ||
* Priority number must be above 100. | ||
* Lowest number is the first to run. | ||
*/ | ||
#ifndef RTE_INIT_PRIO /* Allow to override from EAL */ | ||
#ifndef RTE_TOOLCHAIN_MSVC | ||
#define RTE_INIT_PRIO(func, prio) \ | ||
static void func(void); \ | ||
static void __attribute__((constructor(RTE_PRIO(prio)), used)) init_ ## func(void) \ | ||
{ \ | ||
rte_init_register(__FILE__, __LINE__, func, RTE_PRIO(prio)); \ | ||
} \ | ||
static void func(void) | ||
#else | ||
/* definition from the Microsoft CRT */ | ||
typedef int(__cdecl *_PIFV)(void); | ||
|
||
#define CTOR_SECTION_LOG ".CRT$XIB" | ||
#define CTOR_SECTION_BUS ".CRT$XIC" | ||
#define CTOR_SECTION_CLASS ".CRT$XID" | ||
#define CTOR_SECTION_LAST ".CRT$XIY" | ||
|
||
#define CTOR_PRIORITY_TO_SECTION(priority) CTOR_SECTION_ ## priority | ||
|
||
#define RTE_INIT_PRIO(name, priority) \ | ||
static void name(void); \ | ||
static int __cdecl name ## _thunk(void) { name(); return 0; } \ | ||
__pragma(const_seg(CTOR_PRIORITY_TO_SECTION(priority))) \ | ||
__declspec(allocate(CTOR_PRIORITY_TO_SECTION(priority))) \ | ||
_PIFV name ## _pointer = &name ## _thunk; \ | ||
__pragma(const_seg()) \ | ||
static void name(void) | ||
#endif | ||
#endif | ||
|
||
/** | ||
* Run function before main() with low priority. | ||
* | ||
* The constructor will be run after prioritized constructors. | ||
* | ||
* @param func | ||
* Constructor function. | ||
*/ | ||
#define RTE_INIT(func) \ | ||
RTE_INIT_PRIO(func, LAST) | ||
|
||
/** | ||
* Run after main() with low priority. | ||
* | ||
* @param func | ||
* Destructor function name. | ||
* @param prio | ||
* Priority number must be above 100. | ||
* Lowest number is the last to run. | ||
*/ | ||
#ifndef RTE_FINI_PRIO /* Allow to override from EAL */ | ||
#ifndef RTE_TOOLCHAIN_MSVC | ||
#define RTE_FINI_PRIO(func, prio) \ | ||
static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) | ||
#else | ||
#define DTOR_SECTION_LOG "mydtor$B" | ||
#define DTOR_SECTION_BUS "mydtor$C" | ||
#define DTOR_SECTION_CLASS "mydtor$D" | ||
#define DTOR_SECTION_LAST "mydtor$Y" | ||
|
||
#define DTOR_PRIORITY_TO_SECTION(priority) DTOR_SECTION_ ## priority | ||
|
||
#define RTE_FINI_PRIO(name, priority) \ | ||
static void name(void); \ | ||
__pragma(const_seg(DTOR_PRIORITY_TO_SECTION(priority))) \ | ||
__declspec(allocate(DTOR_PRIORITY_TO_SECTION(priority))) void *name ## _pointer = &name; \ | ||
__pragma(const_seg()) \ | ||
static void name(void) | ||
#endif | ||
#endif | ||
|
||
/** | ||
* Run after main() with high priority. | ||
* | ||
* The destructor will be run *before* prioritized destructors. | ||
* | ||
* @param func | ||
* Destructor function name. | ||
*/ | ||
#define RTE_FINI(func) \ | ||
RTE_FINI_PRIO(func, LAST) | ||
|
||
#endif /* RTE_INIT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
EXPERIMENTAL { | ||
global: | ||
|
||
rte_init_register; | ||
|
||
local: *; | ||
}; | ||
|
||
INTERNAL { | ||
global: | ||
|
||
eal_init_early; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters