Hi,
Sorry about my last post - I think you're right now. I had a good sleep (> 12 hours) and then worked through the enqueue/dequeue code again.
To be specific, for "semaphore_acquire_smp", "spinlock_acquire", "scheduler_enqueue_smp" and "scheduler_dequeue_intel_smp" I checked the enqueue/dequeue code only. For example, for "scheduler_dequeue_intel_smp" I only checked the following parts:
Code:
mov ebx,[esi+4*eax] ;ebx= firstThread
mov edx,[ebx+thread_t.next] ;edx= firstThread.next= secondThread
mov ecx,[ebx+thread_t.prev] ;ecx= firstThread.prev= lastThread
test edx,edx
jz .last
mov [esi+4*eax],edx ;firstThread= secondThread
mov [edx+thread_t.prev],ecx ;secondThread.prev= lastThread
Code:
;----------------------------
; this is the last thread in the queue, so del the bit in the bitmap
align 4
.last:
xor ecx,ecx
mov edx,1
mov [esi+4*eax],ecx
And the equivelent parts of the other functions. This leaves a large amount of code I didn't check, but does mean my earlier post wasn't the problem.
Could you add debugging code and run it through Bochs? After 2 weeks I'd be using Bochs I/O port 0xE9 to get full information when any of the code changes anything...
For example, every time any of these function is used you could display the function name, the CPU that is using it and which thread is running it. You could also dump the contents of each queue every time any queue changes.
I'd start by writing temporary/debugging code that creates something like:
[tt]semaphore_acquire_smp: entered - CPU=0, thread=0x1234
spinlock acquired - CPU=0, lock address=0x12345678
semaphore_acquire_smp: thread queued - CPU=0, thread=0x1234
spinlock released - CPU=0, lock address=0x12345678
scheduler_reschedule_smp: entered - CPU=0, thread=0x1234
THREAD SWITCH: CPU=0 now running thread=0x2345[/tt]
It's a lot of work, but it's an extremely powerful method of bug finding. It can also be a good idea to wrap some of it in conditional code so that it can be re-used each time there's bugs (rather than removing it all when the current problem is fixed)...
I've attached a file containing some "helper routines" - these routines are what I use as a basis for this style of debugging (it's a small start, I know)...
Cheers,
Brendan