Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Oct 2000 11:15:14 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        freebsd-smp@FreeBSD.org, Robert Watson <rwatson@FreeBSD.org>, Cedric Berger <cedric@wireless-networks.com>
Subject:   Re: Reference count invariants in a fine-grained threaded enviro
Message-ID:  <XFMail.001031111514.jhb@FreeBSD.org>
In-Reply-To: <20001031102110.V22110@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help

On 31-Oct-00 Alfred Perlstein wrote:
> * Cedric Berger <cedric@wireless-networks.com> [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 <jhb@FreeBSD.org> -- 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.001031111514.jhb>