From owner-freebsd-smp Tue Oct 31 11:15: 6 2000 Delivered-To: freebsd-smp@freebsd.org Received: from pike.osd.bsdi.com (pike.osd.bsdi.com [204.216.28.222]) by hub.freebsd.org (Postfix) with ESMTP id 93C9637B479; Tue, 31 Oct 2000 11:15:03 -0800 (PST) Received: from laptop.baldwin.cx (john@dhcp241.osd.bsdi.com [204.216.28.241]) by pike.osd.bsdi.com (8.11.0/8.9.3) with ESMTP id e9VJEEf14688; Tue, 31 Oct 2000 11:14:14 -0800 (PST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <20001031102110.V22110@fw.wintelcom.net> Date: Tue, 31 Oct 2000 11:15:14 -0800 (PST) From: John Baldwin To: Alfred Perlstein Subject: Re: Reference count invariants in a fine-grained threaded enviro Cc: freebsd-smp@FreeBSD.org, Robert Watson , Cedric Berger Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On 31-Oct-00 Alfred Perlstein wrote: > * Cedric Berger [001031 10:11] wrote: >> >> >> Robert Watson wrote: >> > >> [...] >> > >> > Rules for interactions between mutexes and reference-counted kernel >> > objects: >> > >> > Assumptions: >> > >> > - Objects with reference counts have a mutex that can protect their >> > reference count, and possibly other variables (or other instances). For >> > example, struct cred might have a mutex per instance, but all struct >> > prison's might use the same mutex. >> > >> >> Is there not a cheaper way to manage reference count then using mutexes? >> I would guess that all architectures must have hardware support (i.e. >> special >> assembly instruction) to atomically increment/decrement+read a 32-bit value >> in a multiprocessor environment > > Yes, but FreeBSD is has too many knights that say NIH! Huh? /me confused > This is where atomic refcounts would simplify the code however for some > reason everyone I've talked to prefers to have this sort of code: Really? Who have you been talking to? :) You can already do this now like so (the KTR code does this for example): static inline int refcount_update(int *ref, int delta) { int old; do { old = *ref; } while (!atomic_cmpset(ref, old, old + delta); return (old + delta); } Then just do: { ... /* add a reference */ refcount_update(&foo->refcount, 1); ... /* remove a reference */ refcount_update(&foo->refcount, -1); } -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message