Linux 2.4 Process Scheduling Analysis 6

zhaozj2021-02-17  51

six. Scheduling related parts of other core applications

Many technologies in the system are related to the scheduler, only a few of them slightly, and do not involve the detail of the technology, only discussions with the schematic part, assuming that the reader has a preliminary understanding of the technology.

Idle process

The initial boot process (init_task) becomes the IDLE process on the CPU 0 after the boot is over. There is an IDLE process on each CPU. As mentioned above, these processes are registered in the init_tasks [] array and can be accessed by IDLE_TASK () macro (see "related data structure"). The IDLE process does not enter the ready queue. After the system is stable, the iDLE process will be scheduled only when the reader is empty.

INIT_TASK's task_struct is a static configuration, defined in the init_task () macro in [include / Linux / Sched.h], and several attributes associated with scheduling are:

State: Task_Running;

Counter: 10 * hz / 100; approximately 100ms on i386

Nice: 0; default priority

Policy: SCHED_OTHER; non-real-time process

CPUS_Runnable: -1; all 1, not running on any CPU

CPUS_ALLOWED: -1; full 1, can run on any CPU

In SMP_INIT () (actually in SMP_BOOT_CPUS () in [Arch / I386 / Kernel / SmpBoot.c]), the init_task's processor property is set to 0, and the corresponding schedule_data also sets the corresponding value. After creating a core thread after executing the init () function ([/init/main.c]rest_init ()), theinit_task sets your own NED_RESCHED equal to 1, then call the CPU_Idle () into the IDLE loop.

In the CPU_Idle (), the NICE value of init_task is set to 20 (minimum priority), and the counter is -100 (unexpected enough), then CPU_Idle () enters an infinite loop:

/ * Selection from [Arch / I386 / Kernel / Processs.c] CPU_IDLE () * /

While (1) {

Void (* idle) = PM_IDLE;

IF (! idle)

IDLE = Default_Idle;

While (! Current-> NEED_RESCHED)

Idle ();

Schedule ();

Check_pgt_cache ();

}

The first time CPU_Idle () during the initialization process, because NEED_RESCHED is 1, so the schedule () is launched directly. As mentioned above, Schedule () will clear the NEED_RESCHED bit, so this loop will be executed until the NEED_RESCHED is set to non-0 (such as in reschedule_idle (), see "scheduler working time ").

There are three implementations of IDLE () functions:

DEFAULT_IDLE (), execute HLT instructions;

Poll_idle (), if "iDle = POLL" is defined on the core parameter, PM_Idle will point to Poll_Idle (), which sets the NEED_RESCHED to special -1, then loop repeatedly until NEED_RESCHED is not equal to -1. Because Poll_Idle () uses a more efficient instruction, running efficiency is higher than default_idle (); the power management-related IDLE process, such as the IDLE process defined in the APM and ACPI modules.

Because only when the read queue is empty, it will be scheduled to the IDLE process, so the check_pgt_cache () operation is only executed when the system is completely idle, and the page table cache is cleared.

2. Process creation

In addition to init_task is manually created, other processes, including the IDLE process, including other CPUs, is created by do_fork (), which is different, using the Clone_PID flag when creating a IDLE process.

In Do_Fork (), the properties of the new process are set to:

State: Task_uninterruptible

PID: If Clone_PID is set, the same is the same as the parent process (only 0), otherwise it is the next reasonable PID.

CPUS_RUNNABLE: All 1; not running on any CPU

Processor: The same as the processor of the parent; where is the child creation, where is it prioritized?

Counter: The parent process is half the value of 1; at the same time, the parent process is also halved. It is guaranteed that the process cannot steal more runtime (same, at the end of the sub-process, its remaining time) The film will also return to the parent process, so as not to suffer from the loss of the time film due to the creation of a child process.

Other values ​​are the same as the parent process

The child process is entered through the SET_LINKS (), then call Wake_up_Process () wake-up (see "Scheduler Working Timer").

转载请注明原文地址:https://www.9cbs.com/read-28423.html

New Post(0)