diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index 1ce6d45..871c963 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -4,39 +4,21 @@ "type": "split", "children": [ { - "id": "d34eff5233313e79", + "id": "792b2a8f7f3f7ac1", "type": "tabs", - "dimension": 50, "children": [ { - "id": "f1e9c17a4ce43dc1", + "id": "c1086d70d8f012dd", "type": "leaf", "state": { "type": "markdown", "state": { - "file": "Extracurricular/Circuitree/Shitter Zero/Agenda.md", + "file": "Operating Systems/Scheduling.md", "mode": "source", "source": false }, "icon": "lucide-file", - "title": "Agenda" - } - } - ] - }, - { - "id": "ad495c8e1240a180", - "type": "tabs", - "dimension": 50, - "children": [ - { - "id": "cbb50d8009087a16", - "type": "leaf", - "state": { - "type": "reveal-preview-view", - "state": {}, - "icon": "lucide-file", - "title": "Slide Preview" + "title": "Scheduling" } } ] @@ -199,8 +181,7 @@ } ], "direction": "horizontal", - "width": 200, - "collapsed": true + "width": 200 }, "left-ribbon": { "hiddenItems": { @@ -217,12 +198,15 @@ "omnisearch:Omnisearch": false } }, - "active": "cbb50d8009087a16", + "active": "c1086d70d8f012dd", "lastOpenFiles": [ - "Extracurricular/Circuitree/Shitter Zero/Timeline.md", - "Extracurricular/Circuitree/Shitter Zero/Agenda.md", - "Extracurricular/Circuitree/Antenna Building/Idea and proposed timeline.md", "Operating Systems/Processes and Threads.md", + "Operating Systems/Overview.md", + "Operating Systems/Scheduling.md", + "Pasted image 20250421222538.png", + "Extracurricular/Circuitree/Shitter Zero/Agenda.md", + "Extracurricular/Circuitree/Shitter Zero/Timeline.md", + "Extracurricular/Circuitree/Antenna Building/Idea and proposed timeline.md", "Extracurricular/Circuitree/Shitter Zero", "Extracurricular/Circuitree/Committee Market/discussion/CA.md", "Extracurricular/Circuitree/Committee Market/discussion/Committee market ideas.md", @@ -246,8 +230,6 @@ "Extracurricular/FCG/Radio reception.md", "Extracurricular/Circuitree/Committee Market/Macro pad.md", "Operating Systems/assets/Pasted image 20250419143713.png", - "Operating Systems/Overview.md", - "Languages & Machines/Introduction.md", "Operating Systems/assets/Pasted image 20250419141856.png", "Languages & Machines/assets/Pasted image 20250414190229.png", "Languages & Machines/assets/Pasted image 20250414190144.png", @@ -259,7 +241,6 @@ "Extracurricular/Circuitree/Antenna Building", "Fundamentals of Electronics", "Pasted image 20250113151159.png", - "Introduction to Machine Learning/image.png", "Extracurricular/Misc/Proposed Routine Plan.canvas", "Introduction to Machine Learning", "Operating Systems/assets", diff --git a/Extracurricular/Circuitree/Shitter Zero/Agenda.md b/Extracurricular/Circuitree/Shitter Zero/Agenda.md deleted file mode 100644 index 7dfb27f..0000000 --- a/Extracurricular/Circuitree/Shitter Zero/Agenda.md +++ /dev/null @@ -1,5 +0,0 @@ -==MOVE THIS TO THE CIRCUITREE REPO!== - -1. 15m intro presentation (present the problem) -2. 30m discussion -3. 10m distribution \ No newline at end of file diff --git a/Operating Systems/Processes and Threads.md b/Operating Systems/Processes and Threads.md index 5cd077c..935f28e 100644 --- a/Operating Systems/Processes and Threads.md +++ b/Operating Systems/Processes and Threads.md @@ -190,8 +190,34 @@ A light-weight process. - **Kernel Threads** - Managed by OS -### Relationship modles -* +### Relationship models +#### Many-to-one + +* User-level threads to one kernel treads +* Management done by thread library in user space +* The entire process blocks whenever a thread makes a blocking sycalls +* Only **one** thread can access the kernel at a time (you can't run multiple threads in parallel on multiprocessors) + +#### One-to-one +Each user thread is mapped to a kernel thread +- Provides more concurrency +Unfortunately: +- Creating a user thread requires creating the corresponding kernel thread +- Overhead of creating kernel threads retricts the number of threads + + +#### Many-to-many +Multiplexes many user threads to a $\leq$ number of kernel threads. + +- Allows creation of however many threads the user wants +- The kernel can schedule another thread for execution whenever a thread performs a blocking system call + + +#### Fork-join +Parent creates forks (children threads) and then waits for the children to terminate, joining with them, at which point it can retrieve and combine results. + +This is also called **synchronous threading**. Parent **cannot** continue until the work has been completed. + [^1]: A batch job is a scheduled task or a set of commands that are executed without manual intervention - **cron** @@ -199,3 +225,21 @@ A light-weight process. [^3]: sequence of programmed instructions that can be managed independently by a scheduler within a computer program + +##### Parallelism + +![](Pasted%20image%2020250421222538.png) + + +## Thread pool +Issue wih threads: +- Overhead when creating +- Exhausting system resources +Solution: thread pools - creating a number of threads at startup and place them into a pool where they sit and wait for work. + + +This optimizes everything because: +Sharing threads: +- If a thread is blocked (e.g., waiting for I/O), it doesn't remain idle; it can be reassigned to another task +- Each thread has its own task queue +- Whenever a thread finishes its tasks it looks through the other threads' queues and "steals" tasks. diff --git a/Operating Systems/Scheduling.md b/Operating Systems/Scheduling.md new file mode 100644 index 0000000..65af60a --- /dev/null +++ b/Operating Systems/Scheduling.md @@ -0,0 +1,123 @@ +--- +type: theoretical +backlinks: + - "[[Overview#Multitasking/Timesharing]]" + - "[[Processes and Threads#Timesharing In-depth]]" +--- +Processes take turns to use the CPU. + +## Long Term Scheduling +Processes that are waiting are put in a *ready* queue. + +## Short Term Scheduling +Which process in the ready queue should be assigned the CPU next + + +## Criteria +We want to: +- Maximize CPU utilization +- Minimize Average Turnaround time +- Maximize throughput +- Minimize waiting and response time + + +### CPU utilization +Each process spends $p$ fraction of its time wating for I/O, having $n$ processes in memory. The probability that all processes are waiting for I/O is $p^n$ +Hence, CPU utilization is: + +$$ +1- p^n +$$ + +### Average Turnaround Time +The time since the process enters the ready queue until it terminates. + +Average is literally the mean of the aforementioned but for many processes. + +### Throughput +Number of processes executed completely in a unit of time. + +## Non-Preemptive scheduling + +If the process executes to complete, the algorithm is non-preemptive. + +- Long average turnaround time +- Whenever a long process starts, short ones have to wait +### FCFS +Read title + +## SJF +Shortest job first. Choose the next process to execute from the processes currently in the ready queue, based on their execution time + + +> [!IMPORTANT] +> Starvation happens when a process waits for a resource for a long time + + + +This could happen with SJF. + + +### Attacking starvation by introducing compound priority[^1] + +So, SJF uses `1/Execution time` priority. We just add `0.1*waiting time` to it. + +[^1]: I made that shit the fuck up just now + +## Preemptive scheduling +Scheduler stops a process and reclaims the CPU after assigning it + + +### SRTF +Shortest remaining time first (as opposed to shortest job first which just takes the initial times, this one is dynamic) + +We keep track of when the processes start and how much time they've taken, calculating how much time they have left. We pick the minimum based on that. + +### RR +Round robing. Just give everyone a small time window for them to do their jobs. + +We need to find a "time quantum"[^2] by balancing minimizing overhead of context switching and maximizing response time + +**no priority** + + +## Process categorization + +| Category | Description | Example | +| ----------- | ------------------------------------------------------------ | ----------------------- | +| Batch | No interaction with users, input/output read/written to file | Cron job | +| Interactive | Requires input from user. Needs short response times. | Chat | +| Real-time | Expects response from user | Industrial applications | + +## Multi-queue scheduling +Multiple priority levels and uses RR for each. +Choses processes from highest level and recurses downwards whenever a level is exhausted. + +### + feedback +Processes can be moved from one queue to another based on the type of operations executed (i.e. I/O is high priority). + + +## Lottery +Random number. Set boundaries. e.g.: + +$$ + +\begin{align*} +p_a \leftarrow 20\% \\ +p_b \leftarrow 50\% \\ +p_c \leftarrow 30\% +\end{align*} +$$ + +So: + +$$ +rand() \rightarrow 0.4 \implies S(\{p_i\}) = p_b +$$ + + +## Real-time scheduling +Dividing the program into a number of short-lived processes. + + +[^2]: Terrible fucking name, why why why, this should be called a window or some shit. diff --git a/Pasted image 20250421222538.png b/Pasted image 20250421222538.png new file mode 100644 index 0000000..14968d2 Binary files /dev/null and b/Pasted image 20250421222538.png differ