Download presentation
Presentation is loading. Please wait.
Published byEustace Neal Modified over 6 years ago
1
Networks and Operating Systems: Exercise Session 2
Salvatore di Girolamo (TA) Networks and Operating Systems: Exercise Session 2
2
Difference between user- and kernel-level threads?
Kernel-level threads: implemented in kernel-space, the OS sees them User-level threads: managed by user-level libraries, much cheaper than kernel threads Advantages/disadvantages Good for frequently blocking applications Scheduling can be inefficient Can block the entire process Significant memory overhead in the kernel Fast switching CPU-time can be assigned according to the their number Slow management operations No OS support required
3
Threads: user- to kernel- level threads mapping
One-to-one Many-to-one Many-to-many Kernel User CPU 0 CPU 1 Kernel User CPU 0 CPU 1 Kernel User CPU 0 CPU 1 Text Data BSS Thread 1 stack Thread 2 stack Thread 3 stack Text BSS Thread 1 stack Thread 2 stack Thread 3 stack Data
4
Scheduling Life of a scheduler: What to schedule? When to schedule? For how long? Scheduler needs CPU to decide what to schedule Any time spent in scheduler is “wasted” time Want to minimize overhead of decisions To maximize utilization of CPU But low overhead is no good if your scheduler picks the “wrong” things to run! Trade-off between: scheduler complexity/overhead and quality of resulting schedule
5
When to schedule? When: A running process blocks (or calls yield())
e.g., initiates blocking I/O or waits on a child A blocked process unblocks I/O completes A running or waiting process terminates An interrupt occurs I/O or timer 2 or 4 can involve preemption
6
Scheduling: Preemption
Difference between preemptive and non-preemptive scheduling? Preemptive: Processes dispatched and descheduled without warning How? timer interrupt, page fault, etc. Non-preemptive: Each process explicitly gives up the scheduler How? Start I/O, executes a “yield()” call, etc. What could be the problem with non-preemptive scheduling? Which one would you use in a real time system?
7
Round-robin Simplest interactive algorithm
Run all runnable tasks for fixed quantum in turn Advantages: It’s easy to implement It’s easy to understand, and analyze Higher turnaround time than SJF, but better response Disadvantages: It’s rarely what you want Treats all tasks the same
8
Priority Very general class of scheduling algorithms
Assign every task a priority Dispatch highest priority runnable task Priorities can be dynamically changed Schedule processes with same priority using Round Robin FCFS etc. Priority 100 Priority 4 Priority 3 Priority 2 Priority 1 T Runnable tasks Priority …
9
Scheduling: First-come first-served
Simplest algorithm! Task Execution time A 24 B 3 C What about the waiting time? Waiting times: 0, 24, 27 Avg. = ( )/3 = 17 A B C 24 27 30
10
Scheduling: First-come first-served
Different arrival order Task Execution time A 24 B 3 C What about the waiting time? Waiting times: 6, 0, 3 Avg. = (0+3+6)/3 = 3 Much better But unpredictable B C A 3 6 30
11
Scheduling: Shortest-job first Task Execution time A 6 B 8 C 7 D 3
Always run process with the shortest execution time. Optimal: minimizes waiting time (and hence turnaround time) Task Execution time A 6 B 8 C 7 D 3 What to do if new jobs arrive (interactive load)? Shortest Remaining Time First: new, short jobs may preempt longer jobs already running D A C B
12
Scheduling: Round Robin
Simplest interactive algorithm Run all runnable tasks for fixed quantum in turn Advantages: It’s easy to implement It’s easy to understand, and analyze Higher turnaround time than SJF, but better response Disadvantages: It’s rarely what you want Treats all tasks the same
13
RT Scheduling: Earliest Deadline First
Schedule task with earliest deadline first (duh..) Dynamic, online. Tasks don’t actually have to be periodic… More complex - O(n) – for scheduling decisions EDF will find a feasible schedule if: Which is very handy. Assuming zero context switch time…
14
Scheduling: exercise Process Burst time Priority P1 10 1 2 5 3 1 4 2
Notes: SJF: equal burst length processes are scheduled in FCFS Priority: non-preemptive priority, small priority number means high priority, equal priority processes are scheduled in FCFS) RR: quantum=1. P2 P3 P4 P5 Time: 1 2 3 4 5 6 7 8 10 9 11 12 13 19 16 14 15 17 18 FCFS: P1 P1 P1 P1 P1 P1 P1 P1 P1 P1 P2 P3 P3 P4 P5 P5 P5 P5 P5 SJF: P2 P4 P3 P3 P5 P5 P5 P5 P5 P1 P1 P1 P1 P1 P1 P1 P1 P1 P1 RR: P1 P2 P3 P4 P5 P1 P3 P5 P1 P5 P1 P5 P1 P5 P1 P1 P1 P1 P1 Source:
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.