All of lore.kernel.org
 help / color / mirror / Atom feed
From: Reshma Pattan <reshma.pattan@intel.com>
To: dev@dpdk.org
Cc: Reshma Pattan <reshma.pattan@intel.com>
Subject: [PATCH v6 1/8] librte_ether: protect add/remove of rxtx callbacks with spinlocks
Date: Thu,  9 Jun 2016 09:50:03 +0100	[thread overview]
Message-ID: <1465462210-4203-2-git-send-email-reshma.pattan@intel.com> (raw)
In-Reply-To: <1465462210-4203-1-git-send-email-reshma.pattan@intel.com>

Added spinlocks around add/remove logic of rxtx callbacks to
avoid corruption of callback lists in multithreaded context.

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
 lib/librte_ether/rte_ethdev.c | 82 +++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 42 deletions(-)

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index e148028..ce70d58 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -77,6 +77,12 @@ static uint8_t nb_ports;
 /* spinlock for eth device callbacks */
 static rte_spinlock_t rte_eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER;
 
+/* spinlock for add/remove rx callbacks */
+static rte_spinlock_t rte_eth_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
+
+/* spinlock for add/remove tx callbacks */
+static rte_spinlock_t rte_eth_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
+
 /* store statistics names and its offset in stats structure  */
 struct rte_eth_xstats_name_off {
 	char name[RTE_ETH_XSTATS_NAME_SIZE];
@@ -1634,7 +1640,6 @@ rte_eth_dev_set_rx_queue_stats_mapping(uint8_t port_id, uint16_t rx_queue_id,
 			STAT_QMAP_RX);
 }
 
-
 void
 rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info)
 {
@@ -2905,7 +2910,6 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
 		rte_errno = EINVAL;
 		return NULL;
 	}
-
 	struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
 
 	if (cb == NULL) {
@@ -2916,6 +2920,7 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
 	cb->fn.rx = fn;
 	cb->param = user_param;
 
+	rte_spinlock_lock(&rte_eth_rx_cb_lock);
 	/* Add the callbacks in fifo order. */
 	struct rte_eth_rxtx_callback *tail =
 		rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
@@ -2928,6 +2933,7 @@ rte_eth_add_rx_callback(uint8_t port_id, uint16_t queue_id,
 			tail = tail->next;
 		tail->next = cb;
 	}
+	rte_spinlock_unlock(&rte_eth_rx_cb_lock);
 
 	return cb;
 }
@@ -2957,6 +2963,7 @@ rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
 	cb->fn.tx = fn;
 	cb->param = user_param;
 
+	rte_spinlock_lock(&rte_eth_tx_cb_lock);
 	/* Add the callbacks in fifo order. */
 	struct rte_eth_rxtx_callback *tail =
 		rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
@@ -2969,6 +2976,7 @@ rte_eth_add_tx_callback(uint8_t port_id, uint16_t queue_id,
 			tail = tail->next;
 		tail->next = cb;
 	}
+	rte_spinlock_unlock(&rte_eth_tx_cb_lock);
 
 	return cb;
 }
@@ -2987,29 +2995,24 @@ rte_eth_remove_rx_callback(uint8_t port_id, uint16_t queue_id,
 		return -EINVAL;
 
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
-	struct rte_eth_rxtx_callback *cb = dev->post_rx_burst_cbs[queue_id];
-	struct rte_eth_rxtx_callback *prev_cb;
-
-	/* Reset head pointer and remove user cb if first in the list. */
-	if (cb == user_cb) {
-		dev->post_rx_burst_cbs[queue_id] = user_cb->next;
-		return 0;
-	}
-
-	/* Remove the user cb from the callback list. */
-	do {
-		prev_cb = cb;
-		cb = cb->next;
-
+	struct rte_eth_rxtx_callback *cb;
+	struct rte_eth_rxtx_callback **prev_cb;
+	int ret = -EINVAL;
+
+	rte_spinlock_lock(&rte_eth_rx_cb_lock);
+	prev_cb = &dev->post_rx_burst_cbs[queue_id];
+	for (; *prev_cb != NULL; prev_cb = &cb->next) {
+		cb = *prev_cb;
 		if (cb == user_cb) {
-			prev_cb->next = user_cb->next;
-			return 0;
+			/* Remove the user cb from the callback list. */
+			*prev_cb = cb->next;
+			ret = 0;
+			break;
 		}
+	}
+	rte_spinlock_unlock(&rte_eth_rx_cb_lock);
 
-	} while (cb != NULL);
-
-	/* Callback wasn't found. */
-	return -EINVAL;
+	return ret;
 }
 
 int
