This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: cyg_ticks_to_timespec()


"Boris V. Guzhov" wrote:
> 
> Hi,
> I use elix ecos configuration.  In the
> packages/compat/posix/current/src/time.cxx file
> there is a  cyg_ticks_to_timespec() function. I think that in the function
> there is a bug.
> For example: for ticks=454 the function should calculate tv_sec=4
> tv_nsec=0.54e9,
> but it calculate  tv_sec=5  tv_nsec=3834967296.

You're right. Out of interest, if you interpret tv_nsec as a signed rather
than unsigned long it comes out as -460000000 which is a more interesting
value. i.e. it is negative.

Hugo, the code for cyg_ticks_to_timespec() just uses your scary clock
convertors. The convertor is:

(gdb) p sec_inverter 
$1 = {mul1 = 1, div1 = 100, mul2 = 1, div2 = 1}

and the conversion is:

    cyg_uint64 t = (cyg_uint64)value;
    // Do this in an order to prevent overflow at the expense of
    // accuracy:
    t *= pcc->mul1;
    t += pcc->div1 / 2;
    t /= pcc->div1;
    t *= pcc->mul2;
    t += pcc->div2 / 2;
    t /= pcc->div2;
    // The alternative would be to do the 2 multiplies first
    // for smaller arguments.
    return (cyg_tick_count)t;

So it seems that rounding off is intentional. In which case I should just
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.

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]