LINUX
Linux LinuxPOSIX 19912001Linux2.4 2003Linux2.6
LinuxPMMU -- VFS TCP/IP SMP3264CPU
LinuxSystem callShelllibKernelimplementation
(the users)
Shells and commands
Compilers and interpreters
System libraries
System-call interface to the kernel
Memory manager
Signal
File systems
Device drivers
Process management
Net work
Kernel interface to the hardware
Memory controllers
Physical memory
Device controllers
Disks and tapes
Terminal controllers
Terminals
lsShelllsforkshellforkforkCOWexeclsShelllsshell
Linux VFS
CkcoreMFCRMTCRPSRSETPSRCLRRFIRTESTOPWAITDOZE
()()
linux
Linux
ckcoreLinux kerneltrap 0
trap 0 PSR1 r1
APIAPI
trap 0
1
2
Linux 2.6 300Cmalloc() sbrk() sys_brk sys_brk 45, C movi r1, 45 trap 0
Linux
slabioremap
324G
CkcoreMMUMMU
USEGSSEG00~512M PAcacheSSEG10~512M PAcacheSSEG2
ckcore Linux2G2G
User Mapped(Useg:2GB)
Supervisor Mapped(SSEG2: 1GB)
Supervisor Unmapped(SSEG1: 512MB)
Supervisor Unmapped(SSEG0: 512MB)
0x0000 0000
0x8000 0000
0xa000 0000
0xc000 0000
0xffff ffff
MMU
CPU
PT 4MB
PT
pte_t
0
12
22
31
PGD PT 4kB+4KB*N
PGD
pgd_t
PT
pte_t
PGD
PT
0
12
22
31
PGD
struct page
struct page
struct page
mem_map
offset
free_area[MAX_ORDER]
mem_map[offset]
zone
free_area[0]
free_area[1]
free_area[2]
free_area[10]
free_area
age
count
page
list
4000
4007
mem_map[4000]
Physical memory
mm
task_struct
mmap
pgd
mm_struct
vm_next
vm_end
vm_start
vm_area_struct
Virtual area
Process virtual memory
0x00000000
0x7fffffff
PGD
PT
pgd_t
pte_t
vm_next
vm_area_struct
Linux
Flash
slab
Slab1mm, skb, vm2
ioremap() :
ioremap()
2GB
Linux VFS
01
task_structPID (Process IDPID)PIDpid
include/linux/sched.h struct task_struct
Linux2.6TASK_RUNNINGTASK_INTERRUPTIBLETASK_UNINTERRUPTIBLEinterruptTASK_STOPPEDTASK_TRACEDTASK_DEADdo_exit()TASK_WAKEKILL
Linux2.6
1. TASK_DEADexit_state EXIT_ZOMBIE EXIT_DEAD wait4() waitpid() wait()
2. TASK_WAKEKILL #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE)#define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED)#define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED)
TASK_KILLABLETASK_UNINTERRUPTIBLE
TASK_DEAD( EXIT_ZOMBIEEXIT_DEAD)
TASK_INTERRUPTIBLEorTASK_UNINTERRUPTIBLEorTASK_KILLABLE
Linux8KBthread_info
8KB thread_info
8ktask_struct (thread);
TASK_RUNNING
n2.4O(n)
Linux 2.6 O(1)
CPUsleep()schedule()need_resched = 1
preemptible C
(process switching)CPU
CPU
linuxthread_infothread_struct,
thread_info
struct thread_info { struct task_struct *task; /* main task structure */ unsigned long flags; struct exec_domain *exec_domain; /* execution domain */ int preempt_count; /* 0 => preemptable, BUG */ mm_segment_t addr_limit;
struct restart_block restart_block; struct pt_regs *regs;};
thread_struct
struct thread_struct { unsigned long ksp; /* kernel stack pointer */ unsigned long usp; /* user stack pointer */ unsigned long sr; /* saved status register */ unsigned long crp[2]; /* cpu root pointer */ unsigned long esp0; /* points to SR of stack frame */
/* Other stuff associated with the thread. */ unsigned long address; /* Last user fault */ unsigned long baduaddr; unsigned long error_code; unsigned long trap_no;};
pt_regs
struct pt_regs { unsigned long pc; long r1; long syscallr2; unsigned long sr; long r2; long r3; long r4; long r5; long r6; long r7; long r8; long r9; long r10; long r11; long r12; long r13; long r14; long r15;};
thread_infothread_info
thread_info
STACK
task_struct
thread_struct
pt_regs
ksp
mm_struct
current taskcurrenttask_struct
Linuxforkvforkclonedo_fork
fork clone vforktask_struct
execveforkexec
If (result = fork() == 0){/* */if (execve(new_program,)
exit()[Cmain()]exit()
CPU
0start_kernel()mmfsfilessignals0initcpu_idle0idle
1initinitinit()
init()execve()initinit
init
Linux VFS
VFSVFS
Virtual Filesystem SwitchVFSread()write()open()file_operations
VFSshell$ cp /floppy/TEST /tmp/test cpVFS
VFSVFSext2ext3ReiserFS MINIX MS-DOS NTFS VFAT DVD JFS NFSCodaAFSSMBNCP/proc
VFSsuperblock inode /inodedentry file
ext2 - - - ext2_inode - ext2_dir_entry_2
super_block inode ext2_inode dentry ext2_dir_entry_2
super_block
dentryinode
dentryinode
Filename
dentryinode
file
/
Fid
file
dentryinode
+
init_mount_tree
sys_mountsys_umountmount -t ext2 /dev/fd0 /mnt
VFSmountumount/sysfs statfsfstatfsustat chroot chdirfchdirgetcwd mkdirrmdir /getdentsreaddir link unlink rename readlink symlink chown fchown lchown chmod fchmod utime openclosecreate
Linux VFS
Unix326432
- - sys_signal(signum, handler)sys_sigaction(signum, act, oact) handleractcurrent->sighand->action[sig-1]
task_structpendingstruct sigpending pendingstruct sigpending{struct list_head list;sigset_t signal;};signal listsigqueuetask_struct struct sigqueue { struct list_head list; int flags; siginfo_t info; struct user_struct *user;};
int kill(pid_t pid,int signo) pid 1. > 0; 2. = 0; 3. = -101current; 4. < -1
int sigqueue(pid_t pid, int sig, const union sigval val)
schedule()
ret_from_exception
ret_from_int
ret_from_syscall
need_reschedule?
signal pending?
do_signal
restore_hw_context
N
Y
N
Y
1. 2. - Terminate- Dumpcore- Ignore- StopTASK_STOPPED- ContinueTASK_RUNNING3. -
do_signal() sighandaction: - SIG_IGN, - SIG_DFL, - handle_signal()
handle_signal() handle_signal
1. 2. 3.
Linuxsys_sigreturn()
Frame1
Frame2
Sigframe
Frame2
Frame1
Frame1
Frame2
1
2
3
4
Frame2
1
2
3
4
Linux VFS
CPUinit
head.Sckcore head.S PSR cache MMU SSEG0BSSstart_kerneljsri
User Mapped(Useg:2GB)
Supervisor Mapped(SSEG2: 1GB)
Supervisor Unmapped(SSEG1: 512MB)
Supervisor Unmapped(SSEG0: 512MB)
0x0000 0000
0x8000 0000
0xa000 0000
0xc000 0000
0xffff ffff
start_kernel setup_arch(): trap_init(): init_IRQ():IRQ sched_init(): 0 softirq_init(): console_init(): init_modules():kernel_module fork_init(): rest_init()kernel_thread()init, init
initinitdo_basic_setup() PCI /dev/console execve/sbin/initlinux
Thank youLinux .LINUX .c640 MMU Micro-Architecture .linux2.6.30.4 .