Computer System
References
- Tutorial: linuxjourney
- O’Reilly series:
- Understanding Linux Kernel
- Understanding Linux Network Internals
- Linux Device Drivers
- The Linux Programming Interface
- INTEL 80386 PROGRAMMER’S REFERENCE MANUAL 1986
- Intel® 64 and IA-32 Architectures Software Developer’s Manual Volume 3A: System Programming Guide, Part 1
- The Linux Development Project
- MIT 6.828
- Linux Kernel Labs
- Linux Kernel Source Code
- Linux Kernel Documentation 4.19, latest
- woboq
Kernel
- Written in GNU C and the GNU toolchain.
- Adheres to ISO C89 standard and some extensions
- sometimes difficul to understand the assumptions the kernel has on the toolchain and the extensions and unfortunately there is no definitive reference :(
Linux
User interface:
/proc
procfs: usually expose complex data and the data are read-onlynet/[dev|dev_mcast|wireless]
: created bynet_[dev|proc]_init
; displays statistics
/proc/sys
sysctl: usually expose simple datakernel/[modprobe]
: change the default path to user-space helpers
/sys
After 2.6, a newer filesystem compared with procfs and sysctl- can configure module options;
/sys/module/sis900/parameters/
- can configure module options;
/var
: valuable data. e.g. system logs, website contentioctl
work with socket. It is processed by kernel in many different placesethtool
,ifconfig
are based onioctl
- netlink: a newer interface
- User-space helpers:
/sbin/modprobe
: kernel module loader that allows kernel components to request the load./etc/modprobe.conf
is the configuration file./etc/modules
: modules loaded at boot time
/sbin/hotplug
Boot
Option
- options of the new option infrastructure are divied into two classes. There are two calls to
parse_args
and each call takes care of one class.linux/init.h
provides__setup_param
wrapper for these classes.- early options:
early_param("keyword=", function_handler)
- default options: register a keyword and the handler:
__steup("keyword=", function_handler)
- early options:
- options are pass through until being accepted
- early options
- default options
- Old option infrastructure
- as arg or env to
init
program
- The new option infrastructure exposed to
/sys
initcall
init/main.c
: initialzation of various critical subsystems- other kernel components that do not need a strict order (
do_initcalls()
). But still, the higher priority (mark as[core|postcore|arch|subsys|fs|device|late]_initcall
) is initilized first.__init
macro: routines that are not needed anymore at the end of the boot phase__initcall
(or with prioirityxxx_initcall
) and__exitcall
. They are often wrapped bymodule_[init|exit]
.module_exit
are never executed when the associated modules are included statically in the kernel. Therefore, in this case, there is no need to includemodule_exit
routines into the kernel image.
Steps for booting
- PC powers on, BIOS initializes hardwares.
- BIOS load the first 512-byte sector of the boot disk at
0x7c00
- BIOS transfer control to boot loader
%ip=0x7c00, %cs=0
- in real mode 16bits: linear address (20bits) = selector x 16 + offset
- boot loader:
- sets up segment descriptor table
gdt
, enters protected mode (since 80286) all segments have a base address of zero and the maximum possible limit. The table has a null entry, one entry for executable code, and one entry to data (only 3 entries). The loader also sets segment selectorsfs,gs / cs / ds,es,ss
to0 / 8 / 16
accordingly. - Now, we evolved from 8088 to 80386 (32bit mode)
- loads kernel (ELF format) from disk (at
1MB
plus a few bytes) and executes kernel starting at_start
- sets up segment descriptor table
set up
entry_pgdir
(cr3)- turn on paging (cr0)
Process
- lightweight process (LWP)
- process descriptor:
mm_struct, tty_struct, fs_struct, signal_struct, files_struct
- each LWP is associated with a Kernel stack
- Created by
clone()
(handled bydo_fork()
function)fork()
is implemented asclone()
withSIGCHLD
signal and all clone flags cleared and whosechild_stack
is equal to the current parent stack pointer.vfork()
is implemented asclone()
withSIGCHLD
signal and the flagsCLONE_VM, CLONE_VFORK
set (CLONE_VM
means to share the memory descriptor and page table,CLONE_VFORK
means to insert the parent process in a wait queue and suspends it until the child releases its memory address space (that is, untail the child either teminates or executes a new program) ), and whosechild_stack
is equal to the current parent stack pointer.
- process descriptor:
- thread group = a set of LWPs
- act as a whole with regards to
kill()
,_exit()
…
- act as a whole with regards to
POSIX-compliant pthread library
- Older version: a multithreaded application is just a normal process. The scheduling happens in User mode.
- Use LWP
Tools
Resources
- install GNU GCC
- Arch Linux packages: to see what configure parameters a package uses (assume they are using autotools for the build system)