[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
I remember that while I was studying, although the teacher taught the operating system course, my understanding was not very good, and I had less practical content. The course content, such as interrupt, mutex, thread, Io, and other concepts, is often well understood and has no special profound experience. After graduation, I began to spend money to buy some books written by foreign authors, which had changed a lot. However, I did not write or debug the code myself. When we started to simulate the UCOS system on the PC last year and perform one-step debugging on each line of code, we understood the system in essence.
Of course, my understanding of many computer courses has basically stuck on books. Whether it's computer networks, compilation principles, or man-machine interfaces, the knowledge points in books may also be known, but you can't say how thorough it is. After you have read the LWIP, Lua, and ftk code, you will scream. It turns out that this is not very complicated. Therefore, the best way to improve your understanding of computers is to practice.
Many people like to study Linux in China, but most of their understanding of Linux kenel stays on books, videos, and PPT. There are not so many friends who really do experiments and understand every line of code. In fact, compared with the past, the current Linux version is more, more stable, and rich in resources. I personally think that Linux is the best computer learning system. Because no one has helped you in such a system, and many puzzles need to be solved by yourself. Only by overcoming one difficulty can you feel that you have actually made progress. This kind of progress doesn't mean you have learned some kind of configuration, installed some software, and become familiar with some kind of environment, but you have a higher understanding of the system itself, and the angle of viewing the problem has changed.
In the bookstore, there are many books about basic Linux software development, but few books about how to learn, compile, debug, and which debugging tools are appropriate in Linux. What they do is to tell you the answer directly, but there is very little to say about the design. On the one hand, this demand is relatively small, and on the other hand, these knowledge points are a little difficult and not easy to accept. In fact, there is a misunderstanding here. The current Linux kernel development is not that difficult. What you need is a PC and a network cable, in this way, you get all the resources for learning. The following describes how to learn Linux kernel, especially in practice.
(1) Select a suitable Linux release version. My own version is centos 6, which is very convenient to use.
(2) download the kernel code from www.kernel.org and learn how to compile the Linux kernel. The steps are not complex.
A) decompress the Linux kernel version.
B) CD Linux directory
C) CP/boot/config-2.6.32-220.el6.i686. config
D) Make menuconfig
E) Save and exit directly.
F) Make bzimage
G) Make modules
H) Make modules_install
I) make install
(3) restart your computer and choose a new Linux kernel. Start to write the hello. c file, generate a module, use the module to interact with Linux kernel functions, and use dmesg-C to view and print
#include <linux/module.h>#include <linux/init.h>MODULE_LICENSE("GPL");MODULE_AUTHOR("feixiaoxing");MODULE_DESCRIPTION("This is just a hello module!\n");static int __init hello_init(void){ printk(KERN_EMERG "hello, init\n"); dump_stack(); return 0;}static void __exit hello_exit(void){ printk(KERN_EMERG "hello, exit\n");}module_init(hello_init);module_exit(hello_exit);
(4) install the elfutils-devel and systemtap installation packages and use STAP-V *. STP to start Kernel Analysis. All you need to do is insert debugging points, write script files, and freely analyze the kernel code content,
A) Basic Printing
probe begin{ printf("hello begin!\n")}probe end{ printf("hello end!\n")}
B) timed Printing
global numberprobe begin{ number = 0}probe timer.ms(5000){ number ++ printf ("%d\n", number)}probe end{ number = 0}
C) Count syscall calls
global syscallsfunction print_top () { cnt = 0 log ("SYSCALL\t\t\tCOUNT") foreach ([name] in syscalls-) { printf("%-20s %5d\n",name, syscalls[name]) if (cnt++ == 20) break } printf("--------------------------------------\n") delete syscalls}probe kernel.function("sys_*") { syscalls[probefunc()]++}# print top syscalls every 5 secondsprobe timer.ms(5000) { print_top ()}
D) count the number of times the schedule function is called.
global countprobe kernel.function("schedule"){ count ++}probe begin{ count = 0}probe end{ printf("count = %d\n", count);}
E) print the callback Stack
global countprobe kernel.function("schedule").return{ if(!count) print_backtrace() count ++}probe begin{ count = 0}probe end{}
F) record a process Switch
global countprobe begin{ count = 0}probe kernel.function("__switch_to"){ if(!count) { printf("from [%s] to [%s]\n", task_execname($prev_p), task_execname($next_p)) } exit()}probe end{}
For more examples of systemtap, refer to systemtap language reference.