Operating system - processor scheduling (study notes)

content

First, the processor scheduling

1. The concept of processor scheduling

2. Three levels of processor scheduling

Advanced Scheduling

Intermediate Scheduling

low-level scheduling

Comparison of Three Schedules

3. Process scheduling

Timing, switching and process

Way

4. Goals and Evaluation Metrics of Scheduling Algorithms

Common Goal of Processor Scheduling Algorithms

Goals of Batch Systems

Evaluation indicators

Second, the scheduling algorithm

1. First Come First Served (FCFS)

2. Short Job First (SJF)

3. High phase ratio priority (HRRN)

4. Time slice rotation (RR)

5. Priority scheduling algorithm

6. Multi-level feedback queue scheduling algorithm


First, the processor scheduling

1. The concept of processor scheduling

Scheduling: When there are multiple tasks that need to be processed, these tasks cannot be processed at the same time due to limited resources. At this time, some kind of rules are needed to determine the order in which these tasks are processed .

Processor scheduling: Select a process from the ready queue according to a certain algorithm and assign a processor to it to run to achieve concurrent execution of the process.

2. Three levels of processor scheduling

Advanced Scheduling

Advanced scheduling is also known as long-range scheduling or job scheduling , and the scheduling object is a job. According to some algorithm, it decides which jobs in the backing queue on the external memory are transferred into the memory, create a process for them, allocate the necessary resources, and put them in the ready queue . Advanced scheduling is mainly used in multi-channel batch systems, and advanced scheduling is not set in time-sharing and real-time systems.

Intermediate Scheduling

Intermediate scheduling is also known as memory scheduling . The operating system will transfer the temporarily inoperable process to the external memory to wait, and the state of the process at this time is called the suspended state. The PCB will not be transferred to the external memory, and the PCB will reside in the memory . Intermediate scheduling is to decide which suspended process is recalled into memory. The main purpose of introducing memory scheduling is to improve memory utilization and system throughput.

low-level scheduling

Low-level scheduling is also known as process scheduling and short-range scheduling , and the objects it schedules are processes (or kernel-level threads). Its main function is to decide, according to some algorithm, which process in the ready queue should get the processor, and the dispatcher will assign the processor to the selected process. Process scheduling is the most basic kind of scheduling , and this level of scheduling must be configured in three types of operating systems: multi-channel batch processing, time-sharing and real-time.

Comparison of Three Schedules

3. Process scheduling

Timing, switching and process

1. The process voluntarily gives up the processor

  • Process terminates normally
  • An exception occurs during operation and terminates
  • The process actively requests blocking (such as waiting for I/O)

2. The process passively abandons the processor

  • The time slice allocated to the process is exhausted
  • Handling more urgent matters (such as I/O interrupts)
  • Processes with higher priority enter the ready queue

3. When the process cannot be switched:

  • in the process of handling an interrupt. The interrupt processing process is complex and closely related to the hardware, so it is difficult to perform process switching during the interrupt processing process.
  • The process is in the critical section of the operating system kernel program.
  • During atomic operations (primitives). Atomic operations are uninterruptible.
     

Process switching has a price, so if process scheduling and switching are performed too frequently, the efficiency of the entire system will inevitably be reduced, so that most of the system time is spent on process switching, and the time actually used to execute the process will be reduced.
 

Way

Non-preemptive: Only processes are allowed to voluntarily relinquish the processor. Even if a more urgent task arrives during the running process, the current process will continue to use the processor until the process terminates or actively requests to enter the blocking.

Preemptive: When a process is executing on the processor, if there is a more urgent or more important need to use the processor, the executing process is immediately suspended and the processor is assigned to the more important and urgent process.

4. Goals and Evaluation Metrics of Scheduling Algorithms

Common Goal of Processor Scheduling Algorithms

 1. High resource utilization

CPU utilization = CPU effective working time / CPU effective working time + CPU idle waiting time
 2. Fairness

Makes all processes get a reasonable amount of CPU time and no process starvation occurs.
 3. Balanced utilization of resources
Because there may be various types of processes in the system, some belong to the computing type, and some belong to the I/O type. In order to make the CPU and various external devices in the system always in a busy state, the scheduling algorithm should keep the balance of system resource usage as much as possible.

 4. Enforcement of policies

