-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
waitUntilQueued times out due to the pin internal lock #57
Comments
There might be conventional instrumentation being added between the INS_IsSyscall call and the syscall actually being taken. Have you tried inserting the SyscallEnter call with CALL_ORDER_LAST? |
Thanks for the hint! I haven't tried it yet. Will check if that works. |
…d SyscallEnterLocked to avoid waitUntilQueued time-outs due to the pin internal lock The functionality of SyscallEnter is moved to SyscallEnterUnlocked called without acquiring the Pin internal lock. The actual modification of system call arguments is done in SyscallEnterLocked with acquiring the Pin internal lock. This commit fixes the following issue: s5z#57
Independently of CALL_ORDER_LAST parameter INS_IsSyscall call (with IPOINT_BEFORE param) is performed before PIN_AddSyscallEntryFunction call. So I chose to split SyscallEnter into 2 methods SyscallEnterUnlocked (INS_IsSyscall call) and SyscallEnterLocked (AddSyscallEntryFunction call). So all the initial functionality of SyscallEnter is moved to SyscallEnterUnlocked and modifications to syscall args are saved. In SyscallEnterLocked saved modifications are applied. |
It has been a while since this issue opened. I have also seen the related pull request #60. Recently I start to see a lot of The syscall issue is a consequence of this bug, because if the thread does not grad I tried a simple fix in another pull request of mine (which also relate to scheduler.cpp/h), i.e., grab |
When I analyzed this problem I came to conclusion that it is related to the the PIN lock hierarchy violation: The following sequence of events happened: With the fix proposed in the pull request #60 it works the following way: I don't quite get the fix 51c4672. It is mentioned that |
I am not 100% on the scheduler logic, either. Let me try to explain my fix: In your example without your fix, thread 2 will be woken up, and right after this wakeup, it is now inside the function The key here is that To summary, I believe that as long as we enforce thread 2 to wait on the Let me know if anything is unclear. I love to discuss this so we all get better understanding of the code :) |
Another thing to mention: |
I was assuming the following logic of this code. The thread is woken and it needs to reach the scheduler. If I agree |
I agree that your understanding is correct based on the current code. I think the woken thread should reach the scheduler ASAP, to ensure that it joins the simulation. I think my fix is more general (in original code, even without syscalls, there can still be deadlocks if thread 2 does not reach scheduler soon enough), but there are extra overheads (lock acquire, though I think it should be minor). Your fix is focusing on syscall, and the overhead should be smaller. I think we are on the same page now. Let's leave it there for the authors to decide which fix to accept. Either should fix the problems we have. |
My goal was to preserve the current behaviour of ZSim when |
I experienced this issue myself and believe that @arodchen patch is correct. It fixes a deadlock that @gaomy3832 patch cannot handle:
I suggest anybody merging @arodchen patch for fixing this issue. |
…d SyscallEnterLocked to avoid waitUntilQueued time-outs due to the pin internal lock The functionality of SyscallEnter is moved to SyscallEnterUnlocked called without acquiring the Pin internal lock. The actual modification of system call arguments is done in SyscallEnterLocked with acquiring the Pin internal lock. This commit fixes the following issue: s5z#57
When syscallLeave is called from SyscallEnter waitUntilQueued can time out if the woken thread is about to call SyscallEnter before reaching sleeping point on schedLock futex. The reason for that is that before calling the function registered in PIN_AddSyscallEntryFunction the pin client lock is obtained as it is written in the Pin documentation.
It is possible to move some functionality from SyscallEnter to another function without a lock by adding instrumentation on INS_IsSyscall condition. I tried to move call to syscallLeave to the unlocked function which is called before SyscallEnter but ZSim failed with panic("Wakeup race in barrier?").
Do you have any ideas how to solve that problem?
The text was updated successfully, but these errors were encountered: