From owner-freebsd-current@FreeBSD.ORG Mon Jul 24 08:40:35 2006 Return-Path: X-Original-To: freebsd-current@FreeBSD.ORG Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 80DAE16A4DD for ; Mon, 24 Jul 2006 08:40:35 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8]) by mx1.FreeBSD.org (Postfix) with ESMTP id E9A3443D5D for ; Mon, 24 Jul 2006 08:40:34 +0000 (GMT) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (hsrqxa@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id k6O8eRod037555 for ; Mon, 24 Jul 2006 10:40:32 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.4/8.13.1/Submit) id k6O8eRJn037554; Mon, 24 Jul 2006 10:40:27 +0200 (CEST) (envelope-from olli) Date: Mon, 24 Jul 2006 10:40:27 +0200 (CEST) Message-Id: <200607240840.k6O8eRJn037554@lurza.secnetix.de> From: Oliver Fromme To: freebsd-current@FreeBSD.ORG In-Reply-To: <44C40E66.8080805@wm-access.no> X-Newsgroups: list.freebsd-current User-Agent: tin/1.8.0-20051224 ("Ronay") (UNIX) (FreeBSD/4.11-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Mon, 24 Jul 2006 10:40:32 +0200 (CEST) X-Mailman-Approved-At: Mon, 24 Jul 2006 11:39:03 +0000 Cc: Subject: Re: vmstat's entries type X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-current@FreeBSD.ORG List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jul 2006 08:40:35 -0000 Sten Daniel Sørsdal wrote: > sthaug@nethelp.no wrote: > > > > > > One approach that we could use for 64-bit counters would be to just > > > > use 32-bits one, and poll them for overflow and bump an overflow > > > > count. This assumes that the 32-bit counters overflow much less often > > > > than the polling interval, and easily triples the amount of storage > > > > for each of them... It is ugly :-( > > > > > > > What's wrong with the add+adc (asm) approach found on any i386? > > > > Presumably the fact that add + adc isn't an atomic operation. So if > > you want to guarantee 64 bit consistency, you need locking or similar. > > Would it not be necessary to do this locking anyway? > I don't see how polling for overflow would help this consistency. When using the polling solution, the overhead of checking for atomicity is moved to the "client" side, so no locking is necessary. The idea is that most counters are updated much more often than they're read, so the updating code should be as efficient as possible, at the cost of more overhead in the reading code. For example, the code reading the sysctl has to perform the following actions (pseudo code): 1. OV1 = read overflow counter 2. OLD = read old counter value 3. NEW = read new counter value 4. OV2 = read overflow counter 5. if OV2 != OV1: go back to 1. 6. if OLD > NEW: OV1++ 7. return OV1 * 2^32 + NEW I think that should cover all possible race conditions. The code updating the overflow counter at certain polling intervals would have to do something similar, of course. The main advantage of that approach is the fact that the counter updating code is a simple 32bit "add". There's no locking or anything required, i.e. it's most efficient, which is important if the counter is updated very often, like vm.stats.sys.v_swtch or vm.stats.sys.v_syscall or vm.stats.sys.v_intr. The disadvantage is that polling the counters for overflows is somewhat ugly, in terms of design. However, personally I think that it's an acceptable solution, given the fact that it is only required for 32bit "legacy" hardware. 64bit machines will be more and more common and become the "standard", and they don't need such work-arounds for 64bit counters. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd Any opinions expressed in this message may be personal to the author and may not necessarily reflect the opinions of secnetix in any way. "C++ is over-complicated nonsense. And Bjorn Shoestrap's book a danger to public health. I tried reading it once, I was in recovery for months." -- Cliff Sarginson