{"componentChunkName":"component---src-templates-post-template-js","path":"/posts/operatingsystems/uniprocessor-scheduling","result":{"data":{"markdownRemark":{"id":"19d66b8f-f557-5e9a-9419-5606d797928a","html":"<h2 id=\"motivation\" style=\"position:relative;\"><a href=\"#motivation\" aria-label=\"motivation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Motivation</h2>\n<p>Given multiple tasks, how do we decide which one to do first?</p>\n<h2 id=\"uniprocessor\" style=\"position:relative;\"><a href=\"#uniprocessor\" aria-label=\"uniprocessor permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Uniprocessor</h2>\n<p>Everything discussed below is work conserving - ie never leaves processor idle</p>\n<h2 id=\"fifofcfs\" style=\"position:relative;\"><a href=\"#fifofcfs\" aria-label=\"fifofcfs permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Fifo/FCFS</h2>\n<p>Perform each task in the order it arrives. Run each task until it finishes</p>\n<p><strong>Pros:</strong> No overhead, fair since every task waits their turn, simple<br>\n<strong>Cons:</strong> If a long task is scheduled before a short task, convoy effect dramatically raises average wait time. Average response time depends on task size distribution</p>\n<h2 id=\"shortest-job-first-sjf--shortest-remaining-time-first-srtf\" style=\"position:relative;\"><a href=\"#shortest-job-first-sjf--shortest-remaining-time-first-srtf\" aria-label=\"shortest job first sjf  shortest remaining time first srtf permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Shortest Job First (SJF) / Shortest Remaining Time First (SRTF)</h2>\n<p>Perform the shortest job first. Run each task till it finishes</p>\n<p><strong>Pros:</strong> Optimal strategy<br>\n<strong>Cons:</strong> Impossible, Increases the variance of average response time, Starvation can occur due to too many short jobs coming in which blocks off the longer jobs on the queue</p>\n<p>This shows that there is a tradeoff between reducing average response time and the variance of average response time</p>\n<h2 id=\"round-robin\" style=\"position:relative;\"><a href=\"#round-robin\" aria-label=\"round robin permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Round Robin</h2>\n<p>Tasks take turns on the processor, if the task is not completed in the given time quanta, it goes to the end of the queue<br>\n<strong>Short time quanta:</strong> Too much time spent context switching, no work will be done\n<strong>Long time quanta:</strong> Tasks spend a long time waiting for a turn\n<strong>Infinite time quanta:</strong> Same as FIFO\n<strong>Zero time quanta:</strong> SJF</p>\n<p>Simultaneous multithreading(SMT)/Hyperthreading: Switch between two processors on a cycle by cycle basis</p>\n<p><strong>Pros:</strong> No starvation<br>\n<strong>Cons:</strong> Context switching takes time, need to evict cache in addition to registers of processor</p>\n<h2 id=\"max-min-fairness\" style=\"position:relative;\"><a href=\"#max-min-fairness\" aria-label=\"max min fairness permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Max min fairness</h2>\n<p>Iteratively maximize the minimum allocation given to a particular process until all resources are assigned</p>\n<p>If all processes are compute bound, this turns into round robin.</p>\n<p>If some processes don’t use entire share of processor becasue they are short running or IO bound, give those processes their entire request and redistribute the unused portion to remaining processes. Recursively distribute unused portions until nothing left. When no remaining requests can be fully satisfied, divide the remainder equally among all remaining processes.</p>\n<p><strong>Pros:</strong> Good for IO bound tasks, no starvation<br>\n<strong>Cons:</strong> Computationally expensive</p>\n<h2 id=\"multi-level-feedback\" style=\"position:relative;\"><a href=\"#multi-level-feedback\" aria-label=\"multi level feedback permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Multi Level Feedback</h2>\n<p>Extension of Round Robin but uses multiple round robin queues, each with a different priority level and time quantum. Higher priority level queues go before lower priority queues, higher priority levels have shorter time quanta than lower levels.</p>\n<p>Meant to favor short tasks over long ones. New tasks enter at top, drops to lower queue when it uses up its time quanta. If task yields the processor bc it is waiting for IO, it stays on the same level, and is removed when task completes.</p>\n<p>Increases Priority when process receives less than its fair shares, reduces priority when process has more than fair share</p>\n<p>Goals: Run short tasks quickly, Low Overhead, no starvation, fair, defers maintenance tasks</p>","fields":{"slug":"/posts/operatingsystems/uniprocessor-scheduling","tagSlugs":["/tag/notes/","/tag/operating-system/"]},"frontmatter":{"date":"2021-10-10T23:46:37.121Z","description":"Notes on the different types of scheduling systems for uniprocessors","tags":["Notes","Operating System"],"title":"Uniprocessor Scheduling"}}},"pageContext":{"slug":"/posts/operatingsystems/uniprocessor-scheduling"}},"staticQueryHashes":["251939775","401334301","825871152"]}