Re: [patch] preemptive kernel, preemptive-2.3.52-A7

From: Ingo Molnar (mingo@chiara.csoma.elte.hu)
Date: Tue Mar 14 2000 - 07:44:48 EST


On Tue, 14 Mar 2000, Andrea Arcangeli wrote:

> >i've also introduced a new light-weight 'IRQ-atomic' increment and
> >decrement method in atomic.h, because ->may_preempt has to be
> >local-IRQ-safe.
>
> Could you describe which race you are talking about? I can't see any
> race on such field.

i've introduced atomic_inc_local() and atomic_dec_local() to implement
'local-CPU-IRQ atomic' increments and decrements. The following increment
which you are using:

        current->blah--;

is not theoretically local-IRQ-safe, because the compiler is free to
reorder this with other lines. (and thus those other lines could get
possibly moved into the 'freely preemptable' area, causing subtle
small-window bugs.)

the following is safe as well:

        barrier();
        current->blah--;
        barrier();

but i just felt we want to make it IRQ-atomic as well (although this is
not strictly necessery now as IRQ contexts never change current->blah.) If
current->blah is modified from IRQ contexts as well then 'current->blah--'
is not IRQ-safe as it might get compiled into several instructions:

        movl blah, %eax
        decl %eax
        movl %eax, blah

although this does not happen on x86 currently, it could theoretically.
But your version is definitely buggy because it lacks a compiler-level
barrier. (which atomic_dec_local() automatically is)

        Ingo

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Mar 15 2000 - 21:00:27 EST