操作系统 cpu调度
调度标准 (Scheduling Criteria)
There are many criteria which have been suggested for comparing the CPU scheduling algorithms. The characteristics which are used for comparison and then used to determine the best algorithms, for this some of the criteria are given below:
已经提出了许多标准来比较CPU调度算法。 下面列出了用于比较然后用于确定最佳算法的特性,其中一些标准如下:
CPU utilization
CPU利用率
This is the main task in which we have to keep the CPU as busy as possible. Its known, that CPU utilization may range from 0 to 100 percent, but in a case of the real system it should range from 40 percent for the low-level system to 90 percent for high level used system.
这是我们必须使CPU尽可能繁忙的主要任务。 众所周知,CPU利用率可能在0到100%的范围内,但是在实际系统中,CPU利用率的范围应该从低级系统的40%到高级系统的90%。
Throughput
通量
The number of processes which complete their execution per unit time it is called Throughput. In the case of CPU scheduling, CPU is busy in executing the process, then the work is being done, and the work completed per unit time can also be called as throughput.
每单位时间完成其执行的进程数称为吞吐量。 在CPU调度的情况下,CPU忙于执行进程,然后完成工作,并且每单位时间完成的工作也称为吞吐量。
Turnaround Time
周转时间
This is an amount of time to execute a particular process. Turnaround time is the sum of the periods spent waiting to get into memory, executing on the CPU, waiting in the queue and doing I/O i.e. the interval between the time of submission of a process to the time of completion is the turnaround time.
这是执行特定过程的时间。 周转时间是等待进入内存,在CPU上执行,在队列中等待以及执行I / O所花费的时间总和,即,从提交进程的时间到完成时间之间的时间间隔就是周转时间。
Waiting time
等待的时间
It is an amount of time in which a process has been waiting in the ready queue. It only affects the amount of time that a process spends waiting in the ready queue.
这是进程在就绪队列中等待的时间。 它仅影响进程在就绪队列中等待所花费的时间。
Response time
响应时间
It is an amount of time in which the request was submitted until the first response is produced, not output.
这是在产生第一个响应(而不是输出)之前提交请求的时间。
In all these cases we need to maximize the CPU utilization and throughput, and to minimize the turnaround time, waiting time, and respond time.
在所有这些情况下,我们都需要最大化CPU利用率和吞吐量,并最小化周转时间,等待时间和响应时间。
调度算法 (Scheduling Algorithms)
Scheduling algorithms deal with the problems of deciding the process which is in the ready queue and need to be allocated in the CPU. There are some algorithms which are discussed below:
调度算法处理确定准备队列中需要在CPU中分配的进程的问题。 下面讨论了一些算法:
1. First-Come First-Served Scheduling
1. First-Come先服务调度
It is a simplest CPU scheduling algorithm. According to this, the process that requests the CPU first is allocated at the CPU first. FCFS is managed with the help of the FIFO queue. When a process enters into a ready queue it will link up at the tail of the queue and when the CPU is free it allocates the process at the head of the queue and by this running, the process is removed from the queue. This is a very simple algorithm for write and to understand.
它是最简单的CPU调度算法。 据此,首先在CPU上分配首先请求CPU的处理。 借助FIFO队列来管理FCFS。 当进程进入就绪队列时,它将在队列的尾部链接,而当CPU空闲时,它将进程分配在队列的开头,并通过此运行将进程从队列中删除。 这是用于编写和理解的非常简单的算法。
Consider the following process that arrives at a time 0 with the CPU burst time in milliseconds.
考虑以下过程,该过程在时间0到达,CPU突发时间以毫秒为单位。
If the process arrive in the order of P1, P2, P3 in order of FCFS then the Gantt chart for this will be:
如果进程按照FCFS的顺序到达P1 , P2 , P3 ,则用于此的甘特图将为:
i.e. average waiting time will be : (0+26+28)/3 = 18. The FCFS scheduling algorithm is non pre-emptive.
即平均等待时间为: (0 + 26 + 28)/ 3 = 18 。 FCFS调度算法是非抢先式的。
2. Shortest Job first scheduling
2.最短的作业优先调度
This is a different approach in need of CPU scheduling. According to this algorithm when the CPU is free, the process will be assigned which will have the smallest next CPU burst. SJF is optimal which means it will provide the average waiting time for a given set of processes. Let us consider an example with the following set of processes, with the length of CPU burst time given in milliseconds.
这是需要CPU调度的另一种方法。 根据该算法,当CPU空闲时,将分配下一个CPU突发最小的进程。 SJF是最佳的,这意味着它将为给定的一组过程提供平均等待时间。 让我们考虑以下一组进程的示例,其中CPU突发时间的长度以毫秒为单位。
Gantt chart for this will be:
甘特图将是:
i.e. average time by using SJF is (0+3+9+16)/4 =7 milliseconds. As SJF is an optimal algorithm which cannot be implemented at the level of short term CPU scheduling as there is no way to know that the length of the next CPU burst.
即使用SJF的平均时间为(0 + 3 + 9 + 16)/ 4 = 7毫秒。 由于SJF是一种最佳算法,无法在短期CPU调度级别上实现,因为无法知道下一个CPU突发的长度。
3. Priority Scheduling
3.优先调度
In this kind of algorithms, a priority is associated with a process and by that CPU will be allocated to the process which will have the highest priority. By this, we can conclude that larger the CPU burst, the lower the priority and vice versa. Let us consider an example with the following set of the process with the length of the CPU burst time given in milliseconds.
在这种算法中,优先级与进程相关联,并由此将CPU分配给优先级最高的进程。 这样,我们可以得出结论,CPU突发越大,优先级越低,反之亦然。 让我们考虑以下过程集的示例,其中以毫秒为单位给出了CPU突发时间的长度。
In this case, the average waiting time is (0+1+6+16+18)/5 =8.2 milliseconds. Priority scheduling can be either pre-emptive or non-pre-emptive. A major problem with the priority scheduling is starvation which means low priority process never executes and the solution to the problem is aging. Aging is a technique of increasing the priority of the process which had wait in the system for a long time.
在这种情况下,平均等待时间为(0 + 1 + 6 + 16 + 18)/ 5 = 8.2毫秒。 优先级调度可以是抢占式或非抢占式。 优先级调度的一个主要问题是饥饿,这意味着永远不会执行低优先级的进程,并且该问题的解决方案是老化。 老化是一种增加已在系统中等待很长时间的进程的优先级的技术。
4. Round Robin Scheduling
4.循环调度
The round robin scheduling algorithm is designed for a time-sharing system in which a small time is defined termed as time quantum. A time quantum is generally from the 10 to 100 milliseconds. For implementing the RR scheduling the CPU scheduler keeps the process for the ready queue and sets a timer to interrupt after the one-time quantum and then the process will be dispatched. If there are m processes in the queue and the time quantum is q then each process gets 1/m of the CPU time and by this, no process will wait for more than (m-1)q time units.
轮循调度算法是为分时系统设计的,在分时系统中,将定义为小时间的时间称为时间量。 时间量通常为10到100毫秒。 为了实现RR调度,CPU调度程序保留准备就绪队列的进程,并将计时器设置为在一次性运行时间后中断,然后将分派该进程。 如果队列中有m个进程,并且时间量为q,则每个进程获得1 / m的CPU时间,这样,没有一个进程将等待超过(m-1)q个时间单位。
翻译自: https://www.includehelp.com/operating-systems/cpu-scheduling.aspx
操作系统 cpu调度