diff mbox

example: l2fwd_simple add termination path

Message ID 1471518023-23559-1-git-send-email-maxim.uvarov@linaro.org
State Accepted
Commit 7528454aaab5c21356631515faf63117dbb9a66b
Headers show

Commit Message

Maxim Uvarov Aug. 18, 2016, 11 a.m. UTC
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

---
 example/l2fwd_simple/l2fwd_simple_run.sh |  6 ++---
 example/l2fwd_simple/odp_l2fwd_simple.c  | 39 +++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 6 deletions(-)

-- 
2.7.1.250.gff4ea60

Comments

Bill Fischofer Aug. 19, 2016, 2:27 p.m. UTC | #1
On Thu, Aug 18, 2016 at 6:00 AM, Maxim Uvarov <maxim.uvarov@linaro.org>
wrote:

> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>

>


Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>



> ---

>  example/l2fwd_simple/l2fwd_simple_run.sh |  6 ++---

>  example/l2fwd_simple/odp_l2fwd_simple.c  | 39

> +++++++++++++++++++++++++++++---

>  2 files changed, 39 insertions(+), 6 deletions(-)

>

> diff --git a/example/l2fwd_simple/l2fwd_simple_run.sh

> b/example/l2fwd_simple/l2fwd_simple_run.sh

> index 292d0e3..130a3a8 100755

> --- a/example/l2fwd_simple/l2fwd_simple_run.sh

> +++ b/example/l2fwd_simple/l2fwd_simple_run.sh

> @@ -12,12 +12,12 @@ echo "using PCAP_IN = ${PCAP_IN}"

>  ./odp_l2fwd_simple pcap:in=${PCAP_IN} pcap:out=pcapout.pcap

> 02:00:00:00:00:01 02:00:00:00:00:02 &

>

>  sleep 1

> -kill $!

> +kill -s SIGINT $!

>  wait $!

>  STATUS=$?

>

> -if [ "$STATUS" -ne 143 ]; then

> -  echo "Error: status was: $STATUS, expected 143"

> +if [ "$STATUS" -ne 0 ]; then

> +  echo "Error: status was: $STATUS, expected 0"

>    exit 1

>  fi

>

> diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c

> b/example/l2fwd_simple/odp_l2fwd_simple.c

> index 8a14e7d..0682d2d 100644

> --- a/example/l2fwd_simple/odp_l2fwd_simple.c

> +++ b/example/l2fwd_simple/odp_l2fwd_simple.c

> @@ -7,6 +7,7 @@

>  #include <stdlib.h>

>  #include <stdio.h>

>  #include <getopt.h>

> +#include <signal.h>

>

>  #include <odp_api.h>

>  #include <odp/helper/linux.h>

> @@ -18,6 +19,9 @@

>  #define MAX_PKT_BURST 32

>  #define MAX_WORKERS 1

>

> +static int exit_thr;

> +static int g_ret;

> +

>  struct {

>         odp_pktio_t if0, if1;

>         odp_pktin_queue_t if0in, if1in;

> @@ -25,6 +29,12 @@ struct {

>         odph_ethaddr_t src, dst;

>  } global;

>

> +static void sig_handler(int signo ODP_UNUSED)

> +{

> +       printf("sig_handler!\n");

> +       exit_thr = 1;

> +}

> +

>  static odp_pktio_t create_pktio(const char *name, odp_pool_t pool,

>                                 odp_pktin_queue_t *pktin,

>                                 odp_pktout_queue_t *pktout)

> @@ -74,6 +84,7 @@ static int run_worker(void *arg ODP_UNUSED)

>  {

>         odp_packet_t pkt_tbl[MAX_PKT_BURST];

>         int pkts, sent, tx_drops, i;

> +       int total_pkts = 0;

>

>         if (odp_pktio_start(global.if0)) {

>                 printf("unable to start input interface\n");

> @@ -87,9 +98,9 @@ static int run_worker(void *arg ODP_UNUSED)

>         printf("started output interface\n");

>         printf("started all\n");

>

> -       for (;;) {

> +       while (!exit_thr) {

>                 pkts = odp_pktin_recv_tmo(global.if0in, pkt_tbl,

> MAX_PKT_BURST,

> -                                         ODP_PKTIN_WAIT);

> +                                         ODP_PKTIN_NO_WAIT);

>

>                 if (odp_unlikely(pkts <= 0))

>                         continue;

> @@ -108,10 +119,15 @@ static int run_worker(void *arg ODP_UNUSED)

>                 sent = odp_pktout_send(global.if1out, pkt_tbl, pkts);

>                 if (sent < 0)

>                         sent = 0;

> +               total_pkts += sent;

>                 tx_drops = pkts - sent;

>                 if (odp_unlikely(tx_drops))

>                         odp_packet_free_multi(&pkt_tbl[sent], tx_drops);

>         }

> +

> +       if (total_pkts < 10)

> +               g_ret = -1;

> +

>         return 0;

>  }

>

> @@ -192,8 +208,25 @@ int main(int argc, char **argv)

>         thr_params.thr_type = ODP_THREAD_WORKER;

>         thr_params.instance = instance;

>

> +       signal(SIGINT, sig_handler);

> +

>         odph_odpthreads_create(thd, &cpumask, &thr_params);

>         odph_odpthreads_join(thd);

>

> -       return 0;

> +       if (odp_pool_destroy(pool)) {

> +               printf("Error: pool destroy\n");

> +               exit(EXIT_FAILURE);

> +       }

> +

> +       if (odp_term_local()) {

> +               printf("Error: term local\n");

> +               exit(EXIT_FAILURE);

> +       }

> +

> +       if (odp_term_global(instance)) {

> +               printf("Error: term global\n");

> +               exit(EXIT_FAILURE);

> +       }

> +

> +       return g_ret;

>  }

> --

> 2.7.1.250.gff4ea60

>

>
Maxim Uvarov Aug. 19, 2016, 3:40 p.m. UTC | #2
Merged,
Maxim.

On 08/19/16 17:27, Bill Fischofer wrote:
>

>

> On Thu, Aug 18, 2016 at 6:00 AM, Maxim Uvarov <maxim.uvarov@linaro.org 

> <mailto:maxim.uvarov@linaro.org>> wrote:

>

>     Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org

>     <mailto:maxim.uvarov@linaro.org>>

>

>

> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org 

> <mailto:bill.fischofer@linaro.org>>

>

>     ---

>      example/l2fwd_simple/l2fwd_simple_run.sh |  6 ++---

>      example/l2fwd_simple/odp_l2fwd_simple.c  | 39

>     +++++++++++++++++++++++++++++---

>      2 files changed, 39 insertions(+), 6 deletions(-)

>

>     diff --git a/example/l2fwd_simple/l2fwd_simple_run.sh

>     b/example/l2fwd_simple/l2fwd_simple_run.sh

>     index 292d0e3..130a3a8 100755

>     --- a/example/l2fwd_simple/l2fwd_simple_run.sh

>     +++ b/example/l2fwd_simple/l2fwd_simple_run.sh

>     @@ -12,12 +12,12 @@ echo "using PCAP_IN = ${PCAP_IN}"

>      ./odp_l2fwd_simple pcap:in=${PCAP_IN} pcap:out=pcapout.pcap

>     02:00:00:00:00:01 02:00:00:00:00:02 &

>

>      sleep 1

>     -kill $!

>     +kill -s SIGINT $!

>      wait $!

>      STATUS=$?

>

>     -if [ "$STATUS" -ne 143 ]; then

>     -  echo "Error: status was: $STATUS, expected 143"

>     +if [ "$STATUS" -ne 0 ]; then

>     +  echo "Error: status was: $STATUS, expected 0"

>        exit 1

>      fi

>

>     diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c

>     b/example/l2fwd_simple/odp_l2fwd_simple.c

>     index 8a14e7d..0682d2d 100644

>     --- a/example/l2fwd_simple/odp_l2fwd_simple.c

>     +++ b/example/l2fwd_simple/odp_l2fwd_simple.c

>     @@ -7,6 +7,7 @@

>      #include <stdlib.h>

>      #include <stdio.h>

>      #include <getopt.h>

>     +#include <signal.h>

>

>      #include <odp_api.h>

>      #include <odp/helper/linux.h>

>     @@ -18,6 +19,9 @@

>      #define MAX_PKT_BURST 32

>      #define MAX_WORKERS 1

>

>     +static int exit_thr;

>     +static int g_ret;

>     +

>      struct {

>             odp_pktio_t if0, if1;

>             odp_pktin_queue_t if0in, if1in;

>     @@ -25,6 +29,12 @@ struct {

>             odph_ethaddr_t src, dst;

>      } global;

>

>     +static void sig_handler(int signo ODP_UNUSED)

>     +{

>     +       printf("sig_handler!\n");

>     +       exit_thr = 1;

>     +}

>     +

>      static odp_pktio_t create_pktio(const char *name, odp_pool_t pool,

>                                     odp_pktin_queue_t *pktin,

>                                     odp_pktout_queue_t *pktout)

>     @@ -74,6 +84,7 @@ static int run_worker(void *arg ODP_UNUSED)

>      {

>             odp_packet_t pkt_tbl[MAX_PKT_BURST];

>             int pkts, sent, tx_drops, i;

>     +       int total_pkts = 0;

>

>             if (odp_pktio_start(global.if0)) {

>                     printf("unable to start input interface\n");

>     @@ -87,9 +98,9 @@ static int run_worker(void *arg ODP_UNUSED)

>             printf("started output interface\n");

>             printf("started all\n");

>

>     -       for (;;) {

>     +       while (!exit_thr) {

>                     pkts = odp_pktin_recv_tmo(global.if0in, pkt_tbl,

>     MAX_PKT_BURST,

>     -                                         ODP_PKTIN_WAIT);

>     +  ODP_PKTIN_NO_WAIT);

>

>                     if (odp_unlikely(pkts <= 0))

>                             continue;

>     @@ -108,10 +119,15 @@ static int run_worker(void *arg ODP_UNUSED)

>                     sent = odp_pktout_send(global.if1out, pkt_tbl, pkts);

>                     if (sent < 0)

>                             sent = 0;

>     +               total_pkts += sent;

>                     tx_drops = pkts - sent;

>                     if (odp_unlikely(tx_drops))

>                             odp_packet_free_multi(&pkt_tbl[sent],

>     tx_drops);

>             }

>     +

>     +       if (total_pkts < 10)

>     +               g_ret = -1;

>     +

>             return 0;

>      }

>

>     @@ -192,8 +208,25 @@ int main(int argc, char **argv)

>             thr_params.thr_type = ODP_THREAD_WORKER;

>             thr_params.instance = instance;

>

>     +       signal(SIGINT, sig_handler);

>     +

>             odph_odpthreads_create(thd, &cpumask, &thr_params);

>             odph_odpthreads_join(thd);

>

>     -       return 0;

>     +       if (odp_pool_destroy(pool)) {

>     +               printf("Error: pool destroy\n");

>     +               exit(EXIT_FAILURE);

>     +       }

>     +

>     +       if (odp_term_local()) {

>     +               printf("Error: term local\n");

>     +               exit(EXIT_FAILURE);

>     +       }

>     +

>     +       if (odp_term_global(instance)) {

>     +               printf("Error: term global\n");

>     +               exit(EXIT_FAILURE);

>     +       }

>     +

>     +       return g_ret;

>      }

>     --

>     2.7.1.250.gff4ea60

>

>
diff mbox

Patch

diff --git a/example/l2fwd_simple/l2fwd_simple_run.sh b/example/l2fwd_simple/l2fwd_simple_run.sh
index 292d0e3..130a3a8 100755
--- a/example/l2fwd_simple/l2fwd_simple_run.sh
+++ b/example/l2fwd_simple/l2fwd_simple_run.sh
@@ -12,12 +12,12 @@  echo "using PCAP_IN = ${PCAP_IN}"
 ./odp_l2fwd_simple pcap:in=${PCAP_IN} pcap:out=pcapout.pcap 02:00:00:00:00:01 02:00:00:00:00:02 &
 
 sleep 1
-kill $!
+kill -s SIGINT $!
 wait $!
 STATUS=$?
 
-if [ "$STATUS" -ne 143 ]; then
-  echo "Error: status was: $STATUS, expected 143"
+if [ "$STATUS" -ne 0 ]; then
+  echo "Error: status was: $STATUS, expected 0"
   exit 1
 fi
 
diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c b/example/l2fwd_simple/odp_l2fwd_simple.c
index 8a14e7d..0682d2d 100644
--- a/example/l2fwd_simple/odp_l2fwd_simple.c
+++ b/example/l2fwd_simple/odp_l2fwd_simple.c
@@ -7,6 +7,7 @@ 
 #include <stdlib.h>
 #include <stdio.h>
 #include <getopt.h>
+#include <signal.h>
 
 #include <odp_api.h>
 #include <odp/helper/linux.h>
@@ -18,6 +19,9 @@ 
 #define MAX_PKT_BURST 32
 #define MAX_WORKERS 1
 
+static int exit_thr;
+static int g_ret;
+
 struct {
 	odp_pktio_t if0, if1;
 	odp_pktin_queue_t if0in, if1in;
@@ -25,6 +29,12 @@  struct {
 	odph_ethaddr_t src, dst;
 } global;
 
+static void sig_handler(int signo ODP_UNUSED)
+{
+	printf("sig_handler!\n");
+	exit_thr = 1;
+}
+
 static odp_pktio_t create_pktio(const char *name, odp_pool_t pool,
 				odp_pktin_queue_t *pktin,
 				odp_pktout_queue_t *pktout)
@@ -74,6 +84,7 @@  static int run_worker(void *arg ODP_UNUSED)
 {
 	odp_packet_t pkt_tbl[MAX_PKT_BURST];
 	int pkts, sent, tx_drops, i;
+	int total_pkts = 0;
 
 	if (odp_pktio_start(global.if0)) {
 		printf("unable to start input interface\n");
@@ -87,9 +98,9 @@  static int run_worker(void *arg ODP_UNUSED)
 	printf("started output interface\n");
 	printf("started all\n");
 
-	for (;;) {
+	while (!exit_thr) {
 		pkts = odp_pktin_recv_tmo(global.if0in, pkt_tbl, MAX_PKT_BURST,
-					  ODP_PKTIN_WAIT);
+					  ODP_PKTIN_NO_WAIT);
 
 		if (odp_unlikely(pkts <= 0))
 			continue;
@@ -108,10 +119,15 @@  static int run_worker(void *arg ODP_UNUSED)
 		sent = odp_pktout_send(global.if1out, pkt_tbl, pkts);
 		if (sent < 0)
 			sent = 0;
+		total_pkts += sent;
 		tx_drops = pkts - sent;
 		if (odp_unlikely(tx_drops))
 			odp_packet_free_multi(&pkt_tbl[sent], tx_drops);
 	}
+
+	if (total_pkts < 10)
+		g_ret = -1;
+
 	return 0;
 }
 
@@ -192,8 +208,25 @@  int main(int argc, char **argv)
 	thr_params.thr_type = ODP_THREAD_WORKER;
 	thr_params.instance = instance;
 
+	signal(SIGINT, sig_handler);
+
 	odph_odpthreads_create(thd, &cpumask, &thr_params);
 	odph_odpthreads_join(thd);
 
-	return 0;
+	if (odp_pool_destroy(pool)) {
+		printf("Error: pool destroy\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (odp_term_local()) {
+		printf("Error: term local\n");
+		exit(EXIT_FAILURE);
+	}
+
+	if (odp_term_global(instance)) {
+		printf("Error: term global\n");
+		exit(EXIT_FAILURE);
+	}
+
+	return g_ret;
 }