From patchwork Tue Dec 1 15:01:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 57497 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2230474lbb; Tue, 1 Dec 2015 07:03:21 -0800 (PST) X-Received: by 10.31.11.204 with SMTP id 195mr59490047vkl.23.1448982201172; Tue, 01 Dec 2015 07:03:21 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id w189si45580403vke.31.2015.12.01.07.03.20; Tue, 01 Dec 2015 07:03:21 -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 A9A1361FA2; Tue, 1 Dec 2015 15:03:20 +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 20A5961C84; Tue, 1 Dec 2015 15:02:09 +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 DCFE161E12; Tue, 1 Dec 2015 15:02:02 +0000 (UTC) Received: from mail-lf0-f42.google.com (mail-lf0-f42.google.com [209.85.215.42]) by lists.linaro.org (Postfix) with ESMTPS id D381561E10 for ; Tue, 1 Dec 2015 15:01:56 +0000 (UTC) Received: by lfaz4 with SMTP id z4so11867282lfa.0 for ; Tue, 01 Dec 2015 07:01: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=I/M5losz8FwhcW2nw5osSZGhO4e3DYXIMLld38o3+bo=; b=S+p6SPocnUhyQnyG0+EHWRuCH2oTWWqnqzJWoJHTjBhlFEPpZkaKC3yzPwjGNc9umc nyt4Y8pkNTayXGpQavqs+43yYgTrDCF35yfOWNl99m432WGg0HdfxRM3/1XaO6zY3s9G S4wM4vIsct+gAQBWl5fgt9+jIr/67Rx8ME/tlesaSqALz/qnVUKTgLN9lL6FQK97c4Ol Mmep07LMkIESfKhT6vm9Y4QjUv2F8WP98WGwKStXLRF9s9nYuAU12Z6smLIOXluNYwB4 zwE2opFwLzcVZQv0hzhklSplyKSFMFqDYjcHyXn/iKzo4C6PiAGDGKqOoWRFYskao0od h4JQ== 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=I/M5losz8FwhcW2nw5osSZGhO4e3DYXIMLld38o3+bo=; b=jlLlVYo3pr0K3m6USb3xAQg09HW9fOo4hphsoqTJwV7TlLlIo/yseSMmja/qX9k1qK W1EoHd4ZyBB7cBbn2HEJqVRBY1qMfAPzeLz+knyJxHnMEox8BpzXScarVRZrh+e+O9Tk BMUuUaBZw5XzwvVOnGQK8GzLvt6PfapMLA5iWhBco3A/79xv3OXHwcQt+BJwClKoqApV SifKty1aUytLb1DGCc09Ewa352RTr3svarfUK6SqrkAtNAOAQ50TBOpZKrjyVsEq0fPS KSn5Uss781znvlikTJqRh6mN+FiJGjM9wAbiXHNYEqx5+Z5veRBqMdcGfI19rWmquF75 LapQ== X-Gm-Message-State: ALoCoQnmiJeAeZvTw0jXftGdX6CS73VwEX8YSMFWM6dwD1zIS1DgU+bPyACxd2wY8I/nsOukf5WU X-Received: by 10.112.158.66 with SMTP id ws2mr29952190lbb.126.1448982115700; Tue, 01 Dec 2015 07:01:55 -0800 (PST) Received: from localhost.localdomain ([212.90.60.8]) by smtp.gmail.com with ESMTPSA id u12sm7995186lbk.45.2015.12.01.07.01.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Dec 2015 07:01:55 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Tue, 1 Dec 2015 17:01:21 +0200 Message-Id: <1448982084-8115-3-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448982084-8115-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1448982084-8115-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v4 5/9] performance: sched: use ODP time API instead of clock_gettime 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" The time API can be used instead of Posix clock_gettime as more accurate and OS independent. Signed-off-by: Ivan Khoronzhuk --- test/performance/odp_scheduling.c | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/test/performance/odp_scheduling.c b/test/performance/odp_scheduling.c index 5d17c47..2c5262f 100644 --- a/test/performance/odp_scheduling.c +++ b/test/performance/odp_scheduling.c @@ -702,7 +702,7 @@ static void *run_thread(void *arg) */ static void test_cpu_freq(void) { - struct timespec tp1, tp2; + odp_time_t cur_time, test_time, start_time, end_time; uint64_t c1, c2, cycles; uint64_t nsec; double diff_max_hz, max_cycles; @@ -710,40 +710,21 @@ static void test_cpu_freq(void) printf("\nCPU cycle count frequency test (runs about %i sec)\n", TEST_SEC); - if (clock_gettime(CLOCK_MONOTONIC, &tp2)) { - LOG_ERR("clock_gettime failed.\n"); - return; - } - - /* Wait until clock moves to the next second. It enables easy comparison - * during the measurement. */ - do { - if (clock_gettime(CLOCK_MONOTONIC, &tp1)) { - LOG_ERR("clock_gettime failed.\n"); - return; - } - - } while (tp1.tv_sec == tp2.tv_sec); + test_time = odp_time_local_from_ns(TEST_SEC * ODP_TIME_SEC_IN_NS); + start_time = odp_time_local(); + end_time = odp_time_sum(start_time, test_time); /* Start the measurement */ c1 = odp_cpu_cycles(); do { - if (clock_gettime(CLOCK_MONOTONIC, &tp2)) { - LOG_ERR("clock_gettime failed.\n"); - return; - } - - } while ((tp2.tv_sec - tp1.tv_sec) < TEST_SEC); + cur_time = odp_time_local(); + } while (odp_time_cmp(end_time, cur_time) > 0); c2 = odp_cpu_cycles(); - nsec = (tp2.tv_sec - tp1.tv_sec) * 1000000000; - - if (tp2.tv_nsec > tp1.tv_nsec) - nsec += tp2.tv_nsec - tp1.tv_nsec; - else - nsec -= tp1.tv_nsec - tp2.tv_nsec; + test_time = odp_time_diff(cur_time, start_time); + nsec = odp_time_to_ns(test_time); cycles = odp_cpu_cycles_diff(c2, c1); max_cycles = (nsec * odp_cpu_hz_max()) / 1000000000.0; @@ -751,7 +732,7 @@ static void test_cpu_freq(void) /* Compare measured CPU cycles to maximum theoretical CPU cycle count */ diff_max_hz = ((double)(cycles) - max_cycles) / max_cycles; - printf("clock_gettime %" PRIu64 " ns\n", nsec); + printf("odp_time %" PRIu64 " ns\n", nsec); printf("odp_cpu_cycles %" PRIu64 " CPU cycles\n", cycles); printf("odp_sys_cpu_hz %" PRIu64 " hz\n", odp_cpu_hz_max()); printf("Diff from max CPU freq %f%%\n", diff_max_hz * 100.0);