[dpdk-dev] [PATCH v3 1/6] ethdev: fix port data mismatched in multiple process model

Thomas Monjalon thomas.monjalon at 6wind.com
Fri Jan 6 14:12:48 CET 2017


2017-01-06 18:16, Yuanhan Liu:
> +static void
> +eth_dev_init(struct rte_eth_dev *eth_dev, uint8_t port_id, const char *name)
> +{
> +	eth_dev->data = &rte_eth_dev_data[port_id];
> +	eth_dev->attached = DEV_ATTACHED;
> +	eth_dev_last_created_port = port_id;
> +	nb_ports++;
> +
> +	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
> +		snprintf(eth_dev->data->name, sizeof(eth_dev->data->name),
> +			 "%s", name);
> +		eth_dev->data->port_id = port_id;
> +	}

Why not keeping eth_dev->data filling in rte_eth_dev_allocate?

> +}
> +
>  struct rte_eth_dev *
>  rte_eth_dev_allocate(const char *name)
>  {
> @@ -211,12 +226,41 @@ struct rte_eth_dev *
>  	}
>  
>  	eth_dev = &rte_eth_devices[port_id];

Why not moving this line in eth_dev_init?

> -	eth_dev->data = &rte_eth_dev_data[port_id];
> -	snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name);
> -	eth_dev->data->port_id = port_id;
> -	eth_dev->attached = DEV_ATTACHED;
> -	eth_dev_last_created_port = port_id;
> -	nb_ports++;
> +	eth_dev_init(eth_dev, port_id, name);
> +
> +	return eth_dev;
> +}

[...]
> +/*
> + * Attach to a port already registered by the primary process, which
> + * makes sure that the same device would have the same port id both
> + * in the primary and secondary process.
> + */
> +static struct rte_eth_dev *
> +eth_dev_attach_secondary(const char *name)

OK, good description

[...]
> -	eth_dev = rte_eth_dev_allocate(ethdev_name);
> -	if (eth_dev == NULL)
> -		return -ENOMEM;
> +	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
> +		eth_dev = rte_eth_dev_allocate(ethdev_name);
> +		if (eth_dev == NULL)
> +			return -ENOMEM;

You could merge here the rest of primary init below.

> +	} else {
> +		eth_dev = eth_dev_attach_secondary(ethdev_name);
> +		if (eth_dev == NULL) {
> +			/*
> +			 * if we failed to attach a device, it means
> +			 * the device is skipped, due to some errors.
> +			 * Take virtio-net device as example, it could
> +			 * due to the device is managed by virtio-net
> +			 * kernel driver.  For such case, we return a
> +			 * positive value, to let EAL skip it as well.
> +			 */

I'm not sure we need an example here.
Is the virtio case special?

nit: "it could due" looks to be a typo

> +			return 1;
> +		}
> +	}
>  
>  	if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
>  		eth_dev->data->dev_private = rte_zmalloc("ethdev private structure",




More information about the dev mailing list