Process Scheduling Operating System Chapter 2 Summary of Knowledge Points

Series of articles

Chapter One Operating System Overview
Chapter Two Process Description and Control

Chapter 2 Process Management-Scheduling

2.7 Types of scheduling

  • Long-distance scheduling: Deciding which program can enter the system to become a process is the part of creating a process, which takes the longest time
  • Mid-range scheduling: Determine which process can enter the memory, which is the part of the process that is swapped in, and the time is medium
  • Short-range scheduling: Decide which process will run next time, the part that is ready to be converted to run, and takes the shortest time

Execution frequency: short-range scheduling>medium-range scheduling>long-range scheduling

CPU-intensive processes: mainly perform calculation work, occasionally using I/O devices
I/O-intensive processes: execution time mainly depends on the time of I/O operations
The purpose of scheduling: to meet the system goals (performance), to allocate the process to one or more CPUs

2.7.1 Long-range scheduling

  • Control which program can enter, that is, control the degree of concurrency (process density)
  • Decision-making reference factors: FCFS, priority, ddl, I/O requirements

2.7.2 Mid-range scheduling

  • Decide which processes to swap in and which swap out
  • Mid-range scheduling is part of the switching function
  • Swap-in depends on the system concurrency requirements and the storage requirements of the swap-out process

2.7.3 Short-range dispatch (dispatch procedure)

  • Decide which process gets the cpu first
  • Short-range scheduling is called when the current process is blocked or preempted

2.8 Rules for short-range scheduling

Performance
  • Response time: the time from the user's request to the receipt of the response = input transmission t + processing t + response transmission t
  • Deadline: the time or DDL when the task must start
  • System throughput: the number of processes completed per unit time
  • CPU usage rate: the percentage of CPU busy state
  • Turnaround time (residence time): time from process submission to completion = waiting for resource t + processing t (calculation: completion time-submission time)
  • Average turnaround time: Average turnaround time
  • Weighted turnaround time (normalized turnaround time): turnaround time/the time the system really provides services for the process
  • Average weighted turnaround time: Average weighted turnaround time

The above performance indicators are divided into user-oriented and system-oriented:
user-oriented: response time, turnaround time, etc., deadline time
System-oriented: throughput, cpu utilization

Non-performance indicators
  • Predictability
  • Fairness (no hunger)
  • Mandatory priority
  • Balance resources

User-oriented indicators are important in any system. System-oriented indicators are not important in a single-user system. These rules cannot be optimized at the same time.

2.9 Decision mode of scheduling

Divided into two categories

  • Preemption: The current process can be stopped halfway by the OS and execute another process
  • Non-preemption: the process will only be blocked by itself
Timing to preempt
  1. When a new process arrives
  2. Set a blocked state to the ready state after interruption
  3. Clock interrupt
Scheduling selection function

Decide who the next process will be
Three parameters:

  • w Waiting time so far
  • e waiting time so far
  • s Total service time required for the process, s>=e, and need to be estimated or provided by the user

2.10 Scheduling algorithm (emphasis)

Hungry understanding

When it is the process’s turn to use the CPU, another process preempts the CPU for some reason (preemption).
Several people eat a piece of cake. When it’s your turn to eat, the person behind you grabs the portion in front of you and eats you. , You will be hungry if you don’t eat what you should eat

Non-preemptive

FCFS、SPN、HRRN

seize

RR、SRT、Feedback

Low overhead

FCFS、RR

Hungry

SPN、SRT、Feedback

2.10.1 FCFS first come first serve

  • Execute in the order of the requested cpu
  • Not good for short process, refer to supermarket shopping
  • Not good for I/O intensive, because the CPU demand is small
  • It is non-preemptive, no hunger , and the response time may be very long
  • Queue in the cafeteria in the morning to buy breakfast is first come first served

2.10.2 RR time slice round-robin scheduling algorithm RoundRobin

  • Add clock interrupt to FCFS

  • Particularly effective in time-sharing systems or transaction processing systems

  • It belongs to preemption, no hunger algorithm , performance is closely related to time slice setting

    • Length of time: good for long jobs
    • Short time slice: good for short jobs
  • It is not good for I/O-intensive processes: I/O-intensive processes will join the tail of the queue for scheduling after each short-term use of the CPU, while cpu-intensive processes can take up the cpu longer, and I/O-intensive processes take longer than estimated time.

    • You go to the cafeteria for breakfast and line up to buy two eggs (short assignment). When you buy an egg rice card and run out of money (I/O interrupted), you can only charge the card. After the card is fully charged (I/O satisfied) ), you come back in line, you can only line up from the end of the line
  • Improved algorithm: URR

  • Newly added I/O blocked process queue queue, which has a higher priority than ready queue and is more fair than RR

    • You go to the cafeteria to buy two eggs in line for breakfast (short assignment), when you buy an egg rice card and run out of money (I/O interrupted), you can only charge the card, after the card is fully charged (I/O satisfied ), if you come back to line up again, you can just line up the line of people who interrupted buying eggs because of the card charge, instead of line up the line of people who have not bought food
  • On the basis of queuing up for breakfast in the cafeteria in the morning, a time limit is added. If you can't finish the meal within 30 seconds, you will have to line up again...

2.10.3 Short job priority SJF/SPN/SPF

  • The algorithm takes care of short jobs, so it is necessary to know who is "short" in advance, so the premise of the algorithm is that the execution time of all processes is known
  • It is a non-preemptive, hunger algorithm
  • Reduced average turnaround time, because it is non-preemptive, not suitable for time-sharing and transaction processing systems
  • Users are not expected to be able to do SJF on time
  • In the morning, the cafeteria queues up to buy breakfast. Whoever buys things sooner will buy first, but while one person is buying, the other person cannot jump in line

2.10.4 The shortest remaining time priority algorithm SRT

  • Choosing the process with the shortest expected remaining time is to increase the preemption mechanism on the basis of short job priority
  • It belongs to preemption and hunger algorithm
  • The process must record the execution time of the process
  • The average turnaround time is better than short jobs, and the process execution time needs to be estimated
  • In the morning, the cafeteria queues up to buy breakfast. Whoever buys things sooner will buy first. If Xiao Zhang has 1 minute to buy it, then someone who can buy it in 59 seconds will be available. Buy in front of Zhang

2.10.5 HRRN highest response ratio priority algorithm

  • When the current process is completed, the next process with the highest response ratio is selected

  • It is non-preemptive and has a starvation algorithm

  • 响应 比 = (waitTime + serveTime) / serveTime = 1 + waitTime / serveTime

  • You go to the cafeteria to buy breakfast. The queuing time in the cafeteria + the time to buy meals divided by the time to buy meals is the response ratio. The higher the value, the lower your efficiency in buying breakfast.

  • Short jobs have smaller serveTime, larger waitTime/serveTime, larger response ratio and priority scheduling

  • After a long job waits for a long time, waitTime/serveTime increases, the response ratio becomes larger, and scheduling is given priority

  • The algorithm is a dynamic priority adjustment algorithm that combines FCFS and SJF

  • The algorithm not only takes care of short processes, but also prevents long processes from starving for a long time

  • This process requires response ratio calculations and estimated execution time

  • Went to the cafeteria to line up to buy breakfast, Xiao Zhang was in a hurry to go to class, shopping quickly, or Xiao Li buying slowly, but was cut in the queue several times, the aunt, in order not to make everyone angry, allowed them to cut in for dinner

2.10.6 FeedBack feedback scheduling algorithm

  • The idea of ​​this algorithm is to punish long processes, while SJF, SRT, and HRRN give preferential treatment to short processes

  • It belongs to preemption and hunger algorithm

  • Set multiple priority queues to treat differently, the time slices in each queue can be different, and the time slices of the queues with higher priority are short

  • The new incoming process is at the end of the highest priority queue

  • The process in the high priority queue is executed first, and the process time slice is used up before the execution is completed, it will be downgraded to the end of the queue with lower priority

  • Generally, the queue time slice with priority i is 2^i

  • Can better meet the needs of various types of users

  • Terminal users, short job users: interactive jobs are often short jobs, which can be executed in a higher priority queue

  • Long process users: As the process drops in the queue, the allocated time slice is enough to execute

  • Went to the cafeteria to queue up for breakfast. There were several windows, but there was only one aunt who was serving a meal. The aunt asked everyone to form a line and take turns to the first window for dinner. Those who did not finish the meal within 10 seconds went to the second window. Waiting in line, wait for the first window to be empty, the aunt will come to the second window to help everyone prepare, and those who have not finished the fight within 20 seconds will go to the third window to queue up. The third window may have a time limit of 40 seconds. The four and the fifth ones can be deduced by analogy. If another person comes to serve the meal at this time, the aunt will return to the first window to help him serve the meal within 10 seconds. Window queue

2.11 Real-time system and real-time scheduling

Some concepts

The calculation result is time-sensitive, expiration is meaningless, such as news

  • Real-time system: The system can respond to external requests in time (even if), complete the processing of the event within the specified time, and control the coordinated operation of all real-time tasks
  • Real-time tasks: specific processes that have timeliness requirements and are often executed repeatedly
  • Start deadline: must start at the end
  • Deadline for completion: deadline

