CS533 Concepts of Operating Systems, Spring 2011 THE MACH SYSTEM "Operating Systems Concepts, Sixth Edition" by Abraham Silberschatz, Peter Baer Galvin, and Greg Gagne, published by J Wiley, 2002. Presented by: Shweta Ojha OUTLINE Introduction MACH Architecture Motivation System Components Process Management Interprocess Communication Memory Management Programmer Interface Summary Introduction MACH: operating system kernel Microkernel Developed at Carnegie Mellon University Logical successor to Accent kernel Developed as a replacement for the kernel in the BSD version of UNIX Basis of modern operating system kernels •Mac OS X •GNU Hurd (Source: Wikipedia) What is a Microkernel ? Near minimum amount of software that can provide the following mechanisms needed to implement an OS: low-level address space management thread management inter-process communication (IPC) (Source: Wikipedia) (Source: http://en.wikipedia.org/wiki/File:OS-structure.svg ) MACH - Architecture BSD code outside the kernel Basic Mach features in the kernel Unix specific code in user mode BSD can be replaced with other OS Concurrently run multiple OS on top of microkernel Motivation Runs on uniprocessors and multiprocessors Capable of functioning on heterogeneous hardware Supports varying degrees of shared memory access: • Uniform Memory Access (UMA) • Non-Uniform Memory Access (NUMA) • No Remote Memory Access (NORMA) Function with varying intercomputer network speeds Supports simultaneous execution of multiple operating systems Motivation Distributed operating providing network transparency to clients Integrated memory management and interprocess communication to provide communication based memory management and for communication of large numbers of data Heterogeneous system support Simple programmer interface with a good set of primitives Easy portability to a wide class of uniprocessors Extensive library of utilities and applications System Components System Components Task: •Consists of a virtual address space •Contains one or more threads •Protected access to system resources via ports Thread: •Basic unit of execution •Runs in the context of a task •Threads within a task share task's resource (ports, memory) Port: •Mechanism to reference an object •Protected by kernel managed capabilities – port rights •Communication by sending messages to ports Port set: •Group of ports sharing a common message queue Message: •Basic method of communication between threads Memory Object: •Source of memory accessed by mapping into task's address space Process Management Basic Structure: •Tasks & Threads Create task: •Similar to Unix (FORK) Parallelism: •1 Task has multiple threads •Threads on parallel processors •Faulty thread delayed, others continue Operations: •Suspend Task => Suspend all threads •Resume Thread ≠> Resume Task Synchronization Primitives: •Mach IPC → exchanging messages •Thread synchronization calls (start , stop) •Semaphores (wait, signal) MACH- Threads User level threads with kernel support C Threads influenced POSIX P Threads standard C Threads package •Thread control routine: create destroy wait yield •Mutual exclusion through spinlocks: mutex_alloc mutex_free mutex_lock mutex_unlock •Synchronization through condition variables: condition_alloc condition_free condition_wait condition_signal CPU Scheduling Only threads are scheduled (not tasks) Thread priority = exponential average of CPU usage Global run queues & per processor (local) run queues •Local run queue absolute priority over global run queue Maintains a list of idle processors Constant time quantum over entire system •Thread time quantum Ξ 1/ Number of threads Yielding CPU while waiting for resource 1st Call: Thread ------------------> Scheduler Alert: Thread Block 2nd Call: Thread moved off the run queue till event Exception Handling Exception Handler = Thread in the task(exception occurred) RPC messages: synchronize & communicate between victim & handler Two granularities of exception handling •Error handlers: per-thread handling •Debuggers: per-task handling •Error handlers have higher precedence over Debuggers Process: Wait routine Victim RPC message: (exception info, thread, task) Victim Thread Handler Clears exception → Resume/Terminate Victim Exception Handling Supports BSD style signals BSD expects hardware exceptions as signals Flow: MACH exception handling Hardware Exceptions Exception RPC receives clears In-kernel Task Exception causing Thread (Blocked) Signal handling code Exception causing Thread (Run) Signal Interprocess Communication Location independent message passing All objects addressed via communications ports Message senders & receivers must have rights •Right = port name + capability(send/receive) on that port •Only 1 task with receive rights to a port •Multiple tasks with send rights •Rights passed in messages by object creator/kernel •Message Receiver gains rights, Sender loses it •Destruction of port/receive right holder → revocation of all rights Component of IPC: Ports Implemented as protected, bounded queue within the kernel of the system on which object resides Sender may abort If a queue is full ask Wait for a slot Kernel Deliver message System calls to provide port functionality: •Allocate a new port (port_allocate + task_self) •Deallocate a task's access rights to a port •Get current status of a task's port •Create backup port Port sets: •When 1 thread has to service multiple objects •Not passed in messages •1 port member of only 1 port set Component of IPC: Messages MESSAGE: Header (fixed length) Destination port name Reply port name Length of the message Data Objects (variable length) In-line data (data in message, less than 8K) Pure typed data Port rights Out-of-line data Pointers to data exceeding 8K Transfers entire address space of a task in one message Address map of receiving task is modified to include copy-on-write copy of message pages Note: Message also stores the type information of data!! NetMsgServer User-level, forwards messages between hosts MACH Tenets: All objects are location independent & location is transparent to the user ● Provides Name Service Primitive Allows tasks networkwide to register ports for lookup Transfers 1st port that allows cross-computer IPC Subsequent IPC interactions are fully transparent ● Maintains a distributed database of ports and port rights ● Uses type information of data Solves the problem of cross-computer data format NetMsgServer Network IPC forwarding Memory Management Memory Objects Manage secondary storage Files/pipes/data mapped into virtual memory Backed by user-level memory managers Has a port associated with it Manipulated by messages being sent to the port Independent of kernel (no knowledge of content) Default Memory Managers Where user-level memory managers are insufficient When user-level fails to pageout Shared Memory Between tasks running on processors that share memory Changes made to the same copy Thread synchronization: critical sections/ mutex Separate Machines → Use External Memory Managers Same external memory manager for unrelated tasks accessing same memory section Memory Management User-level Memory Managers Memory objects mapped into virtual address space of task Maintains cache of memory-resident pages of mapped objects Memory can be paged by user-written memory managers Paging algorithm based on the object it is backing System Calls: vm_map memory_manager_init (routine) memory_object_set_attributes get & set attributes page-level locking memory_object_init memory_object_data_request memory_object_data_provided precious pages memory_object_data_write locking & modification of protection information Programmer Interface System call Interface Emulation libraries (run at user level) OS calls translated to subroutine calls to library Server (run at user level) For system calls that cannot be implemented in library Multithreaded C Threads package Run-time library provides C language interface Provides access to Mach thread primitives Fork, Join Mutex Condition variables MIG Interface / Stub generator Coding send/receive messages Compiler Input = Interface definition (declarations of variables, types & procedures) Output = RPC interface code Summary Micro kernel Operating system emulation at user level Message: only communications method Provides low level system calls Supports many memory models, parallel & distributed computing References Operating Systems Concepts, Sixth Edition" by Abraham Silberschatz, Peter Baer Galvin, and Greg Gagne, published by J Wiley, 2002. http://en.wikipedia.org/wiki/File:OS-structure.svg