[v4,3/3] examples/eventdev: move eth stop to the end

Message ID 20210114103101.738262-4-feifei.wang2@arm.com (mailing list archive)
State Accepted, archived
Delegated to: Jerin Jacob
Headers
Series fix bugs for examples/evnentdev |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS

Commit Message

Feifei Wang Jan. 14, 2021, 10:31 a.m. UTC
  Move eth stop code from "signal_handler" function to the end of "main"
function. There are two reasons for this:

First, this improves code maintenance and makes code look simple and
clear. Based on this change, after receiving the interrupt signal,
"fdata->done" is set as 1. Then the main thread will wait all worker
lcores to jump out of the loop. Finally, the main thread will stop and
then close eth dev port.

Second, for older version, the main thread first stops eth dev port and
then waits the end of worker lcore. This may cause errors because it may
stop the eth dev port which worker lcores are using. This moving change
can fix this by waiting all worker threads to exit and then stop the
eth dev port.

In the meanwhile, remove wmb in signal_handler.

This is because when the main lcore receive the stop signal, it stores 1
into fdata->done. And then the worker lcores load "fdata->done" and jump
out of the loop to stop running. Nothing should be stored after updating
fdata->done, so the wmb is unnecessary.

Fixes: 085edac2ca38 ("examples/eventdev_pipeline: support Tx adapter")
Cc: pbhagavatula@marvell.com
Cc: stable@dpdk.org

Suggested-by: Ruifeng Wang <ruifeng.wang@arm.com>
Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli@arm.com>
Acked-by: Harry van Haaren <harry.van.haaren@intel.com>
---
 examples/eventdev_pipeline/main.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
  

Comments

Pavan Nikhilesh Bhagavatula Jan. 25, 2021, 5:51 p.m. UTC | #1
>Move eth stop code from "signal_handler" function to the end of
>"main"
>function. There are two reasons for this:
>
>First, this improves code maintenance and makes code look simple and
>clear. Based on this change, after receiving the interrupt signal,
>"fdata->done" is set as 1. Then the main thread will wait all worker
>lcores to jump out of the loop. Finally, the main thread will stop and
>then close eth dev port.
>
>Second, for older version, the main thread first stops eth dev port and
>then waits the end of worker lcore. This may cause errors because it
>may
>stop the eth dev port which worker lcores are using. This moving
>change
>can fix this by waiting all worker threads to exit and then stop the
>eth dev port.
>
>In the meanwhile, remove wmb in signal_handler.
>
>This is because when the main lcore receive the stop signal, it stores 1
>into fdata->done. And then the worker lcores load "fdata->done" and
>jump
>out of the loop to stop running. Nothing should be stored after
>updating
>fdata->done, so the wmb is unnecessary.
>
>Fixes: 085edac2ca38 ("examples/eventdev_pipeline: support Tx
>adapter")
>Cc: pbhagavatula@marvell.com
>Cc: stable@dpdk.org
>
>Suggested-by: Ruifeng Wang <ruifeng.wang@arm.com>
>Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
>Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
>Reviewed-by: Honnappa Nagarahalli
><honnappa.nagarahalli@arm.com>
>Acked-by: Harry van Haaren <harry.van.haaren@intel.com>

Acked-by: Pavan Nikhilesh <pbhagavatula@marvell.com>

>---
> examples/eventdev_pipeline/main.c | 16 ++++------------
> 1 file changed, 4 insertions(+), 12 deletions(-)
>
>diff --git a/examples/eventdev_pipeline/main.c
>b/examples/eventdev_pipeline/main.c
>index 3526d4d3d..4621e8a89 100644
>--- a/examples/eventdev_pipeline/main.c
>+++ b/examples/eventdev_pipeline/main.c
>@@ -311,7 +311,6 @@ static void
> signal_handler(int signum)
> {
> 	static uint8_t once;
>-	uint16_t portid;
>
> 	if (fdata->done)
> 		rte_exit(1, "Exiting on signal %d\n", signum);
>@@ -322,17 +321,6 @@ signal_handler(int signum)
> 			rte_event_dev_dump(0, stdout);
> 		once = 1;
> 		fdata->done = 1;
>-		rte_smp_wmb();
>-
>-		RTE_ETH_FOREACH_DEV(portid) {
>-			rte_event_eth_rx_adapter_stop(portid);
>-			rte_event_eth_tx_adapter_stop(portid);
>-			if (rte_eth_dev_stop(portid) < 0)
>-				printf("Failed to stop port %u", portid);
>-		}
>-
>-		rte_eal_mp_wait_lcore();
>-
> 	}
> 	if (signum == SIGTSTP)
> 		rte_event_dev_dump(0, stdout);
>@@ -483,6 +471,10 @@ main(int argc, char **argv)
> 	}
>
> 	RTE_ETH_FOREACH_DEV(portid) {
>+		rte_event_eth_rx_adapter_stop(portid);
>+		rte_event_eth_tx_adapter_stop(portid);
>+		if (rte_eth_dev_stop(portid) < 0)
>+			printf("Failed to stop port %u", portid);
> 		rte_eth_dev_close(portid);
> 	}
>
>--
>2.25.1
  