2.11.1 Real-time task classification

  1. According to the deadline
  • Hard real-time: the deadline must be met, otherwise it will have a destructive impact ( final papers delivered before the deadline )
  • Soft real-time: no mandatory requirement, timeout is still meaningful ( plan to go to bed before 11 o'clock in the evening, although I didn't fall asleep at 11 o'clock, but went to bed earlier than usual )
  1. According to the cycle
  • Non-periodic tasks: total ddl, ( winter vacation homework starts at 3 o'clock, and finished before 6 o'clock )
  • Periodic tasks: there are periodic DDL, ( winter vacation homework starts at 3 o'clock, the Chinese part is written before 4 o'clock, the math part is written before 5 o'clock, and the English part is written before 6 o'clock )

2.11.2 Features of Real-time OS

  • Deterministic: The operation can be performed in an agreed fixed time period
  • Responsiveness: focus on the time to service the interruption
  • User control: the user distinguishes software and hardware in real time and sets priority
  • Reliability: real-time response
  • Failure weakening: When the real-time performance of all processes cannot be met, the real-time requirements of the high-priority tasks are given priority to reduce the loss

2.11.3 Real-time scheduling

  1. Static table scheduling: input periodic arrival time, execution time, periodic end deadline and relative priority of each task, and output the schedule table for scheduling real-time tasks
  • Used to schedule periodic real-time tasks
  • EDF (Earliest Deadline First) algorithm belongs to this type of scheduling
  • Inflexible, any changes will cause the modification of the schedule
  • There are several final exams, you have arranged a schedule to review, but some of the exams have changed the time, and your previous schedule has to be revised
  1. Static priority preemption scheduling: preemption based on priority
  • For scheduling non-real-time multi-program systems
  • Generally set priorities based on the deadline of the task
  • When reviewing, I want to review the more important subjects first, and then review the less important subjects
  1. Dynamic planning and scheduling (dynamic table scheduling): dynamically create a scheduling table for newly arrived real-time tasks and current tasks
  • Under the condition that the current task will not time out, if the new task can be completed, the new task will be executed
  • When reviewing, every time a new exam is announced, you add it to the review plan
  1. Dynamic best effort scheduling
  • Assign priority to newly arrived tasks based on attributes, with the highest priority being scheduled first
  • Do your best to schedule the most advanced tasks first
  • Disadvantages: I don't know if the constraint time can be met, it may cause the original task that did not time out to also time out
  • Simple to implement, used for non-periodic real-time tasks
  • When reviewing, there are still three days to take the high math test. I could have finished the review, but suddenly announced that I took the big thing the day before the high math, so I had to go to review the big thing first. As a result, I might not finish both.
Preemption method
  1. Time slice rotation
  • Response time: second level
  • After the time slice is executed, it is preempted by the next process of FCFS
  • Widely used in time-sharing systems and generally not strict real-time processing systems
  1. Priority non-preemption
  • Response time: 100 milliseconds to second level
  • The real-time process has a higher priority and is executed first, and the next one is scheduled when the current process is completed or blocked
  • Mostly used in multi-pass batch processing systems and less stringent real-time systems
  1. Priority preemption
  • Response time: several milliseconds to tens of milliseconds
  • Priority + clock interruption: real-time process preempts according to priority when the process clock interruption point or process is blocked
  • For general real-time systems
  1. Preempt now
  • Response time: microsecond to millisecond level
  • Direct preemption according to priority
  • For demanding real-time systems

2.11.4 Example of real-time scheduling

Reference information for real-time task scheduling
  • Ready time
  • Start deadline
  • Completion deadline
  • Execution time
  • Resource requirements
  • priority
  • Subtask structure: the part that must be executed (hard real-time part) and the part that can be optionally executed
Scheduling ideas
  1. Decide the scheduling algorithm: decide the priority according to DDL, whoever is the earliest to deal with whom (EDF)
  2. Decide how to preempt
  • The start deadline is clear: adopt a non-preemptive method (the current process is blocked when the point is reached, and the impending process is scheduled, and the impending process will not time out)
  • Clear deadline for completion: take preemption method (judge when to preempt according to the deadline)

For example: for periodic real-time tasks with clear deadlines

  • Periodic Task -> Static Schedule -> EDF Algorithm
  • Clear deadline for completion -> preemption method

For non-periodic real-time tasks with a clear start and deadline

  • Aperiodic -> EDF algorithm that allows CPU idle
  • Prioritize the task with the earliest deadline and let it finish running
  • The CPU utilization rate is not high, but the system tasks can be guaranteed to be completed
Rate monotonic scheduling algorithm RMS
  • Task rate: the reciprocal of the task period (seconds), in hertz
  • Priority determination
  • The shorter the task period, the higher the task rate and the higher the priority
  • That is, the priority function is a monotonically increasing function of task rate
Real-time system processing capacity limitation

That is, the condition that the real-time task system must meet: the
total processor utilization rate of each task in the system cannot exceed 1

2.11.5 Priority inversion

  • That is, the situation where low priority preempts high priority has happened on the Mars Pathfinder of NASA
  • Can occur in any preemptible scheduling scheme based on priority
  • Solution: Priority inheritance: A task with a lower priority inherits the priority of any higher priority task that shares the same resource with it

Guess you like

Origin blog.csdn.net/qq_44722674/article/details/111351587