From patchwork Thu Feb 25 12:35:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 62882 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp136019lbc; Thu, 25 Feb 2016 04:35:47 -0800 (PST) X-Received: by 10.140.161.198 with SMTP id h189mr40546436qhh.24.1456403747532; Thu, 25 Feb 2016 04:35:47 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 128si7822786qhw.119.2016.02.25.04.35.47; Thu, 25 Feb 2016 04:35:47 -0800 (PST) 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 Received: by lists.linaro.org (Postfix, from userid 109) id 299BB62F8A; Thu, 25 Feb 2016 12:35:47 +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 B5DF062F6A; Thu, 25 Feb 2016 12:35:23 +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 CDE9762FEF; Thu, 25 Feb 2016 12:35:17 +0000 (UTC) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com [209.85.217.169]) by lists.linaro.org (Postfix) with ESMTPS id 95B5562F0E for ; Thu, 25 Feb 2016 12:35:14 +0000 (UTC) Received: by mail-lb0-f169.google.com with SMTP id of3so27946559lbc.1 for ; Thu, 25 Feb 2016 04:35:14 -0800 (PST) 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=4bfuaPjtmeXabajdMwg05LeGBiwhcKwSQ1x+NU3WJxY=; b=RJEShv2hpXG8IuU2hvu9INjZNyDYWRRa5040xmapsUABaGFaZ5vitQFSdbcIMYonJB j1GmN+WiRhmHXnY1wOFm7kwQZ1x3rrkjOG20IIExTQRLkOV6A3MXTSkboflo49y8CubD foUJIkiNfCRLfuN5j3VUNevFplBb9UfotZB+R9F6TIb6d3j4eyqtw8uAmvaqYD/xSsdf xXuUTDHx9pPktejkbtkz0/9JJ5C2pS18+5beZz0HQc9nBMXtKzcACXa3zoLAqvuEOPsJ Wn5vBlGN+eZaYucJKW5wxdWD2zaDaYt1HzD3Z30f/ALF40C5Rn3YFssfsvOfaKiz9o77 C2CQ== X-Gm-Message-State: AG10YOSI4dDCXNLahmAqOUiCFTU9bKtSsV1gPzfTxY+E7++kBtA5NN/bj55mFjIrGwgFaMfNzsg= X-Received: by 10.112.202.104 with SMTP id kh8mr12770027lbc.8.1456403713627; Thu, 25 Feb 2016 04:35:13 -0800 (PST) Received: from localhost.localdomain (ppp91-76-173-134.pppoe.mtu-net.ru. [91.76.173.134]) by smtp.gmail.com with ESMTPSA id t12sm1109039lfe.46.2016.02.25.04.35.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Feb 2016 04:35:13 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 25 Feb 2016 15:35:06 +0300 Message-Id: <1456403706-13309-3-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 In-Reply-To: <1456403706-13309-1-git-send-email-maxim.uvarov@linaro.org> References: <1456403706-13309-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv2 2/2] example: generator: clean up termination progress 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" Carefully shutdown all resources before exit. Signed-off-by: Maxim Uvarov --- example/generator/odp_generator.c | 61 ++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index ab8c7fa..b21fc4a 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -98,6 +98,9 @@ typedef struct { /** Global pointer to args */ static args_t *args; +/** Barrier to sync threads execution */ +static odp_barrier_t barrier; + /* helper funcs */ static void parse_args(int argc, char *argv[], appl_args_t *appl_args); static void print_info(char *progname, appl_args_t *appl_args); @@ -408,6 +411,9 @@ static void *gen_send_thread(void *arg) } printf(" [%02i] created mode: SEND\n", thr); + + odp_barrier_wait(&barrier); + for (;;) { int err; @@ -425,14 +431,14 @@ static void *gen_send_thread(void *arg) if (!odp_packet_is_valid(pkt)) { EXAMPLE_ERR(" [%2i] alloc_single failed\n", thr); - return NULL; + break; } err = odp_queue_enq(outq_def, odp_packet_to_event(pkt)); if (err != 0) { EXAMPLE_ERR(" [%02i] send pkt err!\n", thr); odp_packet_free(pkt); - return NULL; + break; } if (args->appl.interval != 0) { @@ -557,6 +563,7 @@ static void *gen_recv_thread(void *arg) } printf(" [%02i] created mode: RECEIVE\n", thr); + odp_barrier_wait(&barrier); for (;;) { if (args->appl.number != -1 && @@ -594,8 +601,7 @@ static void print_global_stats(int num_workers) int verbose_interval = 20; odp_thrmask_t thrd_mask; - while (odp_thrmask_worker(&thrd_mask) < num_workers) - continue; + odp_barrier_wait(&barrier); wait = odp_time_local_from_ns(verbose_interval * ODP_TIME_SEC_IN_NS); next = odp_time_sum(odp_time_local(), wait); @@ -654,6 +660,9 @@ int main(int argc, char *argv[]) odp_timer_pool_param_t tparams; odp_timer_pool_t tp; odp_pool_t tmop; + odp_queue_t tq; + odp_event_t ev; + odp_pktio_t *pktio; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { @@ -752,20 +761,24 @@ int main(int argc, char *argv[]) params.type = ODP_POOL_TIMEOUT; tmop = odp_pool_create("timeout_pool", ¶ms); - - if (pool == ODP_POOL_INVALID) { - EXAMPLE_ERR("Error: packet pool create failed.\n"); + if (tmop == ODP_POOL_INVALID) { + EXAMPLE_ERR("Error: timeout pool create failed.\n"); exit(EXIT_FAILURE); } + + pktio = malloc(sizeof(odp_pktio_t) * args->appl.if_count); + for (i = 0; i < args->appl.if_count; ++i) - create_pktio(args->appl.if_names[i], pool); + pktio[i] = create_pktio(args->appl.if_names[i], pool); /* Create and init worker threads */ memset(thread_tbl, 0, sizeof(thread_tbl)); + /* num workers + print thread */ + odp_barrier_init(&barrier, num_workers + 1); + if (args->appl.mode == APPL_MODE_PING) { odp_cpumask_t cpu_mask; - odp_queue_t tq; int cpu_first, cpu_next; odp_cpumask_zero(&cpu_mask); @@ -817,7 +830,6 @@ int main(int argc, char *argv[]) odp_cpumask_t thd_mask; void *(*thr_run_func) (void *); int if_idx; - odp_queue_t tq; if_idx = i % args->appl.if_count; @@ -866,8 +878,37 @@ int main(int argc, char *argv[]) /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); + for (i = 0; i < args->appl.if_count; ++i) + odp_pktio_stop(pktio[i]); + + for (i = 0; i < num_workers; ++i) { + odp_timer_cancel(args->thread[i].tim, &ev); + odp_timer_free(args->thread[i].tim); + odp_timeout_free(args->thread[i].tmo_ev); + } + + for (i = 0; i < num_workers; ++i) { + while (1) { + ev = odp_queue_deq(args->thread[i].tq); + if (ev == ODP_EVENT_INVALID) + break; + odp_event_free(ev); + } + odp_queue_destroy(args->thread[i].tq); + } + + for (i = 0; i < args->appl.if_count; ++i) + odp_pktio_close(pktio[i]); + free(pktio); free(args->appl.if_names); free(args->appl.if_str); + if (0 != odp_pool_destroy(pool)) + fprintf(stderr, "unable to destroy pool \"pool\"\n"); + odp_timer_pool_destroy(tp); + if (0 != odp_pool_destroy(tmop)) + fprintf(stderr, "unable to destroy pool \"tmop\"\n"); + odp_term_local(); + odp_term_global(); printf("Exit\n\n"); return 0;