From owner-svn-src-all@FreeBSD.ORG Wed Mar 16 05:34:16 2011 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 89294106566C; Wed, 16 Mar 2011 05:34:16 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail08.syd.optusnet.com.au (mail08.syd.optusnet.com.au [211.29.132.189]) by mx1.freebsd.org (Postfix) with ESMTP id 20F948FC21; Wed, 16 Mar 2011 05:34:15 +0000 (UTC) Received: from c122-107-125-80.carlnfd1.nsw.optusnet.com.au (c122-107-125-80.carlnfd1.nsw.optusnet.com.au [122.107.125.80]) by mail08.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id p2G5YAh1004981 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 16 Mar 2011 16:34:12 +1100 Date: Wed, 16 Mar 2011 16:34:10 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Jung-uk Kim In-Reply-To: <201103151714.15829.jkim@FreeBSD.org> Message-ID: <20110316155820.D4010@besplex.bde.org> References: <201103151947.p2FJlK3L057573@svn.freebsd.org> <201103151701.11708.jhb@freebsd.org> <201103151714.15829.jkim@FreeBSD.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, John Baldwin Subject: Re: svn commit: r219676 - head/sys/x86/x86 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Wed, 16 Mar 2011 05:34:16 -0000 On Tue, 15 Mar 2011, Jung-uk Kim wrote: > On Tuesday 15 March 2011 05:01 pm, John Baldwin wrote: >> On Tuesday, March 15, 2011 3:47:20 pm Jung-uk Kim wrote: >>> Author: jkim >>> Date: Tue Mar 15 19:47:20 2011 >>> New Revision: 219676 >>> URL: http://svn.freebsd.org/changeset/base/219676 >>> >>> Log: >>> Do not let machdep.tsc_freq modify tsc_freq itself. It is bad >>> for i386 as it does not operate atomically. Actually, it serves >>> no purpose. >>> >>> Noticed by: bde >> >> Ouch, please revert! We have depended on this for testing to >> workaround BIOS issues (e.g. the USB SMI# handler firing at a bad >> time during boot causing the TSC frequency to be calculated >> incorrectly). I agree it's a hack that this works, but it has >> actually proven useful in the past. Please revert. I use this for setting timecounters from userland. The sysctl is not a hack, but the primary user interface for managing the TSC frequency. The kern.timecounter.tc.TSC.frequency sysctl is secondary, and is readonly anyway, so it cannot be used to manage the TSC frequency or even the timecounter frequency. > You can still change timecounter frequency. Can you please explain > why you need to change tsc_freq directly? 1. All my scripts change tsc_freq directly. They are portable to systems that don't have kern.timecounter.tc.TSC.frequency or even timecounters. Even for systems that have kern.timecounter.tc.TSC.frequency, the scripts would need messes to use this sysctl to read the TSC frequency and the old sysctl to write the timecounter frequency, since the tsc_freq variable can no longer be changed using its own sysctl and the TSC's TSC's timecounter current frequency can no longer be seen using the TSC's sysctl. 2. tsc_freq is used by other subsystems and it doesn't hurt for it to be as accurate as possible: - cputicker - high resolution kernel profiling These are relatively unimportant since you errors of 1 part per million don't really matter and high resolution kernel profiling is broken. The change doesn't even fix races accessing frequency variables. They are still there when the local variable is copied to the timecounter frequency. Timecounter code divides by tc_frequency, so this race is more serious than in most places (other places tend not to use the TSC when tsc_freq is transiently 0 due to the races). The divisions are in: - tc_init - tc_windup. This is called from a fast interrupt handler with nothing but time-domain locking which doesn't help here. - pps_event. This can also be called from a fast interrupt handler. Locking of ntptime's variables is also broken by calling tc_windup and pps_event from fast interrupt handlers. kern_ntptime.c still says that all its routines must run at splclock or higher. But splclock has decayed to null. Some of ntptimes routines are locked by Giant. This is impossible starting in a fast interrupt handler, so tc_windup and pps_event just call up to ntptime (ntp_update_second() and hardpps()) with no locking whatsoever. Bruce