xserver: Branch 'server-1.2-branch' - 7 commits

Daniel Stone daniels at kemper.freedesktop.org
Wed Nov 8 18:55:37 EET 2006


 configure.ac            |   41 ++++++++++++++++++++++++++++++++++++++++-
 include/dix-config.h.in |    3 +++
 os/WaitFor.c            |   32 ++++++++++++++++++++++++++++++--
 os/utils.c              |   30 ++++++++++++++++++++++++++----
 4 files changed, 99 insertions(+), 7 deletions(-)

New commits:
diff-tree 648116bcb890e9401559f64bb04c37b308f9123e (from 161a278afca6bfe22f5c2cba01c7100bd6244824)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sat Nov 4 21:43:22 2006 +0200

    os: fix sun extensions test
    
    'else if' is not very valid, plus the logic is kind of broken, so just
    move it outside the ifdef in the first place.
    (cherry picked from b6d7b537ed8975363ad0f7c4180a62822358e418 commit)

diff --git a/os/utils.c b/os/utils.c
index 65e1311..9824501 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -55,11 +55,13 @@ OR PERFORMANCE OF THIS SOFTWARE.
 
 /* The world's most shocking hack, to ensure we get clock_gettime() and
  * CLOCK_MONOTONIC. */
+#ifdef sun              /* Needed to tell Solaris headers not to restrict to */
+#define __EXTENSIONS__  /* only the functions defined in POSIX 199309.       */
+#endif
+
 #ifdef _POSIX_C_SOURCE
 #define _SAVED_POSIX_C_SOURCE _POSIX_C_SOURCE
 #undef _POSIX_C_SOURCE
-#else if defined(sun)	/* Needed to tell Solaris headers not to restrict to */
-#define __EXTENSIONS__	/* only the functions defined in POSIX 199309.       */
 #endif
 #define _POSIX_C_SOURCE 199309L
 #include <time.h>
diff-tree 161a278afca6bfe22f5c2cba01c7100bd6244824 (from ad6e3994c751bad41f542bedb84fed8dd15d548f)
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Tue Oct 31 15:57:59 2006 -0800

    Make _POSIX_C_SOURCE hack work with Solaris headers
    
    Solaris headers are very literal - if you ask for POSIX_C_SOURCE 199309L,
    they limit to only the functions in that standard and no more, unless you
    also specify __EXTENSIONS__ to allow functions beyond the standard base.
    (cherry picked from a2434ec5f3c9dc79d1f05c2d704a82a766718ed4 commit)

diff --git a/os/utils.c b/os/utils.c
index c7a8964..65e1311 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -58,6 +58,8 @@ OR PERFORMANCE OF THIS SOFTWARE.
 #ifdef _POSIX_C_SOURCE
 #define _SAVED_POSIX_C_SOURCE _POSIX_C_SOURCE
 #undef _POSIX_C_SOURCE
+#else if defined(sun)	/* Needed to tell Solaris headers not to restrict to */
+#define __EXTENSIONS__	/* only the functions defined in POSIX 199309.       */
 #endif
 #define _POSIX_C_SOURCE 199309L
 #include <time.h>
diff-tree ad6e3994c751bad41f542bedb84fed8dd15d548f (from 273eb5297498a6e04e5ffe29db27e287a8f8595e)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sun Oct 29 03:41:34 2006 +0300

    GetTimeInMillis: use correct units for clock_gettime
    Make sure we're treating the nanoseconds as a long, not an int, so we
    don't overflow.
    (cherry picked from 68f595ca6c7883e030947b7f95c50e92aa733f2b commit)

diff --git a/os/utils.c b/os/utils.c
index 7d258a4..c7a8964 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -552,7 +552,7 @@ GetTimeInMillis(void)
 #ifdef MONOTONIC_CLOCK
     struct timespec tp;
     if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
-        return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000);
+        return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
 #endif
 
     X_GETTIMEOFDAY(&tv);
