Linux third week

Source: Internet
Author: User

Linux Kernel directory structure
    • The Arch catalog includes all the core code related to architecture. Each of the subdirectories below represents a Linux-supported architecture, such as i386, a subdirectory of the Intel CPU and its compatible architecture. PC machines are generally based on this directory.

    • The Include directory includes most of the header files needed to compile the core, such as platform-independent header files under the Include/linux subdirectory.

    • The init directory contains the core initialization code (not the system's boot code), with MAIN.C and version.c two files. This is a good starting point for studying how the core works.

    • The MM directory contains all the memory management code. The memory management code associated with the specific hardware architecture is located in the arch/*/mm directory.

    • All device drivers in the system are in the drivers directory. It is further divided into several types of device drivers, each with a corresponding subdirectory, such as the driver of the sound card corresponding to the Drivers/sound.

    • The IPC directory contains the communication code between the core processes.

    • The modules directory contains built-in modules that can be dynamically loaded.

    • The FS directory holds the file system code supported by Linux. Different file systems have different sub-directories, as the Ext3 file system corresponds to the EXT3 subdirectory.

    • The core code for kernel kernel management is here. At the same time, the processor architecture-related code is placed in the Arch/*/kernel directory.

    • NET directory is the core of the network part of the code, each of its subdirectories corresponds to one aspect of the network.

    • The Lib directory contains the core library code, but the library code associated with the processor structure is placed in the arch/*/lib/directory.

    • The scripts directory contains the script files that are used to configure the core.

    • The documentation directory is a document that is a specific description of the role of each directory.

Laboratory building Environment

CD linuxkernel/

Qemu-kernel LINUX-3.18.6/ARCH/X86/BOOT/BZIMAGE-INITRD rootfs.img

qemu:启动一个虚拟机平台-kernel:给一个内核,操作系统-initrd:驱动所需的硬盘rootfs.img:放一个可执行文件由menuOS源代码编译成的init

Access to the menu system, support three commands help version quit

Build yourself

1. Download kernel source code compilation kernel (download, unzip, compile)

2. Make root file system (create directory to store file system)

3. Start Menuos

Third, the analysis of the Start_kernel function of the execution process

The MAIN.C in the Init directory has a function that contains the Start_kernel function

All basic modules need to be start_kernel for initialization.

asmlinkage __visible void __init start_kernel(void)

Among them, there are init_ task,set_ task_ stack_ end_ Magic (&init_task); This is the manually created pcb,0 process, the final idle process.

trap_init();//中断向量初始化mm_init();//内存管理模块初始化sched_init();//调度模块初始化   console_init();//控制模块初始化rest_init(); //其他模块初始化  

where Rest_ init () calls the
-->kernel_ Thread (kernel_ init, NULL, Clone_ FS); Called the
-->run_ init_ Process (ramdisk_ execute_ command);
Init is the first user-state process, which is process number 1th

pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);//创建了线程

In Rest_init, after each part is started,

/* Call to Cpu_idle with preempt disabled */

cpu_startup_entry(CPUHP_ONLINE); 调用static void cpu_idle_loop(void);里面有个while(1)也就是在系统没有进程需要执行时就调度idle进程

Summary: After the Start_ kernel is started, the No. 0 process in the REST_ init will persist.

Linux third week

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.