From patchwork Thu Dec 3 12:49:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 57646 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp3476620lbb; Thu, 3 Dec 2015 04:53:34 -0800 (PST) X-Received: by 10.55.78.78 with SMTP id c75mr10579683qkb.71.1449147214419; Thu, 03 Dec 2015 04:53:34 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id o7si8457875qho.30.2015.12.03.04.53.34; Thu, 03 Dec 2015 04:53:34 -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 0D01E62C8E; Thu, 3 Dec 2015 12:53: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 6704B62CB3; Thu, 3 Dec 2015 12:50: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 CC72262C99; Thu, 3 Dec 2015 12:50:44 +0000 (UTC) Received: from mail-lf0-f44.google.com (mail-lf0-f44.google.com [209.85.215.44]) by lists.linaro.org (Postfix) with ESMTPS id BBF9862C9B for ; Thu, 3 Dec 2015 12:49:53 +0000 (UTC) Received: by lffu14 with SMTP id u14so89612105lff.1 for ; Thu, 03 Dec 2015 04:49:52 -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=fKwA+Hf1FFHfsQEN+Ihk/AhgE0VROCV7cPE0vQG8Jp9ozm/i4PZqc1oJIe1QV74rxc 2tOkO+fv//O84URe9pjxHZX0pVpZWQbekOXsnsZgf4jwxyu7FKZVWmS6SKdc9onaUhAC gvCg2Ij4T7Uup326b636K8oQy1udyIeX/w2Ye+g0rwLLJE8yHD66VEE0EHWrDVIfSArk aU6oNhogLXIRbvl16XYDcjnHIzRt9P1qmt+pdap7Ejb11vA/Fth3SFn76pUN36qilZyP zjoPGcVBNooqZDs8BLg64FOOHPRXWwLLDh3IWuUa3AcGwmbDMii3IXCcEE2TEYy9oXF3 4/2A== 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=cW+uHnzKYf+W0jTlwHxf+xp3h63EVXnwIhR3Oa+HsLxBND/hUYeqSm6Z+T8Arep1PW osEqEG2LxOmFsR8/YZgWKq7YlKvWh114xTK2VapGWDnaXCTvaqUqnNob9V8cxO+st3ot 0TvFiCzC/NUsR57BOVgg0s8fGDGcHPfkow+EObMJm+GOnEy8ZI6vBGohO7Uu2vIh8buz h2E7P6wTkbAeCo0hsztL1g2CQ4NHDzSbsCbVHnENa1uMcf/aAT7vEYVjcboTTmEmxeDS TOhed8eflfurgivCj/kbIKdYgszdAxGNm1ixSZ2mUgtTa6at/pHCCWeGqWOySC2BjEIx ssug== X-Gm-Message-State: ALoCoQnfXsCpx9U3VVPOTb+kglqlSoKEa/THux6SFLxmxYOZPzO+9W1qY5IRNLXmakcKW5xYYpWY X-Received: by 10.25.209.148 with SMTP id i142mr5760553lfg.163.1449146992303; Thu, 03 Dec 2015 04:49:52 -0800 (PST) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id l81sm1392459lfb.40.2015.12.03.04.49.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Dec 2015 04:49:51 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Thu, 3 Dec 2015 14:49:34 +0200 Message-Id: <1449146978-22222-6-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449146978-22222-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1449146978-22222-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v6] 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);