Spin Lock

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
nbdd0121
Member
Member
Posts: 60
Joined: Thu Jul 25, 2013 8:10 am

Spin Lock

Post 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
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Spin Lock

Post 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.
If a trainstation is where trains stop, what is a workstation ?
nbdd0121
Member
Member
Posts: 60
Joined: Thu Jul 25, 2013 8:10 am

Re: Spin Lock

Post 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!
Post Reply