All of lore.kernel.org
 help / color / mirror / Atom feed
From: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
To: pbhagavatula@caviumnetworks.com, jerin.jacob@caviumnetworks.com,
	rsanford@akamai.com
Cc: dev@dpdk.org
Subject: [PATCH 2/3] timer: add function to stop all timers in a list
Date: Thu, 29 Nov 2018 17:35:13 -0600	[thread overview]
Message-ID: <1543534514-183766-3-git-send-email-erik.g.carrillo@intel.com> (raw)
In-Reply-To: <1543534514-183766-1-git-send-email-erik.g.carrillo@intel.com>

Add a function to the timer API that allows a caller to traverse a
specified set of timer lists, stopping each timer in each list,
and invoking a callback function.

Signed-off-by: Erik Gabriel Carrillo <erik.g.carrillo@intel.com>
---
 lib/librte_timer/rte_timer.c           | 81 +++++++++++++++++++++++++++-------
 lib/librte_timer/rte_timer.h           | 32 ++++++++++++++
 lib/librte_timer/rte_timer_version.map |  1 +
 3 files changed, 97 insertions(+), 17 deletions(-)

diff --git a/lib/librte_timer/rte_timer.c b/lib/librte_timer/rte_timer.c
index a76be8b..1eaf755 100644
--- a/lib/librte_timer/rte_timer.c
+++ b/lib/librte_timer/rte_timer.c
@@ -559,39 +559,30 @@ rte_timer_reset_sync(struct rte_timer *tim, uint64_t ticks,
 		rte_pause();
 }
 
-/* Stop the timer associated with the timer handle tim */
-int
-rte_timer_stop(struct rte_timer *tim)
-{
-	return rte_timer_alt_stop(default_data_id, tim);
-}
-
-int __rte_experimental
-rte_timer_alt_stop(uint32_t timer_data_id, struct rte_timer *tim)
+static int
+__rte_timer_stop(struct rte_timer *tim, int local_is_locked,
+		 struct rte_timer_data *data)
 {
 	union rte_timer_status prev_status, status;
 	unsigned lcore_id = rte_lcore_id();
 	int ret;
-	struct rte_timer_data *timer_data;
-
-	TIMER_DATA_VALID_GET_OR_ERR_RET(timer_data_id, timer_data, -EINVAL);
 
 	/* wait that the timer is in correct status before update,
 	 * and mark it as being configured */
-	ret = timer_set_config_state(tim, &prev_status, timer_data);
+	ret = timer_set_config_state(tim, &prev_status, data);
 	if (ret < 0)
 		return -1;
 
-	__TIMER_STAT_ADD(timer_data, stop, 1);
+	__TIMER_STAT_ADD(data, stop, 1);
 	if (prev_status.state == RTE_TIMER_RUNNING &&
 	    lcore_id < RTE_MAX_LCORE) {
-		timer_data->priv_timer[lcore_id].updated = 1;
+		data->priv_timer[lcore_id].updated = 1;
 	}
 
 	/* remove it from list */
 	if (prev_status.state == RTE_TIMER_PENDING) {
-		timer_del(tim, prev_status, 0, timer_data);
-		__TIMER_STAT_ADD(timer_data, pending, -1);
+		timer_del(tim, prev_status, local_is_locked, data);
+		__TIMER_STAT_ADD(data, pending, -1);
 	}
 
 	/* mark timer as stopped */
@@ -603,6 +594,23 @@ rte_timer_alt_stop(uint32_t timer_data_id, struct rte_timer *tim)
 	return 0;
 }
 
+/* Stop the timer associated with the timer handle tim */
+int
+rte_timer_stop(struct rte_timer *tim)
+{
+	return rte_timer_alt_stop(default_data_id, tim);
+}
+
+int __rte_experimental
+rte_timer_alt_stop(uint32_t timer_data_id, struct rte_timer *tim)
+{
+	struct rte_timer_data *timer_data;
+
+	TIMER_DATA_VALID_GET_OR_ERR_RET(timer_data_id, timer_data, -EINVAL);
+
+	return __rte_timer_stop(tim, 0, timer_data);
+}
+
 /* loop until rte_timer_stop() succeed */
 void
 rte_timer_stop_sync(struct rte_timer *tim)
@@ -912,6 +920,45 @@ rte_timer_alt_manage(uint32_t timer_data_id,
 	return 0;
 }
 
