docs: update README for native Arch setup and add ASST1 notes
This commit is contained in:
2 files changed
+98
-20
No files matched your search
@@ -0,0 +1,51 @@
|
||||
# Assignment 1
|
||||
|
||||
## Objectives
|
||||
|
||||
- Understand the OS/161 thread subsystem and existing synchronization primitives: spinlocks and semaphores.
|
||||
- Have implemented working locks, condition variables, and reader-writer locks that you can use it later assignments.
|
||||
- Be able to properly address different synchronization problems by choosing and applying the correct synchronization primitive.
|
||||
|
||||
## Tasks
|
||||
|
||||
- [ ] Implement sleeping lock
|
||||
- [ ] Learn from Linux's implementation of [`rt_mutex`](https://elixir.bootlin.com/linux/v6.16.9/source/include/linux/rtmutex.h#L23)
|
||||
- [ ] Notice how we need 2 things: the details of the cpu task and the wait channel we need to sleep on. Do more research on this.
|
||||
- [ ] Implement condition variables
|
||||
- [ ] Implement reader-writer locks
|
||||
- [ ] Solve synchronization problems
|
||||
- `kern/synchprobs/*`: these files are where you will implement your solutions to the synchronization problems.
|
||||
- `kern/test/synchprobs.c`: this file contains driver code we will use to test your solutions. You can and should change this file to stress test your code.
|
||||
|
||||
## Code Reading Questions
|
||||
|
||||
- Thread questions
|
||||
- What happens to a thread when it calls thread_exit? What about when it sleeps?
|
||||
|
||||
- What function—or functions—handle(s) a context switch?
|
||||
|
||||
- What does it mean for a thread to be in each of the possible thread states?
|
||||
|
||||
- What does it mean to turn interrupts off? How is this accomplished? Why is it important to turn off interrupts in the thread subsystem code?
|
||||
|
||||
- What happens when a thread wakes up another thread? How does a sleeping thread get to run again?
|
||||
|
||||
- Scheduling questions
|
||||
- What function (or functions) choose the next thread to run?
|
||||
|
||||
- How is the next thread to run chosen?
|
||||
|
||||
- What role does the hardware timer play in scheduling?
|
||||
|
||||
- What hardware independent function is called on a timer interrupt?
|
||||
|
||||
- Synchronization questions
|
||||
- Describe how wchan_sleep and wchan_wakeone are used to implement semaphores.
|
||||
|
||||
- Why does the lock API in OS/161 provide lock_do_i_hold, but not lock_get_holder?
|
||||
|
||||
## Notes
|
||||
|
||||
Finally, to successfully run the ASST1 tests you will need to configure your kernel to use a large amount of memory. We suggest the maximum of 16 MB. This is because your kernel currently leaks memory allocations that are larger than a page, and that includes all 4K thread stacks. So you will find that even if you correctly allocate and deallocate memory in your synchronization primitives and problems, your kernel will only run a certain number of tests before it runs out of memory and `panic`s. This is normal. However, you should make sure that your kernel does not leak smaller amounts of memory. Your kernel includes tools to help you measure this.
|
||||
|
||||
- `curthread` is a globally (actually per-CPU) available pointer to "the currently running thread,"
|
||||
@@ -1,32 +1,59 @@
|
||||
# OS161 Learning
|
||||
# OS/161 Learning
|
||||
|
||||
My work on the [ops-class.org](https://ops-class.org/) OS/161 assignments (OS/161 2.0.3).
|
||||
|
||||
- Upstream: `https://github.com/ops-class/os161` (remote `upstream`)
|
||||
- My repo: <https://git.minhtrannhat.com/minhtrannhat/os161> (remote `origin`)
|
||||
|
||||
## Progress
|
||||
|
||||
| Assignment | Topic | Status |
|
||||
| --- | --- | --- |
|
||||
| ASST0 | Introduction, tools, code reading | Done (tag `asst0`) |
|
||||
| ASST1 | Locks, condition variables, reader-writer locks, synchronization problems | Not started |
|
||||
| ASST2 | System calls and processes | Not started |
|
||||
| ASST3 | Virtual memory | Not started |
|
||||
|
||||
## Setup
|
||||
|
||||
- Follow instructions from UBC University: <https://people.ece.ubc.ca/~os161/os161-site/install-docker.html>
|
||||
- Get their docker image and build the container
|
||||
- Go here to get the OS161 base source tarball <http://www.os161.org/download/>
|
||||
- Do your magic (gunzip, tar -xvf) and make sure the folder is named `src`
|
||||
- Next your need a config file, a sample config file (provided by UBC) can be obtained by <https://people.ece.ubc.ca/~os161/os161-site/install.html>
|
||||
- Then we run the kernel with the help of the `sys161` simulator:
|
||||
The toolchain runs natively on Arch Linux. It does not use Docker.
|
||||
|
||||
cd ~/os161/root
|
||||
sys161 kernel
|
||||
1. Install these AUR packages: `mips-harvard-os161-binutils`, `mips-harvard-os161-gcc48`, `mips-harvard-os161-gdb`, `sys161` and `guile2.0`.
|
||||
2. If a package does not build, read [os161-build-fixes.md](./os161-build-fixes.md). It has the fixes for GCC 14 and Python 3.12+.
|
||||
|
||||
## The pieces
|
||||
## Build
|
||||
|
||||
- OS/161 Kernel source tree
|
||||
- The kernel sources for OS/161 is in the `kern` subdirectory, which has its own configuration script.
|
||||
- The `conf.kern` file determines what source files get included in our kernel build so we might have to modify the file later on.
|
||||
Run the script from the repo root:
|
||||
|
||||
- Debugging
|
||||
- Follow the steps at <https://people.ece.ubc.ca/~os161/os161-site/gdb-attach.html>
|
||||
./recompile.sh # builds the ASST1 kernel config
|
||||
./recompile.sh DUMBVM # builds a different kernel config
|
||||
|
||||
## Assignments
|
||||
The script does these steps:
|
||||
|
||||
### Assignments 0
|
||||
- It builds and installs userland.
|
||||
- It configures, builds and installs the kernel into `root/`.
|
||||
- It writes `compile_commands.json` for clangd.
|
||||
|
||||
- [Assignment 0 Answers](./Assignment0.md)
|
||||
## Run
|
||||
|
||||
### Assignments 1
|
||||
cd root
|
||||
sys161 kernel
|
||||
|
||||
- [Assignment 1 Answers](./Assignment1.md)
|
||||
`root/sys161.conf` gives the machine 16 MB of RAM and 8 CPUs. The ASST1 tests need the large RAM size, because the kernel leaks the memory of thread stacks.
|
||||
|
||||
## Source tree
|
||||
|
||||
- `kern/`: the kernel. `kern/conf/conf.kern` sets which source files go into the kernel build.
|
||||
- `kern/thread/synch.c`: the synchronization primitives (ASST1).
|
||||
- `kern/synchprobs/`: the synchronization problems (ASST1).
|
||||
- `userland/`: the user programs and test programs.
|
||||
- `test161/`: the test161 targets and tests.
|
||||
|
||||
## Debugging
|
||||
|
||||
Follow the steps at <https://people.ece.ubc.ca/~os161/os161-site/gdb-attach.html>.
|
||||
|
||||
## Assignment answers
|
||||
|
||||
- [Assignment 0](./Assignment0.md)
|
||||
- [Assignment 1](./Assignment1.md)
|
||||
Reference in new issue
Block a user