Download presentation
Presentation is loading. Please wait.
Published byEsmond Lamb Modified over 6 years ago
3
Kernel Stack Desirable for security:
e.g., illegal parameters might be supplied
4
What’s on the kernel stack?
Upon entering kernel-mode: task’s registers are saved on kernel stack (e.g., address of task’s user-mode stack) During execution of kernel functions: Function parameters and return-addresses Storage locations for ‘automatic’ variables
5
Practice Linux Xinu <--US--| and <--I--<--KS--|
8K per process (thread) Separate from user stack PCB contains pointer to the kernel stack Xinu <--I--<--KS--<--US--| On top of user stack
6
PA0
7
PA0. 0-1 0. Step 2, `cs-status | head -1 | sed 's/://g'`
Step 6, cs-console, OR (control-spacebar) .section data .section text .globl zfunction zfunction: pushl %ebp movl %esp, %ebp …. Leave ret Read In C, we count from 0
8
PA0. 2-3 Try “man end” and see what you can get Use “kprint” for output Read “Print the address of the top of the run- time stack for whichever process you are currently in, right before and right after you get into the printos() function call.” carefully You can use in-line assembly Use ebp, esp
9
Others Course Workspace will also be afs based
Course Workspace will also be afs based Moodle forum is up, please use it
10
Lecture 3 Scheduling
11
Workload Assumptions 1. Each job runs for the same amount of time. 2. All jobs arrive at the same time. 3. Once started, each job runs to completion. 4. All jobs only use the CPU (i.e., they perform no I/O). 5. The run-time of each job is known.
12
Tturnaround = Tcompletion − Tarrival
Scheduling Metrics Performance: turnaround time Tturnaround = Tcompletion − Tarrival As Tarrival is now 0, Tturnaround = Tcompletion
13
First In, First Out Work well under our assumption
Relax “Each job runs for the same amount of time” Convoy effect 120 100 20 40 60 80 20 110 Grocery, be nice 120 100 20 40 60 80
14
Shortest Job First SJF would be optimal
Relax “All jobs arrive at the same time.” 120 100 20 40 60 80 50 103.33 B/C arrive 120 100 20 40 60 80 A B C
15
Shortest Time-to-Completion First
STCF is preemptive, aka PSJF “Once started, each job runs to completion” relaxed B/C arrive 120 100 20 40 60 80 A B C A 50
16
Scheduling Metrics Performance: turnaround time
Tturnaround = Tcompletion − Tarrival As Tarrival is now 0, Tturnaround = Tcompletion Performance: response time Tresponse = Tfirstrun − Tarrival
17
Turnaround time or response time
FIFO, SJF, or STCF Round robin 120 100 20 40 60 80 R 40 8 120 100 20 40 60 80
18
Conflicting criteria Minimizing response time
requires more context switches for many processes incur more scheduling overhead decrease system throughput Increase turnaround time Scheduling algorithm depends on nature of system Batch vs. interactive Designing a generic AND efficient scheduler is difficult
19
Incorporating I/O Poor use of resources
Overlap allows better use of resources CPU Disk A A A A B A A A 120 100 20 40 60 80 CPU Disk A B A B A B A B A A A 120 100 20 40 60 80
20
Multi-level feedback queue
Goal Optimize turnaround time without priori knowledge Optimize response time for interactive users Q6 Q5 Q4 Q3 Q2 Q1 A B Rule 1: If Priority(A) > Priority(B) A runs (B doesn’t). Rule 2: If Priority(A) = Priority(B) A & B run in RR. 1 and 2 are not enough C D
21
How to Change Priority Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue). Rule 4a: If a job uses up an entire time slice while running, its priority is reduced (i.e., it moves down one queue). Rule 4b: If a job gives up the CPU before the time slice is up, it stays at the same priority level.
22
Examples Problems? 120 100 20 40 60 80 Q2 Q1 Q0 A B Q2 Q1 Q0 B B B B B
120 100 20 40 60 80 Q2 Q1 Q0 A B Q2 Q1 Q0 B B B B B B B B B B B B A A A A A A A A A A A A 120 100 20 40 60 80 Problems?
23
Priority Boost Q2 Q1 Q0 Q2 Q1 Q0 A A A A A A A 120 100 20 40 60 80 120 100 20 40 60 80 Rule 5: After some time period S, move all the jobs in the system to the topmost queue.
24
Gaming the scheduler Q2 Q1 Q0 Q2 Q1 Q0 A A A A A A A A A A A A A A A A
B B B B B B B B B B B B B B B B B B B B B B B 120 100 20 40 60 80 120 100 20 40 60 80
25
Better Accounting Rule 4a: If a job uses up an entire time slice while running, its priority is reduced (i.e., it moves down one queue). Rule 4b: If a job gives up the CPU before the time slice is up, it stays at the same priority level. Rule 4: Once a job uses up its time allotment at a given level (regardless of how many times it has given up the CPU), its priority is reduced (i.e., it moves down one queue).
26
Tuning MLFQ And Other Issues
How to parameterize? The system administrator configures it The users provides hints
27
Workload Assumptions 1. Each job runs for the same amount of time. 2. All jobs arrive at the same time. 3. Once started, each job runs to completion. 4. All jobs only use the CPU (i.e., they perform no I/O). 5. The run-time of each job is known.
28
MLFQ rules Rule 1: If Priority(A) > Priority(B), A runs (B doesn’t). Rule 2: If Priority(A) = Priority(B), A & B run in RR. Rule 3: When a job enters the system, it is placed at the highest priority (the topmost queue). Rule 4: Once a job uses up its time allotment at a given level (regardless of how many times it has given up the CPU), its priority is reduced (i.e., it moves down one queue). Rule 5: After some time period S, move all the jobs in the system to the topmost queue.
29
Scheduling Metrics Performance: turnaround time
Tturnaround = Tcompletion − Tarrival As Tarrival is now 0, Tturnaround = Tcompletion Performance: response time Tresponse = Tfirstrun − Tarrival CPU utilization Throughput Fairness
30
A proportional-share or A fair-share scheduler
Each job obtain a certain percentage of CPU time. Lottery scheduling tickets to represent the share of a resource that a process should receive If A 75 tickets, B 25 tickets, then 75% and 25% (probabilistically) A B A A B A A A A A A B A B A A A A A A higher priority => more tickets
31
Lottery Code int counter = 0; Int winner = getrandom(0, totaltickets); node_t *current = head; while(current) { counter += current->tickets; if (counter > winner) break; current = current->next; } // current is the winner
32
Ticket currency User A 100 (global currency) -> 500 (A’s currency) to A1 -> 50 (global currency) -> 500 (A’s currency) to A2 User B 100 (global currency) -> 10 (B’s currency) to B1 -> 100 (global currency)
33
More on Lottery Scheduling
Ticket transfer Ticket inflation Compensation ticket How to assign tickets? Why not Deterministic?
34
Next Holiday next Monday Work on PA0 Reading assigned later tonight
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.