[PATCH] Enable configuration of the MONOTONIC_CLOCK when cross-compiling.

David James davidjames at google.com
Wed May 19 09:12:59 PDT 2010


On Wed, May 19, 2010 at 8:47 AM, Adam Jackson <ajax at nwnk.net> wrote:
> On Tue, 2010-05-18 at 15:17 -0700, David James wrote:
>> When xorg-xserver is being cross-compiled, there is currently no way
>> for us to detect whether the monotonic clock is available on the
>> target system. Currently, in this situation, we default to not use the
>> monotonic clock. One problem with this situation is that the user will
>> be treated as idle when the date is updated.
>>
>> To fix this situation, this patch creates a new variable called
>> xorg_cv_MONOTONIC_CLOCK. If packagers who cross-compile setup this
>> variable appropriately, then we can enable usage of the
>> MONOTONIC_CLOCK when cross-compiling.
>
> This requires editing the configure cache?  That's a little non-obvious.
> I think the liboil-style compile check is probably fine.

The liboil-style compile check is fine? Great! This makes my patch
simpler, and saves everybody the trouble of specifying options or
environment variables. Please take a look at the updated patch
(monotonic-clock-patch-v2.txt).

I tested cross-compiling to arm and x86 from an x86_64 machine and the
compile-time check works great.

Cheers,

David

P.S. Here's the commit message (copied from the attached patch)

[PATCH] Discover monotonic clock using compile-time check.

When xorg-xserver is being cross-compiled, there is currently no way
for us to detect whether the monotonic clock is available on the
target system, because we aren't able to run a test program on the host
system. Currently, in this situation, we default to not use the
monotonic clock. One problem with this situation is that the user will
be treated as idle when the date is updated.

To fix this situation, we now use a compile-time check to detect whether the
monotonic clock is available. This check can run just fine when we are
cross-compiling.
-------------- next part --------------
From cf73e298c8353334923c6e7368bd47d635137ba0 Mon Sep 17 00:00:00 2001
From: David James <davidjames at google.com>
Date: Wed, 19 May 2010 08:54:15 -0700
Subject: [PATCH] Discover monotonic clock using compile-time check.

When xorg-xserver is being cross-compiled, there is currently no way
for us to detect whether the monotonic clock is available on the
target system, because we aren't able to run a test program on the host
system. Currently, in this situation, we default to not use the
monotonic clock. One problem with this situation is that the user will
be treated as idle when the date is updated.

To fix this situation, we now use a compile-time check to detect whether the
monotonic clock is available. This check can run just fine when we are
cross-compiling.

Signed-off-by: David James <davidjames at google.com>
---
 configure.ac |   17 +++++++----------
 1 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index 1c7875e..e5834fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -908,19 +908,16 @@ if ! test "x$have_clock_gettime" = xno; then
         CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200112L"
     fi
 
-    AC_RUN_IFELSE([
+    AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
 #include <time.h>
-
-int main(int argc, char *argv[[]]) {
-    struct timespec tp;
-
-    if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+#include <unistd.h>
+int main() {
+#if !(defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 && defined(CLOCK_MONOTONIC))
+        #error No monotonic clock
+#endif
         return 0;
-    else
-        return 1;
 }
-    ], [MONOTONIC_CLOCK=yes], [MONOTONIC_CLOCK=no],
-       [MONOTONIC_CLOCK="cross compiling"])
+]])],[MONOTONIC_CLOCK=yes], [MONOTONIC_CLOCK=no])
 
     LIBS="$LIBS_SAVE"
     CPPFLAGS="$CPPFLAGS_SAVE"
-- 
1.7.0.1


More information about the xorg-devel mailing list