From patchwork Thu Nov 12 17:05:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 56443 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp535795lbb; Thu, 12 Nov 2015 09:08:35 -0800 (PST) X-Received: by 10.140.28.11 with SMTP id 11mr17233934qgy.94.1447348115284; Thu, 12 Nov 2015 09:08:35 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id u66si12244248qku.123.2015.11.12.09.08.34; Thu, 12 Nov 2015 09:08:35 -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; dkim=neutral (body hash did not verify) header.i=@linaro_org.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id 9B3BB6202C; Thu, 12 Nov 2015 17:08:34 +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.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, 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 ED48A6202F; Thu, 12 Nov 2015 17:06:20 +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 5F6A861A21; Thu, 12 Nov 2015 17:05:59 +0000 (UTC) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by lists.linaro.org (Postfix) with ESMTPS id A2D6861A21 for ; Thu, 12 Nov 2015 17:05:56 +0000 (UTC) Received: by lbbsy6 with SMTP id sy6so10357347lbb.2 for ; Thu, 12 Nov 2015 09:05:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZKiuStc2j9OtmX2zJxV+AQU7sBQnwSli+TeSSPxkHdw=; b=Ar1Y678SlexGt5oNEBwxYUW3cWF1FaDb6UpAUb5F3UzknxwNgi1jFKb4qBXKvnoRMS bCQY4ayYvGTFQg+tJNGMSfozeooEsbobBBKjq7eGtl6PRGgAQL9ItLg7FkUmWzZZuyYh 6wDeRzIEbI4LSUI13AyIkg8oSvzE3J6U+Q+6aNG0r+G8thQmbz+NBXwrEGF80nIawXCJ kvst8wJt03Wv+/KuVNl3kQigqsInD2F9kfcXzBoi3by5sdFGLiu0VJ0es9AMats+zvMH YLEypqAwXqO/RB1PO5JfL0tSH3AegNOemMnxnaNGyAR5qonj1xWymQpi6rSQRU7yd3Yo 097g== 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=ZKiuStc2j9OtmX2zJxV+AQU7sBQnwSli+TeSSPxkHdw=; b=Uy7mKhQZ7+dZKcfjQW6Rte64wqQOzxfiqDrIUshFI3lxw1RsmNWIVdZLwRjyGStc9z yYLZW8IjJk9DyeiqpcrLQqpqUPkTwAtaxT3ww91sDo6I0yfArL4BhUGWqasgBGGHQfxD Rz5ChKEIVrNCjDvY3NipGtaxLlV4A3vnQ6Kzbm9sMNJNHefkEnWcpdWWiU/9uTzC8fZS I/P5oAjh3UPgo539KHKvgvVLM7mSSyuqUY75qU6innZlQkwxggSVc25g7BLYzhjocmt0 bk9+S22FcUNwTnGhvbfQzYDnI9Chm/tbcZOsPCj2x5GTN7f65A1MYrS9F+OFUrWCF78w Owkg== X-Gm-Message-State: ALoCoQluTIuZuMsiXYHJGP3abqONP3tain67rT4BEKmn75clVnl2oQTJaje4Le+4qonHTmItUhwx X-Received: by 10.112.123.208 with SMTP id mc16mr7410695lbb.107.1447347955221; Thu, 12 Nov 2015 09:05:55 -0800 (PST) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id nb1sm2412412lbb.9.2015.11.12.09.05.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Nov 2015 09:05:54 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Thu, 12 Nov 2015 19:05:40 +0200 Message-Id: <1447347943-16807-5-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447347943-16807-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1447347943-16807-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [lng] [PATCH 4/7] api: time: make odp_local_time to be monotonic 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" It's more convenient the local time to be a monotonic source. The monotony allows to use local time in similar manner as it's supposed to be used with global time and the 64-bit timer is enough to guarantee it. Signed-off-by: Ivan Khoronzhuk --- example/generator/odp_generator.c | 10 +++++----- include/odp/api/time.h | 2 +- platform/linux-generic/odp_schedule.c | 9 +++------ test/performance/odp_pktio_perf.c | 16 ++++++++-------- test/validation/pktio/pktio.c | 21 ++++++++------------- 5 files changed, 25 insertions(+), 33 deletions(-) diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 9d79f89..2de530d 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -586,7 +586,7 @@ static void *gen_recv_thread(void *arg) */ static void print_global_stats(int num_workers) { - odp_time_t start, wait, diff; + odp_time_t cur, wait, next; uint64_t pkts, pkts_prev = 0, pps, maximum_pps = 0; int verbose_interval = 20; odp_thrmask_t thrd_mask; @@ -595,7 +595,7 @@ static void print_global_stats(int num_workers) continue; wait = odp_time_local_from_ns(verbose_interval * ODP_TIME_SEC_IN_NS); - start = odp_time_local(); + next = odp_time_sum(odp_time_local(), wait); while (odp_thrmask_worker(&thrd_mask) == num_workers) { if (args->appl.number != -1 && @@ -604,11 +604,11 @@ static void print_global_stats(int num_workers) break; } - diff = odp_time_diff(odp_time_local(), start); - if (odp_time_cmp(wait, diff) > 0) + cur = odp_time_local(); + if (odp_time_cmp(next, cur) > 0) continue; - start = odp_time_local(); + next = odp_time_sum(cur, wait); if (args->appl.mode == APPL_MODE_RCV) { pkts = odp_atomic_load_u64(&counters.udp); diff --git a/include/odp/api/time.h b/include/odp/api/time.h index 2bddb56..3228879 100644 --- a/include/odp/api/time.h +++ b/include/odp/api/time.h @@ -45,7 +45,7 @@ extern "C" { * Current local time * * Returns current local time stamp value. The local time source provides high - * resolution time. + * resolution time and is monotonic. * * @return Local time stamp. */ diff --git a/platform/linux-generic/odp_schedule.c b/platform/linux-generic/odp_schedule.c index 96b3ac5..3017876 100644 --- a/platform/linux-generic/odp_schedule.c +++ b/platform/linux-generic/odp_schedule.c @@ -586,7 +586,7 @@ static int schedule_loop(odp_queue_t *out_queue, uint64_t wait, odp_event_t out_ev[], unsigned int max_num, unsigned int max_deq) { - odp_time_t start_time, time, diff, wtime; + odp_time_t next, wtime; int first = 1; int ret; @@ -604,15 +604,12 @@ static int schedule_loop(odp_queue_t *out_queue, uint64_t wait, if (first) { wtime = odp_time_local_from_ns(wait); - start_time = odp_time_local(); + next = odp_time_sum(odp_time_local(), wtime); first = 0; continue; } - time = odp_time_local(); - diff = odp_time_diff(time, start_time); - - if (odp_time_cmp(wtime, diff) < 0) + if (odp_time_cmp(next, odp_time_local()) < 0) break; } diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c index ffe9844..3d37ae1 100644 --- a/test/performance/odp_pktio_perf.c +++ b/test/performance/odp_pktio_perf.c @@ -305,8 +305,8 @@ static void *run_thread_tx(void *arg) int thr_id; odp_queue_t outq; pkt_tx_stats_t *stats; - odp_time_t start_time, cur_time, send_duration; - odp_time_t burst_start_time, burst_gap; + odp_time_t cur_time, send_time_end, send_duration; + odp_time_t burst_gap_end, burst_gap; uint32_t batch_len; int unsent_pkts = 0; odp_event_t tx_event[BATCH_LEN_MAX]; @@ -336,19 +336,19 @@ static void *run_thread_tx(void *arg) odp_barrier_wait(&globals->tx_barrier); cur_time = odp_time_local(); - start_time = cur_time; - burst_start_time = odp_time_diff(cur_time, burst_gap); - while (odp_time_diff(cur_time, start_time) < send_duration) { + send_time_end = odp_time_sum(cur_time, send_duration); + burst_gap_end = cur_time; + while (odp_time_cmp(send_time_end, cur_time) > 0) { unsigned alloc_cnt = 0, tx_cnt; - if (odp_time_diff(cur_time, burst_start_time) < burst_gap) { + if (odp_time_cmp(burst_gap_end, cur_time) > 0) { cur_time = odp_time_local(); if (!odp_time_cmp(idle_start, ODP_TIME_NULL)) idle_start = cur_time; continue; } - if (odp_time_cmp(idle_start, ODP_TIME_NULL)) { + if (odp_time_cmp(idle_start, ODP_TIME_NULL) > 0) { odp_time_t diff = odp_time_diff(cur_time, idle_start); stats->s.idle_ticks = @@ -357,7 +357,7 @@ static void *run_thread_tx(void *arg) idle_start = ODP_TIME_NULL; } - burst_start_time += burst_gap; + burst_gap_end = odp_time_sum(burst_gap_end, burst_gap); alloc_cnt = alloc_packets(tx_event, batch_len - unsent_pkts); if (alloc_cnt != batch_len) diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 2f42c27..aee3a7d 100644 --- a/test/validation/pktio/pktio.c +++ b/test/validation/pktio/pktio.c @@ -336,18 +336,16 @@ static int destroy_inq(odp_pktio_t pktio) static odp_event_t queue_deq_wait_time(odp_queue_t queue, uint64_t ns) { - odp_time_t start, now, diff; + odp_time_t wait, end; odp_event_t ev; - start = odp_time_local(); - + wait = odp_time_local_from_ns(ns); + end = odp_time_sum(odp_time_local(), wait); do { ev = odp_queue_deq(queue); if (ev != ODP_EVENT_INVALID) return ev; - now = odp_time_local(); - diff = odp_time_diff(now, start); - } while (odp_time_to_ns(diff) < ns); + } while (odp_time_cmp(end, odp_time_local()) > 0); return ODP_EVENT_INVALID; } @@ -355,14 +353,14 @@ static odp_event_t queue_deq_wait_time(odp_queue_t queue, uint64_t ns) static odp_packet_t wait_for_packet(pktio_info_t *pktio_rx, uint32_t seq, uint64_t ns) { - odp_time_t start, now, diff; + odp_time_t wait_time, end; odp_event_t ev; odp_packet_t pkt; uint64_t wait; - start = odp_time_local(); wait = odp_schedule_wait_time(ns); - + wait_time = odp_time_local_from_ns(ns); + end = odp_time_sum(odp_time_local(), wait_time); do { pkt = ODP_PACKET_INVALID; @@ -388,10 +386,7 @@ static odp_packet_t wait_for_packet(pktio_info_t *pktio_rx, odp_packet_free(pkt); } - - now = odp_time_local(); - diff = odp_time_diff(now, start); - } while (odp_time_to_ns(diff) < ns); + } while (odp_time_cmp(end, odp_time_local()) > 0); CU_FAIL("failed to receive transmitted packet");