From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 19 10:40:02 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 15C94106567A for ; Thu, 19 Aug 2010 10:40:02 +0000 (UTC) (envelope-from wdef200@gmail.com) Received: from mail-bw0-f54.google.com (mail-bw0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 94DAE8FC15 for ; Thu, 19 Aug 2010 10:40:01 +0000 (UTC) Received: by bwz20 with SMTP id 20so1819848bwz.13 for ; Thu, 19 Aug 2010 03:39:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=vw1ShQ5Dw4j9rXNLR/ZNaLJ4z5ZgMJ3vyslVsgCdyvQ=; b=PH42hotmGH+aNlP+b1nq/8oKk4Vm9gfGrgs5eXQW0TiSXORoQpozdjPRzdhb35r5aO 8YLZdjO82PCYWBBxHwj7RRd0gborA2MScsFsmS+sh00q0/varp7Tpwf8JyxYzoKivQGS s06i7aSRmMBNIUx4Gu5IQU00dpFArI6XUfjI4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=QXx2SxcS+G3gfUx7dSgWBz6hEDPusmB3TamaLGeHjrv7i9lb3LjtVwO8am3fEZ/v7w XP50vs4JHlUjB8AcZB7cKZq9siIvt+jny9r/IZRuE1asKhgODtqJUDDEkqM1yhnOKyXp BtKPLIN75HkjXiuGnqw6IbXYkgz5UetD0QSX8= MIME-Version: 1.0 Received: by 10.204.59.134 with SMTP id l6mr6426815bkh.103.1282212586963; Thu, 19 Aug 2010 03:09:46 -0700 (PDT) Received: by 10.204.67.3 with HTTP; Thu, 19 Aug 2010 03:09:46 -0700 (PDT) Date: Thu, 19 Aug 2010 13:09:46 +0300 Message-ID: From: phil hefferan To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Reading rtc on FreeBSD 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: Thu, 19 Aug 2010 10:40:02 -0000 I have C code for Linux that, among other things, caches the difference between the rtc and system time, so that the program can detect if the system time has changed more than a threshold between runs. I want to port this code to FreeBSD/Mac. I'm trying to clarify the relationship between rtc and system time on FreeBSD and how the rtc is read. Linux has the utility hwclock which reads /dev/rtc and anyway getting the cmos clock time directly from this interface can be done in a few lines of code. 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 done. http://www.wraith.sf.ca.us/ntp/not-hwclock.c.txt is supposed to be C code to read the software time and then set the cmos clock to match. This code implies that, on FreeBSD, gettimeofday reads the software time and settimeofday sets the cmos clock. I read here http://www.mail-archive.com/freebsd-hardware@freebsd.org/msg03414.html that settimeofday in fact sets both rtc and system time together. On Linux both gettimeofday and settimeofday apply to the software time only. 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; } Which is it? Does gettimeofday read the cmos clock/rtc on FreeBSD? If not, how do I read the battery-backed clock on FreeBSD?