The Master said, “In virtue is beauty. How can we know if we don’t choose benevolence?” The Analects of Confucius: Li Ren

A hundred blog series. This is:

V13. Xx HongMeng kernel source code analysis (source code comments) | HongMeng is bound to be successful, success is inevitable

Some notes

  • Kernel_liteos_a_note | Chinese annotation HongMeng kernel is based on the OpenHarmony kernel_liteos_a add Chinese annotation to the kernel source code version. Monthly synchronization with official source code, synchronization history is as follows:

    • 2021/9/14Common, Extended, and several directory structures and Makefile adjustments
    • 2021/8/19— Each category has been increasedBUILD.gnFile, file system part file adjustment
    • 2021/7/15— Not much changed, newblackbox.hidumperTo normalize the use of some macros
    • 2021/6/27– Major changes to the file system/device driver, reorganized directory structure
    • 2021/6/08– Major changes to build, task and signal modules
    • 2021/5/28— Minor changes, mainly for spelling correction of some wrong words
    • 2021/5/13— System call, task switching, signal processing, exception takeover, file management, shell has been greatly updated, and the code structure is clearer
    • 2021/4/21— Official optimization of a lot of jokes before, like
    • 2020/9/16— Starting point of Chinese annotated version
  • weharmonyos.com| HongMeng research station

    It is divided into three parts

    • OpenHarmony Developer Docs is a very cool static site for official docs. It supports sidebar/breadcrumb/search/Both English and Chinese. It is very easy to view official docs and greatly improves learning and development efficiency
    • Hundreds of blog analysis hongmeng kernel is the kernel source code annotation process sorted out the content output.
    • Collation of some analysis of the kernel tools and books such as: hongmeng source analysis. Offline documentation, GNU assembly, GN reference manual
  • Subsystem annotation repository

    In the process of annotating the source code of the masked kernel, we found that only annotating the kernel repository is not enough, because it is associated with other subsystems, if you do not understand these subsystems is difficult to annotate the masked kernel completely, so we also annotated some of these associated repositories, including:

    • Compile build subsystem | build_lite

    • Protocol stack | lwip

    • The file system | NuttX

    • The standard library | musl

Why peruse kernel source code?

  • Code farming career, should read the kernel source code. To pour the foundation of computer knowledge building, the firmness of the depth of the foundation, to a great extent, can determine how high the future building can be built. So why do you have to read carefully?
  • Because the kernel code itself is not too much, is a concentrated essence, high frequency, intensive reading is to let each knowledge point is not isolated to dot memory, do not have enough points of knowledge is easy to forget, every bits of bit into line, line of adult and connection, the more remember and stronger, so a short time, easy to form a high concentration, high density of systematic knowledge network, train the brain muscle memory, Live in the brain intuitive area, want to erase can not erase, carry for life, call at any time. Like riding a bicycle, once you learn, even if you don’t ride for many years, you can still walk on it.

Love is all reason and answer

  • Because I read in collegeLinux 2.6Kernel pain and happy experience, always have a wish, how to let more friends interested in kernel to reduce reading time, speed up the understanding of computer system level, rather than give up too early. However, due to various processes, there has been no action for many years, and basically we have to give up this matter. To coincide with2020/9/10Hongmeng officially open source, reactivated the wish for many years, there is a point such as the Yellow River water out of control.
  • At present, the annotation of the kernel source code has been completed 70%, the blog analysis of the kernel source code has been completed 65+, every day is very full, very excited, even dream of the kernel code is in line. So crazy to do a thing or fall in love in those days, because love, love is all the reasons and answers. 😛

