[dpdk-dev] [PATCH 07/11] ethdev: add lock to port allocation check

Stephen Hemminger stephen at networkplumber.org
Fri May 11 00:29:37 CEST 2018


On Fri, 11 May 2018 00:10:19 +0200
Thomas Monjalon <thomas at monjalon.net> wrote:

> 10/05/2018 22:33, Stephen Hemminger:
> > On Wed,  9 May 2018 11:43:33 +0200
> > Thomas Monjalon <thomas at monjalon.net> wrote:
> >   
> > >  
> > > +struct rte_eth_dev *
> > > +rte_eth_dev_allocated(const char *name)
> > > +{
> > > +	struct rte_eth_dev *ethdev;
> > > +
> > > +	rte_eth_dev_shared_data_prepare();
> > > +
> > > +	rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock);
> > > +
> > > +	ethdev = rte_eth_dev_allocated_lock_free(name);
> > > +
> > > +	rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
> > > +
> > > +	return ethdev;
> > > +}
> > > +  
> > 
> > Not sure about this. The code it self is correct, but it creates
> > a racy semantic.
> > 
> > If caller doesn't already hold a lock then there is no guarantee that
> > the device returned won't be destroyed by some other thread  
> 
> It is an old high level design decision in DPDK:
> We do not hold a lock during the whole life of a port.
> So it is the application responsibility to not mess its own ports.
> The consequence is that one port must be managed by only one thread.
> 
> We can discuss the original thread design but it is out of the
> scope of this patchset.
> 
> > or that the name was just allocated by some other process.  
> 
> It does not say which process allocated the port, yes.
> But the name is unique among processes.
> So the process knows for sure what to do with the port having this name.

For future, I would like to change rte_eth_devices from an array of structures to
an array of pointers.  Reserving a port could be done with atomic exchange, and keep
a bitmap as hint for next free port to choose.  When supporting tunnels etc, it makes sense
to support lots of ports (like > 16 bit); and devices may come and go.

Also, change link state in eth device into full operational state value.
That should be enough to cover both tunnel and failsafe usage, and existing state
value can go away.

The ownership model should also be expressed more as functional operations in the
device model. It needs to be used consistently in multiple places, allow more layering
and also have more error checks builtin.





More information about the dev mailing list