From owner-freebsd-hackers@FreeBSD.ORG Wed Aug 18 08:41:18 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EB1881065674 for ; Wed, 18 Aug 2010 08:41:17 +0000 (UTC) (envelope-from wdef200@yahoo.co.uk) Received: from web26406.mail.ukl.yahoo.com (web26406.mail.ukl.yahoo.com [217.146.176.30]) by mx1.freebsd.org (Postfix) with SMTP id 4D88D8FC23 for ; Wed, 18 Aug 2010 08:41:17 +0000 (UTC) Received: (qmail 47875 invoked by uid 60001); 18 Aug 2010 08:14:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1282119276; bh=3lz95lXmghfmtGle2AwUVIWKMSn5wuJOJKtsEfzB3dE=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=Z09jljtkN5SaQY0FGAWiY2RbN/O26wIV11eOkPDN/oL91H5U0jcGjg1AkEFSpR3XbgqwVUHtSlOxTq0zDMjDeiYxx7fXQaOjqzIML86CjeoZr2q8pMlssnLY5MF8uEkuoEz7B4+9unREB9vyHvSepTI0T0ZoitRcSNWzD+lViTg= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.co.uk; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=RVe0ZXN3ZWE29Giu8hIW8z7ZoQyLtNfIaqmIvtcrLhvaL7yEt3AYYyNtJH9b+qqMfm+YnJwPCw1bairIyWhVdBNPDM+Y+sJxapxNgAIUUKc3eT0fnU3jRbHwW3/PJ/gdVahmEKVRZ17he+Oisn3tgA8N3kqF85ICcGmCmqoyXCw=; Message-ID: <111186.47487.qm@web26406.mail.ukl.yahoo.com> X-YMail-OSG: rAatE64VM1nDXAmnlOFBfXdUX0T49VBc6paXa62uE__tHNS OUzhYystwA2dZ_qIRtKcEdAyhg3iCf4.BdDlQJOEvhuEesbZqbkIK2XrYx01 fSzu8V8VtqVHH76CK0oAIFcZ318HFSnn.C0z1.U9AD0YNLUF2_wzm3aNklqD cVWYQybL1GLunxUS6e2UNl4q.4ND1IwnICi2gqiyRSN4pN.vjGAod9U6wWl3 kZP9AXyG_lDhRU6iL0wjQDckm734QkZWYT.MODrTssmjLgqE- Received: from [109.123.86.204] by web26406.mail.ukl.yahoo.com via HTTP; Wed, 18 Aug 2010 01:14:35 PDT X-Mailer: YahooMailRC/470 YahooMailWebService/0.8.105.279950 Date: Wed, 18 Aug 2010 01:14:35 -0700 (PDT) From: Phil Grundig To: freebsd-hackers@freebsd.org MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 18 Aug 2010 11:26:22 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: How to read cmos clock - what is gettimeofday reading? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Aug 2010 08:41:18 -0000 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