diff-tree 273eb5297498a6e04e5ffe29db27e287a8f8595e (from b0f0f4bcb6fb0b5e6e32cfaec862c843eafeb461)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Thu Oct 26 01:10:08 2006 +0300

    GetTimeInMillis: simplify monotonic test
    We don't actually need to get the CPU clock ID, which means we don't need
    the monotonic_usable test.  Since there's now only one branch, the
    compiler will treat that as likely, so we don't need xproto 7.0.9 anymore.
    
    The fallthrough to gettimeofday() is preserved.
    (cherry picked from 004d00e6689f452fc9fdf91f5ffc6d6aed697d54 commit)

diff --git a/configure.ac b/configure.ac
index 25570f2..25a35b7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -515,7 +515,7 @@ XEXT_LIB='$(top_builddir)/Xext/libXext.l
 XEXTXORG_LIB='$(top_builddir)/Xext/libXextbuiltin.la'
 
 dnl Core modules for most extensions, et al.
-REQUIRED_MODULES="randrproto renderproto [fixesproto >= 4.0] damageproto xcmiscproto xextproto [xproto >= 7.0.9] xtrans xf86miscproto xf86vidmodeproto xf86bigfontproto [scrnsaverproto >= 1.1] bigreqsproto resourceproto fontsproto inputproto xf86dgaproto [kbproto >= 1.0.3]"
+REQUIRED_MODULES="randrproto renderproto [fixesproto >= 4.0] damageproto xcmiscproto xextproto xproto xtrans xf86miscproto xf86vidmodeproto xf86bigfontproto [scrnsaverproto >= 1.1] bigreqsproto resourceproto fontsproto inputproto xf86dgaproto [kbproto >= 1.0.3]"
 REQUIRED_LIBS="xfont xau fontenc"
 
 AM_CONDITIONAL(XV, [test "x$XV" = xyes])
diff --git a/os/utils.c b/os/utils.c
index 379291c..7d258a4 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -268,8 +268,6 @@ int auditTrailLevel = 1;
 
 _X_EXPORT Bool Must_have_memory = FALSE;
 
-static int monotonic_usable = -1;
-
 #ifdef AIXV3
 int SyncOn  = 0;
 extern int SelectWaitTime;
@@ -550,22 +548,11 @@ _X_EXPORT CARD32
 GetTimeInMillis(void)
 {
     struct timeval tv;
+
 #ifdef MONOTONIC_CLOCK
     struct timespec tp;
-    int spare = 0;
-
-    if (_X_UNLIKELY(monotonic_usable == -1)) {
-        if (clock_gettime(0, &tp) == 0 &&
-            clock_getcpuclockid(0, &spare) == 0)
-            monotonic_usable = 1;
-        else
-            monotonic_usable = 0;
-    }
-
-    if (_X_LIKELY(monotonic_usable == 1)) {
-        if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
-            return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000);
-    }
+    if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+        return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000);
 #endif
 
     X_GETTIMEOFDAY(&tv);
diff-tree b0f0f4bcb6fb0b5e6e32cfaec862c843eafeb461 (from bb7a39ac13731a80fc2d80487f9da760dd34c3ba)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Oct 25 23:57:00 2006 +0300

    GetTimeInMillis: spuport monotonic clock
    Add support for CLOCK_MONOTONIC from clock_gettime, and use that in
    GetTimeInMillis() if available, falling back to the old gettimeofday()
    implementation.
    
    This is _slightly_ faster on some 64-bit architectures, and _slightly_
    slower on others (though barely measurable).
    (cherry picked from d285833290316cb5dd1e7f1e52c96be3e9cf21cd commit)

diff --git a/configure.ac b/configure.ac
index 7945a27..25570f2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -515,7 +515,7 @@ XEXT_LIB='$(top_builddir)/Xext/libXext.l
 XEXTXORG_LIB='$(top_builddir)/Xext/libXextbuiltin.la'
 
 dnl Core modules for most extensions, et al.
