lkml.org 
[lkml]   [2005]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: SMP syncronization on AMD processors (broken?)


    On Thu, 6 Oct 2005, Kirill Korotaev wrote:
    >
    > The question raised because the situation we observe on AMD processors is
    > really strange and makes us believe that something is wrong in kerne/in
    > processor or our minds. Below goes an explanation:

    Your code is buggy.

    > The whole story started when we wrote the following code:
    >
    > void XXX(void)
    > {
    > /* ints disabled */
    > restart:
    > spin_lock(&lock);
    > do_something();
    > if (!flag)
    > need_restart = 1;
    > spin_unlock(&lock);
    > if (need_restart)
    > goto restart; <<<< LOOPS 4EVER ON AMD!!!
    > }
    >
    > void YYY(void)
    > {
    > spin_lock(&lock); <<<< SPINS 4EVER ON AMD!!!
    > flag = 1;
    > spin_unlock(&lock);
    > }

    If you want to notify another CPU that you want the spinlock, then you
    need to set the "flag" variable _outside_ of the spinlock.

    Spinlocks are not fair, not by a long shot. They never have been, and they
    never will. Fairness would be extremely expensive indeed.

    > Other observations:
    > - This does not happen on Intel processors, more over on Intel 2 CPUs take
    > locks in a fair manner, exactly one by one!

    It depends entirely on the cache coherency protocol. I bet you'd find
    differences even within Intel CPU's.

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

    \
     
     \ /
      Last update: 2009-11-18 23:46    [W:0.021 / U:1.308 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site