From 12eb7a44d0a7e561581a77d726fdf535b8c49367 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Fri, 25 Aug 2017 18:05:32 +0200 Subject: [PATCH] x86 timeout test: consider instable tsc (quickfix) This is a quickfix to avoid testing microseconds precise time on older x86 machines that have no invariant TSC as interpolation source. Ref #2400 --- repos/os/run/timeout.run | 6 ++++++ repos/os/src/test/timeout/main.cc | 31 ++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/repos/os/run/timeout.run b/repos/os/run/timeout.run index ebdbed781..c4634eb51 100644 --- a/repos/os/run/timeout.run +++ b/repos/os/run/timeout.run @@ -32,6 +32,12 @@ proc precise_time { } { # time instead. # if {[expr [have_spec arm] && ![have_spec hw]]} { return false } + + # + # Older x86 machines do not have an invariant timestamp + # + if {[have_spec x86] && ![have_spec hw]} { return dynamic } + return true } diff --git a/repos/os/src/test/timeout/main.cc b/repos/os/src/test/timeout/main.cc index a00ddf496..50512e174 100644 --- a/repos/os/src/test/timeout/main.cc +++ b/repos/os/src/test/timeout/main.cc @@ -22,6 +22,35 @@ using namespace Genode; +/** + * FIXME + * This function and its use are a quickfix that avoid refactorization of the + * timeout framework respectively the timeout test for now. It should be + * replaced in the near future by a solution that is part of the base lib and + * thus can be implemented the clean way in platform specific files. + */ +static bool precise_time(Xml_node config) +{ + String<32> attr = config.attribute_value("precise_time", String<32>("false")); + if (attr == "true") { return true; } + if (attr == "false") { return false; } + if (attr == "dynamic") { +#ifdef __x86_64__ + unsigned long cpuid = 0x80000007, edx = 0; + asm volatile ("cpuid" : "+a" (cpuid), "=d" (edx) : : "rbx", "rcx"); + return edx & 0x100; +#elif __i386__ + unsigned long cpuid = 0x80000007, edx = 0; + asm volatile ("push %%ebx \n" + "cpuid \n" + "pop %%ebx" : "+a" (cpuid), "=d" (edx) : : "ecx"); + return edx & 0x100; +#endif + } + return false; +} + + struct Test { Env &env; @@ -553,7 +582,7 @@ struct Fast_polling : Test main_ep(env, STACK_SIZE, "fast_polling_ep"), main_handler(main_ep, *this, &Fast_polling::main) { - if (config.xml().attribute_value("precise_time", true)) { + if (precise_time(config.xml())) { Signal_transmitter(main_handler).submit(); } else { log("... skip test, requires the platform to support precise time");