[dpdk-dev,v9,06/25] eal: introduce init macros
Commit Message
Introduce a RTE_INIT macro used to mark an init function as a constructor.
Current eal macros have been converted to use this (no functional impact).
DRIVER_REGISTER_PCI is added as a helper for pci drivers.
Suggested-by: Jan Viktorin <viktorin@rehivetech.com>
Signed-off-by: David Marchand <david.marchand@6wind.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain@nxp.com>
---
lib/librte_eal/common/include/rte_dev.h | 4 ++--
lib/librte_eal/common/include/rte_eal.h | 3 +++
lib/librte_eal/common/include/rte_pci.h | 10 ++++++++++
lib/librte_eal/common/include/rte_tailq.h | 4 ++--
4 files changed, 17 insertions(+), 4 deletions(-)
Comments
On Wed, Sep 7, 2016 at 4:07 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
> diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
> index fa74962..cf673e4 100644
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -470,6 +470,16 @@ void rte_eal_pci_dump(FILE *f);
> */
> void rte_eal_pci_register(struct rte_pci_driver *driver);
>
> +/** Helper for PCI device registeration from driver (eth, crypto) instance */
Typo: registration
> +#define DRIVER_REGISTER_PCI(nm, pci_drv) \
> +RTE_INIT(pciinitfn_ ##nm); \
> +static void pciinitfn_ ##nm(void) \
> +{ \
> + (pci_drv).name = RTE_STR(nm);\
> + rte_eal_pci_register(&pci_drv); \
> +}\
> +DRIVER_EXPORT_NAME(nm, __COUNTER__)
Checkpatch complains about a missing space.
On Monday 12 September 2016 12:45 PM, David Marchand wrote:
> On Wed, Sep 7, 2016 at 4:07 PM, Shreyansh Jain <shreyansh.jain@nxp.com> wrote:
>> diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
>> index fa74962..cf673e4 100644
>> --- a/lib/librte_eal/common/include/rte_pci.h
>> +++ b/lib/librte_eal/common/include/rte_pci.h
>> @@ -470,6 +470,16 @@ void rte_eal_pci_dump(FILE *f);
>> */
>> void rte_eal_pci_register(struct rte_pci_driver *driver);
>>
>> +/** Helper for PCI device registeration from driver (eth, crypto) instance */
>
> Typo: registration
Ok - I will fix this.
>
>> +#define DRIVER_REGISTER_PCI(nm, pci_drv) \
>> +RTE_INIT(pciinitfn_ ##nm); \
>> +static void pciinitfn_ ##nm(void) \
>> +{ \
>> + (pci_drv).name = RTE_STR(nm);\
>> + rte_eal_pci_register(&pci_drv); \
>> +}\
>> +DRIVER_EXPORT_NAME(nm, __COUNTER__)
>
> Checkpatch complains about a missing space.
Yes, '} \' is expected. somehow missed my merges though checkpatch did
complain. Will fix this.
>
>
@@ -185,8 +185,8 @@ static const char DRIVER_EXPORT_NAME_ARRAY(this_pmd_name, idx) \
__attribute__((used)) = RTE_STR(name)
#define PMD_REGISTER_DRIVER(drv, nm)\
-void devinitfn_ ##drv(void);\
-void __attribute__((constructor, used)) devinitfn_ ##drv(void)\
+RTE_INIT(devinitfn_ ##drv);\
+static void devinitfn_ ##drv(void)\
{\
(drv).name = RTE_STR(nm);\
rte_eal_driver_register(&drv);\
@@ -252,6 +252,9 @@ static inline int rte_gettid(void)
return RTE_PER_LCORE(_thread_id);
}
+#define RTE_INIT(func) \
+static void __attribute__((constructor, used)) func(void)
+
#ifdef __cplusplus
}
#endif
@@ -470,6 +470,16 @@ void rte_eal_pci_dump(FILE *f);
*/
void rte_eal_pci_register(struct rte_pci_driver *driver);
+/** Helper for PCI device registeration from driver (eth, crypto) instance */
+#define DRIVER_REGISTER_PCI(nm, pci_drv) \
+RTE_INIT(pciinitfn_ ##nm); \
+static void pciinitfn_ ##nm(void) \
+{ \
+ (pci_drv).name = RTE_STR(nm);\
+ rte_eal_pci_register(&pci_drv); \
+}\
+DRIVER_EXPORT_NAME(nm, __COUNTER__)
+
/**
* Unregister a PCI driver.
*
@@ -148,8 +148,8 @@ 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) \
-void tailqinitfn_ ##t(void); \
-void __attribute__((constructor, used)) tailqinitfn_ ##t(void) \
+RTE_INIT(tailqinitfn_ ##t); \
+static void tailqinitfn_ ##t(void) \
{ \
if (rte_eal_tailq_register(&t) < 0) \
rte_panic("Cannot initialize tailq: %s\n", t.name); \