This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: cyg_ticks_to_timespec()
Hugo Tyson wrote:
>
> > From: Jonathan Larmour <jlarmour@redhat.com>
>
> Oh, I get it now. The code in cyg_ticks_to_timespec() is using a clock
> converter to convert to whole seconds, then subtracting to get the nS part
> left over! No wonder it gives a "wrong" answer, of course the whole
> seconds answer is rounded.
>
> Use it to convert to nS and do a divide by 10^9 - that way the right answer
> would emerge, that's what clock converters are meant for.
>
> > tweak cyg_ticks_to_timespec to fix up the value if tv_nsec is negative.
> > Before I do it, I just want to check my understanding that the convertors
> > are doing the right thing by rounding not truncating.
>
> Of course they are. Someone misunderstood the purpose of the converters.
> They do conversion taking care that overflow will be avoided at all costs,
> even if it means discarding trailing digits; ie. they will be right at the
> cost of precision even if the conversion factor is great in either
> direction and the arguments are large.
[snip]
I've checked in something that just post-adjusts the timespec if the
nanoseconds are negative. I believe this should produce consistent results
because the sec_convertor and sec_invertor used by the clock convertors
_should_ be the inverse of each other, and therefore conversion in one
direction should always be the inverse mapping of the other.
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine