tech-kern archive

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

MI non-interlocked atomic ops?



Does NetBSD run on any processor architectures where it is difficult
or impossible in the kernel[1] to provide non-interlocked atomic
operations?  That is, operations that are atomic with respect to other
operations *on the same processor*, but possibly divisible by operations
on other processors?

On x86, creating non-interlocked variants of atomic operations is
usually a small matter of leaving the LOCK prefix off of an instruction,
because traps, interrupts, et cetera, only occur between instructions.
(Do correct me if I am wrong about this!)  I figure that it is more
complicated on a RISC machine where there may be no/few instructions
that read-modify-write RAM.

I ask because the other day I stumbled on the statistics-counting
function mbstat_type_add(),

        void
        mbstat_type_add(int type, int diff)
        {
                struct mbstat_cpu *mb;
                int s;

                s = splvm();
                mb = percpu_getref(mbstat_percpu);
                mb->m_mtypes[type] += diff;
                percpu_putref(mbstat_percpu);
                splx(s);
        }

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.

Dave

[1] Or in userland, too, I guess, but I'm mainly interested
    in the kernel.

-- 
David Young
dyoung%pobox.com@localhost    Urbana, IL    (217) 721-9981


Home | Main Index | Thread Index | Old Index