From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from compass.polito.it (compass.polito.it [130.192.55.110]) by dpdk.org (Postfix) with ESMTP id C3D752C69 for ; Mon, 7 Mar 2016 17:20:38 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by compass.polito.it (Postfix) with ESMTP id 90E16100155; Mon, 7 Mar 2016 17:20:38 +0100 (CET) Authentication-Results: compass.polito.it (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=studenti.polito.it DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d= studenti.polito.it; h=x-mailer:message-id:date:date:subject :subject:cc:to:from:from:received:received; s=y2k10; t= 1457367637; bh=u9YyPNYVix1EyljCLEDgxeMrmnmmiPapwzI/ZG1NEdY=; b=S PJSXXpHlQ82938nZSYaHSrxWu4czIb+Ib+XHE2M2iXQUSL9DeAiRFmPm7BAePD0m EaF2h9TNT1crvj7DZDHsWFiI/XupnlGF1+/TY98b9XvaTmzVNRvlMl4xF98K8Gr7 9gxsZ4+KgNH99fLsP8fJx/dSCH3VpxItWJ6QiBZKPA= X-Virus-Scanned: amavisd-new at studenti.polito.it X-Spam-Flag: NO X-Spam-Score: -5.854 X-Spam-Level: X-Spam-Status: No, score=-5.854 tagged_above=-100 required=3.5 tests=[ALL_TRUSTED=-5, AWL=0.646, BAYES_00=-1.5] autolearn=ham Received: from compass.polito.it ([127.0.0.1]) by localhost (compass.polito.it [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id o2IqHrj9t4cX; Mon, 7 Mar 2016 17:20:37 +0100 (CET) Received: from localhost.localdomain (unknown [130.192.225.153]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: s203403@studenti.polito.it) by compass.polito.it (Postfix) with ESMTPSA id 6874B100148; Mon, 7 Mar 2016 17:20:37 +0100 (CET) From: Mauricio Vasquez B To: bruce.richardson@intel.com Date: Mon, 7 Mar 2016 17:20:31 +0100 Message-Id: <1457367631-22726-1-git-send-email-mauricio.vasquezbernal@studenti.polito.it> X-Mailer: git-send-email 1.9.1 Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH] pmd_ring: free rings when detaching 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: Mon, 07 Mar 2016 16:20:38 -0000 When a device is created with "CREATE" as action, new rings are allocated for it, then it is a good practice to free them when the rte_ethdev_dettach method is invoked by the application. Rings are not freeded when "ATTACH" is used or when the device is created by means of the rte_eth_from_rings function. Signed-off-by: Mauricio Vasquez B --- drivers/net/ring/rte_eth_ring.c | 82 ++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/drivers/net/ring/rte_eth_ring.c b/drivers/net/ring/rte_eth_ring.c index d92b088..fd23a91 100644 --- a/drivers/net/ring/rte_eth_ring.c +++ b/drivers/net/ring/rte_eth_ring.c @@ -51,6 +51,11 @@ static const char *valid_arguments[] = { NULL }; +enum dev_action{ + DEV_CREATE, + DEV_ATTACH +}; + struct ring_queue { struct rte_ring *rng; rte_atomic64_t rx_pkts; @@ -66,6 +71,7 @@ struct pmd_internals { struct ring_queue tx_ring_queues[RTE_PMD_RING_MAX_TX_RINGS]; struct ether_addr address; + enum dev_action action; }; @@ -252,12 +258,11 @@ static const struct eth_dev_ops ops = { .mac_addr_add = eth_mac_addr_add, }; -int -rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[], - const unsigned nb_rx_queues, - struct rte_ring *const tx_queues[], - const unsigned nb_tx_queues, - const unsigned numa_node) +static int +do_eth_dev_ring_create(const char *name, + struct rte_ring * const rx_queues[], const unsigned nb_rx_queues, + struct rte_ring *const tx_queues[], const unsigned nb_tx_queues, + const unsigned numa_node, enum dev_action action) { struct rte_eth_dev_data *data = NULL; struct pmd_internals *internals = NULL; @@ -265,20 +270,6 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[], unsigned i; - /* do some parameter checking */ - if (rx_queues == NULL && nb_rx_queues > 0) { - rte_errno = EINVAL; - goto error; - } - if (tx_queues == NULL && nb_tx_queues > 0) { - rte_errno = EINVAL; - goto error; - } - if (nb_rx_queues > RTE_PMD_RING_MAX_RX_RINGS) { - rte_errno = EINVAL; - goto error; - } - RTE_LOG(INFO, PMD, "Creating rings-backed ethdev on numa socket %u\n", numa_node); @@ -327,6 +318,8 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[], /* NOTE: we'll replace the data element, of originally allocated eth_dev * so the rings are local per-process */ + internals->action = action; + internals->nb_rx_queues = nb_rx_queues; internals->nb_tx_queues = nb_tx_queues; for (i = 0; i < nb_rx_queues; i++) { @@ -374,17 +367,37 @@ error: } int +rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[], + const unsigned nb_rx_queues, + struct rte_ring *const tx_queues[], + const unsigned nb_tx_queues, + const unsigned numa_node) +{ + /* do some parameter checking */ + if (rx_queues == NULL && nb_rx_queues > 0) { + rte_errno = EINVAL; + return -1; + } + if (tx_queues == NULL && nb_tx_queues > 0) { + rte_errno = EINVAL; + return -1; + } + if (nb_rx_queues > RTE_PMD_RING_MAX_RX_RINGS) { + rte_errno = EINVAL; + return -1; + } + + return do_eth_dev_ring_create(name, rx_queues, nb_rx_queues, + tx_queues, nb_tx_queues, numa_node, DEV_ATTACH); +} + +int rte_eth_from_ring(struct rte_ring *r) { return rte_eth_from_rings(r->name, &r, 1, &r, 1, r->memzone ? r->memzone->socket_id : SOCKET_ID_ANY); } -enum dev_action{ - DEV_CREATE, - DEV_ATTACH -}; - static int eth_dev_ring_create(const char *name, const unsigned numa_node, enum dev_action action) @@ -408,7 +421,8 @@ eth_dev_ring_create(const char *name, const unsigned numa_node, return -1; } - if (rte_eth_from_rings(name, rxtx, num_rings, rxtx, num_rings, numa_node) < 0) + if(do_eth_dev_ring_create(name, rxtx, num_rings, rxtx, num_rings, + numa_node, action) < 0) return -1; return 0; @@ -570,6 +584,9 @@ static int rte_pmd_ring_devuninit(const char *name) { struct rte_eth_dev *eth_dev = NULL; + struct pmd_internals *internals = NULL; + struct ring_queue *r = NULL; + uint16_t i; RTE_LOG(INFO, PMD, "Un-Initializing pmd_ring for %s\n", name); @@ -584,10 +601,23 @@ rte_pmd_ring_devuninit(const char *name) eth_dev_stop(eth_dev); if (eth_dev->data) { + internals = eth_dev->data->dev_private; + if(internals->action == DEV_CREATE) { + /* + * it is only necessary to delete the rings in rx_queues because + * they are the same used in tx_queues + */ + for(i = 0; i < eth_dev->data->nb_rx_queues; i++) { + r = eth_dev->data->rx_queues[i]; + rte_ring_free(r->rng); + } + } + rte_free(eth_dev->data->rx_queues); rte_free(eth_dev->data->tx_queues); rte_free(eth_dev->data->dev_private); } + rte_free(eth_dev->data); rte_eth_dev_release_port(eth_dev); -- 1.9.1