P23: Solve Lost Wakeup Issue (Built on P22)#218
Closed
illuminati2285 wants to merge 5 commits intocodenet:p22-sleeplocksfrom
Closed
P23: Solve Lost Wakeup Issue (Built on P22)#218illuminati2285 wants to merge 5 commits intocodenet:p22-sleeplocksfrom
illuminati2285 wants to merge 5 commits intocodenet:p22-sleeplocksfrom
Conversation
added 4 commits
March 13, 2026 07:07
This was referenced Mar 14, 2026
Closed
Author
|
Sir @codenet , I noticed this PR was closed without merging. Could you please let me know the reason? If any changes are needed, I would be happy to update the PR. |
Owner
|
Hey I deleted the p22-sleeplock branch. I think GH automatically closed the PR on that change. Let's use discord p23 channel for coordination on this. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note:
This branch (
p23) is built directly on top of my completedp22branch(PR [#215]) . I am pointing this PR top20-execas the base branch since the official upstream branches are not available yet. (Once the p23 branch is created, the base branch of this PR can be changed to p23 for merging.)For the P22 changes please see my previous PR here: [#215]
The changes below specifically outline the P23 bug fix for the lost wakeup problem.
Overview
This PR solves the fatal "Lost Wakeup" concurrency bug present in the naive sleep implementation from P22.
In P22, a process had to manually release its protecting lock before calling
sleep(). This created a dangerous time gap: if a hardware interrupt fired in that exact fraction of a second, it would triggerwakeup(). Because the process hadn't fully transitioned to theSLEEPINGstate yet, the wakeup signal was lost. The process would then finish going to sleep and stay stuck forever.This PR fixes the issue by allowing a process to hold onto its lock while calling
sleep(). Insidesleep(), the kernel safely acquires the globalptable.lock(which blocks all incoming wakeups) before releasing the process's data lock. This safe switch ensures that no wakeup signals are ever missed.Key Changes
sleep()to accept a protecting spinlock as a second argument:void sleep(void *chan, struct spinlock *lk).sleep(): it first acquiresptable.lock, releases the original lock safely, sets the process state toSLEEPING, and restores the locks when the process wakes up.release()andacquire()wrappers around the sleep calls.sleep()to pass their protecting spinlocks directly into the function:ide.cnow callssleep(b, &idelock);sleeplock.cnow callssleep(lk, &lk->lk);log.cnow callssleep(&log, &log.lock);Testing
Ran the multi-process boot sequence successfully.
Executed the custom
stress.cuser program simulating extreme high contention (4 concurrent processes flooding the buffer cache and disk with massive reads/writes).