From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by dpdk.org (Postfix) with ESMTP id D117EB674 for ; Tue, 17 Feb 2015 07:14:19 +0100 (CET) Received: by padbj1 with SMTP id bj1so3926672pad.5 for ; Mon, 16 Feb 2015 22:14:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=S/xcBhc0t+KjObUoXooH2fsqnmE07f3gQeruaLN5rNg=; b=hG/SirgexKc9UqoLOzBIaY/Rc4y7hJcgUFQRxd4in9vBJRZtZUOvpg21WZyab+Eu5I 7Lcc0/H//rCFmKERTjcGoK7CbGvDuDIreM2nZld9CqV7FTsIznlleqWABzGg1TrsCWaL 4R/i0yR2hTZOPH0+JPQaki76g4LqBOOLuilZk2Pb1WcWPpjlfAEeuo7+L781EJJu/kFk HaywuDfwz7mTLLbuRt0hQRkeYvy78F9Nbo3J4kH48DNXsjf4QOjuMzvgkv51nwbmYmWm mzkG2QIvns9n4WEEaldfUVK0bPN5mYf9vPBDiQz02ro9G2cFCBvskSLysTqdLaGPppQe mmqw== X-Gm-Message-State: ALoCoQmnAEzJpxtXCnIENLYMpW+M3sZ+wmwYJoO+dDB6IPUdC+x2mXIyql5WJ9p8QCUOcx8QW4Le X-Received: by 10.67.21.144 with SMTP id hk16mr47259820pad.140.1424153658960; Mon, 16 Feb 2015 22:14:18 -0800 (PST) Received: from [10.16.129.101] (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id dq4sm16448045pdb.96.2015.02.16.22.14.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Feb 2015 22:14:18 -0800 (PST) Message-ID: <54E2DC38.7000907@igel.co.jp> Date: Tue, 17 Feb 2015 15:14:16 +0900 From: Tetsuya Mukawa User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Thomas Monjalon References: <1423470639-15744-2-git-send-email-mukawa@igel.co.jp> <1424060073-23484-1-git-send-email-mukawa@igel.co.jp> <1424060073-23484-4-git-send-email-mukawa@igel.co.jp> <2372286.XQlcQsOEBg@xps13> In-Reply-To: <2372286.XQlcQsOEBg@xps13> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Cc: dev@dpdk.org Subject: Re: [dpdk-dev] [PATCH v8 03/14] eal/pci, ethdev: Remove assumption that port will not be detached X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Feb 2015 06:14:20 -0000 Hi Thomas, I appreciate for your all comments. On 2015/02/17 9:36, Thomas Monjalon wrote: > 2015-02-16 13:14, Tetsuya Mukawa: >> To remove assumption, do like followings. >> >> This patch adds "RTE_PCI_DRV_DETACHABLE" to drv_flags of rte_pci_drive= r >> structure. The flags indicate the driver can detach devices at runtime= =2E >> Also, remove assumption that port will not be detached. >> >> To remove the assumption. >> - Add 'attached' member to rte_eth_dev structure. >> This member is used for indicating the port is attached, or not. >> - Add rte_eth_dev_allocate_new_port(). >> This function is used for allocating new port. >> >> v8: >> - NONE_TRACE is changed to NO_TRACE. >> (Thanks to Iremonger, Bernard) >> v5: >> - Change parameters of rte_eth_dev_validate_port() to cleanup code. >> v4: >> - Use braces with 'for' loop. >> - Fix indent of 'if' statement. >> >> Signed-off-by: Tetsuya Mukawa >> --- >> lib/librte_eal/common/include/rte_pci.h | 2 + >> lib/librte_ether/rte_ethdev.c | 454 +++++++++++++----------= --------- >> lib/librte_ether/rte_ethdev.h | 5 + >> 3 files changed, 186 insertions(+), 275 deletions(-) >> >> diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/= common/include/rte_pci.h >> index 7b48b55..7f2d699 100644 >> --- a/lib/librte_eal/common/include/rte_pci.h >> +++ b/lib/librte_eal/common/include/rte_pci.h >> @@ -207,6 +207,8 @@ struct rte_pci_driver { >> #define RTE_PCI_DRV_FORCE_UNBIND 0x0004 >> /** Device driver supports link state interrupt */ >> #define RTE_PCI_DRV_INTR_LSC 0x0008 >> +/** Device driver supports detaching capability */ >> +#define RTE_PCI_DRV_DETACHABLE 0x0010 >> =20 >> /**< Internal use only - Macro used by pci addr parsing functions **/= >> #define GET_PCIADDR_FIELD(in, fd, lim, dlm) \ >> diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethd= ev.c >> index ea3a1fb..a79fa5b 100644 >> --- a/lib/librte_ether/rte_ethdev.c >> +++ b/lib/librte_ether/rte_ethdev.c >> @@ -175,6 +175,16 @@ enum { >> STAT_QMAP_RX >> }; >> =20 >> +enum { >> + DEV_INVALID =3D 0, >> + DEV_VALID, >> +}; >> + >> +enum { >> + DEV_DISCONNECTED =3D 0, >> + DEV_CONNECTED >> +}; > The commit log explains what is an attached port but not what means > valid or connected. > These enums should have a comment to explain their usage. Sure, I will add comment, and fix commit log. >> + >> static inline void >> rte_eth_dev_data_alloc(void) >> { >> @@ -201,19 +211,34 @@ rte_eth_dev_allocated(const char *name) >> { >> unsigned i; >> =20 >> - for (i =3D 0; i < nb_ports; i++) { >> - if (strcmp(rte_eth_devices[i].data->name, name) =3D=3D 0) >> + for (i =3D 0; i < RTE_MAX_ETHPORTS; i++) { >> + if ((rte_eth_devices[i].attached =3D=3D DEV_CONNECTED) && >> + strcmp(rte_eth_devices[i].data->name, name) =3D=3D 0) >> return &rte_eth_devices[i]; >> } >> return NULL; >> } >> =20 >> +static uint8_t >> +rte_eth_dev_allocate_new_port(void) >> +{ >> + unsigned i; >> + >> + for (i =3D 0; i < RTE_MAX_ETHPORTS; i++) { >> + if (rte_eth_devices[i].attached =3D=3D DEV_DISCONNECTED) >> + return i; >> + } >> + return RTE_MAX_ETHPORTS; >> +} > This function does not allocate a new port. > It get the first free port id. I will change the function name like below. rte_eth_dev_find_free_port() > Is uint8_t sill a good size for hotpluggable virtual device ids? I am not sure it's enough, but uint8_t is widely used in "rte_ethdev.c" as port id. If someone reports it doesn't enough, I guess it will be the time to write a patch to change all uint_8 in one patch. >> + >> struct rte_eth_dev * >> rte_eth_dev_allocate(const char *name) >> { >> + uint8_t port_id; >> struct rte_eth_dev *eth_dev; >> =20 >> - if (nb_ports =3D=3D RTE_MAX_ETHPORTS) { >> + port_id =3D rte_eth_dev_allocate_new_port(); >> + if (port_id =3D=3D RTE_MAX_ETHPORTS) { >> PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n"); >> return NULL; >> } >> @@ -226,10 +251,12 @@ rte_eth_dev_allocate(const char *name) >> return NULL; >> } >> =20 >> - eth_dev =3D &rte_eth_devices[nb_ports]; >> - eth_dev->data =3D &rte_eth_dev_data[nb_ports]; >> + eth_dev =3D &rte_eth_devices[port_id]; >> + eth_dev->data =3D &rte_eth_dev_data[port_id]; >> snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", nam= e); >> - eth_dev->data->port_id =3D nb_ports++; >> + eth_dev->data->port_id =3D port_id; >> + eth_dev->attached =3D DEV_CONNECTED; >> + nb_ports++; >> return eth_dev; >> } >> =20 >> @@ -283,6 +310,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, >> (unsigned) pci_dev->id.device_id); >> if (rte_eal_process_type() =3D=3D RTE_PROC_PRIMARY) >> rte_free(eth_dev->data->dev_private); >> + eth_dev->attached =3D DEV_DISCONNECTED; >> nb_ports--; >> return diag; >> } >> @@ -308,10 +336,28 @@ rte_eth_driver_register(struct eth_driver *eth_d= rv) >> rte_eal_pci_register(ð_drv->pci_drv); >> } >> =20 >> +enum { >> + NO_TRACE =3D 0, >> + TRACE >> +}; > What means this enum? > >> + >> +static int >> +rte_eth_dev_validate_port(uint8_t port_id, int trace) >> +{ >> + if (port_id >=3D RTE_MAX_ETHPORTS || >> + rte_eth_devices[port_id].attached !=3D DEV_CONNECTED) { >> + if (trace) { >> + PMD_DEBUG_TRACE("Invalid port_id=3D%d\n", port_id); >> + } > It's not common in DPDK to have a parameter to toggle log. > It should be enabled globally via the log level. Sure, I will change it. >> + return DEV_INVALID; > It would be simpler to return 0 in a function called "is_valid_port". I will change the function name. >> + } else >> + return DEV_VALID; > So it could 1 (true) here. Sure, I will change like above, also delete DEV_INVALID and DEV_VALID definitions. > [...] >> --- a/lib/librte_ether/rte_ethdev.h >> +++ b/lib/librte_ether/rte_ethdev.h >> @@ -1539,6 +1539,7 @@ struct rte_eth_dev { >> struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */ >> struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing *= / >> struct rte_eth_dev_cb_list callbacks; /**< User application callback= s */ >> + uint8_t attached; /**< Flag indicating the port is attached */ >> }; >> =20 >> struct rte_eth_dev_sriov { >> @@ -1604,6 +1605,10 @@ extern struct rte_eth_dev rte_eth_devices[]; >> * initialized by the [matching] Ethernet driver during the PCI probi= ng phase. >> * All devices whose port identifier is in the range >> * [0, rte_eth_dev_count() - 1] can be operated on by network applic= ations. >> + * immediately after invoking rte_eal_init(). >> + * If the application unplugs a port using hotplug function, The enab= led port >> + * numbers may be noncontiguous. In the case, the applications need t= o manage >> + * enabled port by themselves. >> * >> * @return >> * - The total number of usable Ethernet devices. >> >