The policies formulated, including security policies, must be implemented exactly as needed, even if they cause delays in some work.

Goals of Batch Systems

  •  short turnaround time

Every user wants his turnaround time to be short, and the system wants the average turnaround time to be short.

  • High CPU utilization

Try to choose jobs that are computationally intensive.

  • High system throughput

Throughput refers to the number of jobs completed by the system in unit time.

Throughput of the system = total number of jobs completed / total time spent

Evaluation indicators

Turnaround time: The time interval between when a job is submitted to the system and when the job is completed . (Assignment Completion Time - Assignment Submission Time)

It includes four parts: the time that the job waits for job scheduling (high-level scheduling) on ​​the external memory backup queue, the time that the process waits for process scheduling (low-level scheduling) on ​​the ready queue, the time that the process executes on the CPU , and the process waits for I/O operations. time to finish

Average Turnaround Time = Sum of Turnover Time for Each Job / Number of Jobs

Weighted turnaround time = job turnaround time / job actual allowable time = job completion time - job submission time / job actual allowable time (>=1, the smaller the better the user experience)

Average turnaround time = sum of weighted turnaround time for each job / number of jobs

Wait Time: The sum of the time the process/job waited to be serviced

Response time: the time from the time the user submits the request to the first response


Second, the scheduling algorithm

1. First Come First Served (FCFS)

Scheduling according to the order of arrival, similar to the characteristics of the first-in, first-out queue.

 It will not cause starvation, because even if the waiting time in the queue is long, it will reach the head of the queue for execution.

 example:

2. Short Job First (SJF)

Prioritize short jobs (short service time)

 example:

3. High phase ratio priority (HRRN)

 

At time 0, there is only one process p1, and p1 is scheduled by the processor

Time 7 (p1 gives up the CPU actively): p2 in the ready queue (response ratio: (5+4)/4 = 2.25) p3 (corresponding ratio: (3+1)/1 = 4) p4 (response ratio: (2) +4) / 4 = 1.5) p3 response ratio is the highest scheduled by the processor

8 time (p3 is completed): p2 (2.5), p4 (1.75) p2 is scheduled for execution

Time 12 (p2 completes): p4 is scheduled for execution

Note: These algorithms are mainly concerned with the indicators for evaluating the overall performance of the system, such as fairness to users, average turnaround time, and average waiting time, but they do not care about "response time" and do not distinguish the urgency of tasks. That said, the interactivity is poor. Therefore, these three algorithms are generally suitable for use in early batch systems.
 

4. Time slice rotation (RR)

 

 The time slice size is 2

 The time slice size is 5

Note: If the time slice is too large so that each process can be completed in one time slice, the time slice round-robin scheduling algorithm degenerates into a first-come, first-served scheduling algorithm and increases the process response time. Therefore the time slice cannot be too large.
There is a time cost for process scheduling and switching (saving and restoring the running environment). Therefore, if the time slice is too small, the process switching will be too frequent, and the system will spend a lot of time processing the process switching, resulting in the actual use of process execution. The time scale is reduced, so the time slice cannot be too small.
 

The time slice size is generally chosen to be slightly larger than the time required for a typical interaction.

5. Priority scheduling algorithm

example:

non-preemptive

                The higher the priority number, the higher the priority

preemptive

Of course, this is a static priority: it is determined when the process is created, and it remains unchanged thereafter. There is also dynamic priority, which has an initial value when a process is created and will change continuously thereafter. For example, each time a time slice is executed, the priority is -1

6. Multi-level feedback queue scheduling algorithm

1. Set up a multi-level ready queue, the priority of each level of queue is from high to low, and the time slice is from small to large.
2. When a new process arrives, it first enters the first-level queue, and queues up according to the FCFS principle to wait for the allocated time slice. If the time slice process has not ended, the process enters the end of the next level queue. If it is already in the lowermost queue at this time, it will be put back to the end of the lowermost queue.
3. Only when the k-th level queue is empty, will the time slice be allocated to the process at the head of the k+1 level queue and the process that preempts the processor will be put back to the end of the original queue.

example:

Refer to "Operating System for Wangdao Postgraduate Examination" and "Computer Operating System" (Tang Xiaodan Fourth Edition)

Guess you like

Origin blog.csdn.net/qq_52595134/article/details/121643424