PPC Kernel Gurus Help?
Hi,
I have been trying to track down deadlocks in linuxthreads code when using semaphores. The semaphores are implemented using the lwarx and stwcx. instructions to create both a testandset and compare_and_swap type of intructions.
Unfortunately, things are not working very reliably. I was looking in the PPC Programmers Environment Manual found that in section 6.3 it specifies that the operating system when process switching should do an stwcx. instruction to a nonsense EA to clear any reservations held by the processor before starting the new process.
Is this being done in Linux PPC kernels?
Does anything special have to be done for threads created with the clone system call?
What about in signal handlers? If a signal handler is invoked in the middle of the lwarx/stwcx. instruction pairs, should the handler be clearing the reservation bit?
Should we be clearing the reservation using an stwcx. instruction in the sigsetjmp / longjmp calls because they are often used to longjmp out of signal handlers which in turn might result in a mispaired ldwarx/stwcx. set of instructions similar to a process switch?
Use of these instructions lwarx/stwcx. is not something I am up on. I have been trying to understand things from reading the PPC manuals from Motorola and IBM but the answers to my questions above were not clear.
Any help here would be greatly appreciated? Am I barking up the wrong tree?
Thanks,
Kevin
[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. Please check http://lists.linuxppc.org/ ]]
[[ and http://www.linuxppc.org/ for useful information before posting. ]]
Quoted 7 lines · Kevin B. Hendricks
Unfortunately, things are not working very reliably. I was looking in the PPC Programmers Environment Manual found that in section 6.3 it specifies that the operating system when process switching should do an stwcx. instruction to a nonsense EA to clear any reservations held by the processor before starting the new process.
Is this being done in Linux PPC kernels?
In fact, recent kernels do a dummy stwcx. on every entry to the kernel, not just on context switches. If you want to check the kernel source you're using, look for a stwcx. in the transfer_to_handler routine in arch/ppc/kernel/head.S.
Quoted 2 lines
Does anything special have to be done for threads created with the clone system call?
Not AFAICS, since you have to enter the kernel to switch from one thread to another. If you have a user-level threads implementation, it should do a dummy stwcx. in the context-switch code.
Quoted 3 lines
What about in signal handlers? If a signal handler is invoked in the middle of the lwarx/stwcx. instruction pairs, should the handler be clearing the reservation bit?
Yes.
Quoted 4 lines
Should we be clearing the reservation using an stwcx. instruction in the sigsetjmp / longjmp calls because they are often used to longjmp out of signal handlers which in turn might result in a mispaired ldwarx/stwcx. set of instructions similar to a process switch?
It is maybe worth considering doing a dummy stwcx. in [sig]longjmp. However, the reservation should have been cleared by the time you get into a signal handler anyway, so the only time you should see a problem is if you do an explicit longjmp between the lwarx and stwcx. :-)
Paul.
[[ This message was sent via the linuxppc-dev mailing list. Replies are ]] [[ not forced back to the list, so be sure to Cc linuxppc-dev if your ]] [[ reply is of general interest. Please check http://lists.linuxppc.org/ ]]
[[ and http://www.linuxppc.org/ for useful information before posting. ]]