300 likes | 534 Views
What Is T he Linux Kernel ? A newbie’s guide to the Kernel. Balaji V ijalabv@yahoo.com. Evolution of Operating Systems. Before Multiprogramming “Jobs”, “Offline” Multiprogramming Spooling Timesharing CTSS MULTICS. Minix. Unix becomes proprietary Tanenbaum writes from scratch
E N D
What Is The Linux Kernel ?A newbie’s guide to the Kernel Balaji V ijalabv@yahoo.com
Evolution of Operating Systems • Before Multiprogramming • “Jobs”, “Offline” • Multiprogramming • Spooling • Timesharing • CTSS • MULTICS
Minix • Unix becomes proprietary • Tanenbaum writes from scratch • Unix-like from outside • Readable & teachable • USENET group gets popular • New suggestions, ideas and code offered • Finally, Linux is born
User Mode Vs Kernel Mode • System call Kernel works on behalfof process
Naming Conventions • Words separated by ‘_’ • Wait_queue • Pointer “ptr”, p_ • p_cptr
Process • What is a process ? • Multiprocessing Operating System • task_struct • State – Running, waiting, Zombie, stopped • Scheduling Information • Pid • Links parent, sibling
Process (contd) • … • Identifiers – uid, gid, effective, FS, saved • Timers – time since start, alarm • Filesystem – VFS inode pointer • root directory, alternate root, pwd • Virtual Memory • Processor Specific contexts • sig
{Process} • Hash Table – pidhash[] • extern struct task_struct *pidhash[PIDHASH_SZ]; • find_task_pid() • pidhash_next(), pidhash_prev() • hash_pid() unhash_pid() • Circular Doubly Linked List • Task • Pointers current, running • Lock - tasklist_lock
Scheduling • Preemption • Policy • tq_struct • Priority • rt_priority • States
format next next next count count count load_bin() load_bin() load_bin() coredump() coredump() coredump() Process Image • Extendible Link Format (ELF) • Program Code • Program Data • Stack • Header Table • #!/usr/bin/wish • Shared Libraries
Process Creation • init & init_task • fork(),clone()
System Calls in i386 • 2 classes of Interrupts • Exceptions • Interrupts • Vector • HIGHEST Faults except debug faults . Trap instructions INTO, INT n, INT 3 . Debug traps for this instruction . Debug traps for next instruction . NMI interrupt • LOWEST INTR interrupt
How Linux Uses Interrupts and Exceptions • int 0x80 • syscallX() • Setup the Stack frame & _system_call() • _syscall1(int,setuid,uid_t,uid);_setuid: subl $4,%exp pushl %ebx . . . int $0x80 . . ret
..contd • _system_call() • _ret_from_system_call() • Scheduler ? • Error ?
31 bh_active 0 . . . . . . . . . 31 bh_mask 0 Bottom Half Handlers • Why ? 0 1 31
Inter Process Communication • Why ? • Signals • Kill –l • SIGSTOP, SIGKILL • Core dump ! • Why only 32 signals ?
The File System • Types • Uniform Interface • inode • Directory • Links • The Minix Filesystem • Max size - 64MB • Limited Directory Entries • Maximal File name was 14 chars • Virtual Filesystem
Extended File System • EXT • File size 2GB, 255 characters File name • Drawbacks • No separate access, date modification • Fragmented • Xia Filesystem • 3 Time stamps • Large Partitions
Virtual File System • Indirection Layer • Structure • Kernel Table • inode Descriptor • Open file Descriptor
The Second Extended File System • Motivation • Fix bugs and provide Advanced Semantics • Robust • New Features
VFS at work • Attaching File system int init_ext2_fs(void) { return register_filesystem(&ext2_fs_type); } static struct file_system_type ext2_fs_type = { ext2_read_super, "ext2", 1, NULL }; static struct file_system_type sysv_fs_type[3] = { {sysv_read_super, "xenix", 1, NULL}, {sysv_read_super, "sysv", 1, NULL}, {sysv_read_super, "coherent", 1, NULL} }; • Connect • ext2_read_super() • super_block, super_operations
VFS at work .. contd struct super_operations { void (*read_inode) (struct inode *); int (*notify_change)(struct inode*,struct iattr*); void (*write_inode) (struct inode *); ... void (*statfs)(struct super_block*, struct statfs*,int); int (*remount_fs) (struct super_block *, int *, char *); }; static struct super_operations ext2_sops = { ext2_read_inode, NULL, ... ext2_remount };
VFS at work ..contd • Accessing a File • namei() • Access the inode • Inode Operations • struct inode_operations • struct file_operations
Modules • Why ? • Commands insmod rmmod • Kernel rights • References to Kernel Symbol table • Module Stacking
Module Loading • 2 ways to load • insmod • Demand loading • Relocatable - /lib/modules/version • Exported Symbols • Module init and cleanup list • References
next next ref ref symtab symtab “vfat” “fat” *cleanup() *cleanup() size size n_sym n_sym n_refs n_refs symbols symbols refs refs Module Data Structure module_list