public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Jonathan Larmour <jlarmour@redhat.com>
To: "Boris V. Guzhov" <borg@int.spb.ru>
Cc: ecos-discuss@sourceware.cygnus.com, Hugo Tyson <hmt@redhat.com>
Subject: Re: [ECOS] cyg_ticks_to_timespec()
Date: Wed, 18 Apr 2001 12:44:00 -0000	[thread overview]
Message-ID: <3ADDEE7C.4D31174C@redhat.com> (raw)
In-Reply-To: <003701c0c7dc$c95976f0$7601a8c0@borg>

"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

  reply	other threads:[~2001-04-18 12:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-18  1:12 Boris V. Guzhov
2001-04-18 12:44 ` Jonathan Larmour [this message]
2001-04-19  3:11   ` Hugo Tyson
2001-04-19 14:14     ` Jonathan Larmour
2001-04-19  0:40 Nielsen Linus
2001-04-19 14:56 ` Jonathan Larmour

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=3ADDEE7C.4D31174C@redhat.com \
    --to=jlarmour@redhat.com \
    --cc=borg@int.spb.ru \
    --cc=ecos-discuss@sourceware.cygnus.com \
    --cc=hmt@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).