Transcript General
: Operating System ecs150 Spring 2006 #1: OS Architecture, Kernel, & Process Dr. S. Felix Wu Computer Science Department University of California, Davis http://www.cs.ucdavis.edu/~wu/ [email protected] 03/30/2006 ecs150 Spring 2006 1 VM/MVS, DOS, Win95/98/ME/2000/XP, Freebsd/Linux, MacOS-10, Mach, Minix, PalmOS, uCOS, TinyOS, … 03/30/2006 ecs150 Spring 2006 2 ….where applications meet Hardware!!! Applications…….. OS Hardware: CPU/Memory/HD/DVD/Wireless… 03/30/2006 ecs150 Spring 2006 3 “Information Router” One NIC a process’s user-level memory One file another file – OS kernel layer – Hardware layer 03/30/2006 ecs150 Spring 2006 4 ….where applications meet Hardware!!! Applications…….. OS Hardware: CPU/Memory/HD/DVD/Wireless… 03/30/2006 ecs150 Spring 2006 5 virtualization Unmodified Applications Unmodified OS (XP, Linux, Solaris, or, FreeBSD) VirtualPC Standard Full Virtualization e.g., WindowXP Hardware 03/30/2006 ecs150 Spring 2006 6 03/30/2006 ecs150 Spring 2006 7 Programmable Virtualization Unmodified Applications “Programmable” Full Virtualization DLVM API Unmodified OS (XP, Linux, Solaris, or, FreeBSD) DLVM Hardware 03/30/2006 ecs150 Spring 2006 8 FreeBSD Unmodified OS (XP, Linux, Solaris, or, FreeBSD) API Unmodified Applications Virtual PC or VMware Hardware 03/30/2006 ecs150 Spring 2006 9 This quarter…. The internals of OS The basic design principles of OS The skills to modify or implement an OS. 03/30/2006 ecs150 Spring 2006 10 Operating System An interesting balance between: – Theories and Practical Experiences/Experiments – Architectural Concept and Detailed Design – Formal Verification and Empirical Validation 03/30/2006 ecs150 Spring 2006 11 About the Instructor S. Felix Wu – [email protected], x4-7070 Office: 3057 Engineering II Office Hours: – 1-2 p.m. on Tuesday and Friday – by appointment 03/30/2006 ecs150 Spring 2006 12 About the TA TA Valerie Szudziejka ([email protected]) – Office Hours: TBA – Discussion: 03/30/2006 ecs150 Spring 2006 13 about Web site http://www.cs.ucdavis.edu/~wu/ecs150/ all lectures, notes, announcements, homework assignments, tools, papers will be there. 03/30/2006 ecs150 Spring 2006 14 Textbook Reading this book itself is a major challenge!! But, you really learn when you go through this process! "The Design and Implementation of the FreeBSD Operating Systems" by Marshall Kirk McKusick and George V. Neville-Neil Addison Wesley Professional, 2005, ISBN 0-201-70245-2. http://www.freebsd.org/ 03/30/2006 ecs150 Spring 2006 15 Prerequisites Programming Languages: C and assembly (ecs50) Date Structure (ecs110) and basic Computer Architecture (ecs154a/eec70). ecs40 Please talk to me if you have any concern. 03/30/2006 ecs150 Spring 2006 16 Syllabus Process/Kernel Memory Management midterm IO & File Systems Others final 03/30/2006 ecs150 Spring 2006 (09) (06) (10) (03) 17 OS Principles/Concepts What is “kernel”? What is the difference between a process and a thread? What is the difference between user-level and kernel-level threads? What is the difference between a system call and a library function call? What are SJF, RR, Lottery, LRU, TLB, Second Chance? How to do Mutual Exclusion? What is the difference between deadlock prevention and avoidance? What are the differences among hardware interrupt, hardware trap, and software trap? 03/30/2006 ecs150 Spring 2006 18 OS Let’s examine OS concepts in a realistic context: “FreeBSD” Then, we can re-think those concepts…. – And, maybe you will realize later that some of the concepts are either “misleading” or “irrelevant” in certain context. 03/30/2006 ecs150 Spring 2006 19 Principles vs. Practice Ideas and Theories first, then we will go over some FreeBSD code segments. You will need to learn FreeBSD internals for programming assignments!! The first few discussion sessions will be dedicated to FreeBSD internals. – Most of the discussion sessions are very important and they will appear in the exams and homeworks. 03/30/2006 ecs150 Spring 2006 20 Course Requirements 48%: Programming Assignments – teamwork: 1~3 students – 3 Programming Assignments (12%, 18%, 18%) – HW#1 is out (check the website). 16%: In-class open-book midterm 32%: open-book final 04%: Participation of Lectures and Discussion sessions. – Deducted if missed more than three sessions. 03/30/2006 ecs150 Spring 2006 21 Grading I will give +/- grades. possible grading (not finalized): – A: >= 93 – B: >= 84 – C: >= 75 03/30/2006 A-: >= 90 B-: >= 81 C-: >= 72 ecs150 Spring 2006 B+: >= 87 C+: >= 78 D : > 60 22 FreeBSD Your team need to have access to a FreeBSD environment – I386, VMware, VirtualPC 03/30/2006 ecs150 Spring 2006 23 The Structure of OS The Kernel Processes and Threads The System Call Interface 03/30/2006 ecs150 Spring 2006 24 What is “kernel”? 03/30/2006 ecs150 Spring 2006 25 Kernel The basic OS services Which services? What is it doing? Let’s check a couple examples 03/30/2006 ecs150 Spring 2006 26 ….what are the basic services? OS 03/30/2006 ecs150 Spring 2006 27 FreeBSD Kernel: Services Timer/clock, descriptor, process Memory Management: paging/swapping I/O control and terminal File System Inter-process communication Networking 03/30/2006 ecs150 Spring 2006 28 03/30/2006 ecs150 Spring 2006 29 Kernel of SVR2 of AT&T Unix user User programs trap Libraries System Call Interface File subsys kernel Buffer cache Process Control Subsys. Inter-Process Communication Scheduler Character block device drivers Memory Management Hardware Control hardware 03/30/2006 ecs150 Spring 2006 30 Kernel & Processes The concept of “application process” 03/30/2006 ecs150 Spring 2006 31 Kernel and User Space Process FOO Memory space for this process System call (or trap into the kernel) program conceptually Process FOO in the Kernel System Call Kernel Resources (disk or IO devices) 03/30/2006 ecs150 Spring 2006 32 Processes > ps PID TTY TIME CMD 2910 pts/4 0:00 tcsh > ps -ef UID PID PPID C root 0 0 0 root 1 0 0 root 2 0 0 root 3 0 0 root 223 1 0 root 179 1 0 root 273 1 0 root 56 1 0 root 58 1 0 root 106 1 0 root 197 1 0 root 108 1 0 root 168 1 0 root 118 1 0 root 159 1 0 03/30/2006 STIME TTY Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? Sep 25 ? TIME CMD 0:01 sched 0:00 /etc/init 0:00 pageout 0:01 fsflush 0:00 /usr/lib/utmpd 0:00 /usr/sbin/cron 0:00 /usr/lib/saf/sac -t 300 0:00 /usr/lib/devfsadm/devfseventd 0:00 /usr/lib/devfsadm/devfsadmd 0:00 /usr/sbin/rpcbind 0:01 /usr/sbin/nscd 0:00 /usr/sbin/keyserv 0:00 /usr/sbin/syslogd 0:00 /usr/lib/netsvc/yp/ypbind 0:00 /usr/lib/autofs/automountd ecs150 Spring 2006 33 03/30/2006 ecs150 Spring 2006 34 03/30/2006 ecs150 Spring 2006 35 Memory Structure High Arguments Return address String Growth Prev. frame pointer Local variables Stack Pointer Low 03/30/2006 Stack Growth ecs150 Spring 2006 36 Memory Structure High foo Arguments bar Return address String Growth Prev. frame pointer Local variables Stack Pointer Low 03/30/2006 Stack Growth ecs150 Spring 2006 bar( ) {……} foo( ) { …… call bar( ); …… } 37 Per-process Kernel Stack User-stack Procedure Call on the same User Stack Disk Heap Initialized data Initialized data text a.out header text Memory a.out magic number 03/30/2006 ecs150 Spring 2006 38 Per-process Kernel Stack User-stack System Call on a different stack Disk Heap Initialized data Initialized data text a.out header text Memory a.out magic number 03/30/2006 ecs150 Spring 2006 39 System Calls Not a “normal” procedure call It is a software trap “into” the kernel – Hardware interrupt – Hardware trap – Software trap 03/30/2006 ecs150 Spring 2006 40 System Entry Hardware interrupt – Asynchronous, might not relate to the context of the executing process Hardware trap – Related to the current executing process, e.g., divided by zero Software-initiated trap – Instructions, int 03/30/2006 ecs150 Spring 2006 41 System Entry Vector fork() Trap : : 03/30/2006 ecs150 Spring 2006 42 System Entry Vector fork() Trap Reserved for loadable system calls : : XYZ() 03/30/2006 ecs150 Spring 2006 43 kldload fork() Trap XYZ() : : 03/30/2006 ecs150 Spring 2006 44 Process Process – a program in execution A process includes: – program counter – stack – data section 03/30/2006 ecs150 Spring 2006 45 Context Switching 03/30/2006 ecs150 Spring 2006 46 Scheduling & Context Switching Running Blocked 03/30/2006 Running Ready Blocked Running Ready Blocked ecs150 Spring 2006 Running Ready Blocked Ready 47 States of a Process Running, Blocked, and Ready Running Waiting 03/30/2006 Ready ecs150 Spring 2006 48 03/30/2006 ecs150 Spring 2006 49 1 RR 0 0 : : . 1 0 1 03/30/2006 256 different priorities 64 scheduling classes 0~63 64~127 128~159 160~223 224~255 bottom-half kernel (interrupt) top-half kernel real-time user timeshare idle ecs150 Spring 2006 50 Kernel Processes idle, swapper, vmdaemon, pagedaemon, pagezero, bufdaemon, syncer, ktrace, vnlru, random, g_event, g_up, g_down /usr/src/sys/kern/kern_idle.c /usr/src/sys/kern/init_main.c /usr/src/sys/vm/vm_zeroidle.c /usr/src/sys/kern_ktrace.c /usr/src/sys/dev/random/randomsoft_dev.c 03/30/2006 ecs150 Spring 2006 51 03/30/2006 ecs150 Spring 2006 52 1 RR 0 0 : : . 1 0 1 03/30/2006 256 different priorities 64 scheduling classes 0~63 64~127 128~159 160~223 224~255 bottom-half kernel (interrupt) top-half kernel real-time user timeshare idle ecs150 Spring 2006 53 Running Waiting 03/30/2006 Ready ecs150 Spring 2006 54 4.4BSD Process Structure (/usr/src/sys/sys/proc.h) Process Structure process group session process credential user credential VM space region list file descriptors file entries resource limits statistics signal actions machine-dependent process information 03/30/2006 process control block process kernel stack ecs150 Spring 2006 } user structure 55 FreeBSD User Structure /* * Per process structure containing data that isn’t needed in core when the * process isn’t running (esp. when swapped out). This structure may or may not * be at the same kernel address in all processes. */ struct user { struct pcb u_pcb; struct sigacts u_sigacts; /* p_sigacts points here (use it!) */ struct pstats u_stats; /* p_stats points here (use it!) */ /* Remaining fields only for core dump and/or ptrace— not valid at other times! */ struct kinfo_proc u_kproc; /* proc + eproc */ struce md_coredump u_md; /* machine dependent glop */ } 03/30/2006 ecs150 Spring 2006 56 5.x Kernel 03/30/2006 ecs150 Spring 2006 57 1 RR 0 KSE: Kernel Scheduling Entity kernel-level thread 0 : : . 1 0 1 03/30/2006 256 different priorities 64 scheduling classes 0~63 64~127 128~159 160~223 224~255 bottom-half kernel (interrupt) top-half kernel real-time user timeshare idle ecs150 Spring 2006 58 03/30/2006 ecs150 Spring 2006 59 What is a thread? 03/30/2006 ecs150 Spring 2006 60 Process and Thread (abstraction and abstraction) An execution instance of a program. Threads and resources – a thread is a control entity of the logical flow in the program. – A sequential program needs only one single thread because it only need to be controlled by one entity. – Can you distinguish a process and a thread? User mode versus (trap into the) Kernel mode. 03/30/2006 ecs150 Spring 2006 61 A Program and Threads J=0; (shared) variables If (j==0) J=100 03/30/2006 ecs150 Spring 2006 62 Threads Heavy-weight Process versus Light-weight Thread User-level versus Kernel-level 03/30/2006 ecs150 Spring 2006 63 a Process and a Thread A tradition process contains one thread (i.e, one flow of control) and the resources (user or kernel). Resources No obvious concurrency within a process 03/30/2006 ecs150 Spring 2006 64 Process and Threads A Process can contain more than one threads sharing the resources (user or kernel). Resources 03/30/2006 ecs150 Spring 2006 65 Threads User-level Kernel-level 03/30/2006 ecs150 Spring 2006 66 Threads Blocking/Synchronous I/O – One thread blocks all others??? – “Block one block all” 03/30/2006 ecs150 Spring 2006 67 CPU chip register file ALU system bus memory bus main memory I/O bridge bus interface I/O bus USB controller mouse keyboard 03/30/2006 graphics adapter disk controller Expansion slots for other devices such as network adapters. monitor ecs150 Spring 2006 disk 68 CPU chip register file ALU CPU initiates a disk read by writing a command, logical block number, and destination memory address to a port (address) associated with disk controller. main memory bus interface I/O bus USB controller mouse keyboard 03/30/2006 graphics adapter disk controller monitor ecs150 Spring 2006 disk 69 CPU chip register file ALU Disk controller reads the sector and performs a direct memory access (DMA) transfer into main memory. main memory bus interface I/O bus USB controller mouse keyboard 03/30/2006 graphics adapter disk controller monitor ecs150 Spring 2006 disk 70 CPU chip register file ALU When the DMA transfer completes, the disk controller notifies the CPU with an interrupt (i.e., asserts a special “interrupt” pin on the CPU) main memory bus interface I/O bus USB controller mouse keyboard 03/30/2006 graphics adapter disk controller monitor ecs150 Spring 2006 disk 71 Asynchronous I/O How to deal with multiple I/O operations concurrently? For example: wait for a keyboard input, a mouse click and input from a network connection. Select system call int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); Poll system call (same idea, different implementation) int poll(struct pollfd *ufds, unsigned int nfds, int timeout); struct pollfd { int fd; short events; short revents; }; /* file descriptor */ /* requested events */ /* returned events */ For more info see http://www.kegel.com/c10k.html 03/30/2006 ecs150 Spring 2006 72 /usr/src/sys/kern/vfs_aio.c Solaris, Linux 2.6, FreeBSD pp230~231 POSIX P1003.4 Asynchronous I/O interface functions: – aio_cancel:cancel asynchronous read and/or write requests – aio_error:retrieve Asynchronous I/O error status – aio_fsync:asynchronously force I/O completion, and sets errno to ENOSYS – aio_read:begin asynchronous read – aio_return:retrieve return status of Asynchronous I/O operation – aio_suspend:suspend until Asynchronous I/O Completes – aio_write:begin asynchronous write – lio_listio:issue list of I/O requests 03/30/2006 ecs150 Spring 2006 73 Security Problem!! 03/30/2006 ecs150 Spring 2006 74 User-Level Threads Now, you should get the basic idea about how to avoid “block one block all”…. 03/30/2006 ecs150 Spring 2006 75 Threads User-level – Kernel is unaware of multiple threading within the same process. (Conceptually, the kernel pretends one “kernel” thread per process.) Kernel-level – Kernel is fully aware of multiple kernel threads within the same process, and therefore, it will provide “related kernel services”. 03/30/2006 ecs150 Spring 2006 76 User and Kernel Threads One thread per process or multiple thread per process UTS UserLevelTs KTS 03/30/2006 Which approach is better??? ecs150 Spring 2006 KernelTs KTS 77 User-Level Threads A small OS in the user-space to manage the threads. The kernel is totally unaware how many threads the process currently has. 03/30/2006 ecs150 Spring 2006 78 03/30/2006 ecs150 Spring 2006 79 Why Multiple Threads?? 03/30/2006 ecs150 Spring 2006 80 Responsiveness Resource Sharing Economy Utilization of MP Architectures 03/30/2006 ecs150 Spring 2006 81 fork() Process A Global Variables fork() Process B Code Global Variables Stack Code Stack 03/30/2006 ecs150 Spring 2006 82 Parent fork() execve() Global Variables Child Code Stack 03/30/2006 Child Global Variables Global Variables Code Code Stack Stack ecs150 Spring 2006 83 pthread_create() Process A Thread 1 Global Variables pthread_create() Code Process A Thread 2 Stack Stack 03/30/2006 ecs150 Spring 2006 84 Creation Time Difference Because threads are by definition lightweight, they can be created more quickly that “heavy” processes: – Sun Ultra5, 320 Meg Ram, 1 CPU 94 forks()/second 1,737 threads/second (18x faster) – Sun Sparc Ultra 1, 256 Meg Ram , 1 CPU 67 forks()/second 1,359 threads/second (20x faster) – Sun Enterprise 420R, 5 Gig Ram, 4 CPUs 146 forks()/second 35,640 threads/second (244x faster) – Linux 2.4 Kernel, .5 Gig Ram, 2 CPUs 1,811 forks()/second 227,611 threads/second (125x faster) 03/30/2006 ecs150 Spring 2006 85 03/30/2006 ecs150 Spring 2006 86 User Threads Thread management done by user-level threads library Examples - POSIX Pthreads - Mach C-threads - Solaris threads 03/30/2006 ecs150 Spring 2006 87 Kernel Threads Supported by the Kernel Examples - Windows 95/98/NT/2000 - Solaris - Linux 03/30/2006 ecs150 Spring 2006 88 Solaris 2 Threads 03/30/2006 ecs150 Spring 2006 89 Linux Threads Linux refers to them as tasks rather than threads. Thread creation is done through clone() system call. clone() allows a child task to share the address space of the parent task (process) 03/30/2006 ecs150 Spring 2006 90 Open new connection Application (Web Server) Thread class: run Programming Language (Java) Lib call: pthread_create Programming Library (POSIX thread) System call: Clone 03/30/2006 Operating System (Linux Native Thread) ecs150 Spring 2006 91 KT vs. UT pros and cons? BTW, how about FreeBSD? 03/30/2006 Threads ecs150 Spring 2006 92 03/30/2006 ecs150 Spring 2006 93 UTS + KTS Two independent schedulers: User Space Process Process Scheduler Process Scheduler Scheduler OS Kernel processor 03/30/2006 processor ecs150 Spring 2006 processor 94 KTS One single scheduler: User Space Process Process Process Scheduler OS Kernel processor 03/30/2006 processor ecs150 Spring 2006 processor 95 KT vs. UT UTS Kernel Interface KTS 03/30/2006 ecs150 Spring 2006 96 Solaris 2 Threads mapping but NOT coordinating 03/30/2006 ecs150 Spring 2006 97 Questions to ask Why do we need “coordination”? – kernel-support user-level threads What do we need in this “K/U coordination”? – extended system call API Is this only good for SMP? – How about single processor? – How about NPU? (e.g., IXP-2400) 03/30/2006 ecs150 Spring 2006 98 UTS Library Notify I/O events Notify new decision Kernel KTS 03/30/2006 ecs150 Spring 2006 99 Is this a problem? User Space Kernel Space syscall I/O request interrupt Hardware I don’t know how many UT’s you have up there? I can guess but I am not sure that is exactly what you want! 03/30/2006 ecs150 Spring 2006 100 Scheduler Activations CPU time wasted User Space Kernel Space syscall I/O request interrupt I don’t know how many UT’s you have up there? Hardware CPU used User Space Kernel Space upcall upcall Hardware 03/30/2006 ecs150 Spring 2006 101 Scheduler Activations First proposed by [Anderson et al. 91] Idea: cooperation between schedulers should take place in both directions User scheduler uses system calls Kernel scheduler should use upcalls! Upcalls – Notify the user-level of kernel scheduling events Activations – A new structure to support upcalls (~kernel thread) – As many running activations as processors – Kernel controls activation creation and destruction 03/30/2006 ecs150 Spring 2006 102 One Model (FreeBSD 5.x) UTS - threads Library SA SA Notify I/O events Notify new decision SA SA KTS – virtual CPU’s 03/30/2006 ecs150 Spring 2006 Kernel 103 03/30/2006 ecs150 Spring 2006 104 I/O happens for Thread User Program (2) User-Level Runtime System (3) (1) (A) (4) (B) Add Processor Add Processor Operating System Kernel Processors 03/30/2006 ecs150 Spring 2006 105 A’s Thread has blocked on an I/O request User Program (2) User-Level Runtime System (1) (4) B (A) Operating System Kernel (3) (B) (C) A’s thread has blocked Processors 03/30/2006 ecs150 Spring 2006 106 A’s Thread I/O completed User Program (2) (3) User-Level Runtime System (1) (1) (A) (B) (C) Operating System Kernel (4) (D) A’s thread and B’s Thread can continue Processors “the upcall stack problem” 03/30/2006 ecs150 Spring 2006 107 A’s Thread resumes on Scheduler Activation D User Program (2) (3) (1) User-Level Runtime System (C) Operating System Kernel (1) (4) (D) A’s thread and B’s Thread can continue Processors 03/30/2006 ecs150 Spring 2006 108 03/30/2006 ecs150 Spring 2006 109 One Model (FreeBSD 5.x) UTS - threads Library SA SA Notify I/O events Notify new decision SA SA KTS – virtual CPU’s 03/30/2006 ecs150 Spring 2006 Kernel 110 FreeBSD 5.x Kernel Scheduling Entity (KSE) – a virtual CPU – When “anything” changes regarding the service of this KSE to the process, this KSE is “unassigned” as the kernel doesn’t know what other threads might be there!! – Upcall to the UTS (via KSE mailbox). – UTS uses both KSE mailbox and Thread mailbox to handle/decide. 03/30/2006 ecs150 Spring 2006 111 03/30/2006 ecs150 Spring 2006 112 03/30/2006 ecs150 Spring 2006 113 #include <sys/types.h> #include <sys/kse.h> int kse_create(struct kse_mailbox *mbx, int newsgroup); int kse_exit(void); int kse_release(struct timespec *timeout); int kse_wakeup(struct kse_mailbox *mbx); int kse_thr_interrupt(struct kse_thr_mailbox *tmbx); 03/30/2006 ecs150 Spring 2006 114 struct kse_mailbox { int km_version; struct kse_thr_mailbox *km_curthread; struct kse_thr_mailbox *km_completed; sigset_t km_sigscaught; unsigned int km_flags; kse_func_t *km_func; /* UTS function */ stack_t km_stack; /* UTS context */ void *km_udata; /* For use by the UTS */ struct timespec km_timeofday; /* Time of day */ int km_quantum; int km_spare[8]; }; 03/30/2006 ecs150 Spring 2006 115 struct kse_thr_mailbox { ucontext_t unsigned int struct kse_thr_mailbox void unsigned int unsigned int int }; 03/30/2006 tm_context; tm_flags; *tm_next; *tm_udata; tm_uticks; tm_sticks; tm_spare[8]; ecs150 Spring 2006 /* /* /* /* User and machine context */ Thread flags */ Next thread in list */ For use by the UTS */ 116 upcalls ksec_new ksec_preempt ksec_block ksec_unblock 03/30/2006 ecs150 Spring 2006 117 UTS Library ksec_new ksec_preempt ksec_block ksec_unblock kse_create kse_exit kse_release kse_wakeup kse_thr_interrupt Kernel KTS 03/30/2006 ecs150 Spring 2006 118 KSE Internal KSE KSEG KSEC 03/30/2006 ecs150 Spring 2006 119 03/30/2006 ecs150 Spring 2006 120 03/30/2006 ecs150 Spring 2006 121 03/30/2006 ecs150 Spring 2006 122 03/30/2006 ecs150 Spring 2006 123 Linux VPI (Virtual Processor Interface) Experimental/Research Prototype – Benson/Butner/Padden/Fedosov – Scheduler activation in Linux Kernel 2.4.18 03/30/2006 ecs150 Spring 2006 124 03/30/2006 ecs150 Spring 2006 125 One Model (FreeBSD 5.x) UTS - threads Library SA SA Notify I/O events Notify new decision SA SA KTS – virtual CPU’s 03/30/2006 ecs150 Spring 2006 Kernel 126 Kernel Processes (table 3.1 page 50) idle, swapper, vmdaemon, pagedaemon, pagezero, bufdaemon, syncer, ktrace, vnlru, random, g_event, g_up, g_down “Kernel processes execute code that is complied into the kernel’s load image and operate with the kernel’s privileged execution code.” 03/30/2006 ecs150 Spring 2006 127 FreeBSD Kernel 03/30/2006 ecs150 Spring 2006 128 FreeBSD Kernel 03/30/2006 ecs150 Spring 2006 129 Kernel and User Space Process FOO Memory space for this process System call (or trap into the kernel) program conceptually Process FOO in the Kernel System Call Kernel Resources (disk or IO devices) 03/30/2006 ecs150 Spring 2006 130 What is “micro-kernel”? 03/30/2006 ecs150 Spring 2006 131 ….what are the basic services? OS 03/30/2006 ecs150 Spring 2006 132 An Alternative: Micro-Kernel Message Passing versus Optimized Procedure Calls 03/30/2006 ecs150 Spring 2006 133 03/30/2006 ecs150 Spring 2006 134 Micro versus Monolithic What is the real difference between these two models?? First Brainstorming!! 03/30/2006 ecs150 Spring 2006 135 Micro versus Monolithic Is this really relevant? Advantages of Micro Kernels – Modules (Architectural Cleanness), Adaptive, Small/Quick-to-Boot,… We did learn some lessons – We have to consider the “users” & “applications”, and make a new engineering design decision. 03/30/2006 ecs150 Spring 2006 136 FreeBSD Kernel: Size 689794 machine independent LOC 108346 machine dependent LOC 846525 device driver LOC Comparing: – – – – Windows 3.1 ~ 6M LOC Windows 2000 ~ 30-50M LOC Windows XP ~ 45M LOC Netscape ~ 7M LOC 03/30/2006 ecs150 Spring 2006 137 OS Design Architectural Design – how to organize the user and kernel resources? Module Control Design – how to design a control mechanism to protect the OS resource integrity? Interface Design – how to let user programs access the resources easier? (e.g., system call interface, multi-threaded interface). 03/30/2006 ecs150 Spring 2006 138 What is “Process”? What is “System Call”? What is “Kernel”? 03/30/2006 ecs150 Spring 2006 139