tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: MI non-interlocked atomic ops?

David Young <> wrote:
> <...>
> which spends (on x86) a small but not immeasurable amount of time in
> splx(s), so I was tempted to rewrite it like this:
>         void
>         mbstat_type_add(int type, int diff)
>         {
>                 struct mbstat_cpu *mb;
>                 mb = percpu_getref(mbstat_percpu);
>                 atomic_add_uint_ni(&mb->m_mtypes[type], diff);
>                 percpu_putref(mbstat_percpu);
>         }
> There is no such routine as atomic_add_uint_ni(), though, and I don't
> know if every NetBSD architecture can supply that routine.

Right, spl*()/splx() have a cost.  However, code like this (networking)
should not be in the hard-interrupt handler.  As we move towards a wider
use of software interrupts, SPL calls will disappear and kernel preemption
provides the necessary protection (although software interrupts are not
yet preemptable).

We have non-interlocked CAS operation - atomic_cas_*_ni().  This can be
used to replicate all other operations.  I doubt there is much need to
define them all due to the reason stated above.  CAS is enough for now.


Home | Main Index | Thread Index | Old Index