All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@domain.hid>
To: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
Cc: xenomai-core <xenomai@xenomai.org>,
	"Cornelius Köpp" <Cornelius.Koepp@domain.hid>
Subject: Re: [Xenomai-core] latencys drifting into negative (Xenomai 2.4.2/2.4.3)
Date: Fri, 04 Apr 2008 15:57:11 +0200	[thread overview]
Message-ID: <47F633B7.70003@domain.hid> (raw)
In-Reply-To: <2ff1a98a0804040632w391afda4rf30c8ca09fbb0874@domain.hid>

[-- Attachment #1: Type: text/plain, Size: 4089 bytes --]

Gilles Chanteperdrix wrote:
> On Fri, Apr 4, 2008 at 3:25 PM, Jan Kiszka <jan.kiszka@domain.hid> wrote:
>> Gilles Chanteperdrix wrote:
>>
>>> On Fri, Apr 4, 2008 at 12:45 PM, Jan Kiszka <jan.kiszka@domain.hid> wrote:
>>>
>>>> Sebastian Smolorz wrote:
>>>>
>>>>
>>>>> Jan Kiszka wrote:
>>>>>
>>>>>
>>>>>> Sebastian Smolorz wrote:
>>>>>>
>>>>>>
>>>>>>> Jan Kiszka wrote:
>>>>>>>
>>>>>>>
>>>>>>>> This patch may do the trick: it uses the inverted tsc-to-ns
>> function
>>>> instead of the frequency-based one. Be warned, it is totally untested
>> inside
>>>> Xenomai, I just ran it in a user space test program. But it may give an
>>>> idea.
>>>>
>>>>>>> Your patch needed two minor corrections (ns instead of ts in
>> functions
>>>> xnarch_ns_to_tsc()) in order to compile. A short run (30 minutes) of
>> latency
>>>> -t1 seems to prove your bug-fix: There seems to be no drift.
>>>>
>>>>>> That's good to hear.
>>>>>>
>>>>>>
>>>>>>
>>>>>>> If I got your patch correctly, it doesn't make xnarch_tsc_to_ns
>> more
>>>> precise but introduces a new function xnarch_ns_to_tsc() which is also
>> less
>>>> precise than the generic xnarch_ns_to_tsc(), right?
>>>>
>>>>>> Yes. It is now precisely the inverse imprecision, so to say. :)
>>>>>>
>>>>>>
>>>>>>
>>>>>>> So isn't there still the danger of getting wrong values when
>> calling
>>>> xnarch_tsc_to_ns()  not in combination with xnarch_ns_to_tsc()?
>>>>
>>>>>> Only if the user decides to implement his own conversion. Xenomai
>> with
>>>> all its skins and both in kernel and user space should always run
>> through
>>>> the xnarch_* path.
>>>>
>>>>> OK, would you commit the patch?
>>>>>
>>>>>
>>>>  Will do unless someone else has concerns. Gilles, Philippe? ARM and
>>>> Blackfin then need to be fixed similarly, full patch attached.
>>>>
>>> Well, I am sorry, but I do not like this solution;
>>> - the aim of scaled math is to avoid divisions, and with this patch we
>>> end up using divisions;
>>>
>>  Please check again, no new division due to my patch, just different
>> parameters for the existing one.
> 
> I just checked your patch rapidly, but saw that xnarch_ns_to_tsc was
> using llimd, so does use division. My fast_llimd could be used to
> replace both the llimd calls in xnarch_tsc_to_ns and xnarch_ns_to_tsc.
> 
>>
>>
>>> - with scaled math we do wrong calculations, and making a wrong
>>> xnarch_ns_to_tsc only works for values which should be passed to
>>> xnarch_tsc_to_ns.
>>>
>>  IMHO, the error is within the range of the clock's precision, if not even
>> below. So struggling for mathematically precise conversion of imprecise
>> physical values makes no sense to me. Therefore I once proposed the
>> scaled-math optimization.
> 
> Now that I have understood what really happens, I disagree with this
> approach. Take the implementation of clock_gettime (or
> rtdm_clock_read, for that matter). They basically do
> xnarch_tsc_to_ns(ipipe_read_tsc()). The relative error may be small,
> but in the very frequent use case of substracting two results of
> consecutive reads of ipipe_read_tsc, the result of the substraction is
> essentially garbage, because the result of the substraction may be of
> the same order as the absolute error of the conversion. And I insist,
> this use case of clock_gettime or rtdm_clock_read is a very realistic
> use case.

This use case is valid, but I don't see the error scenario you sketch: 
The error of the conversion is only relevant for large deltas, 
tsc_to_ns(B)-tsc_to_ns(A)=B-A for any small B-A. Cornelius' test nicely 
showed constantly increasing deviation, not something that jumped 
around. Essentially, we are just replacing

	xnarch_llimd(ts, 1000000000, RTHAL_CPU_FREQ);

with

	xnarch_llimd(ts, xnarch_tsc_scale, 1<<xnarch_tsc_shift);

which introduces a linearly increasing error of the _absolute_ results, 
not of relative ones. But if you can prove me wrong, I would take 
everything back and agree on kicking out the scaled math immediately!

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 254 bytes --]

  reply	other threads:[~2008-04-04 13:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-01 23:26 [Xenomai-core] latencys drifting into negative (Xenomai 2.4.2/2.4.3) Cornelius Köpp
2008-04-02  3:01 ` Tomas Kalibera
2008-04-02  9:04 ` Jan Kiszka
2008-04-02 12:00   ` Sebastian Smolorz
2008-04-02 12:28     ` Jan Kiszka
2008-04-02 12:46       ` Gilles Chanteperdrix
2008-04-02 13:00         ` Sebastian Smolorz
2008-04-02 15:28           ` Sebastian Smolorz
2008-04-02 15:58       ` Sebastian Smolorz
2008-04-02 16:05         ` Gilles Chanteperdrix
2008-04-02 16:24           ` Sebastian Smolorz
2008-04-03 12:17             ` Jan Kiszka
2008-04-03 12:27               ` Gilles Chanteperdrix
2008-04-03 12:50                 ` Jan Kiszka
2008-04-03 12:52                   ` Gilles Chanteperdrix
2008-04-03 13:15               ` Sebastian Smolorz
2008-04-03 21:52                 ` Jan Kiszka
2008-04-04  8:23                   ` Sebastian Smolorz
2008-04-04 10:45                     ` Jan Kiszka
2008-04-04 13:18                       ` Gilles Chanteperdrix
2008-04-04 13:25                         ` Jan Kiszka
2008-04-04 13:32                           ` Jan Kiszka
2008-04-04 13:32                           ` Gilles Chanteperdrix
2008-04-04 13:57                             ` Jan Kiszka [this message]
2008-04-04 14:09                               ` Gilles Chanteperdrix
2008-04-04 14:33                                 ` Jan Kiszka
2008-04-04 15:48                                   ` Gilles Chanteperdrix
2008-04-04 15:52                                     ` Philippe Gerum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47F633B7.70003@domain.hid \
    --to=jan.kiszka@domain.hid \
    --cc=Cornelius.Koepp@domain.hid \
    --cc=gilles.chanteperdrix@xenomai.org \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.