From patchwork Tue Mar 3 16:19:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ola Liljedahl X-Patchwork-Id: 45372 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 459E321416 for ; Tue, 3 Mar 2015 16:19:56 +0000 (UTC) Received: by lams18 with SMTP id s18sf30068382lam.1 for ; Tue, 03 Mar 2015 08:19:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=LLEQKN/rsXw2bD94GbNEK2lqMM9oWYWekGk9tXtrcJo=; b=eBWDBwAgyadlxjbBpDTUmv6vkqUKgghMVT61m3O9msCh0IZ/BYpDMIaANqRWRqe/Wh /DVxr3agVAl61c0cH4m5Y2ki2D7QxvgWHyWzZIyxvSmdeObZqXt1XmUg/9Ci8EMP2jff KRPjtgf2jvNmJzugATsWQQ/cM37QlXOzKC0qFwoyC/40yzVMAVyBcMw8RhthS2Xv8c0K Hwuz2F+xWsO6HWzE0W8/wRMN2MMIvKr9N2Yq2IuIHe0hzZxXKbtjZIQCW0UQsrwfx2qw 2EwE0VzcRE1V6IOqy0Q+xhBP67Q41qCUDZxRb0ysUGUxtlB5CT//xqRk87RJoaTqmYee BoNw== X-Gm-Message-State: ALoCoQlEIUu4H828yBEkJEswbZxNWbiSZ+sOya7YDLledh9dqP5y2n3MdqOwcw5DfjA7/7WV/Nbp X-Received: by 10.112.222.131 with SMTP id qm3mr4628831lbc.1.1425399595173; Tue, 03 Mar 2015 08:19:55 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.40 with SMTP id q8ls69887lag.29.gmail; Tue, 03 Mar 2015 08:19:54 -0800 (PST) X-Received: by 10.152.22.67 with SMTP id b3mr29180488laf.117.1425399594940; Tue, 03 Mar 2015 08:19:54 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id sd7si762629lbb.141.2015.03.03.08.19.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Mar 2015 08:19:54 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by labge10 with SMTP id ge10so38453840lab.12 for ; Tue, 03 Mar 2015 08:19:54 -0800 (PST) X-Received: by 10.112.37.198 with SMTP id a6mr15795444lbk.86.1425399594782; Tue, 03 Mar 2015 08:19:54 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp668515lbj; Tue, 3 Mar 2015 08:19:53 -0800 (PST) X-Received: by 10.229.131.138 with SMTP id x10mr13067687qcs.25.1425399593088; Tue, 03 Mar 2015 08:19:53 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id u20si1005429qac.4.2015.03.03.08.19.51 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 03 Mar 2015 08:19:53 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YSpXw-0006Qk-C9; Tue, 03 Mar 2015 16:19:48 +0000 Received: from mail-lb0-f174.google.com ([209.85.217.174]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YSpXq-0006Og-Op for lng-odp@lists.linaro.org; Tue, 03 Mar 2015 16:19:42 +0000 Received: by lbvn10 with SMTP id n10so38203635lbv.6 for ; Tue, 03 Mar 2015 08:19:36 -0800 (PST) X-Received: by 10.152.87.3 with SMTP id t3mr29942657laz.19.1425399576888; Tue, 03 Mar 2015 08:19:36 -0800 (PST) Received: from macmini.lan (78-82-118-111.tn.glocalnet.net. [78.82.118.111]) by mx.google.com with ESMTPSA id p7sm256188lap.18.2015.03.03.08.19.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Mar 2015 08:19:36 -0800 (PST) From: Ola Liljedahl To: lng-odp@lists.linaro.org Date: Tue, 3 Mar 2015 17:19:30 +0100 Message-Id: <1425399570-908-1-git-send-email-ola.liljedahl@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: timers patch Subject: [lng-odp] [PATCH] example: odp_generator: use odp_timer X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ola.liljedahl@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Use ODP timer facility instead of POSIX sleep/nanosleep. Signed-off-by: Ola Liljedahl Reviewed-by: Bill Fischofer --- (This document/code contribution attached is provided under the terms of agreement LES-LTM-21309) example/generator/odp_generator.c | 105 +++++++++++++++++++++++++++++++++++--- 1 file changed, 98 insertions(+), 7 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 3870fd1..9147c15 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -79,6 +79,10 @@ static struct { typedef struct { char *pktio_dev; /**< Interface name to use */ odp_pool_t pool; /**< Pool for packet IO */ + odp_timer_pool_t tp; /**< Timer pool handle */ + odp_queue_t tq; /**< Queue for timeouts */ + odp_timer_t tim; /**< Timer handle */ + odp_timeout_t tmo_ev; /**< Timeout event */ int mode; /**< Thread mode */ } thread_args_t; @@ -104,6 +108,26 @@ static int scan_mac(char *in, odph_ethaddr_t *des); static void tv_sub(struct timeval *recvtime, struct timeval *sendtime); /** + * Sleep for the specified amount of milliseconds + * Use ODP timer, busy wait until timer expired and timeout event received + */ +static void millisleep(uint32_t ms, + odp_timer_pool_t tp, + odp_timer_t tim, + odp_queue_t q, + odp_timeout_t tmo) +{ + uint64_t ticks = odp_timer_ns_to_tick(tp, 1000000ULL * ms); + odp_event_t ev = odp_timeout_to_event(tmo); + int rc = odp_timer_set_rel(tim, ticks, &ev); + if (rc != ODP_TIMER_SUCCESS) + EXAMPLE_ABORT("odp_timer_set_rel() failed\n"); + /* Spin waiting for timeout event */ + while ((ev = odp_queue_deq(q)) == ODP_EVENT_INVALID) + (void)0; +} + +/** * Scan ip * Parse ip address. * @@ -400,11 +424,12 @@ static void *gen_send_thread(void *arg) thr, odp_atomic_load_u64(&counters.seq), odp_atomic_load_u64(&counters.seq)%0xffff); - /* TODO use odp timer */ - struct timespec ts; - ts.tv_sec = 0; - ts.tv_nsec = args->appl.interval; - nanosleep(&ts, NULL); + millisleep(args->appl.interval, + thr_args->tp, + thr_args->tim, + thr_args->tq, + thr_args->tmo_ev); + } if (args->appl.number != -1 && odp_atomic_load_u64(&counters.seq) @@ -419,8 +444,11 @@ static void *gen_send_thread(void *arg) if (odp_atomic_load_u64(&counters.icmp) >= (unsigned int)args->appl.number) break; - /* TODO use odp timer */ - sleep(1); + millisleep(1000, + thr_args->tp, + thr_args->tim, + thr_args->tq, + thr_args->tmo_ev); args->appl.timeout--; } } @@ -567,6 +595,9 @@ int main(int argc, char *argv[]) odp_cpumask_t cpumask; char cpumaskstr[ODP_CPUMASK_STR_SIZE]; odp_pool_param_t params; + odp_timer_pool_param_t tparams; + odp_timer_pool_t tp; + odp_pool_t tmop; /* Init ODP before calling anything else */ if (odp_init_global(NULL, NULL)) { @@ -637,6 +668,31 @@ int main(int argc, char *argv[]) } odp_pool_print(pool); + /* Create timer pool */ + tparams.res_ns = 1 * ODP_TIME_MSEC; + tparams.min_tmo = 0; + tparams.max_tmo = 10000 * ODP_TIME_SEC; + tparams.num_timers = num_workers; /* One timer per worker */ + tparams.priv = 0; /* Shared */ + tparams.clk_src = ODP_CLOCK_CPU; + tp = odp_timer_pool_create("timer_pool", &tparams); + if (tp == ODP_TIMER_POOL_INVALID) { + EXAMPLE_ERR("Timer pool create failed.\n"); + exit(EXIT_FAILURE); + } + odp_timer_pool_start(); + + /* Create timeout pool */ + memset(¶ms, 0, sizeof(params)); + params.tmo.num = tparams.num_timers; /* One timeout per timer */ + params.type = ODP_POOL_TIMEOUT; + + tmop = odp_pool_create("timeout_pool", ODP_SHM_NULL, ¶ms); + + if (pool == ODP_POOL_INVALID) { + EXAMPLE_ERR("Error: packet pool create failed.\n"); + exit(EXIT_FAILURE); + } for (i = 0; i < args->appl.if_count; ++i) create_pktio(args->appl.if_names[i], pool); @@ -645,19 +701,42 @@ int main(int argc, char *argv[]) if (args->appl.mode == APPL_MODE_PING) { odp_cpumask_t cpu0_mask; + odp_queue_t tq; /* Previous code forced both threads to CPU 0 */ odp_cpumask_zero(&cpu0_mask); odp_cpumask_set(&cpu0_mask, 0); + tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL); + if (tq == ODP_QUEUE_INVALID) + abort(); args->thread[1].pktio_dev = args->appl.if_names[0]; args->thread[1].pool = pool; + args->thread[1].tp = tp; + args->thread[1].tq = tq; + args->thread[1].tim = odp_timer_alloc(tp, tq, NULL); + if (args->thread[1].tim == ODP_TIMER_INVALID) + abort(); + args->thread[1].tmo_ev = odp_timeout_alloc(tmop); + if (args->thread[1].tmo_ev == ODP_TIMEOUT_INVALID) + abort(); args->thread[1].mode = args->appl.mode; odph_linux_pthread_create(&thread_tbl[1], &cpu0_mask, gen_recv_thread, &args->thread[1]); + tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL); + if (tq == ODP_QUEUE_INVALID) + abort(); args->thread[0].pktio_dev = args->appl.if_names[0]; args->thread[0].pool = pool; + args->thread[0].tp = tp; + args->thread[0].tq = tq; + args->thread[0].tim = odp_timer_alloc(tp, tq, NULL); + if (args->thread[0].tim == ODP_TIMER_INVALID) + abort(); + args->thread[0].tmo_ev = odp_timeout_alloc(tmop); + if (args->thread[0].tmo_ev == ODP_TIMEOUT_INVALID) + abort(); args->thread[0].mode = args->appl.mode; odph_linux_pthread_create(&thread_tbl[0], &cpu0_mask, gen_send_thread, &args->thread[0]); @@ -670,11 +749,23 @@ 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; args->thread[i].pktio_dev = args->appl.if_names[if_idx]; + tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL); + if (tq == ODP_QUEUE_INVALID) + abort(); args->thread[i].pool = pool; + args->thread[i].tp = tp; + args->thread[i].tq = tq; + args->thread[i].tim = odp_timer_alloc(tp, tq, NULL); + if (args->thread[i].tim == ODP_TIMER_INVALID) + abort(); + args->thread[i].tmo_ev = odp_timeout_alloc(tmop); + if (args->thread[i].tmo_ev == ODP_TIMEOUT_INVALID) + abort(); args->thread[i].mode = args->appl.mode; if (args->appl.mode == APPL_MODE_UDP) {