Jerin Jacob Jan. 26, 2021, 1:37 p.m. UTC | #2
On Mon, Jan 25, 2021 at 11:22 PM Pavan Nikhilesh Bhagavatula
<pbhagavatula@marvell.com> wrote:
>
> >Move eth stop code from "signal_handler" function to the end of
> >"main"
> >function. There are two reasons for this:
> >
> >First, this improves code maintenance and makes code look simple and
> >clear. Based on this change, after receiving the interrupt signal,
> >"fdata->done" is set as 1. Then the main thread will wait all worker
> >lcores to jump out of the loop. Finally, the main thread will stop and
> >then close eth dev port.
> >
> >Second, for older version, the main thread first stops eth dev port and
> >then waits the end of worker lcore. This may cause errors because it
> >may
> >stop the eth dev port which worker lcores are using. This moving
> >change
> >can fix this by waiting all worker threads to exit and then stop the
> >eth dev port.
> >
> >In the meanwhile, remove wmb in signal_handler.
> >
> >This is because when the main lcore receive the stop signal, it stores 1
> >into fdata->done. And then the worker lcores load "fdata->done" and
> >jump
> >out of the loop to stop running. Nothing should be stored after
> >updating
> >fdata->done, so the wmb is unnecessary.
> >
> >Fixes: 085edac2ca38 ("examples/eventdev_pipeline: support Tx
> >adapter")
> >Cc: pbhagavatula@marvell.com
> >Cc: stable@dpdk.org
> >
> >Suggested-by: Ruifeng Wang <ruifeng.wang@arm.com>
> >Signed-off-by: Feifei Wang <feifei.wang2@arm.com>
> >Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
> >Reviewed-by: Honnappa Nagarahalli
> ><honnappa.nagarahalli@arm.com>
> >Acked-by: Harry van Haaren <harry.van.haaren@intel.com>
>
> Acked-by: Pavan Nikhilesh <pbhagavatula@marvell.com>


Series applied to dpdk-next-eventdev/for-main. Thanks.




>
> >---
> > examples/eventdev_pipeline/main.c | 16 ++++------------
> > 1 file changed, 4 insertions(+), 12 deletions(-)
> >
> >diff --git a/examples/eventdev_pipeline/main.c
> >b/examples/eventdev_pipeline/main.c
> >index 3526d4d3d..4621e8a89 100644
> >--- a/examples/eventdev_pipeline/main.c
> >+++ b/examples/eventdev_pipeline/main.c
> >@@ -311,7 +311,6 @@ static void
> > signal_handler(int signum)
> > {
> >       static uint8_t once;
> >-      uint16_t portid;
> >
> >       if (fdata->done)
> >               rte_exit(1, "Exiting on signal %d\n", signum);
> >@@ -322,17 +321,6 @@ signal_handler(int signum)
> >                       rte_event_dev_dump(0, stdout);
> >               once = 1;
> >               fdata->done = 1;
> >-              rte_smp_wmb();
> >-
> >-              RTE_ETH_FOREACH_DEV(portid) {
> >-                      rte_event_eth_rx_adapter_stop(portid);
> >-                      rte_event_eth_tx_adapter_stop(portid);
> >-                      if (rte_eth_dev_stop(portid) < 0)
> >-                              printf("Failed to stop port %u", portid);
> >-              }
> >-
> >-              rte_eal_mp_wait_lcore();
> >-
> >       }
> >       if (signum == SIGTSTP)
> >               rte_event_dev_dump(0, stdout);
> >@@ -483,6 +471,10 @@ main(int argc, char **argv)
> >       }
> >
> >       RTE_ETH_FOREACH_DEV(portid) {
> >+              rte_event_eth_rx_adapter_stop(portid);
> >+              rte_event_eth_tx_adapter_stop(portid);
> >+              if (rte_eth_dev_stop(portid) < 0)
> >+                      printf("Failed to stop port %u", portid);
> >               rte_eth_dev_close(portid);
> >       }
> >
> >--
> >2.25.1
>
  

Patch

diff --git a/examples/eventdev_pipeline/main.c b/examples/eventdev_pipeline/main.c
index 3526d4d3d..4621e8a89 100644
--- a/examples/eventdev_pipeline/main.c
+++ b/examples/eventdev_pipeline/main.c
@@ -311,7 +311,6 @@  static void
 signal_handler(int signum)
 {
 	static uint8_t once;
-	uint16_t portid;
 
 	if (fdata->done)
 		rte_exit(1, "Exiting on signal %d\n", signum);
@@ -322,17 +321,6 @@  signal_handler(int signum)
 			rte_event_dev_dump(0, stdout);
 		once = 1;
 		fdata->done = 1;
-		rte_smp_wmb();
-
-		RTE_ETH_FOREACH_DEV(portid) {
-			rte_event_eth_rx_adapter_stop(portid);
-			rte_event_eth_tx_adapter_stop(portid);
-			if (rte_eth_dev_stop(portid) < 0)
-				printf("Failed to stop port %u", portid);
-		}
-
-		rte_eal_mp_wait_lcore();
-
 	}
 	if (signum == SIGTSTP)
 		rte_event_dev_dump(0, stdout);
@@ -483,6 +471,10 @@  main(int argc, char **argv)
 	}
 
 	RTE_ETH_FOREACH_DEV(portid) {
+		rte_event_eth_rx_adapter_stop(portid);
+		rte_event_eth_tx_adapter_stop(portid);
+		if (rte_eth_dev_stop(portid) < 0)
+			printf("Failed to stop port %u", portid);
 		rte_eth_dev_close(portid);
 	}