vault backup: 2025-04-21 22:49:53

This commit is contained in:
Boyan 2025-04-21 22:49:53 +02:00
parent e87d3b26a1
commit a4a5486252
5 changed files with 181 additions and 38 deletions

View File

@ -4,39 +4,21 @@
"type": "split", "type": "split",
"children": [ "children": [
{ {
"id": "d34eff5233313e79", "id": "792b2a8f7f3f7ac1",
"type": "tabs", "type": "tabs",
"dimension": 50,
"children": [ "children": [
{ {
"id": "f1e9c17a4ce43dc1", "id": "c1086d70d8f012dd",
"type": "leaf", "type": "leaf",
"state": { "state": {
"type": "markdown", "type": "markdown",
"state": { "state": {
"file": "Extracurricular/Circuitree/Shitter Zero/Agenda.md", "file": "Operating Systems/Scheduling.md",
"mode": "source", "mode": "source",
"source": false "source": false
}, },
"icon": "lucide-file", "icon": "lucide-file",
"title": "Agenda" "title": "Scheduling"
}
}
]
},
{
"id": "ad495c8e1240a180",
"type": "tabs",
"dimension": 50,
"children": [
{
"id": "cbb50d8009087a16",
"type": "leaf",
"state": {
"type": "reveal-preview-view",
"state": {},
"icon": "lucide-file",
"title": "Slide Preview"
} }
} }
] ]
@ -199,8 +181,7 @@
} }
], ],
"direction": "horizontal", "direction": "horizontal",
"width": 200, "width": 200
"collapsed": true
}, },
"left-ribbon": { "left-ribbon": {
"hiddenItems": { "hiddenItems": {
@ -217,12 +198,15 @@
"omnisearch:Omnisearch": false "omnisearch:Omnisearch": false
} }
}, },
"active": "cbb50d8009087a16", "active": "c1086d70d8f012dd",
"lastOpenFiles": [ "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/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/Shitter Zero",
"Extracurricular/Circuitree/Committee Market/discussion/CA.md", "Extracurricular/Circuitree/Committee Market/discussion/CA.md",
"Extracurricular/Circuitree/Committee Market/discussion/Committee market ideas.md", "Extracurricular/Circuitree/Committee Market/discussion/Committee market ideas.md",
@ -246,8 +230,6 @@
"Extracurricular/FCG/Radio reception.md", "Extracurricular/FCG/Radio reception.md",
"Extracurricular/Circuitree/Committee Market/Macro pad.md", "Extracurricular/Circuitree/Committee Market/Macro pad.md",
"Operating Systems/assets/Pasted image 20250419143713.png", "Operating Systems/assets/Pasted image 20250419143713.png",
"Operating Systems/Overview.md",
"Languages & Machines/Introduction.md",
"Operating Systems/assets/Pasted image 20250419141856.png", "Operating Systems/assets/Pasted image 20250419141856.png",
"Languages & Machines/assets/Pasted image 20250414190229.png", "Languages & Machines/assets/Pasted image 20250414190229.png",
"Languages & Machines/assets/Pasted image 20250414190144.png", "Languages & Machines/assets/Pasted image 20250414190144.png",
@ -259,7 +241,6 @@
"Extracurricular/Circuitree/Antenna Building", "Extracurricular/Circuitree/Antenna Building",
"Fundamentals of Electronics", "Fundamentals of Electronics",
"Pasted image 20250113151159.png", "Pasted image 20250113151159.png",
"Introduction to Machine Learning/image.png",
"Extracurricular/Misc/Proposed Routine Plan.canvas", "Extracurricular/Misc/Proposed Routine Plan.canvas",
"Introduction to Machine Learning", "Introduction to Machine Learning",
"Operating Systems/assets", "Operating Systems/assets",

View File

@ -1,5 +0,0 @@
==MOVE THIS TO THE CIRCUITREE REPO!==
1. 15m intro presentation (present the problem)
2. 30m discussion
3. 10m distribution

View File

@ -190,8 +190,34 @@ A light-weight process.
- **Kernel Threads** - **Kernel Threads**
- Managed by OS - 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** [^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 [^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.

View File

@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB