CPU scheduling of the operating system

Source: Internet
Author: User
Tags cpu usage

CPU scheduling for multi-channel programs

The following discusses the scheduling problem for a single CPU.

Review the multi-channel program while importing multiple processes into memory so that a process is used to fill the CPU's time when it performs I/O in the CPU.

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.

The node of the ready queue that waits in memory is the PCB. There are many different ways to implement a queue.

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. This will use the contents of the process synchronization. Lock

For situations where interruptions are possible at any time, we can prohibit interrupts when a piece of code is executed.

The dispatcher is used to hand over the ownership of the CPU to the process selected by the short-term scheduler. Use each time you switch processes.

Dispatch delay: The time it takes to dispatch the program.

Factors to consider for CPU scheduling:

1.CPU usage rate.

2. Throughput: The number of processes that are completed per unit time.

3. 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.

4. Wait time: The sum of the time waiting in the ready queue.

5. Response Time: for interactive systems.

CPU Scheduling algorithm: Gantt to find the waiting time

This algorithm is applied to the memory-ready queue-to-CPU process.

1.FCFS first-come-first service

Once a process is selected, it is no longer possible to switch to another process before the end.

2.SJF Shortest first precision 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.

(1) srtf preemption: Also known as the shortest remaining priority, when the new incoming process CPU interval than the current execution of the process of the remaining CPU interval is short, then preemption.

(2) 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.

3. 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.

4. The runner method RR algorithm preemptive type

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.

5. 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 a foreground queue that has an absolute priority over the background queue, so the allocation between queues is as follows:

(1) A low-priority queue can be performed only if the queue with high priority is empty.

(2) assigning different weights to the queue CPU time, high priority allocation time is many.

6. Multi-level feedback queue preemption

Dynamically adjusting processes, processes moving between queues, although moving between queues can be resource-intensive, but more reasonable.

According to the CPU interval of the squad column.

The partitioning between processes is divided by the CPU time spent, such as queue 0 is the ready queue, and a time upper bound, if a process does not specify the time to complete, it is placed in queue 1. A process with a larger CPU interval is placed in a low priority. Each process begins with a ready queue.

Parameters of the multilevel feedback queue:

1. Number of queues.

2. Scheduling algorithm for each queue.

3. How to upgrade to a higher priority queue.

4. Determine how to downgrade to a lower priority queue.

5. The process needs to determine which queue to enter.

Next, you'll talk about load balancing on multiple CPUs.

Assume that multiple CPUs are isomorphic, but there may be special restrictions, such as only one CPU connected to I/O devices.

(1) Asymmetric multi-processing: One processor is dedicated to CPU scheduling decisions, and others are used to execute user code.

(2) Symmetric multi-processing (SMP): self-scheduling for each processor can cause conflicts when multiple processors simultaneously access the same data structure.

Processor affinity: A process only needs to be executed on one processor and does not go to another processor, because if the transfer, the processor cache resources are all invalid, wasted. The cache stores data that is continuously accessed by the process.

Soft affinity: Does not transfer when occupying.

Hard affinity: The operating system does not allow processes to roam between multiprocessor.

Load balancing conditions: Each processor has a private ready queue.

Load balancing methods: Push and pull. That is, from a high-load processor push to a low-load processor, from a low-load processor pull to a high-load processor, but this is missing processor affinity.

A physical processor can be divided into logical processors, and SMT (symmetric multithreading) enables multiple threads to run concurrently on a single physical processor.

A logical processor is like a thread-to-process for a physical processor. Multiple logical processors share the physical processor's resources, such as cache and bus.

For example, like partitions, hard disks are divided into C-drives, D-disks, etc., but in fact they are not really sub-drives. More theoretically, like the logical and physical relationships of databases.

The system dispatches the kernel thread, and the user thread is managed by the thread libraries. If the thread is to run on the CPU, it needs to be connected to a kernel thread.

The user thread needs to connect to the LWP (process race range PCs).

The kernel line thread attached to the physical CPU (System competitive range SCS).

Linux employs preemptive, priority scheduling algorithms, and higher priority processes are allocated more CPU time slices. Each processor maintains a running queue. The running queue is divided into activities and expirations, the former is the process consumes less time than the time slice, the latter is spent more time than the time slice of the task.

When the active queue is empty, two queues are swapped.

Evaluation of scheduling algorithms:

1. Analysis and evaluation method. Determine the load and algorithm beforehand, i.e. some data that can be set by itself, such as determining the specific algorithm FCFS, determining the time and quantity of the process arrival, and comparing performance according to different models. The disadvantage is that it only applies to specific situations.

2. Queuing model. Mathematical formulas to analyze the interval distribution of CPU and I/O, the time distribution of a given process to the system, and the Queueing network analysis. Little formula: The process entering the queue is equal to the process leaving the queue.

3. Simulation. Modeling computer system, simulation program, randomly generated data based on probability distribution, can not predict the front and back events. But by tracking the tapes to record the operation of the real system, then the simulation can be done in this order.

4. Implementation. Programmed into the operating system, observed.

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.