Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/12647/?format=api
http://patches.dpdk.org/api/patches/12647/?format=api", "web_url": "http://patches.dpdk.org/project/dpdk/patch/1462873202-3314-2-git-send-email-reshma.pattan@intel.com/", "project": { "id": 1, "url": "http://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": "<1462873202-3314-2-git-send-email-reshma.pattan@intel.com>", "list_archive_url": "https://inbox.dpdk.org/dev/1462873202-3314-2-git-send-email-reshma.pattan@intel.com", "date": "2016-05-10T09:39:58", "name": "[dpdk-dev,PATCHv2,1/5] librte_ether: protect add/remove of rxtx callbacks with spinlocks", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": true, "hash": "b184dbb9057fc462b0a4a19354de77abf373e3da", "submitter": { "id": 70, "url": "http://patches.dpdk.org/api/people/70/?format=api", "name": "Pattan, Reshma", "email": "reshma.pattan@intel.com" }, "delegate": { "id": 1, "url": "http://patches.dpdk.org/api/users/1/?format=api", "username": "tmonjalo", "first_name": "Thomas", "last_name": "Monjalon", "email": "thomas@monjalon.net" }, "mbox": "http://patches.dpdk.org/project/dpdk/patch/1462873202-3314-2-git-send-email-reshma.pattan@intel.com/mbox/", "series": [], "comments": "http://patches.dpdk.org/api/patches/12647/comments/", "check": "pending", "checks": "http://patches.dpdk.org/api/patches/12647/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 C45639A8D;\n\tTue, 10 May 2016 11:40:09 +0200 (CEST)", "from mga04.intel.com (mga04.intel.com [192.55.52.120])\n\tby dpdk.org (Postfix) with ESMTP id 81EEF6C93\n\tfor <dev@dpdk.org>; Tue, 10 May 2016 11:40:06 +0200 (CEST)", "from orsmga003.jf.intel.com ([10.7.209.27])\n\tby fmsmga104.fm.intel.com with ESMTP; 10 May 2016 02:40:05 -0700", "from irvmail001.ir.intel.com ([163.33.26.43])\n\tby orsmga003.jf.intel.com with ESMTP; 10 May 2016 02:40:05 -0700", "from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com\n\t[10.237.217.46])\n\tby irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id\n\tu4A9e3NA003310; Tue, 10 May 2016 10:40:03 +0100", "from sivswdev02.ir.intel.com (localhost [127.0.0.1])\n\tby sivswdev02.ir.intel.com with ESMTP id u4A9e3Lc003368;\n\tTue, 10 May 2016 10:40:03 +0100", "(from reshmapa@localhost)\n\tby sivswdev02.ir.intel.com with id u4A9e3pK003364;\n\tTue, 10 May 2016 10:40:03 +0100" ], "X-ExtLoop1": "1", "X-IronPort-AV": "E=Sophos;i=\"5.24,604,1455004800\"; d=\"scan'208\";a=\"802904476\"", "From": "Reshma Pattan <reshma.pattan@intel.com>", "To": "dev@dpdk.org", "Cc": "Reshma Pattan <reshma.pattan@intel.com>", "Date": "Tue, 10 May 2016 10:39:58 +0100", "Message-Id": "<1462873202-3314-2-git-send-email-reshma.pattan@intel.com>", "X-Mailer": "git-send-email 1.7.4.1", "In-Reply-To": "<1462873202-3314-1-git-send-email-reshma.pattan@intel.com>", "References": "<1462532139-17848-1-git-send-email-reshma.pattan@intel.com>\n\t<1462873202-3314-1-git-send-email-reshma.pattan@intel.com>", "Subject": "[dpdk-dev] [PATCHv2 1/5] librte_ether: protect add/remove of rxtx\n\tcallbacks with spinlocks", "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 spinlocks around add/remove logic of rxtx callbacks to\n avoid corruption of callback lists in multithreaded context.\n\n* added new public api rte_eth_add_first_rx_callback to add given\n callback as head of list.\n\n* converted rte_eth_dev_get_port_by_name to public API.\n\n* add new fields to rte_eth_dev_info struct\n New fields nb_rx_queues and nb_tx_queues are added to\n rte_eth_dev_info structure.\n Changes to API rte_eth_dev_info_get() are done to update\n these new fields to rte_eth_dev_info object.\n\nSigned-off-by: Reshma Pattan <reshma.pattan@intel.com>\n---\n lib/librte_ether/rte_ethdev.c | 121 +++++++++++++++++++++------------\n lib/librte_ether/rte_ethdev.h | 45 ++++++++++++\n lib/librte_ether/rte_ether_version.map | 9 +++\n 3 files changed, 132 insertions(+), 43 deletions(-)", "diff": "diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c\nindex a31018e..cd2bc17 100644\n--- a/lib/librte_ether/rte_ethdev.c\n+++ b/lib/librte_ether/rte_ethdev.c\n@@ -77,6 +77,12 @@ static uint8_t nb_ports;\n /* spinlock for eth device callbacks */\n static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;\n \n+/* spinlock for add/remove rx callbacks */\n+static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;\n+\n+/* spinlock for add/remove tx callbacks */\n+static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;\n+\n /* store statistics names and its offset in stats structure */\n struct rte_eth_xstats_name_off {\n \tchar name[RTE_ETH_XSTATS_NAME_SIZE];\n@@ -421,7 +427,7 @@ rte_eth_dev_get_name_by_port(uint8_t port_id, char *name)\n \treturn 0;\n }\n \n-static int\n+int\n rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id)\n {\n \tint i;\n@@ -1639,7 +1645,6 @@ rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,\n \t\t\tSTAT_QMAP_RX);\n }\n \n-\n void\n rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)\n {\n@@ -1661,6 +1666,8 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)\n \t(*dev->dev_ops->dev_infos_get)(dev, dev_info);\n \tdev_info->pci_dev = dev->pci_dev;\n \tdev_info->driver_name = dev->data->drv_name;\n+\tdev_info->nb_rx_queues = dev->data->nb_rx_queues;\n+\tdev_info->nb_tx_queues = dev->data->nb_tx_queues;\n }\n \n int\n@@ -2925,7 +2932,6 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,\n \t\trte_errno = EINVAL;\n \t\treturn NULL;\n \t}\n-\n \tstruct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);\n \n \tif (cb == NULL) {\n@@ -2936,6 +2942,7 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,\n \tcb->fn.rx = fn;\n \tcb->param = user_param;\n \n+\trte_spinlock_lock(&rte_eth_rx_cb_lock);\n \t/* Add the callbacks in fifo order. */\n \tstruct rte_eth_rxtx_callback *tail =\n \t\trte_eth_devices[port_id].post_rx_burst_cbs[queue_id];\n@@ -2948,6 +2955,42 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,\n \t\t\ttail = tail->next;\n \t\ttail->next = cb;\n \t}\n+\trte_spinlock_unlock(&rte_eth_rx_cb_lock);\n+\n+\treturn cb;\n+}\n+\n+void *\n+rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,\n+\t\trte_rx_callback_fn fn, void *user_param)\n+{\n+#ifndef RTE_ETHDEV_RXTX_CALLBACKS\n+\trte_errno = ENOTSUP;\n+\treturn NULL;\n+#endif\n+\t/* check input parameters */\n+\tif (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||\n+\t\t queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {\n+\t\trte_errno = EINVAL;\n+\t\treturn NULL;\n+\t}\n+\n+\tstruct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);\n+\n+\tif (cb == NULL) {\n+\t\trte_errno = ENOMEM;\n+\t\treturn NULL;\n+\t}\n+\n+\tcb->fn.rx = fn;\n+\tcb->param = user_param;\n+\n+\trte_spinlock_lock(&rte_eth_rx_cb_lock);\n+\t/* Add the callbacks at fisrt position*/\n+\tcb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];\n+\trte_smp_wmb();\n+\trte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;\n+\trte_spinlock_unlock(&rte_eth_rx_cb_lock);\n \n \treturn cb;\n }\n@@ -2977,6 +3020,7 @@ rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,\n \tcb->fn.tx = fn;\n \tcb->param = user_param;\n \n+\trte_spinlock_lock(&rte_eth_tx_cb_lock);\n \t/* Add the callbacks in fifo order. */\n \tstruct rte_eth_rxtx_callback *tail =\n \t\trte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];\n@@ -2989,6 +3033,7 @@ rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,\n \t\t\ttail = tail->next;\n \t\ttail->next = cb;\n \t}\n+\trte_spinlock_unlock(&rte_eth_tx_cb_lock);\n \n \treturn cb;\n }\n@@ -3007,29 +3052,24 @@ rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,\n \t}\n \n \tstruct rte_eth_dev *dev = &rte_eth_devices[port_id];\n-\tstruct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];\n-\tstruct rte_eth_rxtx_callback *prev_cb;\n-\n-\t/* Reset head pointer and remove user cb if first in the list. */\n-\tif (cb == user_cb) {\n-\t\tdev->post_rx_burst_cbs[queue_id] = user_cb->next;\n-\t\treturn 0;\n-\t}\n-\n-\t/* Remove the user cb from the callback list. */\n-\tdo {\n-\t\tprev_cb = cb;\n-\t\tcb = cb->next;\n-\n+\tstruct rte_eth_rxtx_callback *cb;\n+\tstruct rte_eth_rxtx_callback **prev_cb;\n+\tint ret = -EINVAL;\n+\n+\trte_spinlock_lock(&rte_eth_rx_cb_lock);\n+\tprev_cb = &dev->post_rx_burst_cbs[queue_id];\n+\tfor (; *prev_cb != NULL; prev_cb = &cb->next) {\n+\t\tcb = *prev_cb;\n \t\tif (cb == user_cb) {\n-\t\t\tprev_cb->next = user_cb->next;\n-\t\t\treturn 0;\n+\t\t\t/* Remove the user cb from the callback list. */\n+\t\t\t*prev_cb = cb->next;\n+\t\t\tret = 0;\n+\t\t\tbreak;\n \t\t}\n+\t}\n+\trte_spinlock_unlock(&rte_eth_rx_cb_lock);\n \n-\t} while (cb != NULL);\n-\n-\t/* Callback wasn't found. */\n-\treturn -EINVAL;\n+\treturn ret;\n }\n \n int\n@@ -3046,29 +3086,24 @@ rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,\n \t}\n \n \tstruct rte_eth_dev *dev = &rte_eth_devices[port_id];\n-\tstruct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];\n-\tstruct rte_eth_rxtx_callback *prev_cb;\n-\n-\t/* Reset head pointer and remove user cb if first in the list. */\n-\tif (cb == user_cb) {\n-\t\tdev->pre_tx_burst_cbs[queue_id] = user_cb->next;\n-\t\treturn 0;\n-\t}\n-\n-\t/* Remove the user cb from the callback list. */\n-\tdo {\n-\t\tprev_cb = cb;\n-\t\tcb = cb->next;\n-\n+\tint ret = -EINVAL;\n+\tstruct rte_eth_rxtx_callback *cb;\n+\tstruct rte_eth_rxtx_callback **prev_cb;\n+\n+\trte_spinlock_lock(&rte_eth_tx_cb_lock);\n+\tprev_cb = &dev->pre_tx_burst_cbs[queue_id];\n+\tfor (; *prev_cb != NULL; prev_cb = &cb->next) {\n+\t\tcb = *prev_cb;\n \t\tif (cb == user_cb) {\n-\t\t\tprev_cb->next = user_cb->next;\n-\t\t\treturn 0;\n+\t\t\t/* Remove the user cb from the callback list. */\n+\t\t\t*prev_cb = cb->next;\n+\t\t\tret = 0;\n+\t\t\tbreak;\n \t\t}\n+\t}\n+\trte_spinlock_unlock(&rte_eth_tx_cb_lock);\n \n-\t} while (cb != NULL);\n-\n-\t/* Callback wasn't found. */\n-\treturn -EINVAL;\n+\treturn ret;\n }\n \n int\ndiff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h\nindex 2757510..499e694 100644\n--- a/lib/librte_ether/rte_ethdev.h\n+++ b/lib/librte_ether/rte_ethdev.h\n@@ -882,6 +882,9 @@ struct rte_eth_dev_info {\n \tstruct rte_eth_desc_lim rx_desc_lim; /**< RX descriptors limits */\n \tstruct rte_eth_desc_lim tx_desc_lim; /**< TX descriptors limits */\n \tuint32_t speed_capa; /**< Supported speeds bitmap (ETH_LINK_SPEED_). */\n+\t/** Configured number of rx/tx queues */\n+\tuint16_t nb_rx_queues; /**< Number of RX queues. */\n+\tuint16_t nb_tx_queues; /**< Number of TX queues. */\n };\n \n /**\n@@ -3826,6 +3829,33 @@ void *rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,\n \t\trte_rx_callback_fn fn, void *user_param);\n \n /**\n+ * Add a callback that must be called first on packet RX on a given port and queue.\n+ *\n+ * This API configures a first function to be called for each burst of\n+ * packets received on a given NIC port queue. The return value is a pointer\n+ * that can be used to later remove the callback using\n+ * rte_eth_remove_rx_callback().\n+ *\n+ * Multiple functions are called in the order that they are added.\n+ *\n+ * @param port_id\n+ * The port identifier of the Ethernet device.\n+ * @param queue_id\n+ * The queue on the Ethernet device on which the callback is to be added.\n+ * @param fn\n+ * The callback function\n+ * @param user_param\n+ * A generic pointer parameter which will be passed to each invocation of the\n+ * callback function on this port and queue.\n+ *\n+ * @return\n+ * NULL on error.\n+ * On success, a pointer value which can later be used to remove the callback.\n+ */\n+void *rte_eth_add_first_rx_callback(uint8_t port_id, uint16_t queue_id,\n+\t\trte_rx_callback_fn fn, void *user_param);\n+\n+/**\n * Add a callback to be called on packet TX on a given port and queue.\n *\n * This API configures a function to be called for each burst of\n@@ -4253,6 +4283,21 @@ rte_eth_dev_l2_tunnel_offload_set(uint8_t port_id,\n \t\t\t\t uint32_t mask,\n \t\t\t\t uint8_t en);\n \n+/**\n+ * Get the port id from pci adrress or device name\n+ * Ex: 0000:2:00.0 or vdev name eth_pcap0\n+ *\n+ * @param name\n+ * pci address or name of the device\n+ * @param port_id\n+ * pointer to port identifier of the device\n+ * @return\n+ * - (0) if successful.\n+ * - (-ENODEV) on failure.\n+ */\n+int\n+rte_eth_dev_get_port_by_name(const char *name, uint8_t *port_id);\n+\n #ifdef __cplusplus\n }\n #endif\ndiff --git a/lib/librte_ether/rte_ether_version.map b/lib/librte_ether/rte_ether_version.map\nindex 214ecc7..4de1491 100644\n--- a/lib/librte_ether/rte_ether_version.map\n+++ b/lib/librte_ether/rte_ether_version.map\n@@ -132,3 +132,12 @@ DPDK_16.04 {\n \trte_eth_tx_buffer_set_err_callback;\n \n } DPDK_2.2;\n+\n+DPDK_16.07 {\n+\tglobal:\n+\n+\trte_eth_add_first_rx_callback;\n+\trte_eth_dev_get_port_by_name;\n+\trte_eth_dev_info_get;\n+\n+} DPDK_16.04;\n", "prefixes": [ "dpdk-dev", "PATCHv2", "1/5" ] }{ "id": 12647, "url": "