All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [RFC] eal: rename state values in rte_lcore_state
Date: Tue, 26 Mar 2019 12:25:56 -0700	[thread overview]
Message-ID: <20190326192556.19934-1-stephen@networkplumber.org> (raw)

C language does not really treat enum's as first class symbols.
The values in an enum live in a global namespace.  That means if
DPDK defines "RUNNING" it can't be used by another enum in an
application using DPDK.

To solve this add a prefix "LCORE_" to the enum values, and
make them grammatically consistent.

Also, simplify the inline thread_is_running() which is copied
in softnic and ip_pipeline.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/event/octeontx/ssovf_evdev_selftest.c |  2 +-
 drivers/event/sw/sw_evdev_selftest.c          |  4 ++--
 drivers/net/softnic/rte_eth_softnic_thread.c  |  5 +----
 examples/ip_pipeline/thread.c                 |  5 +----
 examples/l2fwd-keepalive/main.c               |  2 +-
 lib/librte_eal/common/eal_common_launch.c     | 12 ++++++------
 lib/librte_eal/common/include/rte_launch.h    |  6 +++---
 lib/librte_eal/common/rte_service.c           |  2 +-
 lib/librte_eal/freebsd/eal/eal_thread.c       |  6 +++---
 lib/librte_eal/linux/eal/eal.c                |  2 +-
 lib/librte_eal/linux/eal/eal_thread.c         |  8 ++++----
 11 files changed, 24 insertions(+), 30 deletions(-)

diff --git a/drivers/event/octeontx/ssovf_evdev_selftest.c b/drivers/event/octeontx/ssovf_evdev_selftest.c
index 239362fcf549..55d8ac35c190 100644
--- a/drivers/event/octeontx/ssovf_evdev_selftest.c
+++ b/drivers/event/octeontx/ssovf_evdev_selftest.c
@@ -577,7 +577,7 @@ wait_workers_to_join(int lcore, const rte_atomic32_t *count)
 	RTE_SET_USED(count);
 
 	print_cycles = cycles = rte_get_timer_cycles();
