From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH v3 1/6] ethdev: fix port data mismatched in multiple process model Date: Fri, 06 Jan 2017 14:12:48 +0100 Message-ID: <16135200.seSVc815in@xps13> References: <1482922962-21036-1-git-send-email-yuanhan.liu@linux.intel.com> <1483697780-12088-1-git-send-email-yuanhan.liu@linux.intel.com> <1483697780-12088-2-git-send-email-yuanhan.liu@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit Cc: dev@dpdk.org, Ferruh Yigit To: Yuanhan Liu , Bruce Richardson Return-path: Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by dpdk.org (Postfix) with ESMTP id 3E5D72946 for ; Fri, 6 Jan 2017 14:12:50 +0100 (CET) Received: by mail-wm0-f46.google.com with SMTP id k184so28727229wme.1 for ; Fri, 06 Jan 2017 05:12:50 -0800 (PST) In-Reply-To: <1483697780-12088-2-git-send-email-yuanhan.liu@linux.intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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",