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

ykzhao yakui.zhao at intel.com
Tue Aug 24 00:55:41 PDT 2010


On Tue, 2010-08-24 at 09:59 +0800, Daniel Stone wrote:
> On Tue, Aug 24, 2010 at 08:32:48AM +0800, ykzhao wrote:
> > On Mon, 2010-08-23 at 23:25 +0800, Adam Jackson wrote:
> > > On Mon, 2010-08-23 at 10:23 +0200, Mark Kettenis wrote:
> > > > > 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? 
> 
> That doesn't change anything - if a system is using ID 6 for something
> else, then using 6 is wholly incorrect, no matter whether you use the
> constant directly, define some other symbol for it, or whatever.

Maybe the system is using the ID 6 for something else. But in theory it
should not affect the system-call of posix timer.  

If the CLOCK_MONOTONIC_COARSE posix timer is already supported in the
linux kernel(clockid is 6),  the system-call of "clock_getres/gettime(6,
&tp)" will return the valid value.

If the CLOCK_MONOTONIC_COARSE is not supported in the linux kernel, the
system-call of "clock_getres/gettime(6, &tp)" will return the invalid
value, which indicates that we will fallback to the next posix
timer(CLOCK_MONOTONIC). 

Of course there exists another scenario. The CLOCK_MONOTONIC_COARSE
posix timer is not supported. In course of compiling the Xorg we add the
macro definition of "CLOCK_MONOTONIC_COARSE=3". In such case we will use
the incorrect posix timer after calling the function of
clock_getres(CLOCK_MONOTONIC_COARSE, &tp). But if we compile it again
under the latest glibc, we will get the warning message of "macro
redefinition". 

Based on the above consideration, not sure whether it is meaningful to
use the constant value(6) for the system-call of clock_getres? Otherwise
we will have to consider the following two cases:
    a. CLOCK_MONOTONIC_COARSE is not defined
in /usr/include/linux/time.h
    b. CLOCK_MONOTONIC_COARSE is already defined. But the corresponding
id is not 6.

If wrong, please correct me. 

Best regards.
    Yakui
   

> 
> #ifdef CLOCK_MONOTONIC_COARSE
> /* include support for CLOCK_MONOTONIC_COARSE */
> #else
> /* it's not there so don't */
> #endif



More information about the xorg-devel mailing list