From owner-freebsd-stable@FreeBSD.ORG Thu Sep 10 13:50:46 2009 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0CF6C1065692; Thu, 10 Sep 2009 13:50:46 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id C40238FC15; Thu, 10 Sep 2009 13:50:45 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id BE7BB730DA; Thu, 10 Sep 2009 15:56:44 +0200 (CEST) Date: Thu, 10 Sep 2009 15:56:44 +0200 From: Luigi Rizzo To: Daniel O'Connor Message-ID: <20090910135644.GA6109@onelab2.iet.unipi.it> References: <20090906155154.GA8283@onelab2.iet.unipi.it> <20090909203216.GA93761@onelab2.iet.unipi.it> <200909091642.06046.jhb@freebsd.org> <200909102302.26318.doconnor@gsoft.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200909102302.26318.doconnor@gsoft.com.au> User-Agent: Mutt/1.4.2.3i Cc: freebsd-stable@freebsd.org, John Baldwin Subject: Re: incorrect usleep/select delays with HZ > 2500 X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Sep 2009 13:50:46 -0000 On Thu, Sep 10, 2009 at 11:02:19PM +0930, Daniel O'Connor wrote: > On Thu, 10 Sep 2009, John Baldwin wrote: > > > $ARCH/isa/clock.c::DELAY(). I suppose with a few measurements > > > at different HZ values and some back of the envelope calculations > > > one could even determine estimate the frequency and duration > > > of those SMI interrupts! > > > > On recent motherboards I have seen the SMI# interrupt fire every 250 > > ms with execution times ranging from 50 us to 1ms for the legacy USB > > interrupt handler. We consistently see the TSC frequency > > miscalculated on the motherboards with the 1ms duration interrupt. I > > suspect that the clock that drives the periodic SMI# interrupt is > > tied to the i8254 meaning that it often fires at the same time that > > the i8254 wraps causing the TSC frequency to often be wrong. > > Can the calculation code disable the SMI# interrupt? Disabling legacy > USB could be a problem if you want to use a USB keyboard with the > loader (I think). surely I don't think disabling these interrupts is a viable option. Perhaps the best we can do in the calibration loop is alternate reads of the tsc and the i8254 counter (getit()), and if we see too many ticks between two subsequent calls to getit() it means that we have been interrupted and should discard the last measurement interval. Problem is, right now the calibration loop is start = rdtsc(); DELAY(1000000); b = rdtsc; and DELAY is unaware of the existence of the TSC. We should write some custom DELAY() code to implement the calibration as above. cheers luigi