Page 1 of 1

Spin Lock

Posted: Wed Aug 28, 2013 7:24 am
by nbdd0121
My code can run successfully on bochs and QEMU. However, but when I put it on virtualbox (in SMP), it stops running.(1 Core in virtualbox is OK) It seems that the processes are stopped from being scheduled. I guess that my spin lock have a little problem:

Code: Select all

spin_lock:
    mov     edx, [esp+4]
.spin:
    mov     eax, 1
    xchg    eax, [edx]
    or      eax, eax
    jz      .ret
    pause
    jmp     .spin
.ret:
    ret

spin_unlock:
    mov     edx, [esp+4]
    mov     dword[edx], 0
    ret
Can anyone check if the code was wrong or not? I think it is correct

Re: Spin Lock

Posted: Wed Aug 28, 2013 8:51 pm
by gerryg400
It does look correct.

The problem may be that your code (the code that uses the spinlock) has a deadlock in it. It could be an SMP deadlock or an interrupt deadlock.

Re: Spin Lock

Posted: Thu Aug 29, 2013 12:59 am
by nbdd0121
gerryg400 wrote:It does look correct.

The problem may be that your code (the code that uses the spinlock) has a deadlock in it. It could be an SMP deadlock or an interrupt deadlock.
Thank you for your notice! I worked all day and finally found the place where kernel deadlocked. It seems the reason why virtualbox locked is that it runs faster, so the chance when two CPU enters a critical area is increased! Thank you again!