aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@linaro.org>2017-04-28 15:09:57 +0300
committerMaxim Uvarov <maxim.uvarov@linaro.org>2017-06-16 16:51:11 +0300
commit60150bba495711e6fdfc948ffb4ad405878fbcbc (patch)
treef56eeb31e1e26857fb2fddfad7e1563efa74919d /platform/linux-generic
parentfbe34c754b7abe15100779ce9833a7f200517d9f (diff)
linux-gen: time: improve x86 TSC freq measurement accuracy
Add short warm up round and measure over a longer period of time (250ms vs 100ms). Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org> Reviewed-and-tested-by: Bill Fischofer <bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'platform/linux-generic')
-rw-r--r--platform/linux-generic/arch/x86/odp_cpu_arch.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/platform/linux-generic/arch/x86/odp_cpu_arch.c b/platform/linux-generic/arch/x86/odp_cpu_arch.c
index 9ba601a32..b1da428b9 100644
--- a/platform/linux-generic/arch/x86/odp_cpu_arch.c
+++ b/platform/linux-generic/arch/x86/odp_cpu_arch.c
@@ -54,11 +54,16 @@ uint64_t cpu_global_time_freq(void)
uint64_t t1, t2, ts_nsec, cycles, hz;
int i;
uint64_t avg = 0;
- int rounds = 4;
+ int rounds = 3;
+ int warm_up = 1;
for (i = 0; i < rounds; i++) {
- sleep.tv_sec = 0;
- sleep.tv_nsec = SEC_IN_NS / 10;
+ sleep.tv_sec = 0;
+
+ if (warm_up)
+ sleep.tv_nsec = SEC_IN_NS / 1000;
+ else
+ sleep.tv_nsec = SEC_IN_NS / 4;
if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts1)) {
ODP_DBG("clock_gettime failed\n");
@@ -85,8 +90,12 @@ uint64_t cpu_global_time_freq(void)
cycles = t2 - t1;
hz = (cycles * SEC_IN_NS) / ts_nsec;
- avg += hz;
+
+ if (warm_up)
+ warm_up = 0;
+ else
+ avg += hz;
}
- return avg / rounds;
+ return avg / (rounds - 1);
}