Session 1 - Getting started with the Linux Kernel
Tasks
Source Code
Clone the repo with the source code
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Find and analyze the following files or directories: README
, main.c
, development-process/
, tcp.c
, ipv6/
.
Analyze the output of the following commands:
Cscope
The exercises below assume that you are using an already configured cscope and vim editor. For more information about the installation and configuration of cscope, you can check this tutorial.
Go to the directory that has the Linux kernel sources in order to build the cscope database.
Start vim - you can also start it with a C symbol (ex: 'vim -t start_kernel') and it will jump at the symbol's definition in the code.
Put the cursor over a C symbol. Type “CTRL-\ s” (Control-backslash, then just 's'), and you should see a menu with all the uses of the symbol in the program.
Try the same search, but this time via “CTRL-spacebar s”.
CTRL-W w or arrow key, or CTRL-W h/j/k/l for left/up/down/right to move between windows.
Use “CTRL-spacebar CTRL-spacebar s” for vertical split.
If you want to search for a specific symbol, not the one under the cursor, type “:cscope find symbol foo”
Or, more tersely, “:cs f s foo”.
To do the horizontal split version, use “:scscope” (or just “:scs”).
The “CTRL-\ s” (“:cs f s X”) search finds all uses of a symbol X. But if you need more specific searches you only have to change the 's' letter with: 'g' for the global definition(s) of a symbol, 'c' for all calls to a function, 'f' to open the filename under the cursor.
Lets say you hate double pressing “CTRL-spacebar” for a vertical split. Change the mapping so you would only have to press it once for a vertical split.
For more search options use “:help cscope” (in Vim) and/or “man cscope” (from your shell).
Features for larger projects:
You can set $CSCOPE_DB environment variable to point to a Cscope database you create, so you won't always need to launch Vim in the same directory as the database.
When working with larger projects, you may want to exclude some files that increase the amount of code to be parsed and may also contain duplicate definitions. For example, in the Linux sources, you may want to exclude all the code in the docs and scripts directories, plus all of the architecture and assembly code for all chips except for the ones you're interested in (e.g. Intel x86).
Startup Journey
Follow the links from
this page while we discover how the kernel is initialized.
Resources