Operating system CPU Scheduling

Source: Internet
Author: User
Tags cpu usage
Overview

The basis of a multi-channel program operating system. By switching CPUs between processes, the operating system can increase the throughput rate of the computer.
For single-processor systems, only one process is allowed to run at a time: any other process must wait until the CPU is idle to be dispatched.

The CPU selects a process from the ready queue according to a certain scheduling algorithm, gives the CPU's right to the selected process, and if there is no ready process, a system idle process or system Idle process is scheduled.

Schedule Trigger Event: Create, Wake, exit, ETC Process Control operation process waits for I/O,I/O interrupt clock interrupt (time slice run out, timer to time) appear abort exception dispatch process

While importing multiple processes into memory, the node of the ready queue waiting in memory is the PCB, which allows a process to fill the CPU when the CPU is performing I/O. Typically processes are converted between the CPU interval and the I/O interval.

The CPU scheduler is called a short-term scheduler, from memory scheduling to CPU.

Preemption and non-preemptive scheduling (collaboration): The former takes ownership of the CPU before a process is finished, while the latter has a process to end or wait for I/O to give the other process CPU ownership.

Although modern operating systems use preemption scheduling, there is a risk of accessing one data at a time, such as when a process is trying to update one data, but another process is preempted and the data is read to make the data inconsistent. Process synchronization enables secure access to data.

Scheduling guidelines: CPU usage. Throughput: The number of processes completed per unit time. Turnaround time: Process submission to process completion. That is, the wait time from disk waiting to enter memory + ready queue +cpu Execution time +i/o execution time. But the CPU scheduling algorithm is just one piece inside. Wait time: The sum of the time waiting in the ready queue. Response time: Used for interactive systems.

Specific steps: Save process A's context (program counter, program status Word, other registers) update A's PCB (new status and other information) to move process A to the appropriate queue (ready, blocked, ...) ) Sets the state of process B to the run State from the PCB in Process B recovery Context (program counter, program status Word, other registers)

Cost of context switching: Save and restore register switch address space (related instructions may be expensive) cache and buffer invalidation (cache, buffer cache, TLB) scheduling algorithm

Various scheduling algorithms:

Multiprocessor scheduling: You need to decide on which CPU to take into account the overhead of a process migrating between multiple CPUs (cache invalidation, TLB invalidation), as much as possible to make the CPU always execute on the same process

To consider load balancing issues FCFS first-come-first service
Once a process is selected, it is no longer possible to switch to another process before the end. SJF Shortest priority accurate is the shortest next CPU interval algorithm
As mentioned earlier, a process is made up of alternating CPU intervals and I/O intervals. And SJF is to see which process has the shortest CPU interval. sRTF preemption: Also known as the shortest remaining priority, when the new incoming process CPU interval than the current execution of the process remaining CPU interval is short, then preemption. Non-preemption: called the next shortest priority, because the process of selecting the shortest CPU interval in the ready queue is placed on the team header.
SJF is used for long-term scheduling and cannot be used for short-term scheduling because the process is a whole and the CPU cannot know the length of the first CPU interval in the process.
The SJF needs to determine the length of the next CPU interval, which can be approximated by estimating the length of the next CPU interval, such as tn+1=atn+ (1-A) RN TN, which is the most recent CPU time, and Rn is a historical record. A is the given weight.
Priority scheduling algorithm Pintos priority is 0-63 0 is the lowest priority, 63 is the highest priority
SJF is a special priority scheduling algorithm that prioritizes the inverse of the CPU interval length.
(1) Internal priority: Internal data such as memory requirements.
(2) External priority: User-defined. Set_priority
is divided into preemptive and non-preemptive, the former is replaced if the incoming process priority is higher than the running process, the latter is only queued in the ready queue by priority.
Cons: Wireless blocking or starvation. The former is a high priority and long running process has been blocked, the latter is the low priority process will never be executed.
The way to solve hunger is to age. The wait process priority is lowered after each interval. RR algorithm preemption for runner method
Used for time-sharing systems. Each process consumes a time slice of time. The Ready queue is a FIFO loop queue. If the CPU interval length of a process is less than the time slice, the following process continues, and if the time slice is greater than the break, the interrupt is switched to the next process execution.
Typically, the time slice length is 10ms-100ms, so you need to determine the time slice size so that the context switching times are appropriate. Multi-level queue scheduling
Depending on the nature, a ready queue is divided into separate queues, such as system processes, interactive processes (foreground processes), interactive editing processes, batch processes, and student processes.
Each queue has a different scheduling algorithm.
Each queue has a priority, such as the foreground queue has an absolute priority over the background queue, so the allocation method between queues: Only the high priority queue is empty to execute the low priority queue. Assign different weights to the queue CPU time, high priority allocation time is many.CPU Scheduling Examples

Multi-level feedback queue scheduling algorithm (BSD 5.3) sets multiple ready queues, with the first-level queue priority assigning a different length of time slices to processes in different ready queues, with decreasing priority as the first-level queue is empty, the second-level queue is dispatched, and so on Scheduling of all levels in a time-slice rotation when a new creation process is ready, enter the first level queue if the process discards the CPU due to the time slice being exhausted, it enters the next level of readiness queue if the process discards the CPU because of blocking, it enters the appropriate waiting queue, and after the wait event occurs, The process returns to the end of the original level ready queue (or team head) if preemption is allowed, the preemption process returns to the end of the original level ready queue (or team head)

Priority-based preemptive multi-tasking (Windows) scheduling unit is a thread that takes priority-based preemptive scheduling, which combines a time-quota-adjusted-ready thread into the appropriate queue system, always chooses the highest-priority ready thread to run the same priority thread on a time-slice rotation schedule Multi-CPU system allows multiple threads to run the reference in parallel

"Operating system Concept" version seventh

http://blog.csdn.net/xiazdong/article/details/6280345

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.