Operating System Exam Review - Chapter 3 Process Scheduling and Real-Time Scheduling

Process scheduling methods are divided into: preemptive and non-preemptive

When using non-preemptive mode , once the processor is assigned to a process, it will continue to run. The processor of the currently running process will never be preempted due to clock interruption or any other reason. The processor is not allocated to other processes until the process is completed or blocked due to something.

When preemption is used , an executing process is paused according to certain rules and then the processor is assigned to another process. This method is called preemptive. Preemption is not arbitrary and requires compliance with certain rules.

The time slice rotation algorithm is mainly used in time-sharing systems. In this algorithm, the system arranges all ready processes into a ready queue according to the FCFS policy. The scheduling process always chooses the first process in the ready queue to execute, but only Can run for a time slice. After a time slice is used, even if the process is not completed, it must be deprived of the processor to allow the next process to run. Of course, after being deprived, he will queue up again at the end of the queue.

If the time slice is too long, each process can be run to the end, so it is first come, first served. If the time slice is too short, frequent switching will occur, which will cause a lot of processor overhead. Therefore the time slice should be chosen appropriately .

The multi-level feedback scheduling queue combines the time slice rotation scheduling algorithm and the priority scheduling algorithm.

Implementation ideas of multi-level feedback scheduling queue :

1. Set up multiple feedback queues and give each queue a different priority. The first queue has the highest priority, the second queue has the highest priority, and the remaining queues are gradually reduced.

2. The sizes of the running time slices assigned to processes in each queue are different. The higher the priority, the smaller the time slice of the queue.

3. Each queue uses a first-in, first-out algorithm.

4. Schedule according to the priority of the queue

Scheduling algorithm based on the principle of fairness : 1. Guaranteed scheduling algorithm: If there are n processes of the same type running simultaneously in the system, for the sake of fairness, it must be guaranteed that each process gets the same processor time 1/n.

Real-time scheduling

Basic conditions for realizing real-time scheduling

1. Provide necessary information : ready time, start deadline and completion deadline, processing time, resource requirements, priority

2. The system has strong processing capabilities

3. Adopt preemptive scheduling mechanism

4. Has a fast switching mechanism

Real-time scheduling algorithms are also classified into preemptive and non-preemptive

It is divided into earliest deadline first (EDF) and lowest slack (LLF) first algorithms .

Earliest deadline priority (EDF) determines the priority of tasks based on their deadlines. The earlier the task deadlines, the higher the priority. The task with the earliest deadline is at the head of the queue.

Non-preemptive scheduling is used for non-periodic real-time tasks

  • Task 1 is the first to arrive and start execution first.
  • Task 2 and Task 3 arrive during the execution of Task 1. Since Task 3 has an earlier deadline, its priority is higher, so Task 3 is executed after Task 1 is executed.
  • Task 4 arrives during the execution of task 3. Since the earlier the deadline of task 4 is, the higher the priority, task 4 will be executed after task 3 is executed.
  • Last task 2

Preemptive scheduling is used for periodic real-time tasks

In the second line,
the priorities of A and B are fixed, and the priority A>B;
A1 is executed first, and B1 is executed after A1 is executed;
B1 is preempted by A2 after executing 10ms;
B2 continues to be executed after A2 is executed;
B2 is executed after 10ms Preempted by A3;
A3 has reached the deadline of B2 after execution, but B2 executed a total of 20ms, which is obviously lower than the required processing time of 25ms.
In the third line,
the priorities of A and B are fixed, and the priority B>A;
B1 is executed first. After the execution of B1, the deadline of A1 has passed. It can be seen that A1 has not been executed at all.
In the fourth line,
the deadline of A1 is earlier than the deadline of B1, so A1 is executed first; after
A1 is executed, B1 is executed, and A2 arrives 10ms after B1 is executed; the
deadline of A2 is earlier than the deadline of B1, so
A2 is executed first; after A2 is executed, B1 and B1 are executed. A3 arrives after 10ms of execution;
the deadline of B1 is earlier than the deadline of A3, and B3 continues to be executed;
and so on, each task is carried out in an orderly manner and can meet the requirements of the system.

Lowest slack (LLF) first

When this algorithm determines task priority, it is based on the urgency (or slack) of the task. The higher the urgency of the task, the higher the priority.

Mainly used in preemptible scheduling .

Task slack calculation formula: task slack = must-complete time - its own running time - current time

Periodic task A is required to be executed every 20ms and the execution time is 10ms;
periodic task B is required to be executed every 50ms and the execution time is 25ms;
when t=0s, the slack of A1=20ms-10ms-0ms=10ms, The slackness of B1=50ms-25ms-0=25ms, execute A1 first;
after the execution of A1, the slackness of B1=50ms-25ms-10ms=15ms, the slackness of A2=40ms-10ms-10ms=20ms, execute B1 ;
After B1 is executed for 10ms, the slack of B1 = 50ms-25ms-20ms=5ms, the slack of A2 = 40ms-10ms-20ms=10ms, continue to execute B1;

 

Guess you like

Origin blog.csdn.net/m0_53345417/article/details/130491049