From patchwork Tue Feb 25 14:23:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petri Savolainen X-Patchwork-Id: 25298 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4FC5E20543 for ; Tue, 25 Feb 2014 14:22:13 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id oz11sf1127539veb.8 for ; Tue, 25 Feb 2014 06:22:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type; bh=ojxnGzlVJUCYJ1VhupTLhMyIqeuKjIJ+qFmjoa7criE=; b=f/rJLBhveJvNoJ2BOCEA7g47yJ+XIVIg5qRELmd5Vh9oXPjZ/E+IGNvXi0bgID8SBL DrD2EOaaDbPQgPYB1UtRpiZ//wH8+nXRLghm4BDUGBgIyVPgdGwVYfQH6+HQiw45qZ4a 6HnkfK9bZaN/2XpbK1h50Sq5RPoDh8F911HUVKTDKlHxoG4utoV6ITpCtpOFhSCeERSV Qp2zhjalv1KTMtK18FG5b/yi6xDALL4ChAJAwOcSWnk55t7dwpqNQJiTSSThSJDlHGFz jUfTZIyaQzqTsXsrLTNaMcqxIDu9X/4oXAkn+WKxsa6jCycey6qMlY9zgNiPJzx1duWt 9spQ== X-Gm-Message-State: ALoCoQmoQIUvYkpvAJC7JpDL4RUYVXTRGl/hIaWc1Ksom4gKm+KuRwKKeXwcuirIM/iPFYnDzdg8 X-Received: by 10.52.37.33 with SMTP id v1mr655567vdj.1.1393338133088; Tue, 25 Feb 2014 06:22:13 -0800 (PST) MIME-Version: 1.0 X-BeenThere: lng-odp@linaro.org Received: by 10.50.102.7 with SMTP id fk7ls2807100igb.8.canary; Tue, 25 Feb 2014 06:22:12 -0800 (PST) X-Received: by 10.50.17.37 with SMTP id l5mr3458792igd.3.1393338132657; Tue, 25 Feb 2014 06:22:12 -0800 (PST) Received: from mail-ie0-f170.google.com (mail-ie0-f170.google.com [209.85.223.170]) by mx.google.com with ESMTPS id d7si37944063igr.14.2014.02.25.06.22.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 06:22:12 -0800 (PST) Received-SPF: neutral (google.com: 209.85.223.170 is neither permitted nor denied by best guess record for domain of petri.savolainen@linaro.org) client-ip=209.85.223.170; Received: by mail-ie0-f170.google.com with SMTP id y20so327191ier.29 for ; Tue, 25 Feb 2014 06:22:12 -0800 (PST) X-Received: by 10.42.119.134 with SMTP id b6mr19588897icr.31.1393338132493; Tue, 25 Feb 2014 06:22:12 -0800 (PST) Received: from localhost.localdomain (ec2-23-23-178-99.compute-1.amazonaws.com. [23.23.178.99]) by mx.google.com with ESMTPSA id r4sm37935822igh.1.2014.02.25.06.22.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Feb 2014 06:22:11 -0800 (PST) From: Petri Savolainen To: lng-odp@linaro.org Cc: Petri Savolainen Subject: [lng-odp] [PATCH] Cycle count accuracy test Date: Tue, 25 Feb 2014 16:23:21 +0200 Message-Id: <1393338201-15643-1-git-send-email-petri.savolainen@linaro.org> X-Mailer: git-send-email 1.8.5.3 X-Original-Sender: petri.savolainen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.223.170 is neither permitted nor denied by best guess record for domain of petri.savolainen@linaro.org) smtp.mail=petri.savolainen@linaro.org Precedence: list Mailing-list: list lng-odp@linaro.org; contact lng-odp+owners@linaro.org List-ID: X-Google-Group-Id: 474323889996 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Petri Savolainen --- platform/linux-generic/source/odp_time.c | 2 +- test/example/odp_example.c | 61 +++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/platform/linux-generic/source/odp_time.c b/platform/linux-generic/source/odp_time.c index 38c1bdf..23ff8f5 100644 --- a/platform/linux-generic/source/odp_time.c +++ b/platform/linux-generic/source/odp_time.c @@ -85,7 +85,7 @@ uint64_t odp_time_cycles_to_ns(uint64_t cycles) { uint64_t hz = odp_sys_cpu_hz(); - if (cycles > hz) + if (cycles > (UINT64_MAX / 1000000000)) return 1000000000*(cycles/hz); return (1000000000*cycles)/hz; diff --git a/test/example/odp_example.c b/test/example/odp_example.c index 12bb438..0f421a3 100644 --- a/test/example/odp_example.c +++ b/test/example/odp_example.c @@ -19,7 +19,7 @@ /* ODP helper for Linux apps */ #include -/* Linux headers*/ +/* Needs librt*/ #include /* GNU lib C */ @@ -34,6 +34,7 @@ #define ALLOC_ROUNDS (1024*1024) #define MULTI_BUFS_MAX 4 #define SCHED_RETRY 100 +#define TEST_SEC 2 typedef struct { @@ -527,6 +528,61 @@ static void *run_thread(void *arg) } +static void test_time(void) +{ + struct timespec tp1, tp2; + uint64_t t1, t2; + uint64_t ns1, ns2, cycles; + double err; + + if (clock_gettime(CLOCK_MONOTONIC, &tp2)) { + ODP_ERR("clock_gettime failed.\n"); + return; + } + + printf("\nTime accuracy test (%i sec)\n", TEST_SEC); + + do { + if (clock_gettime(CLOCK_MONOTONIC, &tp1)) { + ODP_ERR("clock_gettime failed.\n"); + return; + } + + } while (tp1.tv_sec == tp2.tv_sec); + + t1 = odp_time_get_cycles(); + + do { + if (clock_gettime(CLOCK_MONOTONIC, &tp2)) { + ODP_ERR("clock_gettime failed.\n"); + return; + } + + } while ((tp2.tv_sec - tp1.tv_sec) < TEST_SEC); + + t2 = odp_time_get_cycles(); + + ns1 = (tp2.tv_sec - tp1.tv_sec)*1000000000; + + if (tp2.tv_nsec > tp1.tv_nsec) + ns1 += tp2.tv_nsec - tp1.tv_nsec; + else + ns1 -= tp1.tv_nsec - tp2.tv_nsec; + + cycles = odp_time_diff_cycles(t1, t2); + ns2 = odp_time_cycles_to_ns(cycles); + + err = ((double)(ns2) - (double)ns1) / (double)ns1; + + printf("clock_gettime %"PRIu64" ns\n", ns1); + printf("odp_time_get_cycles %"PRIu64" cycles\n", cycles); + printf("odp_time_cycles_to_ns %"PRIu64" ns\n", ns2); + printf("odp get cycle error %f%%\n", err*100.0); + + printf("\n"); +} + + static void print_usage(void) { printf("\n\nUsage: ./odp_example [options]\n"); @@ -637,6 +693,9 @@ int main(int argc, char *argv[]) thr_id = odp_thread_create(0); odp_init_local(thr_id); + /* Test cycle count accuracy */ + test_time(); + /* * Create message pool */