comp.lang.ada
 help / color / mirror / Atom feed
From: Emanuel Berg <embe8573@student.uu.se>
Subject: Re: how to analyze clock drift
Date: Fri, 21 Nov 2014 04:02:34 +0100
Date: 2014-11-21T04:02:34+01:00	[thread overview]
Message-ID: <87d28h1cj9.fsf@debian.uxu> (raw)
In-Reply-To: 9t7t6al8bmifd9krh6koiegttgsvcovadg@4ax.com

Dennis Lee Bieber <wlfraed@ix.netcom.com> writes:

> Without a separate clock, it is not /drift/... It is
> OS latency in the process of reading the clock after
> the delay expires... And that latency is going to
> vary by how many other processes are running at the
> same or higher priority.
>
> Delay expires, task is put at the end of its
> priority queue, and you only get to /read/ the clock
> value when the OS gives your task its quantum of
> time.

I am aware there are many factors why this is as it
is, including the OS, what configurations of other
processes (and their nature) that runs in parallel,
scheduling and priorities, and so on almost
indefinitely, however I'm not analyzing those factors
here, I'm only analyzing how the outputted data
differs from the ideal, perfect time, which is defined
(here) as a tick every millisecond. The "drift"
mentioned is the drift from that perfect time.

>> Here is how it works:
>>
>> 1. I specify the global period to 1 ms.
>>
>> 2. In the C++ program, at every tick (supposedly
>>    every 1 ms) I log the actual time. I do both those
>>    things
>
> Define "actual time" -- if that actual time is
> coming from the same clock, the clock drift is
> masked.

"Actual time" is defined, in the usage above, as: the
time in nanoseconds that the C++ outputs every global
tick, which is programmed to occur every millisecond
but doesn't keep to that, in ways that are the target
of the inquiry.

>> 4. Now I want to understand the stats (what they
>> express, because I understand how to compute them
>> assuming the Lisp program is correct).
>
> Isn't that basically your assignment?

Well. Have have a 39 page report at this point. This
is a short section but the report is made up of short
sections, for sure.

> To interpret the numbers you first have to define
> what you are measuring.

I'm measuring how the logged times differs from an
imaginary perfect log that would look:

1000000
2000000
3000000
...

> If there is a "sawtooth", running an autocorrelation
> function over the data might indicate the period.
> Then it becomes a task to explain such a period --
> perhaps the OS resolution is some fraction of your
> desired value, and what you are seeing is an
> accumulating error until the next multiple...

No, I'm not going to do that. I'm only going to show
the data and what the data means. What is lacking is
some sort of conclusion, because the stats don't
really tell if you don't know what is normal - is it
bad, good, and how would that show (i.e., could that
be computed, as well - perhaps as a function of all
values...), stuff like that.

Here is what I've written so far. Feel free to suggest
improvements. I'll paste the LaTeX source, I think you
can read it just the same:

\subsection{the C++ and Linux timers}

To uphold an even rate of periodic scheduling, the C++
library function $std::this\_thread::sleep\_until$ is
used. However, on

\url{http://en.cppreference.com/w/cpp/thread/sleep_until}

they mention that $sleep\_until$ may actually ``block
for longer [than what has been specified] due to
scheduling or resource contention delays''.

To get a grip on how jittery the global tick is, $-l$
(or equivalently $--log$) can be used to have the
hierarchical scheduler output the current time (in
nanoseconds), at every tick, again, according to the
\texttt{<chrono>} library functions.

Here is a sample output for a period of one
millisecond:

\begin{verbatim}

    85033684319264
    85033685397613
    85033686471213
    85033687542299
    85033688624839
    85033689696763
    85033690770643
    85033691846478
    85033692929297
    ...

\end{verbatim}

The following method is then used to calculate the
offsets from the intended tick times:

\begin{verbatim}

  offset_0 = time_1 - time_0 - DESIRED_TICK
  offset_1 = time_2 - time_1 - DESIRED_TICK
  ...

\end{verbatim}

This produced, for this example run:

\begin{verbatim}

  82819
  76953
  92876
  79746
  77791
  62146
  75556
  80304
  79747
  ...

\end{verbatim}

Last, for all 543 offsets acquired in this example
computation, the following statistical data were
acquired:

\begin{verbatim}

    readings:            543
    mean:                76367.000000
    variance:            14127140.000000
    standard deviation:  3758.608785
    min:                 62146
    max:                 96508

\end{verbatim}

The mean value is a measure of the size of the drift.
The minimum and maximum values are the worst-case
behaviors for this particular run: they are the
smallest and biggest distances observed off the
intended tick time. The standard deviation is a
measure of the stability of the drift.

-- 
underground experts united


  reply	other threads:[~2014-11-21  3:02 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-18 22:12 how to analyze clock drift Emanuel Berg
2014-11-19  1:41 ` tmoran
2014-11-19  2:10   ` Emanuel Berg
2014-11-19 10:30     ` Jacob Sparre Andersen
2014-11-19 22:15       ` Emanuel Berg
2014-11-20 16:27         ` Stephen Leake
2014-11-20  1:10       ` Emanuel Berg
2014-11-20 14:11         ` Dennis Lee Bieber
2014-11-19 13:08   ` Brian Drummond
2014-11-19  2:10 ` Simon Clubley
2014-11-19  2:37   ` Emanuel Berg
2014-11-19  2:28 ` Dennis Lee Bieber
2014-11-19  2:44   ` tmoran
2014-11-19  2:51     ` Emanuel Berg
2014-11-19  9:01       ` Dmitry A. Kazakov
2014-11-19 22:12         ` Emanuel Berg
2014-11-20  9:42           ` Dmitry A. Kazakov
2014-11-20 20:41             ` Emanuel Berg
2014-11-20 21:27               ` Dmitry A. Kazakov
2014-11-20 21:54                 ` Emanuel Berg
2014-11-20 21:57                   ` Emanuel Berg
2014-11-21  2:27                   ` Dennis Lee Bieber
2014-11-21  3:02                     ` Emanuel Berg [this message]
2014-11-21 16:49                       ` Dennis Lee Bieber
2014-11-21 21:06                         ` Emanuel Berg
2014-11-22 18:18                           ` Dennis Lee Bieber
2014-11-23 20:15                             ` Emanuel Berg
2014-11-24  1:15                               ` Dennis Lee Bieber
2014-11-24  1:34                                 ` Emanuel Berg
2014-11-24  9:22                                   ` Jacob Sparre Andersen
2014-11-24 17:30                                   ` Dennis Lee Bieber
2014-11-24  8:44                                 ` Dmitry A. Kazakov
2014-11-24 17:24                                   ` Dennis Lee Bieber
2014-11-24 18:28                                     ` Dmitry A. Kazakov
2014-11-24 20:30                                       ` brbarkstrom
2014-11-24 21:03                                         ` Dmitry A. Kazakov
2014-11-24 21:34                                           ` brbarkstrom
2014-11-25 14:04                                           ` brbarkstrom
2014-11-25 18:16                                             ` Dennis Lee Bieber
2014-11-25 20:50                                               ` brbarkstrom
2014-11-21 21:15                         ` Emanuel Berg
2014-11-21 22:31                           ` Emanuel Berg
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox