02.Os Structure
-
Upload
applejinghan -
Category
Technology
-
view
3.463 -
download
0
description
Transcript of 02.Os Structure
Computer System Architecture (Software)
Chapter 2. Operating System structure
Spring 2008Guo Xunhua
2Guo, Xunhua
Operating System Structure
Computer hardware structure
System calls
System programs
Operating system components
Computer hardware structure
4Guo, Xunhua
Computer hardware
5Guo, Xunhua
Hardware Architecture(Storage Centric)
6Guo, Xunhua
Hardware Architecture(Bus-based)
Input Devices
Output Devices
... ...
... ...
... ...
... ...
... ...
... ...
CPU
Arithmetric-Logic UnitControl Unit
Primary Storage
SecondaryStorage
CommunicationDevices
... ...
... ...
... ...
BUS
... ...
... ...
... ...
7Guo, Xunhua
Hardware components
Central Processing Unit (CPU)Control UnitArithmetic-Logic Unit
StoragePrimary StorageSecondary Storage
Input/Output Devices (Including Communication Devices)
8Guo, Xunhua
Computer hardware operation
I/O devices and the CPU can execute concurrently.Each device controller is in charge of a particular device type.Each device controller has a local buffer.CPU moves data from/to main memory to/from the local buffers.I/O is from the device to local buffer of controller.Device controller informs CPU that it has finished its operation by causing an interrupt.
Moni tor
Bus
9Guo, Xunhua
Common Functions of InterruptsInterrupt transfers control to the interrupt service routine
interrupt vector contains the addresses of all the service routines.
Interrupt architecture must save the address of the interrupted instruction.Incoming interrupts are disabled while another interrupt is being processed to prevent a lost interrupt.A trap is a software-generated interrupt caused either by an error or a user request.An operating system is interrupt driven.
10Guo, Xunhua
Interrupts
(a) Steps in starting an I/O device and getting interrupt
(b) How the CPU is interrupted
(a) (b)
11Guo, Xunhua
Interrupt time line
12Guo, Xunhua
Synchronous I/O interrupts
After I/O starts, control returns to user program only upon I/O completion.
wait instruction idles the CPU until the next interrupt.wait loop (contention for memory access).at most one I/O request is outstanding at a time; no simultaneous I/O processing.
13Guo, Xunhua
Asynchronous I/O interruptsAfter I/O starts, control returns to user program without waiting
System call – request to the operating systemDevice-status table contains entry for each I/O device indicating its type, address, and state (not functioning, idle or busy)Multiple requests for the same device are maintained in a wait queue.Operating system indexes into I/O device table to determine device status and to modify table entry to include interrupt.
14Guo, Xunhua
DMA Structure
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 the one interrupt per byte.
15Guo, Xunhua
Storage Structure
Main memoryThe only large storage media that the CPU can access directly.
Secondary storageextension of main memory that provides large nonvolatile storage capacity.Magnetic disksOptical disksMagnetic tapes
16Guo, Xunhua
Typical memory hierarchy
Storage systems organized in hierarchy:Speed, cost, volatility
Cachingcopying information into faster storage system; main memory can be viewed as a fast cache for secondary storage.
17Guo, Xunhua
Structure of a large Pentium system
18Guo, Xunhua
Hardware protection
Dual-Mode OperationI/O ProtectionMemory ProtectionCPU Protection
19Guo, Xunhua
Dual-mode operation
Sharing 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 operations.
User mode – execution done on behalf of a user.Monitor mode (also supervisor mode, kernel mode, or system mode) – execution done on behalf of operating system.
20Guo, Xunhua
Dual-mode operation
21Guo, Xunhua
User mode and monitor mode
Mode 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 modePrivileged instructions can be issued only in monitor mode.
22Guo, Xunhua
I/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
i.e., a user program that, as part of its execution, stores a new address in the interrupt vector
23Guo, Xunhua
Memory protection
Must provide memory protection at least for the interrupt vector and the interrupt service routines.In order to have memory protection, add two registers that determine the range of legal addresses a program may access:
base register – holds the smallest legal physical memory address.limit register – contains the size of the range.
Memory outside the defined range is protected.
24Guo, Xunhua
Example of memory protection
25Guo, Xunhua
Protection hardware
26Guo, Xunhua
Question
Given that I/O instructions are privileged, how does the user program perform I/O?
System calls
28Guo, Xunhua
System calls
The method used by a process to request action by the operating system.Usually takes the form of a trap to a specific location in the interrupt vector.Control passes through the interrupt vector to a service routine in the OS, and the mode bit is set to monitor mode.The monitor verifies that the parameters are correct and legal, executes the request, and returns control to the instruction following the system call.
29Guo, Xunhua
System calls
System calls provide the interface between a running program and the operating system.Three general methods are used to pass parameters between a running program and the operating system:
Pass parameters in registers.Store the parameters in a table in memory, and the table address is passed as a parameter in a register.Push (store) the parameters onto the stack by the program, and pop off the stack by the operating system.
30Guo, Xunhua
Steps in making a system call
31
Some System Calls For Process Management
32
Some System Calls For File Management
33
Some System Calls For Directory Management
34
Some System Calls For Miscellaneous Tasks
35
System call interface
The layers of a UNIX system.
UserInterface
System programs
37Guo, Xunhua
System (utility) programs
Solve common problems or perform common operations
File manipulation: e.g., cp, mv, chmod, lsStatus information: e.g., date, ps, dfFile modification: e.g., viProgramming-language support: e.g., gcc, asmProgram loading and execution: e.g., ld, gdbCommunications: e.g., telnet
System programs are invoked from the shell whereas system calls are invoked from programs.
38Guo, Xunhua
UNIX utility programs
Operating system components
40Guo, Xunhua
Common system components
Process ManagementMain-Memory ManagementFile ManagementI/O System ManagementProtection SystemNetworkingCommand-Interpreter System
41Guo, Xunhua
Process managementprogram (passive) vs. process (active)
A process is a program in execution. A process needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task.
The operating system is responsible for:process creation and deletion.process suspension and resumption.provision of mechanisms for:
process synchronizationprocess communicationDeadlock handling
42Guo, Xunhua
Main memory management
Memory is a large array of words or bytes, each with its own address.It is a repository of quickly accessible data shared by the CPU and I/O devices.Main memory is a volatile storage deviceThe operating system is responsible for:
Keep track of which parts of memory are currently being used and by whom.Decide which processes to load when memory space becomes available.Allocate and deallocate memory space as needed.
43Guo, Xunhua
File Management
The OS through the file system provides a uniform logical view of information storage. The operating system is responsible for:
File creation and deletion.Directory creation and deletion.Support of primitives for manipulating files and directories.Mapping files onto secondary storage.File backup on stable (nonvolatile) storage media.
44Guo, Xunhua
I/O system management
The peculiarities of the various I/O devices are hidden from the bulk of the operating system itself by the I/O subsystemThe I/O system consists of:
A buffer-caching systemA general device-driver interfaceDrivers for specific hardware devices
45Guo, Xunhua
Secondary-Storage Management
Most modern computer systems use disks as the principle on-line storage medium, for both programs and data.The operating system is responsible for:
Free-space managementStorage allocationDisk scheduling
46Guo, Xunhua
Protection system
Protection refers to a mechanism for controlling access by programs, processes, or users to both system and user resources.The protection mechanism must:
distinguish between authorized and unauthorized usage.specify the controls to be imposed.provide a means of enforcement.
47Guo, Xunhua
Networking
A distributed system is a collection of processors that do not share memory or a clock. Each processor has its own local memory.The processors in the system are connected through a communication network.A distributed system provides user access to various system resources.
Computation speed-upIncreased data availabilityEnhanced reliability
48Guo, Xunhua
Command-Interpreter System
User interface which deals with:process creation and managementI/O handlingsecondary-storage managementmain-memory managementfile-system accessprotectionNetworking
Command-line and GUI
49Guo, Xunhua
Common system components
Process ManagementMain-Memory ManagementFile ManagementI/O System ManagementProtection SystemNetworkingCommand-Interpreter System
50Guo, Xunhua
Simple structure: MS DOS
51Guo, Xunhua
Monolithic kernel vs. Microkernel
52Guo, Xunhua
The client-server model in a distributed system
53Guo, Xunhua
Operating-System Services
Program executionI/O operationsFile-system manipulationCommunications Error detectionAdditional functions for ensuring efficient system operation.
Resource allocation, Accounting, Protection
54Guo, Xunhua
UNIX Structure
55Guo, Xunhua
Basic characteristics of modern operating systems
Concurrency (并发 )Sharing (共享 )Virtualization (虚拟 )Asynchronism (异步 )
55Guo, Xunhua
56Guo, Xunhua
Concurrency
ConcurrencySeveral events take places in a same time periodSeveral programs (processes) run in the same time
A modern operating system is a concurrency system
The co-existence of multi events and processes is managed by the OS
57Guo, Xunhua
Sharing
Sharing: several processes share the limited computer system resource
An OS shall manage the system resource for proper sharingResources are used alternatively by multi processes
Exclusive sharing: e.g. printersNon-exclusive sharing: e.g. harddisks
58Guo, Xunhua
Virtualization
Virtualization:A physical entity is map to several logical entities with time or spaceAn important way to improve the utilization effectiveness of resources
Virtual processorVirtual storageVirtual device
59Guo, Xunhua
Virtual Machines
60Guo, Xunhua
Asynchronism
ConditionsSeveral processes execute concurrentlyThe execution sequence and time of processes are uncertainThe speed of process execution is not pre-determined
TargetNo matter how the processes are executed, the results must be the sam
61Guo, Xunhua
Exercises
Reading: Chapter 2 and 3, Textbook
Questions:Why is the distinction between monitor mode and user mode important?What are different between system calls and library functions?