From patchwork Tue Mar 29 13:59:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 64601 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp2030033lbc; Tue, 29 Mar 2016 07:01:00 -0700 (PDT) X-Received: by 10.140.154.198 with SMTP id a189mr3068083qha.44.1459260060657; Tue, 29 Mar 2016 07:01:00 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y185si22564168qhc.80.2016.03.29.07.01.00; Tue, 29 Mar 2016 07:01:00 -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 42F54617EE; Tue, 29 Mar 2016 14:01:00 +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, URIBL_BLOCKED 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 88452617FF; Tue, 29 Mar 2016 14:00:00 +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 054AE617D5; Tue, 29 Mar 2016 13:59:55 +0000 (UTC) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by lists.linaro.org (Postfix) with ESMTPS id D01826161D for ; Tue, 29 Mar 2016 13:59:53 +0000 (UTC) Received: by mail-lb0-f182.google.com with SMTP id bc4so10965710lbc.2 for ; Tue, 29 Mar 2016 06:59:53 -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:in-reply-to :references; bh=TuaXZk40auXNMdQXyiEoqS9CQ/XKPm0qJiGKv3ACsu0=; b=EhmJn0VaU2c44QIFopBhDs5YImAGOKbzLZ6Dj6wEz1ziQnCTBhKYQj8JgQbIy2Imfo Ky+tixcBLpKfYU1Apx87atZ0WDQ2NiqWSvjeythyClgVQ4GY9U/277RJxnrbMJXPSzIa xczDke1k68+HIcdtA3t8Y4FC20zBlYdwdDCz5iM/VQb8+D5UsuGNDdIXkKOT3JNdjQ6R wU96sgsvPeTHClooM6D40Uv7ssgBJwRQCslncgJLHnRoH3gkoaoy5oLyb6ySvgId7hAi 6ZU1hnA0EkKEglpQebIP6kRb+ZJmlF3JqS/mfKnHvve+HmfHbVzGoiuB8Mdsx8WhnY0h 1qtA== X-Gm-Message-State: AD7BkJL99Bi1tnRMsPMdh+CoOzBV5CUvMhVtxSpG8oNAh1D5TIeZYLiPGZpohuKvwB5lxkHJgXk= X-Received: by 10.112.54.132 with SMTP id j4mr1221164lbp.3.1459259992597; Tue, 29 Mar 2016 06:59:52 -0700 (PDT) Received: from localhost.localdomain (ppp91-77-172-79.pppoe.mtu-net.ru. [91.77.172.79]) by smtp.gmail.com with ESMTPSA id p141sm5478562lfe.40.2016.03.29.06.59.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Mar 2016 06:59:52 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 29 Mar 2016 16:59:37 +0300 Message-Id: <1459259977-10978-3-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 In-Reply-To: <1459259977-10978-1-git-send-email-maxim.uvarov@linaro.org> References: <1459259977-10978-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH 2/2] example: classifier: 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: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Cleanly destroy all allocated resources. https://bugs.linaro.org/show_bug.cgi?id=1706 Signed-off-by: Maxim Uvarov --- example/classifier/odp_classifier.c | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/example/classifier/odp_classifier.c b/example/classifier/odp_classifier.c index 2f47e74..abf3d26 100644 --- a/example/classifier/odp_classifier.c +++ b/example/classifier/odp_classifier.c @@ -81,6 +81,8 @@ enum packet_mode { APPL_MODE_REPLY /**< Packet is sent back */ }; +static int shutdown; /**< Shutdown threads if !0 */ + /* helper funcs */ static int drop_err_pkts(odp_packet_t pkt_tbl[], unsigned len); static void swap_pkt_addrs(odp_packet_t pkt_tbl[], unsigned len); @@ -270,8 +272,12 @@ static void *pktio_receive_thread(void *arg) for (;;) { odp_pktio_t pktio_tmp; + if (shutdown) + break; + /* Use schedule to get buf from any input queue */ - ev = odp_schedule(&queue, ODP_SCHED_WAIT); + ev = odp_schedule(&queue, + odp_schedule_wait_time(ODP_TIME_SEC_IN_NS)); /* Loop back to receive packets incase of invalid event */ if (odp_unlikely(ev == ODP_EVENT_INVALID)) @@ -397,7 +403,7 @@ static void configure_cos(odp_cos_t default_cos, appl_args_t *args) global_statistics *stats; odp_queue_param_t qparam; - for (i = 0; i < args->policy_count; i++) { + for (i = 0; i < args->policy_count - 1; i++) { stats = &args->stats[i]; odp_queue_param_init(&qparam); @@ -475,6 +481,7 @@ int main(int argc, char *argv[]) appl_args_t *args; odp_cos_t default_cos; odp_shm_t shm; + int ret; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { @@ -573,21 +580,37 @@ int main(int argc, char *argv[]) print_cls_statistics(args); + odp_pktio_stop(pktio); + shutdown = 1; + odph_linux_pthread_join(thread_tbl, num_workers); + for (i = 0; i < args->policy_count; i++) { - odp_cls_pmr_destroy(args->stats[i].pmr); - odp_cos_destroy(args->stats[i].cos); - odp_pool_destroy(args->stats[i].pool); - odp_queue_destroy(args->stats[i].queue); - odp_pool_destroy(args->stats[i].pool); + if ((i != args->policy_count - 1) && + odp_cls_pmr_destroy(args->stats[i].pmr)) + EXAMPLE_ERR("err: odp_cls_pmr_destroy for %d\n", i); + if (odp_cos_destroy(args->stats[i].cos)) + EXAMPLE_ERR("err: odp_cos_destroy for %d\n", i); + if (odp_queue_destroy(args->stats[i].queue)) + EXAMPLE_ERR("err: odp_queue_destroy for %d\n", i); + if (odp_pool_destroy(args->stats[i].pool)) + EXAMPLE_ERR("err: odp_pool_destroy for %d\n", i); } free(args->if_name); odp_shm_free(shm); - odp_pktio_close(pktio); - odp_pool_destroy(pool); + if (odp_pktio_close(pktio)) + EXAMPLE_ERR("err: close pktio error\n"); + if (odp_pool_destroy(pool)) + EXAMPLE_ERR("err: odp_pool_destroy error\n"); + + ret = odp_term_local(); + if (ret) + EXAMPLE_ERR("odp_term_local error %d\n", ret); + ret = odp_term_global(); + if (ret) + EXAMPLE_ERR("odp_term_global error %d\n", ret); printf("Exit\n\n"); - - return 0; + return ret; } /**