From patchwork Mon Apr 25 14:33:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 66590 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1075318qge; Mon, 25 Apr 2016 07:39:24 -0700 (PDT) X-Received: by 10.140.164.71 with SMTP id k68mr36820673qhk.97.1461595164790; Mon, 25 Apr 2016 07:39:24 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id 141si10906955qhq.73.2016.04.25.07.39.24; Mon, 25 Apr 2016 07:39:24 -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 6B0DA618E3; Mon, 25 Apr 2016 14:39:24 +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 31AF1617EF; Mon, 25 Apr 2016 14:38: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 8839C61606; Mon, 25 Apr 2016 14:37:48 +0000 (UTC) Received: from mail-lf0-f52.google.com (mail-lf0-f52.google.com [209.85.215.52]) by lists.linaro.org (Postfix) with ESMTPS id 16C4861873 for ; Mon, 25 Apr 2016 14:33:55 +0000 (UTC) Received: by mail-lf0-f52.google.com with SMTP id j11so118087746lfb.1 for ; Mon, 25 Apr 2016 07:33:55 -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=l68vIHCEh794LEWbsul0mqz1OSSu1bUQ7Yp5pY+j6Ss=; b=NBe2aquZRJk0gt/2rEO8K4NPXGYvmx34husmtFInQI47R3tteEX0yNzW/uQn3MibjT l9cQM4tCjARdpsQLyarZE5gTKQrtxDSsAeC+khxdum7ym4yJs684O1srS3vcFOGzSVYq mf7zF0TNUwsTVQoBjw/awGbcirXY+CUPUsH0p+/U2Bbt3n6SK1m+KPOrvRdxtNHLWDFU jcAASwuiT+OSXLQwvegYJ1xYuuh2FF9CqAXGtJIPQ5reJY4G4OSamBMipR5p90yVPSFw YM9xrHvWJA4daK/PU/gfHViFGGZdgo/nk2JTeZo2uFtI1rmZsJ4iVYacwkWGUdOYl2HM qcIg== X-Gm-Message-State: AOPr4FVjcn1+/mW1lYFWS21uQz0WbWSlPeCyoDGhHBQbNw7UC40/AvQPk4alZ9uyPslsfHoLUdc= X-Received: by 10.25.73.212 with SMTP id w203mr12038116lfa.22.1461594833718; Mon, 25 Apr 2016 07:33:53 -0700 (PDT) Received: from localhost.localdomain (ppp91-77-173-31.pppoe.mtu-net.ru. [91.77.173.31]) by smtp.gmail.com with ESMTPSA id e3sm4457697lbs.48.2016.04.25.07.33.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Apr 2016 07:33:53 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 25 Apr 2016 17:33:46 +0300 Message-Id: <1461594827-2205-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 In-Reply-To: <1461594827-2205-1-git-send-email-maxim.uvarov@linaro.org> References: <1461594827-2205-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 1/2] example: packet: add odp_term_global 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" Add odp_term_global and comment that it will never be called. https://bugs.linaro.org/show_bug.cgi?id=1706 Signed-off-by: Maxim Uvarov --- example/packet/odp_pktio.c | 57 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index f82f01f..dce9447 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -69,6 +69,7 @@ typedef struct { char **if_names; /**< Array of pointers to interface names */ int mode; /**< Packet IO mode */ char *if_str; /**< Storage for interface names */ + int time; /**< Time to run app */ } appl_args_t; /** @@ -87,6 +88,8 @@ typedef struct { appl_args_t appl; /** Thread specific arguments */ thread_args_t thread[MAX_WORKERS]; + /** Flag to exit worker threads */ + int exit_threads; } args_t; /** Global pointer to args */ @@ -177,6 +180,7 @@ static void *pktio_queue_thread(void *arg) odp_event_t ev; unsigned long pkt_cnt = 0; unsigned long err_cnt = 0; + uint64_t sched_wait = odp_schedule_wait_time(ODP_TIME_MSEC_IN_NS * 100); thr = odp_thread_id(); thr_args = arg; @@ -203,18 +207,20 @@ static void *pktio_queue_thread(void *arg) } /* Loop packets */ - for (;;) { + while (!args->exit_threads) { odp_pktio_t pktio_tmp; - if (inq != ODP_QUEUE_INVALID) { + if (inq != ODP_QUEUE_INVALID) ev = odp_queue_deq(inq); - pkt = odp_packet_from_event(ev); - if (!odp_packet_is_valid(pkt)) - continue; - } else { - ev = odp_schedule(NULL, ODP_SCHED_WAIT); - pkt = odp_packet_from_event(ev); - } + else + ev = odp_schedule(NULL, sched_wait); + + if (ev == ODP_EVENT_INVALID) + continue; + + pkt = odp_packet_from_event(ev); + if (!odp_packet_is_valid(pkt)) + continue; /* Drop packets with errors */ if (odp_unlikely(drop_err_pkts(&pkt, 1) == 0)) { @@ -246,7 +252,6 @@ static void *pktio_queue_thread(void *arg) } } -/* unreachable */ return NULL; } @@ -292,7 +297,7 @@ static void *pktio_ifburst_thread(void *arg) } /* Loop packets */ - for (;;) { + while (!args->exit_threads) { pkts = odp_pktin_recv(pktin, pkt_tbl, MAX_PKT_BURST); if (pkts > 0) { /* Drop packets with errors */ @@ -329,7 +334,6 @@ static void *pktio_ifburst_thread(void *arg) } } -/* unreachable */ return NULL; } @@ -443,15 +447,33 @@ int main(int argc, char *argv[]) cpu = odp_cpumask_next(&cpumask, cpu); } + if (args->appl.time) { + odp_time_wait_ns(args->appl.time * + ODP_TIME_SEC_IN_NS); + for (i = 0; i < args->appl.if_count; ++i) { + odp_pktio_t pktio; + + pktio = odp_pktio_lookup(args->thread[i].pktio_dev); + odp_pktio_stop(pktio); + } + /* use delay to let workers clean up queues */ + odp_time_wait_ns(ODP_TIME_SEC_IN_NS); + args->exit_threads = 1; + } + /* 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(odp_pktio_lookup(args->thread[i].pktio_dev)); + free(args->appl.if_names); free(args->appl.if_str); free(args); - printf("Exit\n\n"); - return 0; + odp_pool_destroy(pool); + odp_term_local(); + return odp_term_global(instance); } /** @@ -537,8 +559,10 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) char *token; size_t len; int i; + static struct option longopts[] = { {"count", required_argument, NULL, 'c'}, + {"time", required_argument, NULL, 't'}, {"interface", required_argument, NULL, 'i'}, /* return 'i' */ {"mode", required_argument, NULL, 'm'}, /* return 'm' */ {"help", no_argument, NULL, 'h'}, /* return 'h' */ @@ -546,6 +570,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) }; appl_args->mode = APPL_MODE_PKT_SCHED; + appl_args->time = 0; /**< loop forever */ while (1) { opt = getopt_long(argc, argv, "+c:i:+m:t:h", @@ -558,6 +583,9 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) case 'c': appl_args->cpu_count = atoi(optarg); break; + case 't': + appl_args->time = atoi(optarg); + break; /* parse packet-io interface names */ case 'i': len = strlen(optarg); @@ -693,6 +721,7 @@ static void usage(char *progname) "\n" "Optional OPTIONS\n" " -c, --count CPU count.\n" + " -t, --time Number of seconds to run.\n" " -m, --mode 0: Receive and send directly (no queues)\n" " 1: Receive and send via queues.\n" " 2: Receive via scheduler, send via queues.\n"