Design and Implementation of Linux kernel (II)-Preparations for kernel development

Source: Internet
Author: User


Before trying kernel development, you need to have a general understanding of the kernel. Main Content: Obtain the kernel source code. The kernel source code is structured and compiled. kernel development features 1. obtain the kernel source code www.2cto.com. the kernel is open-source. It is especially convenient to obtain the source code. refer to the following URL to download the compressed source code package through git or directly. Http://www.kernel.org 2. kernel source code structure directory description arch specific architecture code block device I/O layer crypo encryption APIDocumentation kernel source code documentation drivers Device Driver firmware use certain drivers required device firmware fs VFS and various file systems include kernel header file www.2cto.com init kernel boot and initialization
Ipc inter-process communication code: the kernel function is the same as the kernel Function lib of the core subsystem such as the scheduler. Examples of the mm memory management subsystem and the VMnet network subsystem samples are provided, script security Linux security module sound voice subsystem usr early user space code (so-called initramfs) tools used in Linux development virt virtualization Infrastructure 3. the method for compiling the kernel has not actually tried to manually compile the kernel, but has updated the kernel with yum. This classification is manually compiled and then supplemented. After a new kernel is installed, the system will prompt which kernel to enter upon restart. After the new kernel is installed multiple times, the startup list will be very long (because there are many versions of the kernel), which is not very convenient. The following describes three methods to delete unused kernels: (select the corresponding deletion method when installing the kernel) 3.1 rpm Delete method rpm-qa | grep kernel * (find all Linux kernel versions) rpm-e kernel-(version to be deleted) 3.2 yum Delete method www.2cto.com yum remove kernel-(version to be deleted) 3.3 manually delete and delete unnecessary kernel library files in the/lib/modules/directory Delete unnecessary kernel source code in the/usr/src/kernel/directory Delete the cores started in the/boot directory archive kernel image changes grub configuration, delete unnecessary kernel boot list 4. kernel development features 4.1 No standard C library. In order to ensure kernel size and efficiency, the C standard library cannot be used in kernel development, so the most common printf function is not available, but there is a printk function instead. 4.2 When gnu c is used, it is recommended that gcc 4.4 or later versions be used to compile the kernel www.2cto.com. Because gnu c is used, some extensions of gnu c are often used in all kernels: 4.2.1 inline function inline functions are expanded at the place where they are called during compilation, which reduces the overhead of function calls and improves performance. However, frequent use of inline functions can also increase the code length and thus occupy more memory during runtime. Therefore, it is best to meet the following requirements when using inline functions: Small functions are called repeatedly, and strict program time requirements are imposed. Inline Function example: static inline void sample (); 4.2.2 inline assembly is used near the underlying layer or where strict execution time is required. Example: unsigned int low, high; asm volatile ("rdtsc": "= a" (low), "= d" (high )); /* low and high contain 64-bit low 32-bit and high 32-bit respectively */4.2.3 branch statement if a if statement is often true or false in advance, you can use unlikely and likely to optimize the code for this judgment. /* If error is 0 (false) in most cases */if (unlikely (error )){/*... */}/* if success is not 0 (true) in most cases */if (likely (success )){/*... */} www.2cto.com 4.3 has no memory protection. Because the kernel is the lowest-Layer Program, if the kernel accesses illegal memory, the entire system will be suspended !! Therefore, kernel development is more risky than user program development. In addition, the memory in the kernel is non-Paging. Every time one byte of memory is used, the physical memory is one byte less. Therefore, be cautious when using memory in the kernel. 4.4 If you do not use the floating point kernel, you cannot perfectly support floating point operations. When using floating point, you need to manually save and restore floating point registers and other tedious operations. 4.5 The Kernel stack size is small and the size of the fixed kernel stack is determined when the kernel is compiled. for unused architectures, the size of the kernel stack is not the same, but they are all fixed. Run www.2cto.com to check the size of the kernel stack: ulimit-a | grep "stack size" 4.6 synchronization and concurrency Linux is a multi-user operating system, So synchronization and concurrent operations must be well processed, prevent deadlocks due to competition. 4.7 The portable Linux kernel can be used to reflect structures that are not needed and support multiple types of hardware. So always pay attention to portability during development and try to use code unrelated to the architecture.

Related Article

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.