Basic Concepts

CPU –I/O Burst Cycle

• Process execution consists of a cycle of CPU execution and I/O wait.
• Process execution begins with a CPU burst, followed by an I/O burst, then another CPU burst ... etc

• The duration of these CPU bursts has been measured.

• An I/O-bound program would typically have many short CPU bursts, A CPU-bound program might have a few very long CPU bursts

• this can help to select an appropriate CPU-scheduling algorithm.

Types of Processes

I/O bound

• Has small bursts of CPU activity and then waits for I/O (eg. Word processor)
• Affects user interaction (we want these processes to have the highest priority)

CPU bound

• Hardly any I/O, mostly CPU activity (eg. gcc, scientific modeling, 3D rendering, etc.)
• Useful to have long CPU bursts
• Could do with lower priorities

CPU Scheduler

The CPU scheduler is the mechanism to select which process has to be executed next and allocates the CPU to that process. Schedulers are responsible for transferring a process from one state to the other.
3 types of schedulers(recall L1):
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
When timer interrupt occurs or when running process is blocked on I/O, scheduler run
Scheduler picks another process from the ready queue
Performs a context switch

Preemptive scheduling

  • 抢占式调度

The system may stop the execution of the running process and after that, the context switch may provide the processor to another process. The interrupted process is put back into the ready queue and will be scheduled sometime in future, according to the scheduling policy.

Non-preemptive scheduling

When a process is assigned to the processor, it is allowed to execute to its completion, that is, a system cannot take away the processor from the process until it exits. Any other process which enters the queue has to wait until the current finishes its CPU cycle.

典型process的状态图

Schedulers

-Decide which process should run next

CPU scheduling takes place on 4 circumstances:

1. When the process changes state from Running to Ready ex: when an interrupt occurs .
2. Changes state from Running to Waiting ex: as result of I/O request or wait().
3. Changes state from Waiting to Ready ex: at completion of I/O.
4. Process Terminates.
• Scheduling under 2 and 4 is nonpreemptive - a new process must be selected
• Other scheduling is preemptive - either continue running the current process or select a different one

Dispatcher

Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves:
– switching context
– switching to user mode
– jumping to the proper location in the user program to restart that program
Dispatch latency(调度延时) – time it takes for the dispatcher to stop one process and start another running.
Dispatcher is invoked during every process switch; hence it should be as fast as possible

Scheduling Criteria

Max CPU utilization – keep the CPU as busy as possible

Max Throughput(吞吐量) – complete as many processes as possible per unit time
Fairness - give each process a fair share of CPU
Min Waiting time – process should not wait long in the ready queue
Min Response time – CPU should respond immediately

Scheduling Algorithms

术语

Arrival Time (AT): Time at which the process arrives in the ready queue.
Completion Time: Time at which process completes its execution.
Burst Time: Time required by a process for CPU execution.
Turnaround Time (TT): the total amount of time spent by the process from coming in the ready state for the first time to its completion.
        Turnaround time = Exit time - Arrival time
Waiting Time (WT): The total time spent by the process/thread in the ready state waiting for CPU.
        Waiting Time = Turnaround Time – Burst Time
Response time: Time at which the process gets the CPU for the first time.

First-Come, First-Served (FCFS) Scheduling

Processes are executed on first come, first serve basis.

Poor in performance as average wait time is high
Waiting time for P1 = 0; P2 = 24; P3 = 27
Average waiting time: (0 + 24 + 27)/3 = 17

Shortest-Job-First (SJF) Scheduling

Schedule process with the shortest burst time
without preemption
Advantages
– Minimizes average wait time and average response time
Disadvantages
Not practical : difficult to predict burst time
        • Learning to predict future
– May starve long jobs

Average waiting time = (0+3+9+16) / 4 = 7

The real difficulty: knowing the length of the next CPU request
- with short-term scheduling, there is no way to know the length of the next CPU burst.
SJF cannot be implemented at the level of the short-term CPU scheduling

Determining Length of Next CPU Burst

Estimate it using lengths of past bursts: next = average of all past bursts.

Exponential averaging: next = average of (past estimate + past actual)
Let tn = actual length of the nth burst;
Tn+1 = predicted value for the next CPU burst;
a = weighing factor, 0 ≤ a ≤ 1

