[PATCH] use CLOCK_MONOTONIC_COARSE posix timer instead of CLOCK_MONOTONIC in Xorg

ykzhao yakui.zhao at intel.com
Mon Aug 23 18:07:49 PDT 2010


On Tue, 2010-08-24 at 08:42 +0800, Samuel Thibault wrote:
> ykzhao, le Tue 24 Aug 2010 08:32:48 +0800, a écrit :
> > On Mon, 2010-08-23 at 23:25 +0800, Adam Jackson wrote:
> > > On Mon, 2010-08-23 at 10:23 +0200, Mark Kettenis wrote:
> > > > > From: yakui.zhao at intel.com
> > > > > Date: Mon, 23 Aug 2010 15:20:05 +0800
> > > > > From: Zhao Yakui <yakui.zhao at intel.com>
> > > > > 
> > > > > ---
> > > > >  os/utils.c |   14 +++++++++++++-
> > > > >  1 files changed, 13 insertions(+), 1 deletions(-)
> > > > > 
> > > > > diff --git a/os/utils.c b/os/utils.c
> > > > > index 51455cc..a08d591 100644
> > > > > --- a/os/utils.c
> > > > > +++ b/os/utils.c
> > > > > @@ -242,6 +242,10 @@ OsSignal(int sig, OsSigHandlerPtr handler)
> > > > >  #endif
> > > > >  #endif
> > > > >  
> > > > > +#ifndef CLOCK_MONOTONIC_COARSE
> > > > > +#define CLOCK_MONOTONIC_COARSE 6
> > > > > +#endif
> > > > 
> > > > What if an OS doesn't have CLOCK_MONOTONIC_COARSE, but uses the clock
> > > > ID 6 for some other purpose?
> > > 
> > > Then this patch would be wrong.
> > > 
> > > NAK on that basis.
> > 
> > Yes. Agree.
> > 
> > How about using the constant value(6) directly? 
> 
> Err, you must be kidding...
> 
> #ifdef __linux__
> #  ifndef CLOCK_MONOTONIC_COARSE
> #  define CLOCK_MONOTONIC_COARSE 6
> #  endif
> #endif
> 
> should however be fine.

How about the following code? It is only applied to Linux platform.

 
 #ifdef MONOTONIC_CLOCK
     struct timespec tp;
-    if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+    static clockid_t clockid;
+    if (!clockid) {
+#ifdef __linux__
+#ifndef CLOCK_MONONOTIC_COARSE
+#define CLOCK_MONOTONIC_COARSE
+#endif
+	if ((clock_getres(CLOCK_MONOTONIC_COARSE, &tp) == 0) &&
+		(tp.tv_nsec / 1000 <= 1000))
+	    clockid = CLOCK_MONOTONIC_COARSE;
+	else
+	    clockid = CLOCK_MONOTONIC;
+#else
+	clockid = CLOCK_MONOTONIC;
+#endif
+     }
+    if (clock_gettime(clockid, &tp) == 0)
         return (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
 #endif
 


> 
> Samuel



More information about the xorg-devel mailing list