Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/15986/?format=api
https://patches.dpdk.org/api/patches/15986/?format=api", "web_url": "https://patches.dpdk.org/project/dpdk/patch/1474381895-16066-2-git-send-email-marcinx.kerlin@intel.com/", "project": { "id": 1, "url": "https://patches.dpdk.org/api/projects/1/?format=api", "name": "DPDK", "link_name": "dpdk", "list_id": "dev.dpdk.org", "list_email": "dev@dpdk.org", "web_url": "http://core.dpdk.org", "scm_url": "git://dpdk.org/dpdk", "webscm_url": "http://git.dpdk.org/dpdk", "list_archive_url": "https://inbox.dpdk.org/dev", "list_archive_url_format": "https://inbox.dpdk.org/dev/{}", "commit_url_format": "" }, "msgid": "<1474381895-16066-2-git-send-email-marcinx.kerlin@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1474381895-16066-2-git-send-email-marcinx.kerlin@intel.com", "date": "2016-09-20T14:31:34", "name": "[dpdk-dev,v2,1/2] librte_ether: ensure not overwrite device data in mp app", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "bea29d37f2d300bc6d44c91aa5685515c6e0fb2c", "submitter": { "id": 348, "url": "https://patches.dpdk.org/api/people/348/?format=api", "name": "Marcin Kerlin", "email": "marcinx.kerlin@intel.com" }, "delegate": null, "mbox": "https://patches.dpdk.org/project/dpdk/patch/1474381895-16066-2-git-send-email-marcinx.kerlin@intel.com/mbox/", "series": [], "comments": "https://patches.dpdk.org/api/patches/15986/comments/", "check": "pending", "checks": "https://patches.dpdk.org/api/patches/15986/checks/", "tags": {}, "related": [], "headers": { "Return-Path": "<dev-bounces@dpdk.org>", "X-Original-To": "patchwork@dpdk.org", "Delivered-To": "patchwork@dpdk.org", "Received": [ "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 551D98D94;\n\tTue, 20 Sep 2016 16:38:15 +0200 (CEST)", "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n\tby dpdk.org (Postfix) with ESMTP id 1C7378D91\n\tfor <dev@dpdk.org>; Tue, 20 Sep 2016 16:38:13 +0200 (CEST)", "from fmsmga001.fm.intel.com ([10.253.24.23])\n\tby orsmga101.jf.intel.com with ESMTP; 20 Sep 2016 07:38:13 -0700", "from gklab-246-021.igk.intel.com (HELO HANLANCREEK9755-232)\n\t([10.217.246.21])\n\tby fmsmga001.fm.intel.com with SMTP; 20 Sep 2016 07:38:10 -0700", "by HANLANCREEK9755-232 (sSMTP sendmail emulation);\n\tTue, 20 Sep 2016 16:38:25 +0200" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos; i=\"5.30,368,1470726000\"; d=\"scan'208\";\n\ta=\"1043233022\"", "From": "Marcin Kerlin <marcinx.kerlin@intel.com>", "To": "dev@dpdk.org", "Cc": "thomas.monjalon@6wind.com, pablo.de.lara.guarch@intel.com,\n\tMarcin Kerlin <marcinx.kerlin@intel.com>", "Date": "Tue, 20 Sep 2016 16:31:34 +0200", "Message-Id": "<1474381895-16066-2-git-send-email-marcinx.kerlin@intel.com>", "X-Mailer": "git-send-email 1.9.1", "In-Reply-To": "<1474381895-16066-1-git-send-email-marcinx.kerlin@intel.com>", "References": "<1472806710-25866-2-git-send-email-marcinx.kerlin@intel.com>\n\t<1474381895-16066-1-git-send-email-marcinx.kerlin@intel.com>", "Subject": "[dpdk-dev] [PATCH v2 1/2] librte_ether: ensure not overwrite device\n\tdata in mp app", "X-BeenThere": "dev@dpdk.org", "X-Mailman-Version": "2.1.15", "Precedence": "list", "List-Id": "patches and discussions about DPDK <dev.dpdk.org>", "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>", "List-Archive": "<http://dpdk.org/ml/archives/dev/>", "List-Post": "<mailto:dev@dpdk.org>", "List-Help": "<mailto:dev-request@dpdk.org?subject=help>", "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>", "Errors-To": "dev-bounces@dpdk.org", "Sender": "\"dev\" <dev-bounces@dpdk.org>" }, "content": "Added prevention not overwrite device data in array rte_eth_dev_data[].\nSecondary process appends in the first free place rather than at the\nbeginning. This behavior prevents overwriting devices of primary process\nby secondary process.\n\nSigned-off-by: Marcin Kerlin <marcinx.kerlin@intel.com>\n---\n lib/librte_ether/rte_ethdev.c | 90 +++++++++++++++++++++++++++++++---\n lib/librte_ether/rte_ethdev.h | 24 +++++++++\n lib/librte_ether/rte_ether_version.map | 7 +++\n 3 files changed, 113 insertions(+), 8 deletions(-)", "diff": "diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c\nindex 382c959..dadd77a 100644\n--- a/lib/librte_ether/rte_ethdev.c\n+++ b/lib/librte_ether/rte_ethdev.c\n@@ -176,6 +176,19 @@ rte_eth_dev_allocated(const char *name)\n \treturn NULL;\n }\n \n+struct rte_eth_dev_data *\n+rte_eth_dev_data_allocated(const char *name)\n+{\n+\tunsigned int i;\n+\n+\tfor (i = 0; i < RTE_MAX_ETHPORTS; i++) {\n+\t\tif (strcmp(rte_eth_dev_data[i].name, name) == 0)\n+\t\t\treturn &rte_eth_dev_data[i];\n+\t}\n+\n+\treturn NULL;\n+}\n+\n static uint8_t\n rte_eth_dev_find_free_port(void)\n {\n@@ -188,10 +201,43 @@ rte_eth_dev_find_free_port(void)\n \treturn RTE_MAX_ETHPORTS;\n }\n \n+static uint8_t\n+rte_eth_dev_find_free_dev_data_id(void)\n+{\n+\tunsigned int i;\n+\n+\tfor (i = 0; i < RTE_MAX_ETHPORTS; i++) {\n+\t\tif (!strlen(rte_eth_dev_data[i].name))\n+\t\t\treturn i;\n+\t}\n+\treturn RTE_MAX_ETHPORTS;\n+}\n+\n+int\n+rte_eth_dev_release_dev_data(uint8_t port_id)\n+{\n+\tchar device[RTE_ETH_NAME_MAX_LEN];\n+\tstruct rte_eth_dev_data *eth_dev_data = NULL;\n+\n+\t/* get device name by port id */\n+\tif (rte_eth_dev_get_name_by_port(port_id, device))\n+\t\treturn -EINVAL;\n+\n+\t/* look for an entry in the device data */\n+\teth_dev_data = rte_eth_dev_data_allocated(device);\n+\tif (eth_dev_data == NULL)\n+\t\treturn -EINVAL;\n+\n+\t/* clear an entry in the device data */\n+\tmemset(eth_dev_data, 0, sizeof(struct rte_eth_dev_data));\n+\n+\treturn 0;\n+}\n+\n struct rte_eth_dev *\n rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)\n {\n-\tuint8_t port_id;\n+\tuint8_t port_id, dev_data_id;\n \tstruct rte_eth_dev *eth_dev;\n \n \tport_id = rte_eth_dev_find_free_port();\n@@ -203,17 +249,35 @@ rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type)\n \tif (rte_eth_dev_data == NULL)\n \t\trte_eth_dev_data_alloc();\n \n+\tdo {\n+\t\tdev_data_id = rte_eth_dev_find_free_dev_data_id();\n+\t} while (!rte_spinlock_trylock(&rte_eth_dev_data[dev_data_id].lock)\n+\t\t\t&& dev_data_id < RTE_MAX_ETHPORTS);\n+\n+\tif (dev_data_id == RTE_MAX_ETHPORTS) {\n+\t\tRTE_PMD_DEBUG_TRACE(\"Reached maximum number of Ethernet ports by all \"\n+\t\t\t\t\"the processes\\n\");\n+\t\treturn NULL;\n+\t}\n+\n \tif (rte_eth_dev_allocated(name) != NULL) {\n \t\tRTE_PMD_DEBUG_TRACE(\"Ethernet Device with name %s already allocated!\\n\",\n \t\t\t\tname);\n \t\treturn NULL;\n \t}\n \n+\tif (rte_eth_dev_data_allocated(name) != NULL) {\n+\t\tRTE_PMD_DEBUG_TRACE(\"Ethernet Device with name %s already allocated by \"\n+\t\t\t\t\"another process!\\n\", name);\n+\t\treturn NULL;\n+\t}\n+\n \teth_dev = &rte_eth_devices[port_id];\n-\teth_dev->data = &rte_eth_dev_data[port_id];\n+\teth_dev->data = &rte_eth_dev_data[dev_data_id];\n \tsnprintf(eth_dev->data->name, sizeof(eth_dev->data->name), \"%s\", name);\n \teth_dev->data->port_id = port_id;\n \teth_dev->attached = DEV_ATTACHED;\n+\trte_spinlock_unlock(ð_dev->data->lock);\n \teth_dev->dev_type = type;\n \tnb_ports++;\n \treturn eth_dev;\n@@ -417,9 +481,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)\n \t\treturn -EINVAL;\n \t}\n \n-\t/* shouldn't check 'rte_eth_devices[i].data',\n-\t * because it might be overwritten by VDEV PMD */\n-\ttmp = rte_eth_dev_data[port_id].name;\n+\ttmp = rte_eth_devices[port_id].data->name;\n \tstrcpy(name, tmp);\n \treturn 0;\n }\n@@ -438,9 +500,7 @@ rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)\n \n \tfor (i = 0; i < RTE_MAX_ETHPORTS; i++) {\n \n-\t\tif (!strncmp(name,\n-\t\t\trte_eth_dev_data[i].name, strlen(name))) {\n-\n+\t\tif (!strncmp(name, rte_eth_devices[i].data->name, strlen(name))) {\n \t\t\t*port_id = i;\n \n \t\t\treturn 0;\n@@ -631,6 +691,8 @@ int\n rte_eth_dev_detach(uint8_t port_id, char *name)\n {\n \tstruct rte_pci_addr addr;\n+\tstruct rte_eth_dev_data *eth_dev_data = NULL;\n+\tchar device[RTE_ETH_NAME_MAX_LEN];\n \tint ret = -1;\n \n \tif (name == NULL) {\n@@ -642,6 +704,15 @@ rte_eth_dev_detach(uint8_t port_id, char *name)\n \tif (rte_eth_dev_is_detachable(port_id))\n \t\tgoto err;\n \n+\t/* get device name by port id */\n+\tif (rte_eth_dev_get_name_by_port(port_id, device))\n+\t\tgoto err;\n+\n+\t/* look for an entry in the shared device data */\n+\teth_dev_data = rte_eth_dev_data_allocated(device);\n+\tif (eth_dev_data == NULL)\n+\t\tgoto err;\n+\n \tif (rte_eth_dev_get_device_type(port_id) == RTE_ETH_DEV_PCI) {\n \t\tret = rte_eth_dev_get_addr_by_port(port_id, &addr);\n \t\tif (ret < 0)\n@@ -661,6 +732,9 @@ rte_eth_dev_detach(uint8_t port_id, char *name)\n \t\t\tgoto err;\n \t}\n \n+\t/* clear an entry in the shared device data */\n+\tmemset(eth_dev_data, 0, sizeof(struct rte_eth_dev_data));\n+\n \treturn 0;\n \n err:\ndiff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h\nindex 96575e8..541e44e 100644\n--- a/lib/librte_ether/rte_ethdev.h\n+++ b/lib/librte_ether/rte_ethdev.h\n@@ -1708,6 +1708,7 @@ struct rte_eth_dev_data {\n \tenum rte_kernel_driver kdrv; /**< Kernel driver passthrough */\n \tint numa_node; /**< NUMA node connection */\n \tconst char *drv_name; /**< Driver name */\n+\trte_spinlock_t lock; /** Lock on allocate eth device */\n };\n \n /** Device supports hotplug detach */\n@@ -1752,6 +1753,29 @@ struct rte_eth_dev *rte_eth_dev_allocated(const char *name);\n \n /**\n * @internal\n+ * Returns a shared device data slot specified by the unique identifier name.\n+ *\n+ * @param\tname\n+ * The pointer to the Unique identifier name for each shared Ethernet device\n+ * between multiple processes.\n+ * @return\n+ * - The pointer to the device data slot, on success. NULL on error\n+ */\n+struct rte_eth_dev_data *rte_eth_dev_data_allocated(const char *name);\n+\n+/**\n+ * @internal\n+ * Release device data kept in shared memory for all processes.\n+ *\n+ * @param\tport_id\n+ * The port identifier of the device to release device data.\n+ * @return\n+ * - 0 on success, negative on error\n+ */\n+int rte_eth_dev_release_dev_data(uint8_t port_id);\n+\n+/**\n+ * @internal\n * Allocates a new ethdev slot for an ethernet device and returns the pointer\n * to that slot for the driver to use.\n *\ndiff --git a/lib/librte_ether/rte_ether_version.map b/lib/librte_ether/rte_ether_version.map\nindex 45ddf44..f37a15c 100644\n--- a/lib/librte_ether/rte_ether_version.map\n+++ b/lib/librte_ether/rte_ether_version.map\n@@ -139,3 +139,10 @@ DPDK_16.07 {\n \trte_eth_dev_get_port_by_name;\n \trte_eth_xstats_get_names;\n } DPDK_16.04;\n+\n+DPDK_16.11 {\n+\tglobal:\n+\n+\trte_eth_dev_data_allocated;\n+\trte_eth_dev_release_dev_data;\n+} DPDK_16.07;\n", "prefixes": [ "dpdk-dev", "v2", "1/2" ] }{ "id": 15986, "url": "