How to Learn Linux kernel efficiently
Popularity3
2894 times of reading
|
Classification: Linux Kernel
|
Keywords: Linux kernel cultivation Learning
Since it is efficient, it is relatively inefficient. Learning is a very mysterious thing in itself. Some people can get good grades if they don't know how to do it all day, while some others are on the contrary, even if you cast a climbing cone, the performance is still average. A large part of the reason is the learning method.
However, the question of the learning method is not easy to explain, because there is no such standard method based on different situations of everyone, so it is easy to become a big flicker. Just like when Mr. Ren Zhiqiang gave a speech about how to sell a house a while ago, he threw his shoes at the audience because he was too confused.
Next, I will introduce how to learn more efficiently through my own insights.
Linux
Kernel. These words are not limited to some part of the content. They are similar to the slogan. We can also regard them as the big character of kernel learning.
The first sentence is to treat the kernel as a friend. This year, I have a new book called "time as a friend", which tells us that only when we treat time as a friend can we make better use of our time to do useful things. Similarly, we only need to treat the kernel as a friend and put it in a peer-to-peer status. Instead of just a bunch of dead code, we can better understand and understand its essence.
Then the second sentence: use it first. This means that we need to use
Linux
, In accordance with a step-by-step process from top to bottom, skilled in using
Linux
The operating system then studies the implementation in the kernel. This is also
Linus
My opinion.
The third sentence is kernel learning at four levels. In
17
One day in the century, I was bored with writing such a book named "methodology". In this book that most people do not know at present, the method has risen to the theoretical level. In his book, flute summarized the methods of research into a simple sentence:
"
Simplify complex problems
"
.
That is to say, we need to break down complicated problems into many simple small problems and solve them separately. Of course, this sentence can be used for learning the kernel. However, some modifications are required, not just a simple question.
But to divide kernel learning into many different levels, each of which has its own goals and requirements. This is what I think is better at learning the kernel.
Method.
The fourth sentence is to get out of the psychological misunderstanding.
Pair
For complex things such as learning, whether it is our classroom learning in school or kernel learning, the effect of it is good or bad, mainly depends on two aspects: one is the learning method, and the other is learning
Psychology during study. Note: I have ignored the differences in IQ here. IQ is so mysterious that it can be attributed to superstition. However, we often encounter a series of problems or misunderstandings when learning.
These misunderstandings develop a strong understanding in learning, so that we can truly achieve efficiency.
The fifth sentence is to use
VIM + csags + ctags
View the kernel source code. In fact, this sentence mainly means that we need a good tool to browse the kernel code. In
Windows
Below, we may be able to easily find a lot of better
IDE
Can be used to browse code, such
Source insight
It can be easily associated with and read between codes. However,
Linux
For new users, it is a common problem to have a function-like tool to browse code.
The sixth sentence is to use
Kernel
Map positioning target code. It should be said that learning the kernel is to learn the source code of the kernel, but the kernel code is tens of millions, and like a maze, it is difficult to get lost. How can we face it directly? In this case, we need such a kernel map to help us locate the target code to be analyzed and narrow down the scope and amount of the target code.
Connect
Next is the seventh sentence: analyzing the kernel source code, Attitude determines everything. Many of us may be confused and have analyzed and browsed a lot of kernel source code, but we always feel that the analysis is still empty in our mind, and it is not
How much gains do you feel. At this time, we may be able to see if our attitude encountered a problem when analyzing the code. When analyzing the kernel source code, we must follow a rigorous attitude to understand each piece of code.
The implementation of, more questions, more notes, rather than taking a leisurely view of the flowers, a passing attitude, will inevitably have a great harvest.
Most
The next sentence is: Taking the INCORE source code as the center and building learning resources. In our kernel learning process, the kernel source code itself is the best reference material. Any other classic or non-classic books can only be used as an auxiliary tool.
It cannot or should not replace the dominant position of kernel code in our learning process. However, these auxiliary functions cannot be ignored. We need to focus on the INCORE source code and adhere to the long-term construction of various learning resources.
Do not shake.
In addition to the eight sentences, there are many other insights or methods that may help you.
.
When we treat the kernel as a friend, we need to regard the kernel as a living body, rather than a pile of dead code.
With
Specifically, when learning and browsing the implementation of the kernel, we can regard it as a ing of the real world. The kernel is written by people in reality. Therefore, either intentionally or unintentionally, it will inevitably include
Some of our own real feelings, we can understand this context when studying the kernel, this philosophy hidden behind the code. For example, we can think that the kernel is a big world, and processes are one of them.
Processes management and scheduling are the authority in this world. memory is the home of processes, and the goal of the kernel is to make every process have its house.
Since we want to regard the kernel as a fresh individual, the first thing we know about it is to understand some basic information about it, just as we know each other first through basic personal information.
Start with the name,
Kernel
There are two main definitions in the dictionary:
"
Soft, edible part of a nut
"
Linux Kernel
Of course, the second definition is applicable:
"
The core of something
"
. So in a broad sense,
Linux Kernel
Yes
Linux
The most important part of the operating system, but in a narrow sense, it is
Linus
The code written by everyone in the group.
Of course, the code here is quite complex. In terms of code volume alone, it has already exceeded tens of millions. In terms of structure, it has long been impossible for a person to fully understand his own power. So now I want to emphasize the second sentence: to learn the kernel, we should not seek greater perfection. It is not easy to choose a research that is in-depth enough.
The following describes
Kernel
Age,
Kernel
It is not a young girl, so its age does not need to be kept confidential.
1991
The birth of the year began, just last year held its own adult ceremony, entered a mature development period.
Just like we have our own adolescence and mid-year people,
Kernel
There are also a lot of different versions, but the difference is that we don't have to wait until we get off the page,
Kernel
Different Versions coexist.
For many years, the kernel version is
X.y. Z
This
3
Number, an even number in the middle
Y
Stable version, odd
Y
Represents an unstable development version. The so-called stable version means that all features of the kernel are fixed, and the code runs stably and reliably without adding new features. To improve the features, you only need to modify the errors in the code. An unstable version adds new features to the previous stable version and is still developing, so the code is not very reliable.
For the moment,
2.6
The kernel has been released for a long time, So when will it be released?
2.7
?
Linus
My answer is: no
2.7
He will no longer follow the old model, and the new model will be better, and it is not worth repeating. He indicates that he is considering a new numbering method, a time-based version number. For example
2008.7
Replace
2.6.26
, The second digit in the middle represents the year,
2008
Year is
2.8
,
2009
The first version of the year is
2.9.1
, After
2010
Year is
3.0
And so on.
Most
Later I have to mention the dazzling releases. The relationship between the kernel and the release is similar to the Double flowers. Without those releases, the kernel can only be one
It seems that good-looking toys cannot really enter our work and life. Without the kernel, those release versions lack the foundation of existence and can only be a bean curd project.
Now we know the appearance of kernel friends. At this time, we can't just care about external information like those who are not the ones you are the one. We also need to understand the connotation of kernel, that is, the kernel architecture and how the kernel works.
First, let's take a look at the first image, which transmits this information to us.
--
The kernel separates applications from hardware. On the one hand, the kernel is responsible for interacting with computer hardware to control hardware and schedule access to hardware resources. On the other hand, it provides an advanced execution environment for user applications and virtual interfaces for accessing hardware.
Providing hardware compatibility is one of the core design goals. Almost all hardware, as long as it is not customized for other operating systems, can be obtained.
Linux
.
Portability is related to hardware compatibility, that is, running on different hardware platforms.
Linux
Capabilities. Only standards are supported from the beginning
IBM
Compatible machine
Intel x86
The architecture is now supported
Arm
,
MIPs
,
Powerpc
Almost all hardware platforms, such extensive platform support is successful in part because the kernel is clearly divided into system-related parts and system-independent parts. Therefore, we have the second image.
System-independent components usually define interfaces related to the system. In this way, the kernel porting to a new system structure becomes the process of verifying the features of these interfaces and implementing them.
At the same time, the connection between the user application and the kernel is usually through the middle layer between the application and the kernel.
--
Standard
C
Library, and standard
C
Library functions are built on the system calls provided by the kernel. Pass criteria
C
Library, as well as the interface of the system-related parts of the kernel system, user applications and some kernels have become portable.
Because
The third picture is more accurate. Among them, the process management part realizes the abstraction of a process world, which is similar to our human world, but the individual in our world is human, while in the process world
There are processes one by one. We communicate with each other through correspondence, mobile phones, and networks, while processes communicate with each other in different ways, all of us are sharing the same earth, and
All processes are sharing one or more
CPU
.
In this process world, memory is one of the important resources, just like our land. Therefore, memory management is a key factor that determines system performance.
After learning about the kernel architecture, let's take a look at how the kernel works.
First, the kernel makes the application running on it available through system calls. System calling is a bridge between the kernel and applications, compared with
Open ()
,
Close ()
,
Read ()
,
Write ()
For process operations
Fork ()
,
Wait ()
And also for network operations
Socket ()
And so on. They provide an abstraction of the hardware, so sometimes called
Linux
Virtual Machine.
The obvious abstraction provided by the kernel closest to the actual user is the file system, which we can easily exploit.
Open ()
Wait for several systems to call and write a program to open a file and copy its content to the standard output. Through these system calls, the kernel provides users with a file
"
Illusion
"
In fact, it is just a pile of data with a name, so that it does not have to negotiate with the underlying hardware stack, partition and pointer, which is what we often call Abstract
(Billing action)
To express the underlying things in a more understandable way.
The file system is an obvious abstraction provided by the kernel. We can say that the file system is located before the stage, and there are still some behind the scenes, such as process scheduling. In
Linux
On, any
Several processes or programs may be running at a time. Kernel Time Scheduling is assigned to each process
CPU
Time, so for a while, we have the illusion that the computer runs several programs at the same time.
Another example is the memory management behind the scenes, which is invisible to application developers. Each program runs as if it has its own address space for calling. In fact, it shares the physical storage of the computer like other processes. Another aspect of memory management is to prevent a process from accessing the address space of other processes.
--
This is a necessary precaution for a multi-process operating system.
Of course, there are other roles, such as networks, behind the scenes.
Now let's take a brief look at its physical composition. Earlier versions of the kernel are integral, that is, all parts are statically connected to a large execution file.