[dpdk-dev] [PATCH 03/15] pmd: Add PMD_REGISTER_DRIVER macro

Neil Horman nhorman at tuxdriver.com
Wed Apr 16 15:08:48 CEST 2014


On Wed, Apr 16, 2014 at 01:52:49PM +0200, Thomas Monjalon wrote:
> 2014-04-15 14:05, Neil Horman:
> > Rather than have each driver have to remember to add a constructor to it to
> > make sure its gets registered properly, wrap that process up in a macro to
> > make registration a one line affair.  This also sets the stage for us to
> > make registration of vdev pmds and physical pmds a uniform process
> > 
> > Signed-off-by: Neil Horman <nhorman at tuxdriver.com>
> 
> Could you explain why having a macro is better than an explicit constructor 
> function?
> 
Because its a one line declaration inside a driver function that points to the
structure used to initilze the pmd?  Having to append ((__constructor__)) to
each initalization function is both error prone during entry and exposes the
possibiilty of developers doing "too much" in their constructor.  It also allows
for easy updating to all drivers, if additional boilerplate work needs to be
done in the future for all pmds.

> > +enum rte_pmd_driver_type {
> > +	PMD_VDEV = 1
> > +};
> > +
> > +extern void rte_eal_nonpci_dev_init_register(const char *name, int
> > (*dev_initfn)(const char *, const char *)); +#define PMD_REGISTER_DRIVER(d,
> > t)\
> > +void devinitfn_ ##d(void);\
> > +void __attribute__((constructor, used)) devinitfn_ ##d(void)\
> > +{\
> > +	enum rte_pmd_driver_type _t = (t);\
> > +	switch(_t)\
> > +	{\
> > +		case PMD_VDEV:\
> > +			rte_eal_vdev_driver_register(&d);\
> > +			break;\
> > +	};\
> 
> Are you sure this switch is needed?
> You are removing it in patch 7.
> 
I think you answered your own question :).  It was needed when this patch was
written because the physical pmd regitration differed from the virtual pmd.  As
you note though, its removed in patch 7 because we merged the registration
methods.  Could I merge them earlier?  sure, but its not at all needed.  It
works in this invocation, and it works (better in the final version at the end
of the series).

> If someone else think this macro is a good idea, or not, speak now :)
> 
I'm speaking up, its a good idea :)

> -- 
> Thomas
> 


More information about the dev mailing list