ntp and adjtime?

Christian Helmuth christian.helmuth at ...1...
Thu Nov 9 12:11:55 CET 2017


On Mon, Nov 06, 2017 at 01:02:49PM -0600, Steven Harp wrote:
> Some hardware platforms have no real time clock (RTC), or an inaccurate one.
> I have an SNTP client working in Genode that could substitute for or supplement
> an RTC, but am not sure about the most sensible way to integrate that with Genode
> components using libc.  My intent is that gettimeofday() would return the periodically
> adjusted UTC in each component.  Do I understand correctly that libc will currently
> only probe /dev/rtc upon the first call needing time of day? Maybe there is
> mechanism to signal the need to invoke adjtime?

You're right the libc fetches the wall-clock time only once from the
RTC-Service if configured and calculates the current time stamp using
the the libc internal Libc::current_time(). The corresponding code is
in repos/libports/src/lib/libc/gettimeofday.cc and (unfortunately)
also in clock_gettime.cc. These implementations had to be merged and
adapted to periodically update the wall-clock time.

Further, I should have a look into rtc.cc which is the backend for
reading the RTC from a file mounted into the VFS. The current time
format is

  "%Y-%m-%d %R" which corresponds to YYYY-MM-DD HH:MM

Note, this should become

  "%F %T" or "%Y-%m-%d %H:%M:%S" ISO 8601 format YYYY-MM-DD HH:MM:SS

in the future for seconds granularity.

I'm not familiar with the mechanics of adjtime, though, so I can't
give any hints in this regard. But, it may be best to provide the
RTC-Service by your SNTP implementation and reply with the current
wall-clock time on request. This keeps the adaption in the libc
backend minimal. If there's an RTC in the platform this can be used by
SNTP to provide an initial time value.

Christian Helmuth
Genode Labs

https://www.genode-labs.com/ · https://genode.org/
https://twitter.com/GenodeLabs · /ˈdʒiː.nəʊd/

Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth

More information about the users mailing list