Presentation is loading. Please wait.

Presentation is loading. Please wait.

Project 2: Preemption CS 4411 Spring 2017

Similar presentations


Presentation on theme: "Project 2: Preemption CS 4411 Spring 2017"— Presentation transcript:

1 Project 2: Preemption CS 4411 Spring 2017
xkcd.com/1542

2 Administrative Information
Project 1 is still being graded – results should be ready by beginning of next week. Project 2 will be due Fri 3/3.

3 Fix Project 1 Bugs!!!! First Step
OS prac builds on each project, and P1 is literally the foundation of everything.

4 Purpose Made a major assumption in Project 1
Threads behave nicely and yield CPU Issues? Selfish Threads Starvation Need the ability to interrupt running threads… Selfish Threads

5 P2 Overview Three main parts of P2: Receive Clock Interrupts
Add Alarms Allow threads to sleep Multilevel Feedback Queue Scheduler

6 Introducing Interrupts
Every clock tick the interrupt handler will be called. Allows us to schedule a new thread to be run without relying on nice behavior.

7 Disabling Interrupts For operations that must be atomic
Typically when working with shared data structures. E.g. Modifying the cleanup queue. Trivial way of achieving correctness: disable interrupts for everything. Why is this a bad idea?

8 Interrupt Handler - Reminder
Just a function that runs when an interrupt occurs. Are there problems if the interrupt handler is interrupted? Yes – accessing shared data structures Solution – disable interrupt in the interrupt handler CANNOT BLOCK

9 Alarms Alarms = Schedule a function for future execution
minithread_sleep() Timeouts Each alarms requires a call back function Call back functions might not be executed by the thread that registered the alarm!

10 Performance Matters! Remember, checking alarms will take place inside your interrupt handler. How long does it take to find an element in your Project 1 queue? We need a different approach. You may add extra functionality to your Project 1 queue Some sort of queue where elements have different priorities

11 Scheduling: FIFO Now lets talk about scheduling
Suppose our strategy is FIFO (like in P1) What problems can arise? CPU bound vs IO bound Ice cream analogy, or counting words vs moving your mouse

12 Shortest Job First Suppose our strategy is shortest job first
What problems can arise?

13 What we want Goals: - Short jobs added later don’t starve due to long jobs added earlier - Long jobs don’t get perpetually starved if short jobs keep coming in Also, how do we even know how long a job will take????

14 Introducing the Multi Level Queue!
Round Robin Highest Round Robin Round Robin Idea: Jobs start at highest priority because we have no idea how long it will take Round Robin Lowest

15 Scheduling Total 80 quanta – 1 quanta per thread
1 2 Two numbers, First how long does the CPU spend in that level, then how long does the CPU run each individual thread for in that level 3 Do we achieve our goals?

16 Scheduling If there are no threads in a given level, schedule threads from the next available level Threads are demoted after using up their time for that level Thread level starts at 0 and can only increase throughout its lifetime.

17 Testing There are a lot of parts to this project Common pitfalls
Multi-level queue Interrupts Alarms Thread levels Common pitfalls Unnecessarily disabling interrupts Not disabling interrupts when necessary Multi-level queue corner cases

18 Questions Questions?

19 Project 2 FAQ All library calls are safe: interrupts are automatically disabled upon calling interrupts will be restored to its original state (enabled/disabled) after the call. Units of time PERIOD is defined as 50 ms, which is as a constant. Alarm and wakeup delays are specified in milliseconds. You have to convert units; don’t blindly subtract PERIOD. Irregular/random clock interrupts This is normal Be careful of introducing heisenbugs because of your debug statements.


Download ppt "Project 2: Preemption CS 4411 Spring 2017"

Similar presentations


Ads by Google