Reading rtc on FreeBSD

Peter Jeremy peterjeremy at
Thu Aug 19 11:38:37 UTC 2010

Repeating your question will not encourage an answer.

On 2010-Aug-19 13:09:46 +0300, phil hefferan <wdef200 at> wrote:
>I've been looking around for how to read the cmos/rtc on FreeBSD. There is
>no hwclock utility in FreeBSD that I can read sources for to see how it is

The RTC is only accessed within the kernel (/sys/isa/atrtc.c for
i386 and amd64) and read in /sys/kern/subr_rtc.c::inittodr()

>implies that, on FreeBSD, gettimeofday reads the software time and
>settimeofday sets the cmos clock. I read here
> that
>settimeofday in fact sets both rtc and system time together.

gettimeofday(2) reads the software clock only.
settimeofday(2) writes both the software clock and RTC.

>BUT the source to adjkerntz.c for FreeBSD seems to say that gettimeofday
>reads the CMOS clock not the system time:
>/* get local CMOS clock and possible kernel offset */
>if (gettimeofday(&tv, &tz)) {
>    syslog(LOG_ERR, "gettimeofday: %m");
>    return 1;

That comment is incorrect.

>Which is it? Does gettimeofday read the cmos clock/rtc on FreeBSD? If not,
>how do I read the battery-backed clock on FreeBSD?

There is no managed access to the RTC in FreeBSD.  Your only option to
read the RTC is to directly access its IO port registers via io(4) or

Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url :

More information about the freebsd-hackers mailing list