scheduling Algorithm for process

Source: Internet
Author: User
Tags cpu usage

In the operating system, the process is a very important concept!!!!

process is a computer program on a data set on a running activity, the system is the basic unit of resource allocation and scheduling, is the basis of the operating system structure. In the early process design-oriented computer architecture, the process is the basic execution entity of the program, and in the contemporary thread-oriented computer architecture, the process is the container of the thread. A program is a description of instructions, data, and its organization, and the process is the entity of the program.

The purpose of the introduction of the process, after the advent of the multi-channel program system, in order to describe the internal dynamics of the system, describing the system of internal procedures of the Movement of the rules introduced a concept, all the multi-channel program design operating system based on the process.

Characteristics of the process:

Dynamics: The essence of the process is that the program multi-Channel program system in the process of execution, the process is generated dynamically, the dynamic extinction.

Concurrency: Any process can execute concurrently with other processes

Independence: The process is a basic unit that can operate independently, and it is also an independent unit for allocating resources and dispatching.

Asynchrony: Because of the inter-process constraints, the process has a discontinuity of execution, that is, the process at its own independent, unpredictable speed ahead

Today is mainly the learning process scheduling algorithm:

(1) FIFO algorithm ( FIFO )

The algorithm always Processor assigned to the process that first enters the ready queue, once a process has been allocated to the processor, it continues to execute until the process is complete or blocked before releasing the processor.

For example, there are three processes P1, P2, and P3 successively ready Queue , they are 21, 6, and 3 units of time, respectively ,

Implementation of the situation such as:

for P1, P2, P3 Turnaround Time is 21, 27, 30, the average turnaround time is 26.

It can be seen that the FIFO algorithm service quality is poor, easy to cause the job user dissatisfaction, often as an auxiliary Scheduling Algorithm .

(2) Short process priority

Minimum CPU run time preferred Scheduling Algorithm (scbf--shortest CPU Burst first)

the algorithm from the Ready Queue The Next "CPU execution period Shortest" process is selected and assigned Processor .

For example, in the Ready Queue There are four processes P1, P2, P3, and P4, and their next implementation period is 16, 12, 4 and 3 units of time, with the following performance:

P1, P2, P3 and P4. Turnaround Time They were 35, 19, 7, 3, with an average turnaround time of 16.

Although the algorithm can obtain better scheduling performance, it is difficult to know exactly the next CPU execution period, but can only be predicted according to the execution history of each process.

(3) Rotation method

The previous algorithms are mainly used for Batch processing System , cannot be used as Time Sharing System in the main Scheduling Algorithm , in the time-sharing system, all use Time Slice rotation law.

Simple rotation: The system queues up all the ready processes in a FIFO rule and assigns the processor to the process in the queue at a certain interval. In this way, all processes in the ready queue can be run with a processor for the time slice .

Multilevel Queue method : Divide all the processes in the system into classes, each class being one level.

(4) Multilevel feedback queue

Multilevel Feedback Queue The way is to set up multiple ready queues in the system and give each queue a different priority.

The following is mainly about the process scheduling method in Linux

the scheduling method under Linux is similar to the above algorithm:

1,sched_other time-sharing scheduling strategy,

2,sched_fifo Real-time scheduling strategy, first-come-first service

3,SCHED_RR Real-time scheduling strategy, Time Slice rotation

The difference between SHCED_RR and Sched_fifo:

when the time slices of the process using the SHCED_RR strategy are exhausted, the system will redistribute the time slices and place them in the ready Queue tail. Placing at the end of the queue ensures that all RR tasks with the same priority are scheduled fairly.

Sched_fifo is always running once the CPU is occupied. Run until a higher priority task arrives or abandons itself.

If a real-time process with the same priority (which is the same as the scheduling weights computed by the priority) is ready, the FIFO must wait for the process to be actively discarded before it can run the same priority task. The RR allows each task to execute for a period of time.

Same point:

Both RR and FIFO are used for real-time tasks only.

The priority at creation is greater than 0 (1-99).

according to preemption priority Scheduling Algorithm proceed.

Real-time tasks of ready state immediately preempt non-real-time tasks.

All tasks are implemented with the Linux time-sharing scheduling strategy.

1, create a task to specify a time-sharing scheduling policy and specify a priority nice value ( -20~19).

2, the execution time on the CPU is determined based on the nice value of each task (counter).

3, if no resources are waiting, the task is added to the ready queue.

4, Scheduler traversal ready Queue , the task will be placed at the end of the ready queue (when the time slice is exhausted (counter is reduced to 0), or when the CPU is actively discarded, by the calculation of the dynamic priority of each task (Counter+20-nice) result, and by selecting the one with the highest calculation result (time slice runs out ) or wait for the queue (the CPU is discarded as a result of waiting for the resource).

5, the scheduler repeats the above calculation process and goes to step 4th.

6, repeat the 2nd step when the scheduler finds that all the ready tasks calculate a weight of less than 0 o'clock.

When all tasks are FIFO,

1, the process is created by specifying a FIFO and setting real-time priority rt_priority (1-99).

2, if no resources are waiting, the task is added to the ready queue.

3, the scheduler traverses the ready queue, according to the real-time priority calculation of the scheduling weights (1000+rt_priority), the highest-weighted task to use the CPU, the FIFO task will always occupy the CPU until a higher priority task is ready (even if the priority is the same) or actively discard ( Wait for the resource).

4, the scheduler discovers that a higher priority task arrives (the high-priority task may be interrupted or the timer task wakes up, or is awakened by the currently running task, and so on), the scheduler immediately in the current task Stack saves all data from the current CPU register and reloads the register data to the CPU from the stack of the high-priority task, at which point the high-priority task begins to run. Repeat the 3rd step.

5, if the current task is actively abandoning the CPU usage due to waiting for resources, the task will be from the Ready Queue , join the wait queue, and repeat the 3rd step at this time.

When all tasks are using RR scheduling policy

1, specify the schedule parameter as RR when creating the task, and set the task's real-time priority and nice value (the nice value will be converted to the length of the task's time slice ).

2, if no resources are waiting, the task is added to the ready queue.

3, the scheduler traverses the ready queue, calculates the scheduling weights (1000+rt_priority) based on the real-time priority, and selects the task with the highest weights to use the CPU.

4, if Ready Queue The RR task time slice in is 0, the task's time slice is set according to the Nice value, and the task is placed at the end of the ready queue. Repeat step 3.

5, the current task, due to wait for resources and actively quit the CPU, it joined Wait Queue the. Repeat step 3.

the system has both time-sharing scheduling and time slice rotation scheduling and FIFO scheduling

The process of 1,RR scheduling and FIFO scheduling belongs to real-time process, and the process of scheduling with ticks is non-real-time process.

2, when the real-time process is ready, if the current CPU is running a non-real-time process, the real-time process immediately preempt the non-real-time process.

both the 3,RR process and the FIFO process use real-time priority as the weighted standard for scheduling, and RR is an extension of the FIFO. FIFO, if two processes have the same priority, then the two priority-like processes are specifically executed by their unknown in the queue , which leads to some injustice (the priority is the same, do not know the first run), If you set the scheduling policy for the two priority tasks to RR, then the two tasks can be executed in a loop, guaranteeing fairness.

Scheduling algorithm for processes

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.