@@ -3026,29 +3029,24 @@ rte_eth_remove_tx_callback(uint8_t port_id, uint16_t queue_id,
 		return -EINVAL;
 
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
-	struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
-	struct rte_eth_rxtx_callback *prev_cb;
-
-	/* Reset head pointer and remove user cb if first in the list. */
-	if (cb == user_cb) {
-		dev->pre_tx_burst_cbs[queue_id] = user_cb->next;
-		return 0;
-	}
-
-	/* Remove the user cb from the callback list. */
-	do {
-		prev_cb = cb;
-		cb = cb->next;
-
+	int ret = -EINVAL;
+	struct rte_eth_rxtx_callback *cb;
+	struct rte_eth_rxtx_callback **prev_cb;
+
+	rte_spinlock_lock(&rte_eth_tx_cb_lock);
+	prev_cb = &dev->pre_tx_burst_cbs[queue_id];
+	for (; *prev_cb != NULL; prev_cb = &cb->next) {
+		cb = *prev_cb;
 		if (cb == user_cb) {
-			prev_cb->next = user_cb->next;
-			return 0;
+			/* Remove the user cb from the callback list. */
+			*prev_cb = cb->next;
+			ret = 0;
+			break;
 		}
+	}
+	rte_spinlock_unlock(&rte_eth_tx_cb_lock);
 
-	} while (cb != NULL);
-
-	/* Callback wasn't found. */
-	return -EINVAL;
+	return ret;
 }
 
 int
