From owner-svn-src-all@FreeBSD.ORG Thu Feb 21 15:35:49 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 0EF801B8; Thu, 21 Feb 2013 15:35:49 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id DD7A2E07; Thu, 21 Feb 2013 15:35:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r1LFZm2p069188; Thu, 21 Feb 2013 15:35:48 GMT (envelope-from imp@svn.freebsd.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r1LFZmG0069187; Thu, 21 Feb 2013 15:35:48 GMT (envelope-from imp@svn.freebsd.org) Message-Id: <201302211535.r1LFZmG0069187@svn.freebsd.org> From: Warner Losh Date: Thu, 21 Feb 2013 15:35:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r247101 - head/sys/x86/isa X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Feb 2013 15:35:49 -0000 Author: imp Date: Thu Feb 21 15:35:48 2013 New Revision: 247101 URL: http://svnweb.freebsd.org/changeset/base/247101 Log: Use critical_enter/critical_exit around the time sensitive part of this code to depessimize the worst case we've lived with silently and uneventfully for the past 12 years. Add a comment about a refinement for those needing more assurance of accuracy. Fix ddb's show rtc command deadlock potential when debugging rtc code by not taking the lock if we're in the debugger. If you need a thumb to count the number of people that have encountered this, I'd be surprised. Submitted by: bde Modified: head/sys/x86/isa/atrtc.c Modified: head/sys/x86/isa/atrtc.c ============================================================================== --- head/sys/x86/isa/atrtc.c Thu Feb 21 15:26:26 2013 (r247100) +++ head/sys/x86/isa/atrtc.c Thu Feb 21 15:35:48 2013 (r247101) @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -52,8 +53,8 @@ __FBSDID("$FreeBSD$"); #include #include "clock_if.h" -#define RTC_LOCK mtx_lock_spin(&clock_lock) -#define RTC_UNLOCK mtx_unlock_spin(&clock_lock) +#define RTC_LOCK do { if (!kdb_active) mtx_lock_spin(&clock_lock); } while (0) +#define RTC_UNLOCK do { if (!kdb_active) mtx_unlock_spin(&clock_lock); } while (0) int atrtcclock_disable = 0; @@ -335,10 +336,16 @@ atrtc_gettime(device_t dev, struct times return (EINVAL); } - /* wait for time update to complete */ - /* If RTCSA_TUP is zero, we have at least 244us before next update */ + /* + * wait for time update to complete + * If RTCSA_TUP is zero, we have at least 244us before next update. + * This is fast enough on most hardware, but a refinement would be + * to make sure that no more than 240us pass after we start reading, + * and try again if so. + */ while (rtcin(RTC_STATUSA) & RTCSA_TUP) continue; + critical_enter(); ct.nsec = 0; ct.sec = readrtc(RTC_SEC); ct.min = readrtc(RTC_MIN); @@ -352,6 +359,7 @@ atrtc_gettime(device_t dev, struct times #else ct.year += 2000; #endif + critical_exit(); /* Set dow = -1 because some clocks don't set it correctly. */ ct.dow = -1; return (clock_ct_to_ts(&ct, ts));