From patchwork Sat Feb 20 08:35:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 62451 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp225329lbl; Sat, 20 Feb 2016 00:37:25 -0800 (PST) X-Received: by 10.140.173.133 with SMTP id t127mr23301150qht.23.1455957445436; Sat, 20 Feb 2016 00:37:25 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id y69si18575739qka.73.2016.02.20.00.37.25; Sat, 20 Feb 2016 00:37:25 -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 18E2E65111; Sat, 20 Feb 2016 08:37:25 +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 0E2CF675D2; Sat, 20 Feb 2016 08:35: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 C9B0B65109; Sat, 20 Feb 2016 08:35:28 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id C903065100 for ; Sat, 20 Feb 2016 08:35:25 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id 78so67339032lfy.3 for ; Sat, 20 Feb 2016 00:35:25 -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=G1me1h2h3pc0CwGLo7gVqBbvIbpsWq87jAapKk9C+pY=; b=SMNd6Dvb1QbLZsnIGomHhV71xXEk/2RGKGK/iN6uzSQyYBNIq6DEghgrQAGjrQj54J HJva4mri5IcI7vpHVc+kA6SPTmh5390DbdBR0LnCvJXgMYTgMdwMMJcK8S9RaKlbfyqQ NGttZpzBeBSEBebMgjYabeuAhqxzhww2hhPBjW3lkg9cyWRryQ0Yr8Vfo7gjbjn1OGtH 2dvmSY4Y2jHIdLXyD2Tl2eRpvkt45jHPb3PE7eVndEuvtLyrsA1krqUX5ZlMnKc8Ex5B oa3CPCIz/HM/uL6iCIqQWjXhHIp11+22mRhNEUD/oAL2LOUineChI3ZdJ3EyaRmqv6xK 24UQ== X-Gm-Message-State: AG10YORfeeJBBXo+wNmz6rSvqyD3iesUfPiav2fBtNbm4LWrDw3vBlrBkDTNNZZ60xJzjzQOHsY= X-Received: by 10.25.37.136 with SMTP id l130mr5843622lfl.60.1455957324773; Sat, 20 Feb 2016 00:35:24 -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 34sm1994206lfv.35.2016.02.20.00.35.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 20 Feb 2016 00:35:24 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Sat, 20 Feb 2016 11:35:18 +0300 Message-Id: <1455957318-9392-4-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 In-Reply-To: <1455957318-9392-1-git-send-email-maxim.uvarov@linaro.org> References: <1455957318-9392-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 3/3] 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 0ba5224..e41cc96 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); @@ -382,6 +385,9 @@ static void *gen_send_thread(void *arg) } printf(" [%02i] created mode: SEND\n", thr); + + odp_barrier_wait(&barrier); + for (;;) { int err; @@ -399,14 +405,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) { @@ -531,6 +537,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 && @@ -568,8 +575,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); @@ -628,6 +634,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)) { @@ -726,20 +735,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); @@ -791,7 +804,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; @@ -840,8 +852,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_close(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;