-	while (rte_eal_get_lcore_state(lcore) != FINISHED) {
+	while (rte_eal_get_lcore_state(lcore) != LCORE_FINISHED) {
 		uint64_t new_cycles = rte_get_timer_cycles();
 
 		if (new_cycles - print_cycles > rte_get_timer_hz()) {
diff --git a/drivers/event/sw/sw_evdev_selftest.c b/drivers/event/sw/sw_evdev_selftest.c
index d00d5de613d7..7deb70918fc4 100644
--- a/drivers/event/sw/sw_evdev_selftest.c
+++ b/drivers/event/sw/sw_evdev_selftest.c
@@ -3116,8 +3116,8 @@ worker_loopback(struct test *t, uint8_t disable_implicit_release)
 	rte_eal_remote_launch(worker_loopback_worker_fn, t, w_lcore);
 
 	print_cycles = cycles = rte_get_timer_cycles();
-	while (rte_eal_get_lcore_state(p_lcore) != FINISHED ||
-			rte_eal_get_lcore_state(w_lcore) != FINISHED) {
+	while (rte_eal_get_lcore_state(p_lcore) != LCORE_FINISHED ||
+	       rte_eal_get_lcore_state(w_lcore) != LCORE_FINISHED) {
 
 		rte_service_run_iter_on_app_lcore(t->service_id, 1);
 
diff --git a/drivers/net/softnic/rte_eth_softnic_thread.c b/drivers/net/softnic/rte_eth_softnic_thread.c
index 57989a5aac54..6a06a19bcd3e 100644
--- a/drivers/net/softnic/rte_eth_softnic_thread.c
+++ b/drivers/net/softnic/rte_eth_softnic_thread.c
@@ -118,10 +118,7 @@ thread_is_valid(struct pmd_internals *softnic, uint32_t thread_id)
 static inline int
 thread_is_running(uint32_t thread_id)
 {
-	enum rte_lcore_state_t thread_state;
-
-	thread_state = rte_eal_get_lcore_state(thread_id);
-	return (thread_state == RUNNING)? 1 : 0;
+	return rte_eal_get_lcore_state(thread_id) == LCORE_RUNNING;
 }
 
 static int32_t
diff --git a/examples/ip_pipeline/thread.c b/examples/ip_pipeline/thread.c
index 272fbbeed1bc..6819dd5323e9 100644
--- a/examples/ip_pipeline/thread.c
+++ b/examples/ip_pipeline/thread.c
@@ -158,10 +158,7 @@ thread_init(void)
 static inline int
 thread_is_running(uint32_t thread_id)
 {
-	enum rte_lcore_state_t thread_state;
-
-	thread_state = rte_eal_get_lcore_state(thread_id);
-	return (thread_state == RUNNING) ? 1 : 0;
+	return rte_eal_get_lcore_state(thread_id) == LCORE_RUNNING;
 }
 
 /**
diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c
index 0bf2b533648a..8c56f4aa5ebf 100644
--- a/examples/l2fwd-keepalive/main.c
+++ b/examples/l2fwd-keepalive/main.c
@@ -502,7 +502,7 @@ dead_core(__rte_unused void *ptr_data, const int id_core)
 	if (terminate_signal_received)
 		return;
 	printf("Dead core %i - restarting..\n", id_core);
-	if (rte_eal_get_lcore_state(id_core) == FINISHED) {
+	if (rte_eal_get_lcore_state(id_core) == LCORE_FINISHED) {
 		rte_eal_wait_lcore(id_core);
 		rte_eal_remote_launch(l2fwd_launch_one_lcore, NULL, id_core);
 	} else {
diff --git a/lib/librte_eal/common/eal_common_launch.c b/lib/librte_eal/common/eal_common_launch.c
index fe0ba3f0d617..febf9c7b0c40 100644
--- a/lib/librte_eal/common/eal_common_launch.c
+++ b/lib/librte_eal/common/eal_common_launch.c
@@ -21,17 +21,17 @@
 int
 rte_eal_wait_lcore(unsigned slave_id)
 {
-	if (lcore_config[slave_id].state == WAIT)
+	if (lcore_config[slave_id].state == LCORE_WAITING)
 		return 0;
 
-	while (lcore_config[slave_id].state != WAIT &&
-	       lcore_config[slave_id].state != FINISHED)
+	while (lcore_config[slave_id].state != LCORE_WAITING &&
+	       lcore_config[slave_id].state != LCORE_FINISHED)
 		rte_pause();
 
 	rte_rmb();
 
 	/* we are in finished state, go to wait state */
-	lcore_config[slave_id].state = WAIT;
+	lcore_config[slave_id].state = LCORE_WAITING;
 	return lcore_config[slave_id].ret;
 }
 
@@ -49,7 +49,7 @@ rte_eal_mp_remote_launch(int (*f)(void *), void *arg,
 
 	/* check state of lcores */
 	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-		if (lcore_config[lcore_id].state != WAIT)
+		if (lcore_config[lcore_id].state != LCORE_WAITING)
 			return -EBUSY;
 	}
 
@@ -60,7 +60,7 @@ rte_eal_mp_remote_launch(int (*f)(void *), void *arg,
 
 	if (call_master == CALL_MASTER) {
 		lcore_config[master].ret = f(arg);
-		lcore_config[master].state = FINISHED;
+		lcore_config[master].state = LCORE_FINISHED;
 	}
 
 	return 0;
diff --git a/lib/librte_eal/common/include/rte_launch.h b/lib/librte_eal/common/include/rte_launch.h
index 06a671752ace..45704e37eedf 100644
--- a/lib/librte_eal/common/include/rte_launch.h
+++ b/lib/librte_eal/common/include/rte_launch.h
@@ -19,9 +19,9 @@ extern "C" {
  * State of an lcore.
  */
 enum rte_lcore_state_t {
-	WAIT,       /**< waiting a new command */
-	RUNNING,    /**< executing command */
-	FINISHED,   /**< command executed */
+	LCORE_WAITING,    /**< waiting a new command */
+	LCORE_RUNNING,    /**< executing command */
+	LCORE_FINISHED,   /**< command executed */
 };
 
 /**
diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c
index 03fde97a9c89..4468b33a377d 100644
--- a/lib/librte_eal/common/rte_service.c
+++ b/lib/librte_eal/common/rte_service.c
@@ -450,7 +450,7 @@ rte_service_runner_func(void *arg)
 		rte_smp_rmb();
 	}
 
-	lcore_config[lcore].state = WAIT;
+	lcore_config[lcore].state = LCORE_WAITING;
 
 	return 0;
 }
diff --git a/lib/librte_eal/freebsd/eal/eal_thread.c b/lib/librte_eal/freebsd/eal/eal_thread.c
index 309b5872666b..c0a26c65bc27 100644
--- a/lib/librte_eal/freebsd/eal/eal_thread.c
+++ b/lib/librte_eal/freebsd/eal/eal_thread.c
@@ -41,7 +41,7 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
 	int m2s = lcore_config[slave_id].pipe_master2slave[1];
 	int s2m = lcore_config[slave_id].pipe_slave2master[0];
 
-	if (lcore_config[slave_id].state != WAIT)
+	if (lcore_config[slave_id].state != LCORE_WAITING)
 		return -EBUSY;
 
 	lcore_config[slave_id].f = f;
@@ -136,7 +136,7 @@ eal_thread_loop(__attribute__((unused)) void *arg)
 		if (n <= 0)
 			rte_panic("cannot read on configuration pipe\n");
 
-		lcore_config[lcore_id].state = RUNNING;
+		lcore_config[lcore_id].state = LCORE_RUNNING;
 
 		/* send ack */
 		n = 0;
@@ -153,7 +153,7 @@ eal_thread_loop(__attribute__((unused)) void *arg)
 		ret = lcore_config[lcore_id].f(fct_arg);
 		lcore_config[lcore_id].ret = ret;
 		rte_wmb();
-		lcore_config[lcore_id].state = FINISHED;
+		lcore_config[lcore_id].state = LCORE_FINISHED;
 	}
 
 	/* never reached */
diff --git a/lib/librte_eal/linux/eal/eal.c b/lib/librte_eal/linux/eal/eal.c
index 13f40168415d..8b93a7b929a9 100644
--- a/lib/librte_eal/linux/eal/eal.c
+++ b/lib/librte_eal/linux/eal/eal.c
@@ -1158,7 +1158,7 @@ rte_eal_init(int argc, char **argv)
 		if (pipe(lcore_config[i].pipe_slave2master) < 0)
 			rte_panic("Cannot create pipe\n");
 
-		lcore_config[i].state = WAIT;
+		lcore_config[i].state = LCORE_WAITING;
 
 		/* create a thread for each lcore */
 		ret = pthread_create(&lcore_config[i].thread_id, NULL,
diff --git a/lib/librte_eal/linux/eal/eal_thread.c b/lib/librte_eal/linux/eal/eal_thread.c
index 379773b683e8..63f3e66110e7 100644
--- a/lib/librte_eal/linux/eal/eal_thread.c
+++ b/lib/librte_eal/linux/eal/eal_thread.c
@@ -41,7 +41,7 @@ rte_eal_remote_launch(int (*f)(void *), void *arg, unsigned slave_id)
 	int m2s = lcore_config[slave_id].pipe_master2slave[1];
 	int s2m = lcore_config[slave_id].pipe_slave2master[0];
 
-	if (lcore_config[slave_id].state != WAIT)
+	if (lcore_config[slave_id].state != LCORE_WAITING)
 		return -EBUSY;
 
 	lcore_config[slave_id].f = f;
@@ -136,7 +136,7 @@ eal_thread_loop(__attribute__((unused)) void *arg)
 		if (n <= 0)
 			rte_panic("cannot read on configuration pipe\n");
 
-		lcore_config[lcore_id].state = RUNNING;
+		lcore_config[lcore_id].state = LCORE_RUNNING;
 
 		/* send ack */
 		n = 0;
@@ -158,9 +158,9 @@ eal_thread_loop(__attribute__((unused)) void *arg)
 		 * state, because the application will not lcore_wait() for it.
 		 */
 		if (lcore_config[lcore_id].core_role == ROLE_SERVICE)
-			lcore_config[lcore_id].state = WAIT;
+			lcore_config[lcore_id].state = LCORE_WAITING;
 		else
-			lcore_config[lcore_id].state = FINISHED;
+			lcore_config[lcore_id].state = LCORE_FINISHED;
 	}
 
 	/* never reached */
-- 
2.17.1

             reply	other threads:[~2019-03-26 19:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-26 19:25 Stephen Hemminger [this message]
2019-03-27  0:42 ` [RFC] eal: rename state values in rte_lcore_state Thomas Monjalon
2019-04-02 15:57 ` [PATCH v2] " Stephen Hemminger
2019-04-02 20:15   ` David Marchand
2019-04-02 20:48     ` Stephen Hemminger
2019-04-02 21:03       ` David Marchand
2019-04-02 21:07         ` Stephen Hemminger
2019-04-02 21:21           ` David Marchand
2019-04-02 20:53   ` [PATCH v3] " Stephen Hemminger
2019-04-03 11:59     ` David Marchand

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=20190326192556.19934-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --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.