-REQUIRED_MODULES="randrproto renderproto [fixesproto >= 4.0] damageproto xcmiscproto xextproto xproto xtrans xf86miscproto xf86vidmodeproto xf86bigfontproto [scrnsaverproto >= 1.1] bigreqsproto resourceproto fontsproto inputproto xf86dgaproto [kbproto >= 1.0.3]"
+REQUIRED_MODULES="randrproto renderproto [fixesproto >= 4.0] damageproto xcmiscproto xextproto [xproto >= 7.0.9] xtrans xf86miscproto xf86vidmodeproto xf86bigfontproto [scrnsaverproto >= 1.1] bigreqsproto resourceproto fontsproto inputproto xf86dgaproto [kbproto >= 1.0.3]"
 REQUIRED_LIBS="xfont xau fontenc"
 
 AM_CONDITIONAL(XV, [test "x$XV" = xyes])
@@ -873,9 +873,46 @@ PKG_CHECK_MODULES([XSERVERLIBS], [$REQUI
 
 XSERVER_CFLAGS="${XSERVERCFLAGS_CFLAGS}"
 XSERVER_LIBS="${XSERVERLIBS_LIBS} ${SYS_LIBS} -lm"
-AC_SUBST([XSERVER_LIBS])
 AC_SUBST([SYS_LIBS])
 
+AC_CHECK_FUNCS([clock_gettime], [have_clock_gettime=yes],
+               [AC_CHECK_LIB([rt], [clock_gettime], [have_clock_gettime=-lrt],
+                             [have_clock_gettime=no])])
+
+AC_MSG_CHECKING([for a useful monotonic clock ...])
+
+if ! test "x$have_clock_gettime" = xno; then
+    if ! test "x$have_clock_gettime" = xyes; then
+        LIBS="$have_clock_gettime"
+    else
+        LIBS=""
+    fi
+
+    AC_RUN_IFELSE([
+#define _POSIX_C_SOURCE 199309L
+#include <time.h>
+
+int main(int argc, char *argv[]) {
+    struct timespec tp;
+
+    if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+        return 0;
+    else
+        return 1;
+}
+    ], [MONOTONIC_CLOCK=yes], [MONOTONIC_CLOCK=no],
+       [MONOTONIC_CLOCK="cross compiling"])
+else
+    MONOTONIC_CLOCK=no
+fi
+
+AC_MSG_RESULT([$MONOTONIC_CLOCK])
+
+if test "x$MONOTONIC_CLOCK" = xyes; then
+    AC_DEFINE(MONOTONIC_CLOCK, 1, [Have monotonic clock from clock_gettime()])
+    XSERVER_LIBS="$XSERVER_LIBS $LIBS"
+fi
+
 dnl Imake defines SVR4 on SVR4 systems, and many files check for it, so
 dnl we need to replicate that here until those can all be fixed
 AC_MSG_CHECKING([if SVR4 needs to be defined])
@@ -890,6 +927,8 @@ AC_MSG_RESULT([yes])], AC_MSG_RESULT([no
 XSERVER_CFLAGS="$XSERVER_CFLAGS $CORE_INCS $XEXT_INC $COMPOSITE_INC $DAMAGE_INC $FIXES_INC $XI_INC $MI_INC $MIEXT_SHADOW_INC $MIEXT_LAYER_INC $MIEXT_DAMAGE_INC $RENDER_INC $RANDR_INC $FB_INC"
 AC_DEFINE_UNQUOTED(X_BYTE_ORDER,[$ENDIAN],[Endian order])
 
+AC_SUBST([XSERVER_LIBS])
+
 dnl ---------------------------------------------------------------------------
 dnl DDX section.
 dnl ---------------------------------------------------------------------------
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 65c42e6..35700e4 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -445,4 +445,7 @@
 /* Define to 1 if modules should avoid the libcwrapper */
 #undef NO_LIBCWRAPPER
 
+/* Have a monotonic clock from clock_gettime() */
+#undef MONOTONIC_CLOCK
+
 #endif /* _DIX_CONFIG_H_ */
diff --git a/os/utils.c b/os/utils.c
index 31ae26a..379291c 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -53,6 +53,19 @@ OR PERFORMANCE OF THIS SOFTWARE.
 #include <dix-config.h>
 #endif
 
+/* The world's most shocking hack, to ensure we get clock_gettime() and
+ * CLOCK_MONOTONIC. */
+#ifdef _POSIX_C_SOURCE
+#define _SAVED_POSIX_C_SOURCE _POSIX_C_SOURCE
+#undef _POSIX_C_SOURCE
+#endif
+#define _POSIX_C_SOURCE 199309L
+#include <time.h>
+#undef _POSIX_C_SOURCE
+#ifdef _SAVED_POSIX_C_SOURCE
+#define _POSIX_C_SOURCE _SAVED_POSIX_C_SOURCE
+#endif
+
 #ifdef __CYGWIN__
 #include <stdlib.h>
 #include <signal.h>
@@ -92,7 +105,6 @@ OR PERFORMANCE OF THIS SOFTWARE.
 #if !defined(SYSV) && !defined(WIN32) && !defined(Lynx) && !defined(QNX4)
 #include <sys/resource.h>
 #endif
-#include <time.h>
 #include <sys/stat.h>
 #include <ctype.h>    /* for isspace */
 #include <stdarg.h>
@@ -256,6 +268,8 @@ int auditTrailLevel = 1;
 
 _X_EXPORT Bool Must_have_memory = FALSE;
 
+static int monotonic_usable = -1;
+
 #ifdef AIXV3
 int SyncOn  = 0;
 extern int SelectWaitTime;
@@ -535,10 +549,27 @@ GiveUp(int sig)
 _X_EXPORT CARD32
 GetTimeInMillis(void)
 {
-    struct timeval  tp;
+    struct timeval tv;
+#ifdef MONOTONIC_CLOCK
+    struct timespec tp;
+    int spare = 0;
+
+    if (_X_UNLIKELY(monotonic_usable == -1)) {
+        if (clock_gettime(0, &tp) == 0 &&
+            clock_getcpuclockid(0, &spare) == 0)
+            monotonic_usable = 1;
+        else
+            monotonic_usable = 0;
+    }
+
+    if (_X_LIKELY(monotonic_usable == 1)) {
+        if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+            return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000);
+    }
+#endif
 
-    X_GETTIMEOFDAY(&tp);
-    return(tp.tv_sec * 1000) + (tp.tv_usec / 1000);
+    X_GETTIMEOFDAY(&tv);
+    return(tv.tv_sec * 1000) + (tv.tv_usec / 1000);
 }
 
 _X_EXPORT void
diff-tree bb7a39ac13731a80fc2d80487f9da760dd34c3ba (from 8d3b465eb3d6c93cbbcebe8e5c9298caaaeb650b)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Sun Oct 29 03:40:57 2006 +0300

    WaitForSomething: only rewind when delta is more than 250ms
    Only rewind time when we're more than (original delta + 250ms) away from
    executing the timer.
    When we're walking the timer list, use a goto to iterate all of them from
    the start again, since timers may drop out of the list.
    Don't bother trying to be smart in TimerSet, we'll pick it up in
    WaitForSomething anyway.
    (cherry picked from 51a06b3c44509c72279b5cfcf2b52b9a35c461b0 commit)

diff --git a/os/WaitFor.c b/os/WaitFor.c
index 896fdf1..6109e34 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -202,11 +202,12 @@ WaitForSomething(int *pClientsReady)
         {
             now = GetTimeInMillis();
 	    timeout = timers->expires - now;
-            /* time has rewound.  reset the timers. */
-            if (timeout > timers->delta) {
+            if (timeout > 0 && timeout > timers->delta + 250) {
+                /* time has rewound.  reset the timers. */
                 CheckAllTimers(now);
                 timeout = timers->expires - now;
             }
+
             if (timeout < 0)
                 timeout = 0;
 	    waittime.tv_sec = timeout / MILLI_PER_SECOND;
@@ -434,17 +435,18 @@ ANYSET(FdMask *src)
 #endif
 
 /* If time has rewound, re-run every affected timer.
- * TimerForce will change timer->next, but it will _generally_ only
- * promote timers in the list, meaning that we should still be
- * walking every timer. */
+ * Timers might drop out of the list, so we have to restart every time. */
 static void
 CheckAllTimers(CARD32 now)
 {
     OsTimerPtr timer;
 
+start:
     for (timer = timers; timer; timer = timer->next) {
-        if (timer->expires - now > timer->delta)
+        if (timer->expires - now > timer->delta + 250) {
             TimerForce(timer);
+            goto start;
+        }
     }
 }
 
@@ -507,10 +509,8 @@ TimerSet(OsTimerPtr timer, int flags, CA
     }
     for (prev = &timers;
 	 *prev && (int) ((*prev)->expires - millis) <= 0;
-	 prev = &(*prev)->next) {
-        if ((*prev)->expires - now > (*prev)->delta)
-            CheckAllTimers(now);
-    }
+	 prev = &(*prev)->next)
+        ;
     timer->next = *prev;
     *prev = timer;
     return timer;
diff-tree 8d3b465eb3d6c93cbbcebe8e5c9298caaaeb650b (from 22bccea8dcf332bf0077440b76daf6703da42da2)
Author: Daniel Stone <daniel at fooishbar.org>
Date:   Wed Oct 25 23:55:43 2006 +0300

    WaitForSomething: allow time to rewind
    If time rewinds dramatically, reset all the timers to fix their expiry.
    (cherry picked from d3e57faffee63df1424a209d0418d3a712f91ae6 commit)

diff --git a/os/WaitFor.c b/os/WaitFor.c
index 0457678..896fdf1 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -119,11 +119,13 @@ mffs(fd_mask mask)
 struct _OsTimerRec {
     OsTimerPtr		next;
     CARD32		expires;
+    CARD32              delta;
     OsTimerCallback	callback;
     pointer		arg;
 };
 
 static void DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev);
+static void CheckAllTimers(CARD32 now);
 static OsTimerPtr timers = NULL;
 
 /*****************
@@ -200,6 +202,11 @@ WaitForSomething(int *pClientsReady)
         {
             now = GetTimeInMillis();
 	    timeout = timers->expires - now;
+            /* time has rewound.  reset the timers. */
+            if (timeout > timers->delta) {
+                CheckAllTimers(now);
+                timeout = timers->expires - now;
+            }
             if (timeout < 0)
                 timeout = 0;
 	    waittime.tv_sec = timeout / MILLI_PER_SECOND;
@@ -426,6 +433,20 @@ ANYSET(FdMask *src)
 }
 #endif
 
+/* If time has rewound, re-run every affected timer.
+ * TimerForce will change timer->next, but it will _generally_ only
+ * promote timers in the list, meaning that we should still be
+ * walking every timer. */
+static void
+CheckAllTimers(CARD32 now)
+{
+    OsTimerPtr timer;
+
+    for (timer = timers; timer; timer = timer->next) {
+        if (timer->expires - now > timer->delta)
+            TimerForce(timer);
+    }
+}
 
 static void
 DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev)
@@ -467,8 +488,13 @@ TimerSet(OsTimerPtr timer, int flags, CA
     }
     if (!millis)
 	return timer;
-    if (!(flags & TimerAbsolute))
+    if (flags & TimerAbsolute) {
+        timer->delta = millis - now;
+    }
+    else {
+        timer->delta = millis;
 	millis += now;
+    }
     timer->expires = millis;
     timer->callback = func;
     timer->arg = arg;
@@ -481,8 +507,10 @@ TimerSet(OsTimerPtr timer, int flags, CA
     }
     for (prev = &timers;
 	 *prev && (int) ((*prev)->expires - millis) <= 0;
-	 prev = &(*prev)->next)
-	;
+	 prev = &(*prev)->next) {
+        if ((*prev)->expires - now > (*prev)->delta)
+            CheckAllTimers(now);
+    }
     timer->next = *prev;
     *prev = timer;
     return timer;



More information about the xorg-commit mailing list