Reading Notes _ windows kernel debugging _ part2 _ multi-core Startup Process

Source: Internet
Author: User

 

Multi-core Startup Process

Next we will look at the startup process of multi-core processors. In Part 1, we have introduced that each CPU will execute the kiinitializekernel function, but only the first CPU will execute all the initialization work, including global initialization, other CPUs only execute CPU-related components. The number 0 CPU calls and executes kiinitsystem. the initialization of the idle process is only executed by the number 0 CPU, because only one idle process is required. However, each cpu requires an idle thread, so each CPU executes the code for initializing the idle thread. The kiinitializekernel function uses parameters to understand the current CPU number. The global variable kenumberprocessors indicates the number of CPUs in the system. Its initial value is 0. Therefore, kenumberprocessors points to the current CPU number. Multi-core systems are executed in ascending order of CPU numbers until all CPUs start to run. The first parameter of the expinitializeexecutive function is the CPU number. Many codes in this function are determined based on the CPU number.

For details, refer to the kiinitsystem that can be executed by CPU 0. Kiinitsystem initializes the global data structure of the system. Call keinitializeprocess to create and initialize the idle process, call keinitializethread to initialize the idle thread, and call expinitializeexcutive () to initialize the so-called stage 0. Expinitializeexecutive calls the stage 0 initialization function of each institution of the execution body in sequence, including calling mminitsystem to construct the basic data structure of the page table and Memory Manager, and calling psinitsystem to perform stage 0 Initialization on the Process Manager, call ppinitsystem to enable the plug-and-play manager to initialize the device linked list.

Phase 0 Initialization

Next, let's take a look at the process manager's Stage 0 initialization. Its main tasks include:

1. Define the process and thread object types

2. Create a chain table structure for all processes in the record system, and use the PsActiveProcessHead global variable to point to this chain table. WinDBG later! The process command can only work.

3. Create a process object (PsIdleProcess) for the initial process and name it Idle.

4. Create a system process and thread, and use the Phase1Initialization function as the starting address of the thread. The Phase1Initialization function is used as the end of Stage 0 and connects to the beginning of Stage 1. The Phase1Initialization function does not directly call the initialization function of phase 1, but uses it as the entry function for creating a new system thread. At this time, the current IRQL is very high, so this thread is not executed yet. Only when KiInitlizeKernel returns, KiSystemStartup will reduce IRQL, and the kernel will start to execute this thread the next time it schedules the thread.

Phase 1 Initialization

Stage 1 initialization takes most of the system startup time. Its main task is to call the initialization function of Stage 1 of each institution of the execution body. Some execution parts use the same parameter as the initialization functions of Phase 0 and Phase 1, and use parameters to differentiate them. Call KeStartAllProcessors () to initialize all CPUs, this function will first build and initialize a processor State structure, and then call the HalStartNextProcessor function of the hardware abstraction layer to pay this structure to a new CPU. The new CPU is still executed from KiSystemStartup. Then, call the KdInitSystem function again and call KdDebuggerInitialize1 to initialize the kernel debugging extension DLL (KDCOM. DLL ).

Two calls to kdinitsystem

During Windows Startup, the Kernel debugging engine initialization function KdInitSystem is called twice (Kd, short for Kernel Debug, and all functions starting with kd are used for Kernel debugging ). The first parameter of the KdInitSystem function is the stage number. 0 indicates the first call, and 1 indicates the second call. The first call is called by the entry function KiSystemStartup after the kernel starts execution. The main task is to initialize the data linked list and data structure, the initialization of the communication module, and the initialization of some global variables. During phase 1 initialization, KdInitSystem is called for the second time, mainly to initialize the variable KdPerformanceCounterRate (performance counter frequency.

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.