Date: Wed, 18 Aug 2010 01:14:35 -0700 (PDT) From: Phil Grundig <wdef200@yahoo.co.uk> To: freebsd-hackers@freebsd.org Subject: How to read cmos clock - what is gettimeofday reading? Message-ID: <111186.47487.qm@web26406.mail.ukl.yahoo.com>
next in thread | raw e-mail | index | archive | help
I have C code for Linux that, among other things, caches the difference bet= ween =0Athe rtc and system time. I want to port this code to FreeBSD/Mac. L= inux has the =0Autility hwclock which reads /dev/rtc and anyway getting the= cmos clock time =0Adirectly from this interface can be done in a few lines= of code.=0A=0AI've been looking around for how to read the cmos/rtc on Fre= eBSD. There is no =0Ahwclock utility in FreeBSD that I can read sources for= to see how it is done.=0Ahttp://www.wraith.sf.ca.us/ntp/not-hwclock.c.txt = is supposed to be C code to =0Aread the software time and then set the cmos= clock to match. This code implies =0Athat, on FreeBSD, gettimeofday reads = the software time and settimeofday sets the =0Acmos clock. On Linux gettime= ofday does indeed read the software time.=0A=0ABUT the source to adjkerntz.= c for FreeBSD says that gettimeofday reads the CMOS =0Aclock not the system= time:=0A=0A/* get local CMOS clock and possible kernel offset */=0Aif (get= timeofday(&tv, &tz)) {=0A syslog(LOG_ERR, "gettimeofday: %m");=0A ret= urn 1;=0A}=0A=0AWhich is it? Does gettimeofday read the cmos clock/rtc on F= reeBSD? If not, how =0Ado I read the battery-backed clock on FreeBSD?=0A=0A= To further confuse matters there appears to be a common misconception on th= e web =0Athat the cmos time is automatically synced to system time on FreeB= SD. This is =0Aincorrect: see msg03414 on freebsd-hardware@freebsd.org.=0A= =0AThanks=0A=0A=0A=0A
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?111186.47487.qm>