Title: Class 11: Smarter Scheduling
Date: 2014-02-27
Category: Classes
Tags: operating systems, Apple fail, scheduling, round-robin, priority inversion
Author: David Evans

   <div class="todo">
**[Problem Set 3](|filename|../../pages/ps/ps3/ps3.md)** is due by
  11:59pm on **Wednesday, 5 March** (note this is a two-day extension
  from the original due date).  You should have definitely at least
  finished Problem 5 by today.  

  **Exam 2** has been postponed until after Spring Break (schedule to be
    announced later).  If you follow a hard real-time scheduling policy,
    though, you can elect to do the exam according to the original
    schedule.  If you want to do this, let me know by Friday (28 Feb).
   </div>

   <center>
   <iframe src="http://www.slideshare.net/slideshow/embed_code/31792578" width="476" height="400" frameborder="2" marginwidth="0" marginheight="0" scrolling="no"></iframe><br>
[Videos](https://www.youtube.com/playlist?list=PLvpsxlEF9cP2mphWRTf0K0-0MJGpoq1cZ)
   </center>

## Readings

The OSTEP book covers scheduling in these sections:

- [7. Scheduling: Introduction](http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-sched.pdf) 
- [8. Scheduling: The Multi-Level Feedback Queue](http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-sched-mlfq.pdf)
- [9. Scheduling: Proportional Share](http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-sched-lottery.pdf) (Lottery Scheduling)
- [10. Multiprocessor Scheduling](http://pages.cs.wisc.edu/~remzi/OSTEP/cpu-sched-multi.pdf)

These provide a lot more detail on several of the scheduling policies we
discuss in class, as well as several policies we didn't cover in class.
You are not expected to know details of other scheduling policies beyond
what we discuss in class and what you explore in PS3, but you should
find these sections well worth reading.

The _Shortest Job First_ and _Shortest Time-to-Completion First_
policies described in Section 7 are similar to the SRPT policy you are
implementing for PS3 Problem 5 (you should consider which one of these
is closer to what you should do for PS3).

## Scheduling Recap

<center>
<iframe width="640" height="360" src="//www.youtube-nocookie.com/embed/w3XjhJ7Ex1Y?list=PLvpsxlEF9cP2mphWRTf0K0-0MJGpoq1cZ" frameborder="0" allowfullscreen></iframe>
</center>

When is planned scheduling used?
<div class="gap">

</div>

What is a _hard real-time system_?
<div class="gap">

</div>

## Scheduling Strategies

<center>
<iframe width="640" height="360" src="//www.youtube-nocookie.com/embed/hMGZx3N1czs?list=PLvpsxlEF9cP2mphWRTf0K0-0MJGpoq1cZ" frameborder="0" allowfullscreen></iframe>
</center>


**First Come, First Served** (FIFO): processes run to completion, in the
  order they are started.

**Round-Robin**: each process gets to run for a given time slice (or
  until it finishes or is blocked).

What are the advantages and disadvantages of Round-Robin scheduling
compred to First Come, First Served?

<div class="gap">
</div>

## Exploring Processes and Priorities

<center>
<iframe width="640" height="360" src="//www.youtube-nocookie.com/embed/1GiUVZOZdts?list=PLvpsxlEF9cP2mphWRTf0K0-0MJGpoq1cZ" frameborder="0" allowfullscreen></iframe>
</center>

What does the priority of a process mean?
<div class="gap">

</div>

Try this: `ps -w -e -o pri,pid,pcpu,vsz,cputime,command | sort -n -r --key=5 | sort --stable -n --key=1`

## Preemptive Priority Scheduling

<center>
<iframe width="640" height="360" src="//www.youtube-nocookie.com/embed/_l1FK8CimRk?list=PLvpsxlEF9cP2mphWRTf0K0-0MJGpoq1cZ" frameborder="0" allowfullscreen></iframe>
</center>

- Always run the _highest priority process_ that is ready to run
- _Round-robin_ schedule among equally high, ready to run, highest-priority
processes

What are the advantages and disadvantages of preemptive priority
scheduling?

<div class="gap">

</div>

What really happened on Mars?  [Glen Reeve's account](http://research.microsoft.com/en-us/um/people/mbj/mars_pathfinder/authoritative_account.html)

<div class="gap">

</div>

Is priority inheritance a good solution?

<div class="gap">

</div>

## Lottery Scheduling

<center>
<iframe width="640" height="360" src="//www.youtube-nocookie.com/embed/qAx4IxrOoAM?list=PLvpsxlEF9cP2mphWRTf0K0-0MJGpoq1cZ" frameborder="0" allowfullscreen></iframe>
</center>

Carl Waldspurger's PhD dissertation: [_Lottery and Stride Scheduling:
Flexible Proportional-Share Resource
Management_](http://www.waldspurger.org/carl/papers/phd-mit-tr667.pdf)
(If you are considering going to grad school and want a good model of
what a PhD involves, this is the best example I know of a [dissertation
worth reading](http://www.paulgraham.com/college.html).)

## Stride Scheduling

What are the advantages of stride scheduling over lottery scheduling?

<div class="gap">

</div>

<div id="disqus_thread"></div>

<script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'rust-class'; // required: replace example with your forum shortname
	var disqus_url = 'http://www.rust-class.org/class-11-smarter-scheduling.html';

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
