atomic reference counting primatives.

Max Laier max at love2party.net
Thu May 20 21:10:22 PDT 2004


On Friday 21 May 2004 05:45, Bruce Evans wrote:
> On Thu, 20 May 2004, Julian Elischer wrote:
> > This has been raised before but I've come across uses for it again and
> > again so I'm raising it again.
> > JHB once posted some atomic referenc counting primatives. (Do you still
> > have them John?)
> > Alfred once said he had soem somewhere too, and other s have commentted
> > on this before, but we still don't seem to have any.
> >
> > every object is reference counted with its own code and
> > sometimes it's done poorly.
> >
> > Some peiople indicated that there are cases where a generic refcounter
> > can not be used and usd this as  a reason to not have one at all.
>
> Now we know that a generic reference counter would be even better for
> pessimizing FreeBSD than was first thought, since on P4's locked
> instructions are very expensive.  See the thread about bridging.  A
> pessimization by a factor of 2 or so has been achieved using little
> more than normal locking, since there are lots of lock/unlock pairs
> per packet and each lock and unlock takes hundreds (?) of cycles for
> the bus lock part and very little else.  General atomic counters of
> any sort would take about half as lock as a lock/unlock pair (since
> they only need 1 lock, but would always needed it even if running in
> a locked region).  The pessimizations from them could be broken using
> algorithms that don't need fine-grained locking.

I find atomic counters still very attractive for a simple sx lock. The current 
implementation uses (as far as I know) a normal mutex to protect the busy 
count, so you have four lock/unlock operations that need bus interaction, 
when we move to updating the busy count with atomic ops we have only two and 
could start to actually use sx locks.

The BANG from Warner's reply could be avoided by decrementing to ($magicval) 
rather than 0 when exlusive mode is requested. But I am not entirely sure if 
I got the point ... but that's always the/my problem when it comes to 
unterstanding locks.

-- 
Best regards,				| mlaier at freebsd.org
Max Laier				| ICQ #67774661
http://pf4freebsd.love2party.net/	| mlaier at EFnet


More information about the freebsd-arch mailing list