“(” · Armament · armament)ゞ the kernel developer

  • Thank you to the Open Atom Foundation, and pay tribute to the Hongmeng kernel developers for providing such excellent source code, a long-cherished wish, with great delight. Perusing the kernel source code to annotate and file can be challenging, in months or even years, but it’s worth it because it’s so hard! If you do difficult things, you will get something. Focus, and you will reap the rewards.
  • Line after line of code in the kernel gives a deep sense of the developer’s hard work and persistence, and the value of the ecosystem for the future, in a way that Internet trolls with their mouths open can never appreciate. It is no exaggeration to say that hongmeng kernel source code can be used as a university C language, data structure, operating system, assembly language, computer system structure, computer composition principle of six courses of teaching projects. Such a treasure, not in-depth study is really reckless, yuxinxin, note firmly believe that hongmeng general trend, the future can be, its success is bound to succeed, oath to do its firm followers and communicators.

Understand the three levels of the kernel

  • General concept mapping level: this level does not involve professional knowledge, but can understand what a concept is with the public cognition known by the public, that is to say, to interpret or map a concept they have never heard with a concept that ordinary people understand. Let unfamiliar knowledge points and the brain in the heart of the knowledge points to establish multiple links, deepen memory. It is important to speak in a way that others can understand!! Can’t a vegetable lady with no computer education know the basic workings of the kernel? Not necessarily! In the series, the author tries to guide the cognition of this level with the story of the kernel source analysis (total catalog), hoping to involve more people to pay attention to the basic software, especially those capital big crocodile, increase the investment in the basic software.
  • Professional Concept Abstraction Level: Professional logic of abstract concept embodied cognition, such as virtual memory, common people is not understand, studied computer people understand, specific how to realize a lot of people don’t understand again, but this does not hinder to become an excellent upper application developers, because virtual memory has been abstracted, purpose is to block the upper the cognition of its concrete implementation. Try to use hongmeng kernel source code analysis (total directory) hundred blogs to disassemble those have been abstract out of professional concepts, hope to be involved in more interested in the kernel of application software talent flow into the basic software and hardware ecology, application software we are invincible universe, but the basic software is very weak.
  • Specific micro code level: this level is specific to the implementation of each line of code, to the point of using code instruction level, what does this code mean? Why do they do that? Is there a better plan? Hongmeng kernel source code annotation analysis attempts to explain the code implementation layer from the details, English is really naturally suitable for the design of programming language human language, computer 01 code mapping to the human world of 26 letters, born too many great miracles. But our mother tongue is destined to a large part of the people there are natural language level of understanding mapping, I hope the hongmeng kernel source code annotation analysis can let more enthusiasts quickly understand the kernel, common progress.

What is the filling method?

  • Because HongMeng kernel 6 w + code, itself only less annotation, Chinese annotation to wrong code into the premise, the original source of all English part is the original comments, all the Chinese part is the Chinese version of the notes, for the convenience of synchronous official version update at the same time, try not to increase the number of rows, code does not destroy the file structure, annotation more similar to the following way:

    At the beginning of the.c/.h file of important modules, make an overall introduction to module functions. For example, the annotation of abnormal takeover module is shown in the figure below:

    During the annotation process, I consulted a lot of materials and books, and attached reference links to specific codes.

  • Function-level annotations go down to important lines, or even each line, such as the body function that applies a mutex, is not unimportant, whereas the official comment is only one line, as shown in the figure

  • In addition, some character diagrams are drawn for easy understanding, embedded directly in the header file, such as the virtual memory panorama, because without these diagrams it is difficult to understand how virtual memory is managed.

What special notations are there

  • Search @note_pic to see the full character graph drawn
  • Search @note_WHY is not clear, if there is clear, please Pull Request to improve
  • Search @note_thinking for some thoughts and suggestions
  • The search @note_#if0 was added for ease of understanding by a third party project that provided extremely important constructs not defined in the kernel source code.
  • Search @note_good to give the source code a thumbs up

The directory structure

