From owner-freebsd-arch Mon Jan 14 18:41:33 2002 Delivered-To: freebsd-arch@freebsd.org Received: from albatross.prod.itd.earthlink.net (albatross.mail.pas.earthlink.net [207.217.120.120]) by hub.freebsd.org (Postfix) with ESMTP id B59D737B400; Mon, 14 Jan 2002 18:41:30 -0800 (PST) Received: from pool0039.cvx22-bradley.dialup.earthlink.net ([209.179.198.39] helo=mindspring.com) by albatross.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16QJXU-0005JK-00; Mon, 14 Jan 2002 18:41:28 -0800 Message-ID: <3C4396D5.93A84596@mindspring.com> Date: Mon, 14 Jan 2002 18:41:25 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: David Greenman Cc: "James E. Housley" , Thomas Hurst , arch@FreeBSD.org Subject: Re: 64 bit counters again References: <3C41F3FD.4ECC8CD@mindspring.com> <20020113231459.GA30349@voi.aagh.net> <3C42390A.F9E9F533@mindspring.com> <3C42E899.CB21BD0A@FreeBSD.org> <3C431EE5.1CFF557B@mindspring.com> <20020114100633.B8955@nexus.root.com> <3C43355D.8C9A35A0@mindspring.com> <20020114115739.E8955@nexus.root.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG David Greenman wrote: > >Use a modular counter; count bytes, and reflect them out at 1K > >boundaries. Thus the accuracy is 1K, but the precision is 1 > >byte. > > It's not how we "reflect them out" that's the problem. It's the overflow > on the internal 32bit precision that's the problem. You could export the > data in Kbps for all I care, but that has nothing to do with the problem. The overflow you fear never happens, because you subtract out the div'ed value from the internal counter each time you add it to the externalized one, which is why it's a "modular counter", e.g.: driver_byte_count_32 += bytes_this_ISR; driver_k_count_32 = driver_byte_count_32 >> 10; lock_global_stat(); global_k_count_32 += driver_k_count_32; unlock_global_stat(); /* avoid feared overflow: this is a modular counter */ driver_byte_count_32 -= driver_k_count_32 << 10; -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message