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

Tiago Vignatti tiago.vignatti at nokia.com
Fri Apr 16 05:10:19 PDT 2010


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

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

One, using this patch, should worry about a possible performance degradation
due it's not going through optimized code in C library. Therefore, the simple
program bellow (kudos to Adam Jackson) should performs equally in the practice,
for both syscall and C library implementation:

  #ifdef SYSCALL_MONOTONIC_CLOCK
  #define clock_gettime(a, b) syscall(SYS_clock_gettime, a, b)
  #endif

  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>
---
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.

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

diff --git a/configure.ac b/configure.ac
index b1d5119..43fd1fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -645,6 +645,7 @@ AC_ARG_ENABLE(vgahw,          AS_HELP_STRING([--enable-vgahw], [Build Xorg with
 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])
 AC_ARG_ENABLE(windowswm,      AS_HELP_STRING([--enable-windowswm], [Build XWin with WindowsWM extension (default: no)]), [WINDOWSWM=$enableval], [WINDOWSWM=no])
+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 and discouraged if you don't know what it is doing (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])
@@ -934,7 +935,12 @@ AC_MSG_RESULT([$MONOTONIC_CLOCK])
 
 if test "x$MONOTONIC_CLOCK" = xyes; then
     AC_DEFINE(MONOTONIC_CLOCK, 1, [Have monotonic clock from clock_gettime()])
-    LIBS="$LIBS $CLOCK_LIBS"
+    if test "x$SYSCALL_CLOCK" = xyes; then
+        AC_DEFINE(SYSCALL_MONOTONIC_CLOCK, 1,
+                    [Use syscall based monotonic clock])
+    else
+        LIBS="$LIBS $CLOCK_LIBS"
+    fi
 fi
 
 AM_CONDITIONAL(XV, [test "x$XV" = xyes])
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 058c8fd..f1ba99e 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -417,6 +417,9 @@
 /* Have a monotonic clock from clock_gettime() */
 #undef MONOTONIC_CLOCK
 
+/* Have a monotonic clock from a direct syscall */
+#undef SYSCALL_MONOTONIC_CLOCK
+
 /* Define to 1 if the DTrace Xserver provider probes should be built in */
 #undef XSERVER_DTRACE
 
diff --git a/os/utils.c b/os/utils.c
index 13d3b3f..9db7c96 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -124,6 +124,11 @@ __stdcall unsigned long GetTickCount(void);
 #include "picture.h"
 #endif
 
+#if defined (SYSCALL_MONOTONIC_CLOCK) && defined(linux)
+#include <sys/syscall.h>
+#define clock_gettime(a, b) syscall(SYS_clock_gettime, a, b)
+#endif
+
 Bool noTestExtensions;
 #ifdef COMPOSITE
 Bool noCompositeExtension = FALSE;
-- 
1.6.0.4



More information about the xorg-devel mailing list