The estimate of the next CPU burst period is:

Commonly, a set to ½

- If a=0, then recent history has no effffect
- If a=1, then only the most recent CPU bursts matter

Shortest Remaining Time First (SRTF) Scheduling

Average waiting time = [(10-1)+(1-1)+(17-2)+(5-3)]/4 = 26/4 = 6.5 msec

Priority Scheduling

Each process is assigned a priority (just a number)
The CPU is allocated to the process with the highest priority (smallest integer)
Priorities may be:
        Internal priorities based on criteria within OS. Ex: memory needs.
        External priorities based on criteria outside OS. Ex: assigned by
        administrators

PROBLEM: Starvation – low priority processes may never execute
SOLUTION: Aging – as time progresses increase the priority of the process
Example: do priority = priority – 1 every 15 minutes

Average waiting time = = (0 + 1 + 6 + 16 + 18) / 5 = 8.2

Round Robin(RR) Scheduling

Each process gets a small unit of CPU time (time quantum or time-slice), usually 10-100 milliseconds.
After this time has elapsed, the process is preempted and added to the end of the ready queue Ready queue is treated as a circular queue
If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
Performance
q large  RR scheduling = FCFS scheduling
        q small  q must be large with respect to context switch, otherwise overhead is too high

e.g.

Multiple-Level Queues Scheduling

• Ready queue is partitioned into separate queues; e.g., two queues containing
        o foreground (interactive) processes . May have externally defined priority over                       background processes
        o background (batch) processes
Process permanently associated to a given queue; no move to a different queue
There are two types of scheduling in multi-level queue scheduling:
        • Scheduling among the queues.
        • Scheduling between the processes of the selected queue.
Must schedule among the queues too (not just processes):
        Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation.
        Time slice – each queue gets a certain amount of CPU time which it can
schedule amongst its processes;

80% to foreground in RR, and 20% to background in FCFS
The various categories of processes can be:
• Interactive processes
• Non-interactive processes
• CPU-bound processes
• I/O-bound processes
• Foreground processes
• Background processes

Multilevel Feedback Queue Scheduling

Multilevel feedback queues - automatically place processes into priority levels based on their CPU burst behavior.
• I/O-intensive processes will end up on higher priority queues
and CPU-intensive processes will end up on low priority queues.

A process can move between the various queues
        - aging can be implemented this way.
A multilevel feedback queue uses two basic rules:
1. A new process gets placed in the highest priority queue.
2. If a process does not finish its quantum, then it will stay at the same priority level otherwise it moves to the next lower priority level
Multilevel-feedback-queue scheduler defined by the following parameters:

– number of queues
– scheduling algorithms for each queue
– method used to determine when to upgrade a process
– method used to determine when to demote a process
– method used to determine which queue a process will enter when that process needs service

Three queues:
Q0 – RR with time quantum 8 milliseconds
▪ Highest priority. Preempts Q1 and Q2 proc’s
Q1 – RR time quantum 16 milliseconds
▪ Medium priority. Preempts processes in Q2
Q2 – FCFS
▪ Lowest priority

A new job enters queue Q0  ->  If it does not finish in 8 milliseconds, job is moved to queue Q1  and receives 16 additional milliseconds  ->  If it still does not complete, it is preempted and moved to queue Q2

