From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id C755CD59A for ; Thu, 5 Jan 2017 07:24:12 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP; 04 Jan 2017 22:24:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,319,1477983600"; d="scan'208";a="1108211323" Received: from yliu-dev.sh.intel.com (HELO yliu-dev) ([10.239.67.162]) by fmsmga002.fm.intel.com with ESMTP; 04 Jan 2017 22:24:10 -0800 Date: Thu, 5 Jan 2017 14:25:57 +0800 From: Yuanhan Liu To: Thomas Monjalon Cc: dev@dpdk.org, Bruce Richardson , Ferruh Yigit , "Gonzalez Monroy, Sergio" Message-ID: <20170105062557.GO21228@yliu-dev.sh.intel.com> References: <1482391123-8149-1-git-send-email-yuanhan.liu@linux.intel.com> <1482922962-21036-1-git-send-email-yuanhan.liu@linux.intel.com> <1482922962-21036-2-git-send-email-yuanhan.liu@linux.intel.com> <1506472.SIAYXrUjSr@xps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1506472.SIAYXrUjSr@xps13> User-Agent: Mutt/1.5.23 (2014-03-12) Subject: Re: [dpdk-dev] [PATCH v2 1/6] ethdev: fix port data mismatched in multiple process model X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Jan 2017 06:24:13 -0000 On Wed, Jan 04, 2017 at 06:34:40PM +0100, Thomas Monjalon wrote: > +Cc Sergio (maintainer of the secondary process thing) > > 2016-12-28 19:02, Yuanhan Liu: > > --- a/lib/librte_ether/rte_ethdev.c > > +++ b/lib/librte_ether/rte_ethdev.c > > @@ -201,9 +201,6 @@ rte_eth_dev_allocate(const char *name) > > return NULL; > > } > > > > - if (rte_eth_dev_data == NULL) > > - rte_eth_dev_data_alloc(); > > - > > It is dangerous to move this to rte_eth_dev_pci_probe. > Please keep it here and duplicate it in eth_dev_attach. Oh, right, I missed the fact that it could be invoked from other places. > [...] > > +/* > > + * Attach to a port already registered by the primary process, which > > + * makes sure that the same device would both have the same port id > > + * in the primary and secondary process. > > + */ > > +static struct rte_eth_dev * > > +eth_dev_attach(const char *name) > > Maybe that the word "secondary" could help to differentiate of > the function rte_eth_dev_attach(). Yes, it's better. How about "_attach_secondary", or "_attach_to_primary"? > > +{ > > + uint8_t i; > > + struct rte_eth_dev *eth_dev; > > + > > + for (i = 0; i < RTE_MAX_ETHPORTS; i++) { > > + if (strcmp(rte_eth_dev_data[i].name, name) == 0) > > + break; > > + } > > + if (i == RTE_MAX_ETHPORTS) { > > + RTE_PMD_DEBUG_TRACE( > > + "device %s is not driven by the primary process\n", > > + name); > > + return NULL; > > + } > > + > > + RTE_ASSERT(eth_dev->data->port_id == i); > > + > > + eth_dev = &rte_eth_devices[i]; > > + eth_dev->data = &rte_eth_dev_data[i]; > > + eth_dev->attached = DEV_ATTACHED; > > + nb_ports++; > > I am a bit nervous when I see these lines duplicated from rte_eth_dev_allocate. > Not sure whether it deserves a common function or not. I don't think so, they do share some common assignments, but the assignments are actually not the same. The primary one has few more: notably, they are: - eth_dev->data - eth_dev->data->name - eth_dev->data->port_id > > [...] > > @@ -246,9 +275,26 @@ rte_eth_dev_pci_probe(struct rte_pci_driver *pci_drv, > > - eth_dev = rte_eth_dev_allocate(ethdev_name); > > - if (eth_dev == NULL) > > - return -ENOMEM; > > + if (rte_eth_dev_data == NULL) > > + rte_eth_dev_data_alloc(); > > + > > + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { > > + eth_dev = rte_eth_dev_allocate(ethdev_name); > > + if (eth_dev == NULL) > > + return -ENOMEM; > > + } else { > > + /* > > + * if we failed to attach a device, it means that > > + * device is skipped, due to some errors. Take > > + * virtio-net device as example, it could be the > > + * device is managed by virtio-net kernel driver. > > + * For such case, we return a positive value, to > > + * let EAL skip it as well. > > + */ > > This comment (a bit too long) should be placed between "if" and "return". Okay. --yliu