From patchwork Mon Nov 23 21:20:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 57203 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1686178lbb; Mon, 23 Nov 2015 13:25:49 -0800 (PST) X-Received: by 10.140.40.38 with SMTP id w35mr29266898qgw.52.1448313949773; Mon, 23 Nov 2015 13:25:49 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id p104si2128843qgd.126.2015.11.23.13.25.49; Mon, 23 Nov 2015 13:25:49 -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 672C561CF5; Mon, 23 Nov 2015 21:25:49 +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 E233A61CC6; Mon, 23 Nov 2015 21:21:50 +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 6DF3761D0A; Mon, 23 Nov 2015 21:21:44 +0000 (UTC) Received: from mail-lf0-f54.google.com (mail-lf0-f54.google.com [209.85.215.54]) by lists.linaro.org (Postfix) with ESMTPS id 62CB261CC6 for ; Mon, 23 Nov 2015 21:21:09 +0000 (UTC) Received: by lfaz4 with SMTP id z4so120289800lfa.0 for ; Mon, 23 Nov 2015 13:21:08 -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=mJU3WQSof1r31r7GREPMWLaWZEyBU/ewKeMsdWXeaq8=; b=jYpbiGCXSIuTtI4p+lk6egN07XkSX6S+A8R6zGsN4WFKTwlqrPbAW+yZ79u/fp0hpB sif42/u9opSuK3Rlzy3JhCX3Ozc6EFSKY/7XOBzLrJb9XuL1UOph7DGIOcYhzc54IhuI PiaDh6VLSjCw7exstjg+TxE3BpWmbdW/dT79jPyV+UHI9wYoL2Z91QFRhF3RHnHp8Xhw oqEt1qQTBZkFw1VVbacYONXsj3uKwT+fF1M9+Y1suvYiw64Anc2C7LEf5Z5/Pq25XddW v/dAf0Ji26YjF6L9eavIqQ9faJ6XzW/NPZYTVRuL5GBmwx+g1+zgQ3fmZmpsZUeJQ+OB s4Fw== 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=mJU3WQSof1r31r7GREPMWLaWZEyBU/ewKeMsdWXeaq8=; b=mTNAClzTP2Erp3rKqk9JYBWBoiWcjR0ZHXnZusZSNtgz0GgL157PoKY5TZSRKpreAz yaQPj+/7zqw4rJQDYvwmStg0oREvr1HuyFo6vHXyB9SM1PLOdneuZo35ZU36tt9RSvdy wX9v2AZQYaAEr9EF/Fp8iOoxZn6hOVWGjEtAWydxlc3ZASEpXhwtcNLz5z4vGI8UKHG9 W8z1niayutVT0wycEvSEr0zji5krC7MoRIrkr6r6nxERG1Txcq03WxunNZu4VSeCZ1Wl pRtoTy53qgOp2yiC8THf/7jxns6G5mNEM00k4I0kDg2NB9FWPLmqyEXqL3cPBh02XF/o HJUQ== X-Gm-Message-State: ALoCoQnzZsIceu04CDVOdJpUZYos6Y96AMjRAFTV5+iYukzcPmiIlfPXJy6THHyY+TT6j533W7Zr X-Received: by 10.25.7.6 with SMTP id 6mr9459099lfh.107.1448313668282; Mon, 23 Nov 2015 13:21:08 -0800 (PST) Received: from localhost.localdomain ([212.90.60.8]) by smtp.gmail.com with ESMTPSA id r2sm2122027lfe.28.2015.11.23.13.21.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Nov 2015 13:21:07 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Mon, 23 Nov 2015 23:20:54 +0200 Message-Id: <1448313655-7949-7-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448313655-7949-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1448313655-7949-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v3 6/7] api: time: make odp_local_time to be monotonic wall time 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 wall time. That means time starts from 0 and not wraps. It 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 | 3 +- platform/linux-generic/include/odp_internal.h | 2 + platform/linux-generic/odp_schedule.c | 9 ++-- platform/linux-generic/odp_time.c | 61 +++++++++++++++++++-------- test/performance/odp_pktio_perf.c | 26 ++++++------ test/validation/pktio/pktio.c | 21 ++++----- 7 files changed, 75 insertions(+), 57 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 50a0bf5..9865d81 100644 --- a/include/odp/api/time.h +++ b/include/odp/api/time.h @@ -45,7 +45,8 @@ extern "C" { * Current local time * * Returns current local time stamp value. The local time source provides high - * resolution time. + * resolution time, it is initialized to zero during ODP startup and will not + * wrap around in at least 10 years. * * @return Local time stamp. */ diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index 14ba159..baff135 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -79,6 +79,8 @@ int odp_schedule_term_local(void); int odp_timer_init_global(void); int odp_timer_disarm_all(void); +int odp_time_local_init(void); + void _odp_flush_caches(void); #ifdef __cplusplus 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/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index b725086..1aae88c 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -11,19 +11,21 @@ #include #include -odp_time_t odp_time_local(void) +static __thread struct timespec start_local; + +static inline +uint64_t _odp_time_to_ns(odp_time_t val) { - int ret; - struct timespec time; + uint64_t ns; - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); - if (odp_unlikely(ret != 0)) - ODP_ABORT("clock_gettime failed\n"); + ns = val.tv_sec * ODP_TIME_SEC_IN_NS; + ns += val.tv_nsec; - return time; + return ns; } -odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) +static inline +odp_time_t _odp_time_diff(odp_time_t t2, odp_time_t t1) { struct timespec time; @@ -38,24 +40,36 @@ odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) return time; } -uint64_t odp_time_to_ns(odp_time_t time) +odp_time_t odp_time_local(void) { - uint64_t ns; + int ret; + struct timespec time; + + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); + if (odp_unlikely(ret != 0)) + ODP_ABORT("clock_gettime failed\n"); - ns = time.tv_sec * ODP_TIME_SEC_IN_NS; - ns += time.tv_nsec; + return _odp_time_diff(time, start_local); +} - return ns; +odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) +{ + return _odp_time_diff(t2, t1); +} + +uint64_t odp_time_to_ns(odp_time_t time) +{ + return _odp_time_to_ns(time); } odp_time_t odp_time_local_from_ns(uint64_t ns) { - struct timespec time; + struct timespec val; - time.tv_sec = ns / ODP_TIME_SEC_IN_NS; - time.tv_nsec = ns % ODP_TIME_SEC_IN_NS; + val.tv_sec = ns / ODP_TIME_SEC_IN_NS; + val.tv_nsec = ns % ODP_TIME_SEC_IN_NS; - return time; + return val; } int odp_time_cmp(odp_time_t t2, odp_time_t t1) @@ -96,10 +110,21 @@ uint64_t odp_time_to_u64(odp_time_t time) resolution = (uint64_t)tres.tv_nsec; - return odp_time_to_ns(time) / resolution; + return _odp_time_to_ns(time) / resolution; } odp_time_t odp_time_null(void) { return (struct timespec) {0, 0}; } + +int odp_time_local_init(void) +{ + int ret; + struct timespec time; + + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); + start_local = ret ? odp_time_null() : time; + + return ret; +} diff --git a/test/performance/odp_pktio_perf.c b/test/performance/odp_pktio_perf.c index 2e49f50..8737bc8 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,21 +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_cmp(odp_time_diff(cur_time, start_time), - send_duration) > 1) { + 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_cmp(odp_time_diff(cur_time, burst_start_time), - burst_gap) > 1) { + 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 = @@ -359,7 +357,7 @@ static void *run_thread_tx(void *arg) idle_start = ODP_TIME_NULL; } - burst_start_time = odp_time_sum(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) @@ -597,13 +595,13 @@ static int setup_txrx_masks(odp_cpumask_t *thd_mask_tx, */ static void busy_loop_ns(uint64_t wait_ns) { - odp_time_t diff; - odp_time_t start_time = odp_time_local(); odp_time_t wait = odp_time_local_from_ns(wait_ns); + odp_time_t cur = odp_time_local(); + odp_time_t end_time = odp_time_sum(cur, wait); do { - diff = odp_time_diff(odp_time_local(), start_time); - } while (odp_time_cmp(wait, diff) > 0); + cur = odp_time_local(); + } while (odp_time_cmp(end_time, cur) > 0); } /* diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c index 0a6592c..002c26b 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");