Skip to content

P22: Implement Sleep Locks, Scheduler Support and FS Concurrency (Built on P21)#215

Closed
illuminati2285 wants to merge 5 commits intocodenet:p22-sleeplocksfrom
illuminati2285:p22
Closed

P22: Implement Sleep Locks, Scheduler Support and FS Concurrency (Built on P21)#215
illuminati2285 wants to merge 5 commits intocodenet:p22-sleeplocksfrom
illuminati2285:p22

Conversation

@illuminati2285
Copy link
Copy Markdown

@illuminati2285 illuminati2285 commented Mar 13, 2026

Note:
This branch (p22) is built directly on top of my completed p21 branch(for which I have already raised a PR[#214 ]). I am pointing this PR to p20-exec as the base branch since the official upstream p22 branch is not available yet. (Once the p22 branch is created, the base branch of this PR can be changed to p22 for merging.)
For the P21 changes, please see my previous PR here: [#214 ]
The changes below specifically outline the P22 architecture(built on top of my p21 branch).

Overview

This PR fulfills the P22 requirements by implementing sleep locks and adding sleeping process support to the scheduler. As per the xv6-public design, processes can now sleep and be woken up. Sleep locks have been incorporated everywhere across the file system, allowing a process to safely sleep on a disk buffer and get woken up inside a disk interrupt.

Key Changes

  • sleeplock.c, sleeplock.h, proc.c
    • Added sleep locks. Processes can now sleep() and be wakeup().
    • Added sleeping process support directly into the CPU scheduler to prevent busy-waiting.
  • ide.c, bio.c
    • Incorporated sleep locks everywhere as per xv6-public.
    • A process now safely sleeps on a disk buffer while waiting for hardware I/O and gets woken up inside the disk interrupt (ideintr).
    • Implemented identity re-verification in bget() to prevent stale data corruption if a block is recycled while a process is sleeping.
  • fs.c, file.c
    • Replaced the unprotected valid flag disk reads with ilock() and iunlock() wrappers.
    • Ensured files are exclusively locked during read, write, and exec operations.
  • log.c
    • Implemented begin_op() and end_op() using the new sleep/wakeup logic to guarantee safe log commits across multiple concurrent file system calls.
  • main.c, proc.c
    • Moved the setup for the file system and console (initlog, mknod) out of main.c. Setting these up now uses the disk, which means the system needs to be able to sleep().
    • Put this setup into forkret() instead, so the very first process takes care of it.
    • Added a waiting loop (yield()) in forkret(). This forces any other starting processes to patiently wait until the first process finishes loading the main disk info (Superblock) before they try to run.

Testing(until now)
Multi-process boot succeeds (race condition mitigated).
Standard single-process commands execute normally. (Note: High contention stress-testing triggers the expected lost-wakeup deadlock, which is addressed in P23).

@illuminati2285 illuminati2285 changed the title P22: Implement Sleep Locks and FS Concurrency (Built on P21) P22: Implement Sleep Locks, Scheduler Support and FS Concurrency (Built on P21) Mar 13, 2026
@codenet codenet changed the base branch from p20-exec to p22-sleeplocks March 14, 2026 09:31
@codenet
Copy link
Copy Markdown
Owner

codenet commented Mar 14, 2026

There are merge conflicts now. Can you please merge p22-sleeplocks into your branch or rebase on p22-sleeplocks? We can merge after that.

@illuminati2285
Copy link
Copy Markdown
Author

Done, I have merged p22-sleeplocks into my branch and manually resolved all the merge conflicts

@codenet
Copy link
Copy Markdown
Owner

codenet commented Mar 14, 2026

GitHub is still not happy with the diff. This happened because of some mess in p20-exec. It's history was not built on top of p19-syscalls.

It might be better to create a new branch from p22-sleeplocks, copy back your changes, and again raise the PR. Please make sure that the GitHub diffs are clean when you make the PR again. Sorry for the inconvenience.

@illuminati2285
Copy link
Copy Markdown
Author

Link to the clean PR [#226]

@codenet
Copy link
Copy Markdown
Owner

codenet commented Mar 14, 2026

ok closing this.

@codenet codenet closed this Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants