From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: how to analyze clock drift Date: Thu, 20 Nov 2014 10:42:36 +0100 Organization: cbb software GmbH Message-ID: <188uppnlnvqgq$.1kjz3jnhjxqji.dlg@40tude.net> References: <6uun6alsp3jh1pob6g9qgcg85etqgenmd0@4ax.com> <87zjbn3nss.fsf@debian.uxu> <1nvfhit2csxr5.41v36jksch28$.dlg@40tude.net> <87k32qet5y.fsf@debian.uxu> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: nyHeW7QjJmC1odUjK4LkDA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:23566 Date: 2014-11-20T10:42:36+01:00 List-Id: On Wed, 19 Nov 2014 23:12:41 +0100, Emanuel Berg wrote: > "Dmitry A. Kazakov" > writes: > >> You certainly can use OS services from C++, instead >> of them. > > What I use is the stuff, e.g.: > > std::chrono::system_clock::now() > std::this_thread::sleep_until(re_sched_time) I don't use C++'s libraries, so I cannot tell what the thing actually does. Usually you would use simple tests to check timer functions, that is by waiting 0.01ms (a value much lower than the minimal waitable duration greater than zero). You do that in a sequence and print real-time clock (the reference clock) differences between consequent calls. That will give you first impression of the accuracy of waitable timer. Depending on the OS and system settings and can be from 10ms under Windows to 0.1ms under VxWorks. >> You need a reference clock [big cut] > > Thank you for that post, it is a bit too advanced to > me, Come on, linear regression is simple: http://en.wikipedia.org/wiki/Linear_regression You can do it in Excel: http://www.clemson.edu/ces/phoenix/tutorials/excel/regression.html > so I'll print it and read it again and probably be > back with some questions. > > I got a mail from my teacher - it sounds like a lot of > what you said (?): > > You could [...] calculate with the offsets from > the desired values [...] > > o0 = t1 - t0 - DESIRED_TICK > o1 = t2 - t1 - DESIRED_TICK > o2 = t3 - t2 - DESIRED_TICK > ... > > where DESIRED_TICK is the tick lengths you were > aiming for. [...] Yes, that is when you already know the expected time. I assumed that the reference clock and the clock used in wait are different clocks, deviating at constant speed. Modern computers have many time sources with many clocks derived from them, which is why. When you *know* that the time source is same, THEN you know that the deviation a=0. Which looks like what your teacher assumed. If a/=0 then you first estimate a, e.g. using regression which will appear in the formula calculating differences. To summarize, you calculate D = Tset - Tis Where Tset is the expected time after waiting and Tis the actual measured time. Then you calculate the mean and dispersion. The mean must be DESIRED_TICK. A difference indicates a systematic error, including the error in estimated drift, e.g. when the drift is not really 0. Dispersion (standard deviation) characterizes jitter. > From these points you can easily calculate the > average, minimum and maximum values and their > standard deviation. The average will be a measure > of the drift, the min/max the worst-case > (observed) behaviors and the standard deviation a > measure of the stability. Minimum and maximum can be used to verify how far the jitter wanders from the Normal distribution. Jitter is never distributed quite normally. From the normal distribution you can get the probabilities of P(D>Max) and P(D > Also, you mention the short trace. How long a > > trace is needed (like a rule-of-thumb) to cover > > all or most patterns? > > It's difficult to say. As a rule-of-thumb I > suppose one can say that when the values you are > calculating don't change significantly with longer > traces, the trace is long enough. But by the > nature of the problem you can never know, for > example, if a larger maximum value would be seen > if the trace was just a little longer. For a normal distribution there is so-called three-sigma rule which you could use to estimate the sample set size: http://en.wikipedia.org/wiki/68-95-99.7_rule Of course, jitter is not distributed normally, but it is a good starting point. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de