From patchwork Thu Aug 18 11:00:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 74152 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp283791qga; Thu, 18 Aug 2016 04:00:47 -0700 (PDT) X-Received: by 10.200.50.199 with SMTP id a7mr1542595qtb.43.1471518047404; Thu, 18 Aug 2016 04:00:47 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l83si862697qki.167.2016.08.18.04.00.46; Thu, 18 Aug 2016 04:00:47 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id B0D1C60D52; Thu, 18 Aug 2016 11:00:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id B9A4260CFC; Thu, 18 Aug 2016 11:00:37 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1F83960CBE; Thu, 18 Aug 2016 11:00:35 +0000 (UTC) Received: from mail-lf0-f51.google.com (mail-lf0-f51.google.com [209.85.215.51]) by lists.linaro.org (Postfix) with ESMTPS id 825D660CBE for ; Thu, 18 Aug 2016 11:00:32 +0000 (UTC) Received: by mail-lf0-f51.google.com with SMTP id g62so9172674lfe.3 for ; Thu, 18 Aug 2016 04:00:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zEgp99+06Xs5RvWFFw+mPXGt+W0djDWFI2bog0WkgSQ=; b=YX7XzvR2YqWpIQ8MWIlPbnkXZIN/kxVFDYDJR4nW3qj3DllrlpvYwKaFNcTz6bWabC uysraUAFnbKIpNQjDRHx0tftlc5BOgOUWcHrDSD36G6B47FjUqMmHoTZcSsM5yOj7DbE eEIg6fnUYbgZsCO4z9LY8JgOq7ypBm/0SGgLzktGfKzwhkJlXIFEkgoCSG5AG1cBcb4g jzbfx/7rbLJ8Inhld05zJMaMoBgz313uOjOmAcP2CH+sajq9hdjoM4Zla20nJAvHqjqU jm+rBZ3s1KHrTrvseIiSVlkB4HsFrj1yxUELhC9qgxomNGPbn9fo9fFhaz5hgj1jKS6b ZvFg== X-Gm-Message-State: AEkoous/CpkVa+Kxd+7O9JhC1yIF1nXd/Nr+JW3rqkms7LljJrapoWrG5NK98DgwrU6qvMhBAC8= X-Received: by 10.25.31.9 with SMTP id f9mr498590lff.34.1471518030923; Thu, 18 Aug 2016 04:00:30 -0700 (PDT) Received: from maxim-Aspire-VN7-791.d-systems.local ([185.75.190.112]) by smtp.gmail.com with ESMTPSA id 83sm255804ljj.14.2016.08.18.04.00.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Aug 2016 04:00:29 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 18 Aug 2016 14:00:23 +0300 Message-Id: <1471518023-23559-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 X-Topics: patch Subject: [lng-odp] [PATCH] example: l2fwd_simple add termination path X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Maxim Uvarov --- 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 Reviewed-by: Bill Fischofer 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 #include #include +#include #include #include @@ -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; }