RFC: Change OML_sync_control UST to CLOCK_MONOTONIC
Michel Dänzer
michel at daenzer.net
Wed Jun 13 00:42:12 PDT 2012
On Die, 2012-06-12 at 20:04 -0700, Ian Romanick wrote:
> On 06/11/2012 03:02 AM, Michel Dänzer wrote:
> > On Son, 2012-06-10 at 11:56 +0000, Joakim Plate wrote:
> >> Hi,
> >>
> >> I'm currently trying to make use of OML_sync_control extension to schedule
> >> presentation of video frames in xbmc.
> >>
> >> I've run into somewhat of a snag. It seem the spec doesn't specify what
> >> time the UST clock really is, nor can i find any mention of it elsewhere
> >> in docs.
> >>
> >> Code wise it seem to be using do_gettimeofday(), which seems like a rather
> >> poor choice given that it can jump forward and back in time due to
> >> settimeofday calls.
> >>
> >> We normally make use of clock_gettime(CLOCK_MONOTONIC) to timestamp display
> >> of video frames, so to avoid major changes I'd need a way to convert to
> >> gettimeofday (seem same as CLOCK_REALTIME).
> >>
> >> Currently i'm trying:
> >> struct timespec mon, rel;
> >> clock_gettime(CLOCK_MONOTONIC,&mon);
> >> clock_gettime(CLOCK_REALTIME ,&rel);
> >>
> >> ticks += (rel.tv_sec - mon.tv_sec) * 1000000000;
> >> ticks += (rel.tv_nsec - mon.tv_nsec);
> >>
> >> To convert between the two, but that is quite a hack both in the
> >> possibility of clock changes and scheduling errors.
> >>
> >> Is there a better way, or perhaps the DRI code should use CLOCK_MONOTONIC
> >> in the first place?
> >
> > From the GLX_OML_sync_control spec:
> >
> > The Unadjusted System Time (or UST) is a 64-bit monotonically
> > increasing counter [...]
> >
> > So, without having thought a lot about potential ramifications, I'm
> > inclined to say that CLOCK_MONOTONIC should indeed be used.
>
> Maybe. Isn't CLOCK_MONOTONIC per-process?
According to the test code below, it's not here. While the clock_gettime
manpage doesn't explicitly state that it's system-wide, it does mention
it being affect by adjtime and NTP, which kind of implies it is?
#include <stdio.h>
#include <string.h>
#include <time.h>
int main(void)
{
struct timespec tp;
int ret;
memset(&tp, 0, sizeof(tp));
ret = clock_gettime(CLOCK_MONOTONIC, &tp);
printf("clock_gettime(CLOCK_MONOTONIC) returned %d, timestamp %lu.%09lu\n",
ret, tp.tv_sec, tp.tv_nsec);
return ret;
}
--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Debian, X and DRI developer
More information about the dri-devel
mailing list