[dpdk-dev,1/7] eal: use different constructor priorities for initcalls
Checks
Commit Message
This introduces different initcall macros to allow for late registration of
the virtual device bus.
Signed-off-by: Jan Blunck <jblunck@infradead.org>
---
lib/librte_eal/common/include/rte_bus.h | 17 ++++++++++++++++-
lib/librte_eal/common/include/rte_eal.h | 12 ++++++++++--
lib/librte_eal/common/include/rte_tailq.h | 2 +-
3 files changed, 27 insertions(+), 4 deletions(-)
Comments
On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
> This introduces different initcall macros to allow for late registration of
> the virtual device bus.
>
> Signed-off-by: Jan Blunck <jblunck@infradead.org>
> ---
> lib/librte_eal/common/include/rte_bus.h | 17 ++++++++++++++++-
> lib/librte_eal/common/include/rte_eal.h | 12 ++++++++++--
> lib/librte_eal/common/include/rte_tailq.h | 2 +-
> 3 files changed, 27 insertions(+), 4 deletions(-)
>
> diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
> index 7c36969..9f161f2 100644
> --- a/lib/librte_eal/common/include/rte_bus.h
> +++ b/lib/librte_eal/common/include/rte_bus.h
> @@ -50,6 +50,7 @@ extern "C" {
> #include <stdio.h>
> #include <sys/queue.h>
>
> +#include <rte_eal.h>
> #include <rte_log.h>
> #include <rte_dev.h>
>
> @@ -145,7 +146,21 @@ void rte_bus_dump(FILE *f);
> * The constructor has higher priority than PMD constructors.
> */
> #define RTE_REGISTER_BUS(nm, bus) \
> -static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
> +RTE_EAL_INIT(businitfn_ ##nm); \
> +static void businitfn_ ##nm(void) \
> +{\
> + (bus).name = RTE_STR(nm);\
> + rte_bus_register(&bus); \
> +}
> +
> +/**
> + * Helper for late Bus registration.
> + * The constructor still has higher priority than PMD constructors but has
> + * lower priority than RTE_REGISTER_BUS.
> + */
> +#define RTE_REGISTER_BUS_LATE(nm, bus) \
> +RTE_POST_EAL_INIT(businitfn_ ##nm); \
> +static void businitfn_ ##nm(void) \
> {\
> (bus).name = RTE_STR(nm);\
> rte_bus_register(&bus); \
> diff --git a/lib/librte_eal/common/include/rte_eal.h b/lib/librte_eal/common/include/rte_eal.h
> index 03fee50..3a6bd71 100644
> --- a/lib/librte_eal/common/include/rte_eal.h
> +++ b/lib/librte_eal/common/include/rte_eal.h
> @@ -258,8 +258,16 @@ static inline int rte_gettid(void)
> return RTE_PER_LCORE(_thread_id);
> }
>
> -#define RTE_INIT(func) \
> -static void __attribute__((constructor, used)) func(void)
> +#define RTE_EAL_INIT(func) \
> +static void __attribute__((constructor(101), used)) func(void)
> +
> +#define RTE_POST_EAL_INIT(func) \
> +static void __attribute__((constructor(102), used)) func(void)
> +
> +#define RTE_DEV_INIT(func) \
> +static void __attribute__((constructor(103), used)) func(void)
Shouldn't we simply allow this priority to be default to allow for some
priority space between buses and default init?
> +
> +#define RTE_INIT(func) RTE_DEV_INIT(func)
>
> #ifdef __cplusplus
> }
> diff --git a/lib/librte_eal/common/include/rte_tailq.h b/lib/librte_eal/common/include/rte_tailq.h
> index 3aae098..07ceec1 100644
> --- a/lib/librte_eal/common/include/rte_tailq.h
> +++ b/lib/librte_eal/common/include/rte_tailq.h
> @@ -148,7 +148,7 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
> int rte_eal_tailq_register(struct rte_tailq_elem *t);
>
> #define EAL_REGISTER_TAILQ(t) \
> -RTE_INIT(tailqinitfn_ ##t); \
> +RTE_EAL_INIT(tailqinitfn_ ##t); \
> static void tailqinitfn_ ##t(void) \
> { \
> if (rte_eal_tailq_register(&t) < 0) \
>
On Wed, Feb 15, 2017 at 3:37 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>>
>> --- a/lib/librte_eal/common/include/rte_eal.h
>> +++ b/lib/librte_eal/common/include/rte_eal.h
>> @@ -258,8 +258,16 @@ static inline int rte_gettid(void)
>> return RTE_PER_LCORE(_thread_id);
>> }
>>
>> -#define RTE_INIT(func) \
>> -static void __attribute__((constructor, used)) func(void)
>> +#define RTE_EAL_INIT(func) \
>> +static void __attribute__((constructor(101), used)) func(void)
>> +
>> +#define RTE_POST_EAL_INIT(func) \
>> +static void __attribute__((constructor(102), used)) func(void)
>> +
>> +#define RTE_DEV_INIT(func) \
>> +static void __attribute__((constructor(103), used)) func(void)
>
>
> Shouldn't we simply allow this priority to be default to allow for some
> priority space between buses and default init?
>
The absolute numbers are not that important. We can always adjust
them. Important is the relative order. If you have a use-case for
something that needs to be initialized before the devices but can't
get initialized with the eal/post-eal then please speak up.
On Wednesday 15 February 2017 08:35 PM, Jan Blunck wrote:
> On Wed, Feb 15, 2017 at 3:37 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> On Wednesday 15 February 2017 03:32 PM, Jan Blunck wrote:
>>>
>>> --- a/lib/librte_eal/common/include/rte_eal.h
>>> +++ b/lib/librte_eal/common/include/rte_eal.h
>>> @@ -258,8 +258,16 @@ static inline int rte_gettid(void)
>>> return RTE_PER_LCORE(_thread_id);
>>> }
>>>
>>> -#define RTE_INIT(func) \
>>> -static void __attribute__((constructor, used)) func(void)
>>> +#define RTE_EAL_INIT(func) \
>>> +static void __attribute__((constructor(101), used)) func(void)
>>> +
>>> +#define RTE_POST_EAL_INIT(func) \
>>> +static void __attribute__((constructor(102), used)) func(void)
>>> +
>>> +#define RTE_DEV_INIT(func) \
>>> +static void __attribute__((constructor(103), used)) func(void)
>>
>>
>> Shouldn't we simply allow this priority to be default to allow for some
>> priority space between buses and default init?
>>
>
> The absolute numbers are not that important. We can always adjust
> them. Important is the relative order. If you have a use-case for
> something that needs to be initialized before the devices but can't
> get initialized with the eal/post-eal then please speak up.
>
No use-case as of now.
@@ -50,6 +50,7 @@ extern "C" {
#include <stdio.h>
#include <sys/queue.h>
+#include <rte_eal.h>
#include <rte_log.h>
#include <rte_dev.h>
@@ -145,7 +146,21 @@ void rte_bus_dump(FILE *f);
* The constructor has higher priority than PMD constructors.
*/
#define RTE_REGISTER_BUS(nm, bus) \
-static void __attribute__((constructor(101), used)) businitfn_ ##nm(void) \
+RTE_EAL_INIT(businitfn_ ##nm); \
+static void businitfn_ ##nm(void) \
+{\
+ (bus).name = RTE_STR(nm);\
+ rte_bus_register(&bus); \
+}
+
+/**
+ * Helper for late Bus registration.
+ * The constructor still has higher priority than PMD constructors but has
+ * lower priority than RTE_REGISTER_BUS.
+ */
+#define RTE_REGISTER_BUS_LATE(nm, bus) \
+RTE_POST_EAL_INIT(businitfn_ ##nm); \
+static void businitfn_ ##nm(void) \
{\
(bus).name = RTE_STR(nm);\
rte_bus_register(&bus); \
@@ -258,8 +258,16 @@ static inline int rte_gettid(void)
return RTE_PER_LCORE(_thread_id);
}
-#define RTE_INIT(func) \
-static void __attribute__((constructor, used)) func(void)
+#define RTE_EAL_INIT(func) \
+static void __attribute__((constructor(101), used)) func(void)
+
+#define RTE_POST_EAL_INIT(func) \
+static void __attribute__((constructor(102), used)) func(void)
+
+#define RTE_DEV_INIT(func) \
+static void __attribute__((constructor(103), used)) func(void)
+
+#define RTE_INIT(func) RTE_DEV_INIT(func)
#ifdef __cplusplus
}
@@ -148,7 +148,7 @@ struct rte_tailq_head *rte_eal_tailq_lookup(const char *name);
int rte_eal_tailq_register(struct rte_tailq_elem *t);
#define EAL_REGISTER_TAILQ(t) \
-RTE_INIT(tailqinitfn_ ##t); \
+RTE_EAL_INIT(tailqinitfn_ ##t); \
static void tailqinitfn_ ##t(void) \
{ \
if (rte_eal_tailq_register(&t) < 0) \