public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Absolute vs. relative tick count.
@ 2009-06-29 17:10 Rene Nielsen
  2009-06-30 10:04 ` [ECOS] " Daniel Néri
  0 siblings, 1 reply; 2+ messages in thread
From: Rene Nielsen @ 2009-06-29 17:10 UTC (permalink / raw)
  To: ecos-discuss

Hello there,

For NTP to work accurately, we need to be able to call clock_settime()
defined in .../compat/posix/current/src/time.cxx.

Subsequent calls to e.g. gettimeofday() and clock_gettime() will then
return the absolute time set with the call to clock_settime().

The clock_settime() function calls
Cyg_Clock::real_time_clock->set_value(), which in turn changes the
Cyg_RealTimeClock class' counter member inherited from Cyg_Counter. So
far so good.

The problem is that changing the counter member has some side-effects:
cyg_current_time(), for instance, starts returning the new tick count,
which causes threads to time-out sooner than expected, and alarms/timers
created with timer_settime() or directly with the Cyg_Alarm() class
might start behaving strangely.

An alternative to using clock_settime() is to use
cyg_libc_time_settime(), which uses the WallClock (with the emulated
device) for storing the time. The problem with this approach is that a
call to time(NULL) won't roll-over to the next second at the correct
point in time (it has a 1 second resolution), and a call to
Cyg_WallClock::init_hw_seconds() won't help us much, I think.

I'd really like to have two counters in the Cyg_RealTimeClock (or one of
its parent classes): One that can be changed with a call to
clock_settime()/Cyg_Clock::real_time_clock->set_value() and one that
counts the number of ticks since boot and can't be changed. There should
also be two sets of functions for obtaining these values depending on
whether they're going to be used in e.g. gettimeofday() or for
timers/alarms.

Any suggestions/ideas would be very helpful.

Thanks in advance,
Rene Schipp von Branitz Nielsen
Vitesse Semiconductors


--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ECOS]  Re: Absolute vs. relative tick count.
  2009-06-29 17:10 [ECOS] Absolute vs. relative tick count Rene Nielsen
@ 2009-06-30 10:04 ` Daniel Néri
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Néri @ 2009-06-30 10:04 UTC (permalink / raw)
  To: ecos-discuss

"Rene Nielsen" <rbn@vitesse.com> writes:

> I'd really like to have two counters in the Cyg_RealTimeClock (or one of
> its parent classes): One that can be changed with a call to
> clock_settime()/Cyg_Clock::real_time_clock->set_value() and one that
> counts the number of ticks since boot and can't be changed. There should
> also be two sets of functions for obtaining these values depending on
> whether they're going to be used in e.g. gettimeofday() or for
> timers/alarms.
>
> Any suggestions/ideas would be very helpful.

Here's what I did:

  * Added Cyg_WallClock::get_hw_usecs to the emulated wallclock driver:
    returns the number of µs elapsed since initialisation.

  * Added Cyg_WallClock::adjtime to the wallclock base driver: takes a
    positive/negative offset [µs] as argument and updates an internally
    kept variable "adj_delta".

  * Added Cyg_WallClock::get_current_time_us to the wallclock base
    driver: returns the number of µs elapsed since 1970-01-01T00:00,
    offset by "adj_delta" and implemented in terms of
    Cyg_WallClock::get_hw_usecs.

  * Changed gettimeofday to use Cyg_WallClock::get_current_time_us.

  * In the (S)NTP client use gettimeofday to calculate the time
    difference and, if needed, adjust the clock with
    Cyg_WallClock::adjtime (I use my own SNTP implementation though).


I hope that helps, and if the maintainers are interested I could maybe
clean this up a bit and submit a patch.


Regards,
-- 
Daniel Néri <daniel.neri@sigicom.com>
Sigicom AB, Stockholm, Sweden


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-06-30 10:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-29 17:10 [ECOS] Absolute vs. relative tick count Rene Nielsen
2009-06-30 10:04 ` [ECOS] " Daniel Néri

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).