290 likes | 472 Views
CS 423 – Operating Systems Design Lecture 5 – UNIX and Windows Architectures. Klara Nahrstedt/Sam King Fall 2007. Overview. Administrative Issues Overview of UNIX Architecture (T.10.2) Overview of Windows 2000 Architecture (T.11.1-3). Administrative .
E N D
CS 423 – Operating Systems DesignLecture 5 – UNIX and Windows Architectures Klara Nahrstedt/Sam King Fall 2007 CS 423 - Fall 2007
Overview • Administrative Issues • Overview of UNIX Architecture (T.10.2) • Overview of Windows 2000 Architecture (T.11.1-3) CS 423 - Fall 2007
Administrative • MP1 posted, deadline September 10, 8am • Take-Home Review Exam posted 8/31 • Solutions will be posted next Friday 9/7 • Exam not graded, but each student should check his/her knowledge and aim to know at least 60-70% of the problems how to solve them, or go about them CS 423 - Fall 2007
UNIX Utility Programs • Large number of utility programs • Divided into six categories • File and directory manipulation commands • Example: cp a b | ls *.* • Filters • Example: grep (extracts lines containing patterns), cut, paste, • Program development tools such as editors/compilers • Example: cc (C compiler), make (maintain large programs whose source code consists of multiple files) • Text processing • Example: vi • System administration • Example: mount (mount file system) • Miscellaneous • Example: kill 1325 (kill a process), chmod (change privileges of a file) CS 423 - Fall 2007
UNIX Kernel Approximate structure of generic UNIX kernel CS 423 - Fall 2007
Kernel Structure • All UNIX drivers are classified as either character device drivers (mouse, keyboard) or block device drivers (disk) • Network device drivers (possible character devices, but handled very differently) • Process dispatching – when interrupt happens, context switch happens between processes CS 423 - Fall 2007
Kernel Structure • Editors such as vi/emacs need raw tty • Shell is line oriented, hence uses cooked mode and line disciplines • Networking software is layered with MAC/Routing/Transport layers and Socket interface • On top of buffer cache sits file system • Most UNIX systems support multiple file systems • Berkeley fast file system • Log-structured file system • Various System V file systems CS 423 - Fall 2007
Kernel Structure • On top of file system comes file naming, directory management, hard link and symbolic link management, etc • On top page cache sits virtual memory (VM) • All paging logic is here, such as replacement algorithm • On top of VM is mapping files onto VM and high level page fault management code • Figure out what to do when a page fault occurs • On top of process dispatching is process management • Process scheduler to choose which process to run next • If threads are managed in the kernel, thread management is also here • Note in some UNIX systems, threads are managed in user space • On top of scheduling we have signal processing and process creation and termination CS 423 - Fall 2007
Kernel Structure • Top layer has the system call interface • All system calls are directed to one of the lower modules, depending on the nature of the call • Top layer also has entrance to interrupts and traps • Entrance to signals, page faults, processor exceptions of all kinds, I/O interrupts CS 423 - Fall 2007
Summary of UNIX kernels • Most UNIX kernels are monolithic: each kernel layer is integrated into the whole kernel program and runs in Kernel Mode on behalf of current process • Some kernels use micro-kernel approach • Very small set of functions from the kernel • Few synchronization primitives • Simple scheduler • Inter-process communication mechanism • Several system processes run on top of micro-kernel • Memory allocators, device drivers, system call handlers • Disadvantage: Microkernels are generally slower than monolithic ones due to explicit message passing between different layers of the OS • Advantage: Microkernels force system programmers to adopt a modularized approach since OS layer is relatively independent program that must interact with the other layers through well-defined and clean software interfaces • Advantage: Microkernels are easily ported to other architectures CS 423 - Fall 2007
Summary of UNIX kernels • Linux – wants to achieve theoretical advantages of micro-kernels without introducing performance penalties • Linux kernel offers modules • Module is an object file whose code can be linked to kernel at runtime • Advantages of modules: • Modularized approach • Platform independence • Frugal memory usage • No performance penalty CS 423 - Fall 2007
History of Windows 2000 • MS-DOS • 1981, IBM – 8088-based IBM PC run OS 16-bit, single user, command-line, 8KB memory resident code, MS-DOS 1.0, given to start-up company, Microsoft • 1983, 24 KB OS with shell, number of features from UNIX, MS-DOS 2.0 • 1986, IBM PC/AT, 8 MHz, uses Microsoft’s MS-DOS 3.0, 36 KB OS • Consumer Windows (Windows 95/98/Me) • 1985: MS-DOS with Windows graphical user interface, Windows 1.0 OS • 1991: Windows 3.0, 3.1, 3.11 – huge commercial success (MS-DOS still the underlying OS • 1995: Windows 95 – moved nearly all features of MS-DOS to Windows part • Windows 95 and MS-DOS 7.0 – full blown OS with VM, process management, multi-programming • 1998: Windows 98 – MS-DOS 7.1 still there running 16-bit code (main difference to Windows 95 was the user interface which integrated desktop and Internet) • 2000: Windows Me – fixed bugs, few new features (catalog/share images, music, movies, support for home-networking, multi-user games), still Windows 98 • Windows NT • Late 1980s – can’t build modern 32-bit OS on top of leaky 16-bit MS-DOS • 1993: Windows NT 3.1 – 32-bit OS – failure • 1996: Windows NT.4.0 – server system with security and reliability features, UI the same as Windows 95 • NT written in C, portable, small assembly code for interrupt handling CS 423 - Fall 2007
Windows 2000 • It is Windows NT 5.0, 32-bit multi-programming system • OS runs in kernel mode, user processes in user mode, complete protection • Processes can have threads, scheduled by OS • C2 security for all files, directories, processes, etc. • Support for symmetric multiprocessors with up to 32 CPUs • Support of plug-and-play devices, USB bus, IEEE 1394 (FireWire), IrDA (Infrared link between portable laptops, printers), power management • Support of Kerberos, smart cards, system monitoring tools • Support of NTFS with encrypted files, quotas, linked files, mounted volumes, content indexing • OS does not have MS-DOS • It runs only on two platforms, Pentium and Intel IA-64 • It is much bigger than UNIX CS 423 - Fall 2007
Windows XP • Built on code base of Windows NT and Windows 2000, 32-bit architecture, fully protected memory model • New Features • Digital photography • Games for Windows • Making Movies • TV and multimedia • Instant messaging • Security and privacy • Computer setup and maintenance • Home and small office networking • Pen and ink • Working remotely • Accessibility for Everyone (Blind, hearing difficulties, difficulties using keyboard or mouse, CS 423 - Fall 2007
Programming Interface of Windows CS 423 - Fall 2007
Win32 API • System calls not public in Windows • Library procedures (function calls) public • Win32 philosophy: provide a very comprehensive interface, often with 3-4 ways of doing the same thing, including functions that are not system calls • Many Win32 calls create kernel objects (e.g., files, processes, threads). • Every call creating an object returns handle to the caller • Handles are used to perform any operation on the object • Windows 2000 sometimes called ‘object-oriented’ OS, but it lacks inheritance andpolymorphism properties • If all code is written without mention of any specific type and thus can be used transparently with any number of new types, it is called parametric polymorphism. • Programming using parametric polymorphism is called generic programming, particularly in the object-oriented community. CS 423 - Fall 2007
Win32 • Thousands and thousands of calls for the graphical interfaces. • Calls for creating, destroying, managing, using windows, menus, tool bars, status bars, scroll bars, dialog boxes, icons, • Calls for drawing geometric figures, filling them in, managing the color palettes they use, dealing with fonts, placing icons o n te screen • Calls for dealing with keyboard, mouse, etc. CS 423 - Fall 2007
Windows OS Structure • Kernel mode – OS itself • Traditional, handles process management, memory management, file system, … • User mode – environment subsystems • Unusual, env. Subsystems are separate processes that help user programs carry out certain system functions • NT started as a moderately small kernel plus server processes in user mode • Starting NT 4.0, all of OS services are in kernel mode in Windows 2000 CS 423 - Fall 2007
Windows 2000 Structure (simplified) CS 423 - Fall 2007
OS Structure • HAL and kernel written in C and assembly • Upper layers written in C; device drivers in C, some in C++ • HAL • Layer to hide many of the machine dependencies • Present OS with abstract hardware devices in form of machine-independent services • HAL does not provide: services to I/O devices such as keyboard, disk, mice. CS 423 - Fall 2007
HAL CS 423 - Fall 2007
Kernel Layer • Access to HAL • Kernel provides complete mechanisms for context switches (saves CPU registers, changes page tables, flushes CPU cache..) • Thread scheduling is in kernel • Key function: providing low-level support for two classes of objects: control objects and dispatcher objects • Control objects – control system, including process objects, interrupt objects, DPC (deferred procedure call) and APC (asynchronous procedure call). • DPC – splits off the non-time-critical part of an interrupt service from the time critical part. • Example: Interrupt service saves a few volatile hardware registers so that they don’t get overwritten, but saves the bulk of processing for later • APS – like DPC, only execute in the context of a specific process • Dispatcher objects – semaphores, mutexes, events, waitable timers, other objects threads can wait on CS 423 - Fall 2007
Executive • Is written in C, architecture independent, ported to new machines with little effort • Object manager • Manages all objects known to OS (processes, threads files, directories, semaphores, I/O devices, timers) • Allocates a block of virtual memory from the kernel space when object is created, returns it to the free list when object de-allocated; • Keeps track of objects • Manages name space in which newly created objects may be placed so that they can be referred to later CS 423 - Fall 2007
Components of Executive • I/O Manager • Framework for managing I/O devices, provides device-independent I/O services • File systems are technically device drivers under control of I/O manager • FAT and NTFS • Process Manager • Handling of processes, threads, including creation and termination • It deals with mechanisms used to manage them, not policies about how they are used!!! • Key to multiprogramming in Windows 2000 CS 423 - Fall 2007
Components of Executive • Memory Manager • Demand-paged virtual memory architecture • Mapping of virtual pages onto physical page frames • Enforces protection rules that restrict each process to use its own pages • Security manager • Elaborate security mechanisms, e.g., authenticated login • Cache Manager • Keeps most recently used disk blocks in memory • Power Manager • Manages resources for power-savings • Turns off monitor, disks after they have been idle for a while • Manages battery usage on laptops and takes action when the battery is about to run out CS 423 - Fall 2007
Interfaces • GDI – Graphics Devices Interface • Handles image management for printer and monitor • System services – interface to executive • Accepts true Windows 2000 system calls and calls other parts of executive for execution CS 423 - Fall 2007
Bootstrap of Windows 2000 • Load Windows 2000 as a collection of files into memory • Main part of OS – kernel and executive – located in ntoskrnl.exe • HAL is shared library located in separate file hal.dll • Win32 and GDI are in third file win32k.sys • Many device drivers (separately) are loaded (have extension .sys) • Device drivers are not part of the ntoskrnl.exe binary, so they can be loaded dynamically when system boots • New drivers have the power to affect kernel and corrupt system – must be written with great care CS 423 - Fall 2007
User Model Components • DLLs (Dynamic Link Libraries) – implement published interface (hide true system call from application program) • Environment subsystems: e.g., Win32 subsystem • Three documented APIs: Win32 (most developed), POSIX (P1003.1, does not have threads, networking, windowing), OS/2 (useless, very limited) CS 423 - Fall 2007
Summary • Objects – the single most important concept in Windows 2000 • Represent a uniform and consistent interface to all system resources and data structures • Many differences between UNIX and Windows to keep in mind CS 423 - Fall 2007