+/* Walk pending lists, stopping timers and calling user-specified function */
+int __rte_experimental
+rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores,
+		   int nb_walk_lcores,
+		   rte_timer_stop_all_cb_t f, void *f_arg)
+{
+	int i;
+	struct priv_timer *priv_timer;
+	uint32_t walk_lcore;
+	struct rte_timer *tim, *next_tim;
+	struct rte_timer_data *timer_data;
+
+	TIMER_DATA_VALID_GET_OR_ERR_RET(timer_data_id, timer_data, -EINVAL);
+
+	for (i = 0, walk_lcore = walk_lcores[i];
+	     i < nb_walk_lcores;
+	     walk_lcore = walk_lcores[++i]) {
+		priv_timer = &timer_data->priv_timer[walk_lcore];
+
+		rte_spinlock_lock(&priv_timer->list_lock);
+
+		for (tim = priv_timer->pending_head.sl_next[0];
+		     tim != NULL;
+		     tim = next_tim) {
+			next_tim = tim->sl_next[0];
+
+			/* Call timer_stop with lock held */
+			__rte_timer_stop(tim, 1, timer_data);
+
+			if (f)
+				f(tim, f_arg);
+		}
+
+		rte_spinlock_unlock(&priv_timer->list_lock);
+	}
+
+	return 0;
+}
+
 /* dump statistics about timers */
 void rte_timer_dump_stats(FILE *f)
 {
diff --git a/lib/librte_timer/rte_timer.h b/lib/librte_timer/rte_timer.h
index 9daa334..27b1ebd 100644
--- a/lib/librte_timer/rte_timer.h
+++ b/lib/librte_timer/rte_timer.h
@@ -446,6 +446,38 @@ rte_timer_alt_manage(uint32_t timer_data_id, unsigned int *poll_lcores,
 		     int n_poll_lcores, rte_timer_alt_manage_cb_t f);
 
 /**
+ * Callback function type for rte_timer_stop_all().
+ */
+typedef void (*rte_timer_stop_all_cb_t)(struct rte_timer *tim, void *arg);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice
+ *
+ * Walk the pending timer lists for the specified lcore IDs, and for each timer
+ * that is encountered, stop it and call the specified callback function to
+ * process it further.
+ *
+ * @param timer_data_id
+ *   An identifier indicating which instance of timer data should be used for
+ *   this operation.
+ * @param walk_lcores
+ *   An array of lcore ids identifying the timer lists that should be processed.
+ * @param nb_walk_lcores
+ *   The size of the walk_lcores array.
+ * @param f
+ *   The callback function which should be called for each timers. Can be NULL.
+ * @param f_arg
+ *   An arbitrary argument that will be passed to f, if it is called.
+ * @return
+ *   - 0: success
+ *   - EINVAL: invalid timer_data_id
+ */
+int __rte_experimental
+rte_timer_stop_all(uint32_t timer_data_id, unsigned int *walk_lcores,
+		   int nb_walk_lcores, rte_timer_stop_all_cb_t f, void *f_arg);
+
+/**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice
  *
diff --git a/lib/librte_timer/rte_timer_version.map b/lib/librte_timer/rte_timer_version.map
index 1e6b70d..0fab845 100644
--- a/lib/librte_timer/rte_timer_version.map
+++ b/lib/librte_timer/rte_timer_version.map
@@ -28,5 +28,6 @@ EXPERIMENTAL {
 	rte_timer_alt_stop;
 	rte_timer_data_alloc;
 	rte_timer_data_dealloc;
+	rte_timer_stop_all;
 	rte_timer_subsystem_finalize;
 };
-- 
2.6.4

  parent reply	other threads:[~2018-11-29 23:35 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 23:35 [PATCH 0/3] new software event timer adapter Erik Gabriel Carrillo
2018-11-29 23:35 ` [PATCH 1/3] timer: allow timer management in shared memory Erik Gabriel Carrillo
2018-11-29 23:35 ` Erik Gabriel Carrillo [this message]
2018-11-29 23:35 ` [PATCH 3/3] eventdev: add new software event timer adapter Erik Gabriel Carrillo
2018-11-30  7:26 ` [PATCH 0/3] " Pavan Nikhilesh
2018-11-30 19:07   ` Carrillo, Erik G
2018-12-07 17:52 ` [PATCH v2 0/2] Timer library changes Erik Gabriel Carrillo
2018-12-07 17:52   ` [PATCH v2 1/2] timer: allow timer management in shared memory Erik Gabriel Carrillo
2018-12-07 18:10     ` Stephen Hemminger
2018-12-07 19:21       ` Carrillo, Erik G
2018-12-07 17:53   ` [PATCH v2 2/2] timer: add function to stop all timers in a list Erik Gabriel Carrillo
2018-12-13 22:26   ` [PATCH v3 0/2] Timer library changes Erik Gabriel Carrillo
2018-12-13 22:26     ` [PATCH v3 1/2] timer: allow timer management in shared memory Erik Gabriel Carrillo
2018-12-13 22:26     ` [PATCH v3 2/2] timer: add function to stop all timers in a list Erik Gabriel Carrillo
2018-12-19  3:35     ` [PATCH v3 0/2] Timer library changes Thomas Monjalon
2018-12-19  7:33       ` Mattias Rönnblom
2019-03-05 22:41     ` Carrillo, Erik G
2019-03-05 22:58       ` [dpdk-techboard] " Thomas Monjalon
2019-03-06 18:54         ` Carrillo, Erik G
2019-03-06 20:17           ` Thomas Monjalon
2019-03-06  2:39       ` Varghese, Vipin
2019-03-06 15:15         ` Carrillo, Erik G
2019-03-07  2:33           ` Varghese, Vipin
2019-03-06 17:20     ` [PATCH v4 " Erik Gabriel Carrillo
2019-03-06 17:20       ` [PATCH v4 1/2] timer: allow timer management in shared memory Erik Gabriel Carrillo
2019-03-20 13:52         ` Sanford, Robert
2019-03-21  1:01           ` Carrillo, Erik G
2019-03-27 14:03             ` Thomas Monjalon
2019-03-28 12:42               ` Carrillo, Erik G
2019-04-15 21:49           ` [dpdk-dev] " Carrillo, Erik G
2019-03-06 17:20       ` [PATCH v4 2/2] timer: add function to stop all timers in a list Erik Gabriel Carrillo
2019-04-15 21:41       ` [dpdk-dev] [PATCH v5 0/2] Timer library changes Erik Gabriel Carrillo
2019-04-15 21:41         ` [dpdk-dev] [PATCH v5 1/2] timer: allow timer management in shared memory Erik Gabriel Carrillo
2019-04-17 17:09           ` Thomas Monjalon
2019-04-15 21:41         ` [dpdk-dev] [PATCH v5 2/2] timer: add function to stop all timers in a list Erik Gabriel Carrillo
2019-04-17 19:54         ` [dpdk-dev] [PATCH v5 0/2] Timer library changes Thomas Monjalon
2018-12-07 20:34 ` [PATCH v2 0/1] New software event timer adapter Erik Gabriel Carrillo
2018-12-07 20:34   ` [PATCH v2 1/1] eventdev: add new " Erik Gabriel Carrillo
2018-12-09 19:17     ` Mattias Rönnblom
2018-12-10 17:17       ` Carrillo, Erik G
2018-12-14 15:45   ` [PATCH v3 0/1] New " Erik Gabriel Carrillo
2018-12-14 15:45     ` [PATCH v3 1/1] eventdev: add new " Erik Gabriel Carrillo
2018-12-14 21:15       ` Mattias Rönnblom
2018-12-14 23:04         ` Carrillo, Erik G
2018-12-14 23:15     ` [PATCH v4 0/1] New " Erik Gabriel Carrillo
2018-12-14 23:15       ` [PATCH v4 1/1] eventdev: add new " Erik Gabriel Carrillo
2018-12-18 20:11       ` [EXT] [PATCH v4 0/1] New " Jerin Jacob Kollanukkaran
2018-12-18 20:14         ` Carrillo, Erik G
2019-04-22 14:57       ` [dpdk-dev] [PATCH v5 " Erik Gabriel Carrillo
2019-04-22 14:57         ` [dpdk-dev] [PATCH v5 1/1] eventdev: add new " Erik Gabriel Carrillo
2019-04-26 15:14         ` [dpdk-dev] [PATCH v6 0/1] New " Erik Gabriel Carrillo
2019-04-26 15:14           ` [dpdk-dev] [PATCH v6 1/1] eventdev: add new " Erik Gabriel Carrillo
2019-04-26 18:51             ` Honnappa Nagarahalli
2019-04-26 18:58               ` Carrillo, Erik G
2019-06-05 13:34                 ` Jerin Jacob Kollanukkaran
2019-06-19 15:14           ` [dpdk-dev] [PATCH v7 0/1] New " Erik Gabriel Carrillo
2019-06-19 15:14             ` [dpdk-dev] [PATCH v7 1/1] eventdev: add new " Erik Gabriel Carrillo
2019-06-19 16:25               ` [dpdk-dev] [PATCH v8 0/1] New " Erik Gabriel Carrillo
2019-06-19 16:25                 ` [dpdk-dev] [PATCH v8 1/1] eventdev: add new " Erik Gabriel Carrillo
2019-06-24  6:12                   ` Jerin Jacob Kollanukkaran
2019-06-25  6:06                     ` Jerin Jacob Kollanukkaran

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=1543534514-183766-3-git-send-email-erik.g.carrillo@intel.com \
    --to=erik.g.carrillo@intel.com \
    --cc=dev@dpdk.org \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=pbhagavatula@caviumnetworks.com \
    --cc=rsanford@akamai.com \
    /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.