-- 
2.5.0

  reply	other threads:[~2016-06-09  8:50 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 10:55 [PATCH 0/5] add packet capture framework Reshma Pattan
2016-05-06 10:55 ` [PATCH 1/5] librte_ether: protect add/remove of rxtx callbacks with spinlocks Reshma Pattan
2016-05-06 10:55 ` [PATCH 2/5] lib/librte_pdump: add new library for packet capturing support Reshma Pattan
2016-05-06 10:55 ` [PATCH 3/5] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-05-06 10:55 ` [PATCH 4/5] app/test-pmd: add pdump initialization uninitialization Reshma Pattan
2016-05-06 10:55 ` [PATCH 5/5] doc: update doc for packet capture framework Reshma Pattan
2016-05-10  9:39 ` [PATCHv2 0/5] add " Reshma Pattan
2016-05-10  9:39   ` [PATCHv2 1/5] librte_ether: protect add/remove of rxtx callbacks with spinlocks Reshma Pattan
2016-05-10  9:39   ` [PATCHv2 2/5] lib/librte_pdump: add new library for packet capturing support Reshma Pattan
2016-05-10  9:40   ` [PATCHv2 3/5] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-05-10  9:40   ` [PATCHv2 4/5] app/test-pmd: add pdump initialization uninitialization Reshma Pattan
2016-05-10  9:40   ` [PATCHv2 5/5] doc: update doc for packet capture framework Reshma Pattan
2016-05-10 10:13   ` [PATCHv2 0/5] add " Remy Horton
2016-05-17 16:37   ` [PATCH v3 0/8] " Reshma Pattan
2016-05-17 16:37     ` [PATCH v3 1/8] librte_ether: protect add/remove of rxtx callbacks with spinlocks Reshma Pattan
2016-05-17 16:37     ` [PATCH v3 2/8] librte_ether: add new api rte_eth_add_first_rx_callback Reshma Pattan
2016-05-17 16:37     ` [PATCH v3 3/8] librte_ether: add new fields to rte_eth_dev_info struct Reshma Pattan
2016-05-17 16:37     ` [PATCH v3 4/8] librte_ether: make rte_eth_dev_get_port_by_name api public Reshma Pattan
2016-05-17 16:37     ` [PATCH v3 5/8] lib/librte_pdump: add new library for packet capturing support Reshma Pattan
2016-05-17 16:37     ` [PATCH v3 6/8] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-05-17 16:37     ` [PATCH v3 7/8] app/test-pmd: add pdump initialization uninitialization Reshma Pattan
2016-05-17 16:37     ` [PATCH v3 8/8] doc: update doc for packet capture framework Reshma Pattan
2016-05-23 21:38     ` [PATCH v4 0/9] add " Reshma Pattan
2016-05-23 21:38       ` [PATCH v4 1/9] librte_ether: protect add/remove of rxtx callbacks with spinlocks Reshma Pattan
2016-05-23 21:38       ` [PATCH v4 2/9] librte_ether: add new api rte_eth_add_first_rx_callback Reshma Pattan
2016-05-23 21:38       ` [PATCH v4 3/9] librte_ether: add new fields to rte_eth_dev_info struct Reshma Pattan
2016-05-23 22:24         ` Stephen Hemminger
2016-05-24  8:09           ` Pattan, Reshma
2016-05-23 21:38       ` [PATCH v4 4/9] librte_ether: make rte_eth_dev_get_port_by_name api public Reshma Pattan
2016-05-23 21:38       ` [PATCH v4 5/9] lib/librte_pdump: add new library for packet capturing support Reshma Pattan
2016-05-27 13:39         ` Ananyev, Konstantin
2016-05-27 14:54           ` Pattan, Reshma
2016-05-27 15:25             ` Ananyev, Konstantin
2016-05-31 14:55               ` Pattan, Reshma
2016-05-31 15:00           ` Pattan, Reshma
2016-05-23 21:38       ` [PATCH v4 6/9] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-05-27 15:21         ` Ananyev, Konstantin
2016-05-31 14:50           ` Pattan, Reshma
2016-05-31 17:21             ` Ananyev, Konstantin
2016-06-02 12:31               ` Pattan, Reshma
2016-06-02 14:22                 ` Ananyev, Konstantin
2016-05-23 21:38       ` [PATCH v4 7/9] app/test-pmd: add pdump initialization uninitialization Reshma Pattan
2016-05-23 21:38       ` [PATCH v4 8/9] doc: update doc for packet capture framework Reshma Pattan
2016-05-23 21:38       ` [PATCH v4 9/9] doc: announce ABI change for rte_eth_dev_info structure Reshma Pattan
2016-05-26  8:15       ` [PATCH v4 0/9] add packet capture framework Thomas Monjalon
2016-06-08 13:38       ` [PATCH v5 " Reshma Pattan
2016-06-08 13:38         ` [PATCH v5 1/9] librte_ether: protect add/remove of rxtx callbacks with spinlocks Reshma Pattan
2016-06-08 13:38         ` [PATCH v5 2/9] librte_ether: add new api rte_eth_add_first_rx_callback Reshma Pattan
2016-06-08 13:38         ` [PATCH v5 3/9] librte_ether: add new fields to rte_eth_dev_info struct Reshma Pattan
2016-06-08 13:38         ` [PATCH v5 4/9] librte_ether: make rte_eth_dev_get_port_by_name rte_eth_dev_get_name_by_port public Reshma Pattan
2016-06-08 13:38         ` [PATCH v5 5/9] lib/librte_pdump: add new library for packet capturing support Reshma Pattan
2016-06-08 13:38         ` [PATCH v5 6/9] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-06-08 13:38         ` [PATCH v5 7/9] app/test-pmd: add pdump initialization uninitialization Reshma Pattan
2016-06-08 13:38         ` [PATCH v5 8/9] doc: update doc for packet capture framework Reshma Pattan
2016-06-08 16:02           ` Mcnamara, John
2016-06-08 13:38         ` [PATCH v5 9/9] doc: announce ABI change for rte_eth_dev_info structure Reshma Pattan
2016-06-08 16:15           ` Mcnamara, John
2016-06-09  8:50         ` [PATCH v6 0/8] add packet capture framework Reshma Pattan
2016-06-09  8:50           ` Reshma Pattan [this message]
2016-06-09  8:50           ` [PATCH v6 2/8] librte_ether: add new api rte_eth_add_first_rx_callback Reshma Pattan
2016-06-09  8:50           ` [PATCH v6 3/8] librte_ether: add new fields to rte_eth_dev_info struct Reshma Pattan
2016-06-09  8:50           ` [PATCH v6 4/8] librte_ether: make rte_eth_dev_get_port_by_name rte_eth_dev_get_name_by_port public Reshma Pattan
2016-06-09  8:50           ` [PATCH v6 5/8] lib/librte_pdump: add new library for packet capturing support Reshma Pattan
2016-06-09 15:59             ` Aaron Conole
2016-06-09 16:05               ` Ananyev, Konstantin
2016-06-09 17:23                 ` Aaron Conole
2016-06-09 19:32                   ` Ananyev, Konstantin
2016-06-09 19:56                     ` Aaron Conole
2016-06-10 16:22               ` Pattan, Reshma
2016-06-09  8:50           ` [PATCH v6 6/8] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-06-09  8:50           ` [PATCH v6 7/8] app/test-pmd: add pdump initialization uninitialization Reshma Pattan
2016-06-09  8:50           ` [PATCH v6 8/8] doc: update doc for packet capture framework Reshma Pattan
2016-06-09 16:10           ` [PATCH v7 0/8] add " Reshma Pattan
2016-06-09 16:10             ` [PATCH v7 1/8] librte_ether: protect add/remove of rxtx callbacks with spinlocks Reshma Pattan
2016-06-09 16:10             ` [PATCH v7 2/8] librte_ether: add new api rte_eth_add_first_rx_callback Reshma Pattan
2016-06-09 16:10             ` [PATCH v7 3/8] librte_ether: add new fields to rte_eth_dev_info struct Reshma Pattan
2016-06-09 16:10             ` [PATCH v7 4/8] librte_ether: make rte_eth_dev_get_port_by_name rte_eth_dev_get_name_by_port public Reshma Pattan
2016-06-09 16:10             ` [PATCH v7 5/8] lib/librte_pdump: add new library for packet capturing support Reshma Pattan
2016-06-09 16:10             ` [PATCH v7 6/8] app/pdump: add pdump tool for packet capturing Reshma Pattan
2016-06-09 16:10             ` [PATCH v7 7/8] app/test-pmd: add pdump initialization uninitialization Reshma Pattan
2016-06-09 16:10             ` [PATCH v7 8/8] doc: update doc for packet capture framework Reshma Pattan
2016-06-09 17:34             ` [PATCH v7 0/8] add " Ananyev, Konstantin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465462210-4203-2-git-send-email-reshma.pattan@intel.com \
    --to=reshma.pattan@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.