[PATCH v2] configure: introduce --{enable, disable}-syscall-clock

Tiago Vignatti tiago.vignatti at nokia.com
Mon Mar 29 11:26:35 PDT 2010

Some Linux systems might not want to link against rt and pthread libraries
simply to implement monotonic clock, inside GetTimeInMillis(). For those, use
a direct syscall instead. This is discouraged if someone doesn't know what's

This patch keeps the new syscall version disabled by default - therefore not
changing the original behaviour of the xserver build.

The main concern was regarding some eventual performance degradation when not
going through optimized code in C library, or because syscall is varargs
based. The simple program bellow (kudos to Adam Jackson) performs equally in
the practice, for both syscall and C library implementation, when executed in
several architectures:

  #define clock_gettime(a, b) syscall(SYS_clock_gettime, a, b)

  int main(void) {
      int i;
      struct timespec tp;

      for (i = 0; i < 1e7; i++)
      clock_gettime(CLOCK_MONOTONIC, &tp);

      return 0;

Signed-off-by: Tiago Vignatti <tiago.vignatti at nokia.com>
changes since v1 (kudos to alanc):
- added a description on configure.ac mentioning that only Linux support
  syscall monotonic clock
- a conditional was set on os/utils.c (or should be inside configure.ac?) to 
  let only Linux falls in that code, thus providing more safety.
- changed the bit commit message warning about the private implementation of

Myself, ajax, alanc and others discussed already on IRC about the performance
degradation. We all ran the program above, obtaining equally results within
different environments.

I guess also one will like to work out a bit the autoconf code. It's gigantic
and confusing! But lets work on it in another patch instead :)

I'd like to point that I'll work on the other alanc's suggestion, to improve
the current configure mess. I'll probably set up a --enable-embedded option
which will cover all bunch of other options that we currently have concerning
embedded environments. But will be in another patch...

 configure.ac            |   11 ++++++++++-
 include/dix-config.h.in |    3 +++
 os/utils.c              |    5 +++++
 3 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index a6b058d..b1003dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -632,6 +632,10 @@ AC_ARG_ENABLE(xaa,               AS_HELP_STRING([--enable-xaa], [Build XAA (defa
 AC_ARG_ENABLE(vgahw,          AS_HELP_STRING([--enable-vgahw], [Build Xorg with vga access (default: enabled)]), [VGAHW=$enableval], [VGAHW=yes])
 AC_ARG_ENABLE(vbe,            AS_HELP_STRING([--enable-vbe], [Build Xorg with VBE module (default: enabled)]), [VBE=$enableval], [VBE=yes])
 AC_ARG_ENABLE(int10-module,     AS_HELP_STRING([--enable-int10-module], [Build Xorg with int10 module (default: enabled)]), [INT10MODULE=$enableval], [INT10MODULE=yes])
+dnl clock_gettime() uses rt library and some systems might not want to link
+dnl against it, so the alternative is to use syscall directly. This is
+dnl discouraged if someone doesn't know what's doing.
+AC_ARG_ENABLE(syscall-clock,    AS_HELP_STRING([--enable-syscall-clock], [Use syscall to build monotonic clock instead C library based version. This option is supported only in Linux (default: disabled)]), [SYSCALL_CLOCK=$enableval], [SYSCALL_CLOCK=no])
 dnl DDXes.
 AC_ARG_ENABLE(xorg,    	      AS_HELP_STRING([--enable-xorg], [Build Xorg server (default: auto)]), [XORG=$enableval], [XORG=auto])
@@ -912,7 +916,12 @@ AC_MSG_RESULT([$MONOTONIC_CLOCK])
 if test "x$MONOTONIC_CLOCK" = xyes; then
     AC_DEFINE(MONOTONIC_CLOCK, 1, [Have monotonic clock from clock_gettime()])
+    if test "x$SYSCALL_CLOCK" = xyes; then
+                    [Use syscall based monotonic clock])
+    else
+    fi
 AM_CONDITIONAL(XV, [test "x$XV" = xyes])
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 32e88d9..1fd6310 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -402,6 +402,9 @@
 /* Have a monotonic clock from clock_gettime() */
+/* Have a monotonic clock from a direct syscall */
 /* Define to 1 if the DTrace Xserver provider probes should be built in */
diff --git a/os/utils.c b/os/utils.c
index 5a5a203..be51bcb 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -124,6 +124,11 @@ __stdcall unsigned long GetTickCount(void);
 #include "picture.h"
+#if defined (SYSCALL_MONOTONIC_CLOCK) && defined(linux)
+#include <sys/syscall.h>
+#define clock_gettime(a, b) syscall(SYS_clock_gettime, a, b)
 Bool noTestExtensions;
 Bool noCompositeExtension = FALSE;

More information about the xorg-devel mailing list