From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 1 04:02:59 2005 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9F6E216A4CE for ; Tue, 1 Feb 2005 04:02:59 +0000 (GMT) Received: from gw.catspoiler.org (217-ip-163.nccn.net [209.79.217.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5334343D1F for ; Tue, 1 Feb 2005 04:02:59 +0000 (GMT) (envelope-from truckman@FreeBSD.org) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.13.1/8.13.1) with ESMTP id j1142mBt081759; Mon, 31 Jan 2005 20:02:53 -0800 (PST) (envelope-from truckman@FreeBSD.org) Message-Id: <200502010402.j1142mBt081759@gw.catspoiler.org> Date: Mon, 31 Jan 2005 20:02:48 -0800 (PST) From: Don Lewis To: cal@rushg.aero.org In-Reply-To: <200501262105.j0QL5x9W042384@calamari.aero.org> MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii cc: freebsd-hackers@FreeBSD.org Subject: Re: bug in calcru() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Feb 2005 04:02:59 -0000 On 26 Jan, Chris Landauer wrote: > > hihi, doug - > >> Doug Ambrisko wrote >> ... >> The assumption with this calculation is that st & it tend to be >> small compared to tt so the 1024 X shouldn't overflow much. >> ... >> cal@aero.org wrote: >> | ...but i'm a little worried that the 1024 multiplications aren't >> | large enough when tt gets really large >> | > Doug Ambrisko wrote >> | > ... >> | > /* Subdivide tu. try to becareful of overflow */ >> | > su = tu * (st * 1024 / tt) / 1024; >> | > iu = tu * (it * 1024 / tt) / 1024; >> | > uu = tu - (su + iu); >> | > ... > > i'm not so worried about the overflow limit (that's what the mathematical > analysis is intended to discover, and i assume that the bound is large enough > to ignore the issue - that is the really clever part about computing su and iu > first instead of uu), but the underflow - if st and it are small enough and tt > is large enough, these equations produce 0 for both su and iu (and the > reported percentage will rightly be 0.00%, but i want to see the rest of the > detail for my time models) It looks like the worst case for overflow would be if st == tt or it == tt, and even then overflow would not happen until the run time got up above 500 years according to my calculations, so it would probably be safe to increase the 1024 factor by quite a bit. Even at 1024, the system and interrupt time will be calculated to about 0.1%, though you might want to tweak the formula a bit to do rounding. su = tu * ((st * 1024 + 512) / tt) / 1024;