CPT104操作系统笔记(scheduling I)相关推荐

  1. 操作系统存储器管理实验报告_献上膝盖!华为工程师抛出一份堪称“举世无双”操作系统笔记...

    写在前面 操作系统在计算机行业中是一门最基础的技术,无论是在开发项目还是在算法岗,我们都是基于计算机上进行的,我们对操作系统的了解体现我们从事计算机相关岗位的资深素质,因此,接下来,这篇文章给大家介绍 ...

  2. 操作系统笔记整理12——磁盘存储器的管理

    点此链接可跳转到:操作系统笔记整理--目录索引页 参考书籍:<计算机操作系统>第四版 汤小丹等编著 文章目录 点此链接可跳转到:操作系统笔记整理--目录索引页 外存的组织方式 连续组织方式 ...

  3. 【王道考研】操作系统 笔记 第一章

    特此鸣谢王道考研 本文参考王道考研的相关课程 若有侵权请联系,立删 其余笔记链接: [王道考研]操作系统笔记 第一章_才疏学浅743的博客-CSDN博客 [王道考研]操作系统 笔记 第二章上 进程调度 ...

  4. 操作系统笔记 第二章

    操作系统笔记 第二章 1.有两个程序:A程序按顺序使用CPU10秒.设备甲5秒.CPU5秒.设备乙10秒.CPU10秒:B程序按顺序使用设备甲10秒.CPU 10秒.CPU5秒.设备乙5秒.CPU 5 ...

  5. 操作系统笔记——Linux系统实例分析、Windows系统实例分析

    文章目录 传送门 Linux进程管理 Linux进程组成 Linux进程链表 Linux进程控制 用户进程创建与撤销 0,1,2号进程 Linux进程切换 Linux进程调度 内核同步 Linux储存 ...

  6. 【王道考研】操作系统 笔记 第二章上 进程调度

    本文内容,1.进程和线程 2.进程调度 特此鸣谢王道考研 本文参考王道考研的相关课程 若有侵权请联系,立删 其余笔记链接: [王道考研]操作系统笔记 第一章_才疏学浅743的博客-CSDN博客 [王道 ...

  7. OrangeS操作系统笔记1_环境的配置与第一个系统

    OrangeS操作系统笔记1_环境的配置与第一个系统 前言 开始学习Orange's:一个操作系统的实现,记录并总结一下学习中遇到的一些问题,由于我汇编基础几乎为0,对计算机也不是很了解,所以写的这些 ...

  8. 操作系统笔记——概述、进程、并发控制

    文章目录 传送门 概述 入门书籍与视频推荐 定义操作系统 操作系统的形成 顺序处理(无操作系统) 批处理系统 单通道批处理系统 多通道批处理系统 分时系统 实时系统 嵌入式系统 操作系统类型总结 操作 ...

  9. 现代操作系统笔记 2.1 进程

    现代操作系统笔记 2.1 进程 前言 从本章开始我们将深入考察操作系统是如何设计和构造的.操作系统中最核心的概念是进程:这是对正在运行程序的一个抽象. 操作系统的其他所有内容都是围绕着进程的概念展开的 ...

最新文章

  1. 怎样写C代码——《狂人C》习题解答1(第一章习题7)
  2. 为了更高效的开发代码,这里列出了一些webstorm的快捷键和zencoding
  3. wsl用户帐户没有必要的权限_Windows的Linux子系统(WSL)即将带来图形化应用
  4. 中国.COM域名注册量达404万个 排名全球第三
  5. java 界面框架源码_轻量级java web实践-8(框架源码-6)
  6. pytorch Alexnet
  7. php无限级回复页面如何嵌套,php无限级评论嵌套实现代码
  8. 10月8日提交的结对编程工程中的经验和教训
  9. 91卫图助手-使用及下载
  10. log4cpp编译安装
  11. 把握人类的八大本能,让你拥有“营销作弊器”
  12. 创建第一个Android Kotlin应用
  13. Microbiome:根际微生物影响植物开花时间
  14. 【设计模式系列】--单例模式
  15. 函数部分编程大作业(持续更新)
  16. 一台电脑如何开俩虚拟机_一台电脑两个系统怎么实现?虚拟机安装系统了解一下...
  17. 奥鹏计算机文化基础在线考试,奥鹏中国石油大学北京《计算机文化基础》在线考试客观题答案.doc...
  18. 二叉树的前序中序后序遍历图示
  19. Centos8安装Python3
  20. centos7.6使用kubeadm安装kubernetes的master worker节点笔记及遇到的坑

热门文章

  1. 睡眠监测APP开发了解睡眠数据
  2. 女神节,谈美工和美编
  3. div实现简单的页面布局
  4. 某某程序员对加班的看法
  5. 不要玩羊,会变得不幸
  6. 【BAT批处理】while 10000 删除MP3文件,中文字符,密码显示*号,计数,延时,循环
  7. lbp代码matlab实现,统一化LBP算子UniformLBP的MATLAB实现程序
  8. 思科和华为常见命令对比
  9. Raspberry Pi Pico 之YL-56声音传感器模块
  10. Solidworks窗口程序