2Computer System & OS Structures Computer System OperationI/O StructureStorage Structure, Storage HierarchyHardware ProtectionOperating System Services, System calls, System ProgramsStructuring OSVirtual Machine Structure and OrganizationOS Design and ImplementationProcess Management, Memory Management, Secondary Storage Management, I/O System Management, File Management, Protection System, Networking, Command-Interpreter.
4What happens during execution? FetchExecR0…R31F0F30PCAddr 232-1…Data1Data0Inst237Inst236Inst5Inst4Inst3Inst2 Inst1Inst0Execution sequence:Fetch Instruction at PCDecodeExecute (possibly using registers)Write results to registers/memPC = Next Instruction(PC)RepeatPCPCPCPCAddr 0From Berkeley OS course
5Computer System Organization I/O devices and the CPU execute concurrently.Each device controller is in charge of a particular device typeEach device controller has a local buffer. I/O is from the device to local buffer of controllerCPU moves data from/to main memory to/from the local buffersDevice controller interrupts CPU on completion of I/O
6InterruptsInterrupt transfers control to the interrupt service routineInterrupt Service Routine: Segments of code that determine action to be taken for each type of interrupt.Interrupt vector contains the address of service routines.OS preserves the state of the CPUstores registers and the program counter (address of interrupted instruction).Trapsoftware generated interrupt caused either by an error or a user request.
7Interrupt Handling Types of interrupt PollingVectored interrupt systemIncoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt.
8I/O Structure Synchronous I/O Asynchronous I/O wait instruction idles CPU until next interruptno simultaneous I/O processing, at most one outstanding I/O request at a time.Asynchronous I/OAfter I/O is initiated, control returns to user program without waiting for I/O completion.System callDevice Status table - holds type, address and state for each deviceOS indexes into I/O device table to determine device status and modify table entry to include interrupt.
9Direct Memory Access (DMA) Used for high speed I/O devices able to transmit information at close to memory speeds.Device controller transfers blocks of data from buffer storage directly to main memory without CPU intervention.Only one interrupt is generated per block, rather than one per byte (or word).MemoryCPUI/O devicesI/O instructions
10Storage StructureMain memory - only large storage media that the CPU can access directly.Secondary storage - extension of main memory that has large nonvolatile storage capacity.Magnetic disks - rigid metal or glass platters covered with magnetic recording material.Disk surface is logically divided into tracks, subdivided into sectors.Disk controller determines logical interaction between device and computer.
11Storage HierarchyStorage systems are organized in a hierarchy based onSpeedCostVolatilityCaching - process of copying information into faster storage system; main memory can be viewed as fast cache for secondary storage.
14Dual-mode operationSharing system resources requires operating system to ensure that an incorrect program cannot cause other programs to execute incorrectly.Provide hardware support to differentiate between at least two modes of operation:1. User mode -- execution done on behalf of a user.2. Monitor mode (supervisor/kernel/system mode) -- execution done on behalf of operating system.
15Dual-mode operation(cont.) UserMode bit added to computer hardware to indicate the current mode: monitor(0) or user(1).When an interrupt or fault occurs, hardware switches to monitor mode.Privileged instructions only in monitor mode.Interrupt/faultSetusermodeMonitor
16I/O Protection All I/O instructions are privileged instructions. Must ensure that a user program could never gain control of the computer in monitor mode, for e.g. a user program that as part of its execution, stores a new address in the interrupt vector.
17Memory ProtectionMust provide memory protection at least for the interrupt vector and the interrupt service routines.To provide memory protection, add two registers that determine the range of legal addresses a program may address.Base Register - holds smallest legal physical memory address.Limit register - contains the size of the range.Memory outside the defined range is protected.When executing in monitor mode, the OS has unrestricted access to both monitor and users’ memory.monitor256000Job1Base register300040Job 2420940120900Job 3Limit register880000Job 4
18Hardware Address Protection The load instructions for the base and limit registers are privileged instructions.
19More detail: A Program’s Address Space Address space the set of accessible addresses + state associated with them:For a 32-bit processor there are 232 = 4 billion addressesWhat happens when you read or write to an address?Perhaps NothingPerhaps acts like regular memoryPerhaps ignores writesPerhaps causes I/O operation(Memory-mapped I/O)Perhaps causes exception (fault)Program Address Space
20Providing the Illusion of Separate Address Spaces Data 2Stack 1Heap 1OS heap &StacksCode 1Stack 2Data 1Heap 2Code 2OS codeOS dataCodeDataHeapStackCodeDataHeapStackProg 1VirtualAddressSpace 1Prog 2VirtualAddressSpace 2Translation Map 1Translation Map 2Load new Translation Map on SwitchPhysical Address Space
21CPU ProtectionTimer - interrupts computer after specified period to ensure that OS maintains control.Timer is decremented every clock tick.When timer reaches a value of 0, an interrupt occurs.Timer is commonly used to implement time sharing.Timer is also used to compute the current time.Load timer is a privileged instruction.
22General System Architecture Given the I/O instructions are privileged, how do users perform I/O?Via system calls - the method used by a process to request action by the operating system.
23System Calls Interface between running program and the OS. Assembly language instructions (macros and subroutines)Some higher level languages allow system calls to be made directly (e.g. C)Passing parameters between a running program and OS via registers, memory tables or stack.Unix has about 32 system callsread(), write(), open(), close(), fork(), exec(), ioctl(),…..
24Operating System Services Services that provide user-interfaces to OSProgram execution - load program into memory and run itI/O Operations - since users cannot execute I/O operations directlyFile System Manipulation - read, write, create, delete filesCommunications - interprocess and intersystemError Detection - in hardware, I/O devices, user programsServices for providing efficient system operationResource Allocation - for simultaneously executing jobsAccounting - for account billing and usage statisticsProtection - ensure access to system resources is controlled
25System ProgramsConvenient environment for program development and execution. User view of OS is defined by system programs, not system calls.Command Interpreter (sh, csh, ksh) - parses/executes other system programsFile manipulation - copy (cp), print (lpr), compare(cmp, diff)File modification - editing (ed, vi, emacs)Application programs - send mail (mail), read news (rn)Programming language support (cc)Status information, communicationetc….
26Command Interpreter System Commands that are given to the operating system via command statements that executeProcess creation and deletion, I/O handling, Secondary Storage Management, Main Memory Management, File System Access, Protection, Networking.Obtains the next command and executes it.Programs that read and interpret control statements also called -Control card interpreter, command-line interpreter, shell (in UNIX)
27System Design and Implementation Establish design goalsUser GoalsSystem GoalsSoftware Engineering -Separate mechanism from policy. Policies determine what needs to be done, mechanisms determine how they are done.Choose a high-level implementation languagefaster implementation, more compact, easier to debug
28System GenerationOS written for a class of machines, must be configured for each specific site.SYSGEN program obtains info about specific hardware configuration and creates version of OS for hardwareBootingBootstrap program - loader program loads kernel, kernel loads rest of OS.Bootstrap program stored in ROM
29Operating Systems: How are they organized? SimpleOnly one or two levels of codeLayeredLower levels independent of upper levelsMicrokernelOS built from many user-level processesModularCore kernel with Dynamically loadable modules
30OS Structure - Simple Approach MS-DOS - provides a lot of functionality in little space.Not divided into modules, Interfaces and levels of functionality are not well separated
31UNIX System StructureUNIX - limited structuring, has 2 separable partsSystems programsKerneleverything below system call interface and above physical hardware.Filesystem, CPU scheduling, memory management
32Layered OS StructureOS divided into number of layers - bottom layer is hardware, highest layer is the user interface.Each layer uses functions and services of only lower-level layers.THE Operating System Kernel has successive layers of abstraction.
34Microkernel Structure Moves as much from the kernel into “user” spaceSmall core OS running at kernel levelOS Services built from many independent user-level processesCommunication between modules with message passingBenefits:Easier to extend a microkernelEasier to port OS to new architecturesMore reliable (less code is running in kernel mode)Fault Isolation (parts of kernel protected from other parts)More secureDetriments:Performance overhead severe for naïve implementation
35Modules-based Structure Most modern operating systems implement modulesUses object-oriented approachEach core component is separateEach talks to the others over known interfacesEach is loadable as needed within the kernelOverall, similar to layers but with more flexible
36OS Task: Process Management Process - fundamental concept in OSProcess is a program in execution.Process needs resources - CPU time, memory, files/data and I/O devices.OS is responsible for the following process management activities.Process creation and deletionProcess suspension and resumptionProcess synchronization and interprocess communicationProcess interactions - deadlock detection, avoidance and correction
37OS Task: Memory Management Main Memory is an array of addressable words or bytes that is quickly accessible.Main Memory is volatile.OS is responsible for:Allocate and deallocate memory to processes.Managing multiple processes within memory - keep track of which parts of memory are used by which processes. Manage the sharing of memory between processes.Determining which processes to load when memory becomes available.
38OS Task: Secondary Storage and I/O Management Since primary storage is expensive and volatile, secondary storage is required for backup.Disk is the primary form of secondary storage.OS performs storage allocation, free-space management and disk scheduling.I/O system in the OS consists ofBuffer caching and managementDevice driver interface that abstracts device detailsDrivers for specific hardware devices
39OS Task: File System Management File is a collection of related information defined by creator - represents programs and data.OS is responsible forFile creation and deletionDirectory creation and deletionSupporting primitives for file/directory manipulation.Mapping files to disks (secondary storage).Backup files on archival media (tapes).
40OS Task: Protection and Security Protection mechanisms control access of programs and processes to user and system resources.Protect user from himself, user from other users, system from users.Protection mechanisms must:Distinguish between authorized and unauthorized use.Specify access controls to be imposed on use.Provide mechanisms for enforcement of access control.Security mechanisms provide trust in system and privacyauthentication, certification, encryption etc.
41OS Task: Networking Connecting processors in a distributed system Distributed System is a collection of processors that do not share memory or a clock.Processors are connected via a communication network.Advantages:Allows users and system to exchange informationprovide computational speedupincreased reliability and availability of information
42Virtual Machines Logically treats hardware and OS kernel as hardware Provides interface identical to underlying bare hardware.Creates illusion of multiple processes - each with its own processor and virtual memoryprocessesprocessesprocesseskernelkernelkernelVirtual machinehardware
43Summary of OS Structures Operating System ConceptsOperating System Services, System Programs and System callsOperating System Design and ImplementationStructuring Operating Systems