Linux core source code reading method

http://www.cnblogs.com/preacher/p/4647573.html


Usually Linux will have the following directory The
arch subdirectory includes all the core code related to the architecture. It also has deeper subdirectories, each representing a supported architecture. The
include subdirectory contains most of the include files needed to compile the core. It also has deeper subdirectories, one for each supported architecture. include/asm is a soft link to the actual include directory required by this architecture, eg include/asm-i386. To change the architecture, you need to edit the kernel's makefile and rerun the Linux kernel configuration program
init This directory contains the initialization code for the kernel, and is a good starting point to study how the kernel works.
mm This directory contains all the memory management code. The memory management code related to the architecture is located in arch/*/mm/
drivers All device drivers of the system are in this directory. They are divided into device driver classes
ipc This directory contains the core inter-process communication code
modules This is just a directory
fs used to store all the file system code for the established modules. Divided into subdirectories, each supported filesystem contains a
kernel's main core code. Similarly, the core code related to the system is placed in the arch/*/kernel
net core network code
lib directory where the core library code is placed. Architecture-related library code is in arch/*/lib/
scripts This directory contains scripts (such as awk and tk scripts) for configuring the
core It is easier to read the source code in the following order
Core function (kernel)
memory management (mm)
file system (fs)
process communication (ipc)
network (net)
system startup and initialization (init/main and head.S)
others, etc.

System Startup and Initialization (system startup and initialization)

On an Intel system, the kernel starts when loadlin.exe or LILO loads the kernel into memory and passes control to it. See arch/i386/kernel/head.S for this part. head.S does some architecture-dependent setup and jumps to the main() routine in init/main.c.

Memory Management

code is mostly in mm but architecture-related code is in arch/*/mm. The page fault handling code is in mm/memory.c, and the memory map and page cache code is in mm/filemap.c. The Buffer cache is implemented in mm/buffer.c, and the swap cache is in mm/swap_state.c and mm/swapfile.c.

Most of the relatively general code of Kernel

is in the kernel, and the code related to the architecture is in arch/*/kernel. The scheduler is in kernel/sched.c and the fork code is in kernel/fork.c. The bottom half handling code is in include/linux/interrupt.h. The task_struct data structure can be found in include/linux/sched.h

PCI

PCI pseudo-drivers are in drivers/pci/pci.c and system-wide definitions are in include/linux/pci.h. Each architecture has some special PCI BIOS code, the Alpha AXP is located in arch/alpha/kernel/bios32.c

Interprocess Communication

all in the ipc directory. All System V IPC objects include the ipc_perm data structure, which can be found in include/linux/ipc.h. System V messages are implemented in ipc/msg.c, shared memory in ipc/shm.c, and semaphores in ipc/sem.c. Pipes are implemented in ipc/pipe.c.

The interrupt handling code at the core of Interrupt Handling

is almost all microprocessor (and usually platform) dependent. The Intel interrupt handling code is in arch/i386/kernel/irq.c and its definition is in incude/asm-i386/irq.h.

Device Drivers

Most of the Linux core source code is in its device drivers. All device driver source code for Linux is in drivers, but they are further categorized:
/block block device drivers such as ide ( ide.c ). If you want to see how all devices that may contain filesystems are initialized, you can see device_setup() in drivers/block/genhd.c. It not only initializes the hard disk, but also initializes the network, because you need the network when you mount the nfs file system. Block devices include IDE- and SCSI-based devices.
/char Here you can view character-based devices such as tty, serial port, etc.
/cdrom Linux All CDROM code. Special CDROM devices (eg Soundblaster CDROM) can be found here. Note that the ide CD driver is ide-cd.c in drivers/block, while the SCSI CD driver is in drivers/scsi/scsi.c
/pci PCI pseudo-driver. This is a good place to observe how the PCI subsystem is mapped and initialized. Alpha AXP PCI grooming code is also worth looking at in arch/alpha/kernel/bios32.c
/scsi not only drivers for all Linux supported scsi devices but also all SCSI code
/net can be found here Network device drivers such as DEC Chip 21040 PCI Ethernet driver are in tulip.c
/sound The location of all sound card drivers

File Systems (file system)

The source program of the EXT2 file system is in the fs/ext2/ subdirectory, data structure The definitions are in include/linux/ext2_fs.h, ext2_fs_i.h and ext2_fs_sb.h. The data structure of the virtual file system is described in include/linux/fs.h, the code is fs/*. The Buffer cache and update core daemons are both

Network (Network) implemented with fs/buffer.c

The network code is placed in the net subdirectory, and most of the include files are in include/net. The BSD socket code is in net/socket.c, and the Ipv4 INET socket code is in net/ipv4/af_inet.c. The support code for the common protocols (including the sk_buff handling routines) is in net/core, and the TCP/IP networking code is in net/ipv4. Network device drivers are in the drivers/net

Modules (module)

core module code part in the core, part in the modules package. The core code is all in kernel/modules.c, the data results and the message of the core daemon kerneld are in include/linux/module.h and include/linux/kerneld.h respectively. You may also wish to see the structure of an ELF object file in include/linux/elf.h

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326360567&siteId=291194637