/kernel/ Liteos_A ├─ Apps ├─ Arch ├─ ├─ BSD # FreeBSD, ├─ BSD # FreeBSD Such as USB ├ ─ ─ compat # kernel interface compatibility directory │ └ ─ ─ the posix # posix interface related ├ ─ ─ drivers # kernel driver │ └ ─ ─ char # character device │ ├ ─ ─ mem # access to physical I/o device driver │ ├ ─ ─ │ ├─ ├─ Video # ├─ ├─ system ├─ ├─ ├─ system # ├─ system # NuttX open source project │ ├─ FAT # FAT File System │ ├─ jffs2 # JFFs2 file system │ ├─ include # NFS file system │ ├─ Proc # Proc filesystem │ ├ ─ ─ ramfs # ramfs file system │ └ ─ ─ the VFS # the VFS layer ├ ─ ─ the kernel # process, memory, and IPC module │ ├ ─ ─ base # based kernel, │ ├─ Common # ├─ Extended # Including dynamic loading, vdso, liteipc module │ ├ ─ ─ the include # exposed header file storage directory │ └ ─ ─ the user # loading the init process ├ ─ ─ lib # kernel lib library ├ ─ ─.net # network module, ├─ Platform # Support for different chip platform code Such as Hi3516DV300 │ ├ ─ ─ hw # clock logic code associated with the interrupt │ ├ ─ ─ the include # exposed outside the header file storage directory │ └ ─ ─ # uart serial port related logic code ├ ─ ─ platform # support different chip platform code, Like Hi3516DV300, etc. ├─ Security # code Including process rights management and virtual id mapping management ├ ─ ─ the syscall # system call ├ ─ ─ the tools # build tools and related configuration and code └ ─ ─ z # version than the official version of the Chinese listed no new files, only have one more ZZZ directory, inside put some picture/file/tools, # it has nothing to do with the kernel code, you can ignore it, named z to row in the end, the invasion of the directory level to reduce the original code, # ZZZ idea of WeChat name for AAA that help a friend, you should also have them in your WeChat familiar figure: | PCopy the code

Intensive reading of the kernel source code

Four code stores synchronous annotation kernel source code, >> view the Gitee repository

Analysis of 100 blogs. Dig deep into the core

Add comments to hongmeng kernel source code process, sort out the following article. Content based on the source code, often in life scene analogy as much as possible into the kernel knowledge of a scene, with a pictorial sense, easy to understand memory. It’s important to speak in a way that others can understand! The 100 blogs are by no means a bunch of ridiculously difficult concepts being put forward by Baidu. That’s not interesting. More hope to make the kernel become lifelike, feel more intimate. It’s hard, it’s hard, but there’s no turning back. 😛 and code bugs need to be constantly debug, there will be many mistakes and omissions in the article and annotation content, please forgive, but will be repeatedly amended, continuous update. Xx represents the number of modifications, refined, concise and comprehensive, and strive to create high-quality content.

Compile build The fundamental tools Loading operation Process management
Compile environment

The build process

Environment script

Build tools

Designed.the gn application

Ninja ninja

Two-way linked list

Bitmap management

In the stack way

The timer

Atomic operation

Time management

The ELF format

The ELF parsing

Static link

relocation

Process image

Process management

Process concept

Fork

Special process

Process recycling

Signal production

Signal consumption

Shell editor

Shell parsing

Process of communication Memory management Ins and outs Task management
spinlocks

The mutex

Process of communication

A semaphore

Incident control

The message queue

Memory allocation

Memory management

Memory assembly

The memory mapping

Rules of memory

Physical memory

Total directory

Scheduling the story

Main memory slave

The source code comments

Source structure

Static site

The clock task

Task scheduling

Task management

The scheduling queue

Scheduling mechanism

Thread concept

Concurrent parallel

The system calls

Task switching

The file system Hardware architecture
File concept

The file system

The index node

Mount the directory

Root file system

Character device

VFS

File handle

Pipeline file

Compilation basis

Assembly and the cords

Working mode

register

Anomaly over

Assembly summary

Interrupt switch

Interrupt concept

Interrupt management

HongMeng station | into a little bit every day, the original is not easy, welcome to reprint, please indicate the source.