From patchwork Fri Dec 4 17:51:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 57716 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp702507lbb; Fri, 4 Dec 2015 09:55:22 -0800 (PST) X-Received: by 10.140.228.68 with SMTP id y65mr21374690qhb.78.1449251722387; Fri, 04 Dec 2015 09:55:22 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id q68si15163278qgq.99.2015.12.04.09.55.22; Fri, 04 Dec 2015 09:55:22 -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 E09B761B7C; Fri, 4 Dec 2015 17:55:21 +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 C926562D6F; Fri, 4 Dec 2015 17:52:47 +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 8017462D85; Fri, 4 Dec 2015 17:52:44 +0000 (UTC) Received: from mail-lf0-f50.google.com (mail-lf0-f50.google.com [209.85.215.50]) by lists.linaro.org (Postfix) with ESMTPS id 592F862D6D for ; Fri, 4 Dec 2015 17:51:50 +0000 (UTC) Received: by lfaz4 with SMTP id z4so117224961lfa.0 for ; Fri, 04 Dec 2015 09:51:49 -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=EmMMcXTDVEM7VptpI9juO1euLZaH3dVvaLqw/HJJQBI=; b=U5B3llfgqihLWtt9RiWsPklWwNu99Wiet4tRvfBZlfG9J0a3bLdDAd/OheyUvFddXS dStYMcVuayb+Flpk8vP1IOyh+7IybzpC2ofJs1AzNuq7Tl1tSrIEeWen5tkeQ022401A hakfeGul34AF30D5+Fys9fRdoALMZAFBztHI5XpD7u1oNViBCJa1xxJbyT2rj5qai3oR Q7Hh7F5+9zfQa5cyCWSWjhyDB6JEco457DPerpR9Rv5Rq4dtR9wTTta01nf35w2OUWFL Be+D1QXD7hM39fASWOGBX0IhsU/UFuZWWHVa79o2SIQXbVUptXsIehsxr2QUXmB1wQNJ fzLg== 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=EmMMcXTDVEM7VptpI9juO1euLZaH3dVvaLqw/HJJQBI=; b=b2XHAEP01Nanf014vVd9AynfTHGXRPhpmfUhjs8v2aT8tAXhsoM2BdKEkVbzcYlTc9 0y+pTXW+quXfbV3UjbSbdaKLa7PoEC2uzU6jX3greT3wa4d/ZPu0g4CNtvQmnh2IbIOn 8hKzI8xLBPJ6LS84Ns6V2xRQE7d43kk/4OI3jYbPK2TnTnp6vfDrD9TLZy+t672KVRSF IHsCicqwtJfjnktsKSTcoKL2n91t7YDczQqimeAepA9mDeynZZPJJ4WdEgEY7bj9OCQ/ ovaAILRGKeedtIXDSpVoK/Yh8jIYh/MkTjfzVjZ0E89fu/Wi1zW8SbTXVTJIoeFiD5LG xniA== X-Gm-Message-State: ALoCoQn0MHcZnWkmJ1xpfOzYvWXKVVRXct76EJI5uKEcKg0YJljulyjISBjRzSQGZyHQMxwC/vj5 X-Received: by 10.25.152.133 with SMTP id a127mr8665236lfe.152.1449251509218; Fri, 04 Dec 2015 09:51:49 -0800 (PST) Received: from localhost.localdomain ([212.90.60.8]) by smtp.gmail.com with ESMTPSA id rm5sm2483518lbb.20.2015.12.04.09.51.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Dec 2015 09:51:48 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Fri, 4 Dec 2015 19:51:30 +0200 Message-Id: <1449251494-23210-6-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449251494-23210-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1449251494-23210-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v7 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. Reviewed-by: Petri Savolainen 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);