From owner-freebsd-hackers@FreeBSD.ORG Thu Aug 19 12:50:25 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 E1B081065697 for ; Thu, 19 Aug 2010 12:50:25 +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 D49F38FC1D for ; Thu, 19 Aug 2010 12:50:15 +0000 (UTC) Received: by bwz20 with SMTP id 20so1932015bwz.13 for ; Thu, 19 Aug 2010 05:50:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=x4xTeIvXt3WQ/9Rvxx2yKibYeSfGVzdjgDg74MUgRaI=; b=F0nLZ9fSYAXHF3dXfObwBkrmyaM4rI01e3cHqbrlZAXFiq8Z0aCr9GRPIG09R8KMzj tvSxCUzq1QTcodlNIwbDuRNOYLElNGA0GmCxXOwe4rQKhzz/lIMZnJJUOBScHSGW2cbf XD0jziZZ8FcUwKqlCdJa9yqvxIQmlAvgodgT4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=oskoxGSM4ucV69qR32yXKaIvqirx1u31NuK+3TekPRL3N+Qe47Bnz12kEWLevFHHi1 dQ29EZT/k/gu5OoKlU9ZYrCqyvw1HZNVkh9mA3TIDWyppFPmpndTwD8GplAz0a0JXBZf HZ0xkRsO9JoRXZNyXyjP1hkS44fcK8lIY+wl0= MIME-Version: 1.0 Received: by 10.204.7.88 with SMTP id c24mr6516554bkc.172.1282222211914; Thu, 19 Aug 2010 05:50:11 -0700 (PDT) Received: by 10.204.67.3 with HTTP; Thu, 19 Aug 2010 05:50:11 -0700 (PDT) In-Reply-To: <20100819113833.GA59397@server.vk2pj.dyndns.org> References: <20100819113833.GA59397@server.vk2pj.dyndns.org> Date: Thu, 19 Aug 2010 15:50:11 +0300 Message-ID: From: phil hefferan To: Peter Jeremy Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-hackers@freebsd.org Subject: Re: 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 12:50:26 -0000 On Thu, Aug 19, 2010 at 2:38 PM, Peter Jeremy wrote: > Repeating your question will not encourage an answer. > I realize that - it was inadvertent and sloppy. I assumed the yahoo post hadn't gone through when I posted from gmail. Again I apologize for the bad netiquette. > > On 2010-Aug-19 13:09:46 +0300, phil hefferan 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 > >done. > > 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() > > Thanks. No equivalent to an ioctl on /dev/rtc/ > > >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.htmlthat > >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. > > This might explain why some people assume the RTC is automatically synced to software time. If they change the software time, presumably this is most likely done through settimeofday()? This suggests also that comparing software time and RTC won't be useful for what I want to do (detect if software time has been changed) since settimeofday will have synced these if it has been changed. Is there any other clock that can be read in userspace which does not change immediately if software time is changed? > >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. > > Maybe worth a bug report? Also - wondering then if adjkerntz is actually working as advertised. > >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 > i386_set_ioperm(2) > > Thanks Peter. -phil