文章目录
- OS——Introduction
- 1.1 What Operating Systems Do
- 1.2 Computer-System Organization
- 1.3 Computer-System Architecture (*)
- 1.4 Operating-System Structure
- 1.5 Operating-System Operations
- 1.6 Process Management
- 1.7 Memory Management
- 1.8 Storage Management
- 1.9 Protection and Security
- 1.10 Kernel Data structures (*)
- 1.11 Computing Environments (*)
- 1.12 Open-Source Operating Systems (*)
OS——Introduction
1.1 What Operating Systems Do
- Computer System Components
1. Hardware provides basic computing resources, such as CPU, memory, I/O device
2. Operating system controls and coordinates the use of the hardware among the various application programs for the various users.
3. Applications programs define the ways in which the system resources are used to
solve user’s computing problems (compilers, DBMS, database systems, word processors,
video games, business programs).
4. Users people, machines, other computers - Services Provided by the OS
Program development– Editors and debuggers
Program execution
Access to I/O devices
Controlled access to files
System access
Error detection and response
Accounting
Explore from two view points
User view
– PC
• ease to use, performance,none paid to resource utilization
– Mainframe, minicomputer
• Maximize resource utilization
– workstation
• Usability and resource utilization
– Handheld computer
• Individual usability, performance per amount of battery life
– Embedded computer
• Have little or no user view
System view
Resource allocator
Control program
- define the operating system
操作系统是计算机系统中的一个系统软件, 是一些程序模块的集合,它们能以尽量有效、合理的方式组织和管理计算机的软硬件资源, 合理地组织计算机的工作流程,控制程序的执行, 向用户提供各种服务功能, 使得用户能够灵活、方便、有效的使用计算机, 使整个计算机系统能高效地运行。
1.2 Computer-System Organization
Types of instructions
Processor-memory – transfer data between processor and memory
Processor-I/O – data transferred to or from a peripheral device
Data processing – arithmetic or logic operation on data
Control – alter sequence of execution
Computer Startup
bootstrap program is loaded at power-up or reboot
– Typically stored in ROM or EEPROM, generally known as firmware
– Initializes all aspects of system( CPU registers to device controllers to memory contents )
– Locates operating system kernel and Loads it into memory, and starts execution
OS starts executing the first process, such as “init”and waits for some events to occur
– An interrupt from the hardware
• Sending a signal to CPU by way of the system bus
– An interrupt from the software
• Executing a system call
Computer-System Operation
CPU moves data from/to main memory to/from 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.
Interrupt
在中断方式传送时, 当外设需要服务时,向CPU提出中断请求,CPU转入中断服务程序,在中断服务程序中实现与外设的数据传送,然后返程序。外设在进行数据传送的准备工作,而CPU同时执行原程序,这就是并行工作。
class of Interrupt
A trap is a software-generated interrupt caused either by an error or a user request. An operating system is interrupt driven.
The operating system preserves the state of the CPU by storing registers and the program counter.
Storage Structure
Main memory – only large storage area that the processor can access directly.
Secondary storage – extension of main memory that provides large nonvolatile storage capacity.
Magnetic disks – rigid metal or glass platters covered with magnetic recording material
– Disk surface is logically divided into tracks, which are subdivided into sectors.
– The disk controller determines the logical interaction between the device and the computer.
Magnetic tapes - used for backup, for storage of infrequently used information
Storage systems organized in hierarchy.
– Speed – Cost – Volatility
Volatile storage loses its contents when the power to the device is removed. 、
Principle of design a computer memory system
– uses only as much expensive memory as necessary
– provides as much inexpensive, nonvolatile memory as possible.
I/O operation
device controller
– Local buffer storage
– A set of special-purpose registers
– Moving data between device and its local buffer storage
device driver
– One for each device controller
– Presents a uniform interface to the device
I/O operation
– Device driver loads registers within the controller
– Controller examines the contents of the registers to determine what action to take
– Controller starts the transfer of data between the device and its local buffer
– Once done, controller informs the driver via an interrupt
– Driver returns control to the OS, with data if ‘read’
Direct Memory Access
Transfers a block of data directly to or from memory.
Used for high-speed I/O devices able to transmit information at close to memory speeds.
After setting up buffers, pointers, and counters for the I/O devices , 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.
– An interrupt is sent when the task is complete
– The processor is only involved at the beginning and end of the transfer
CPU is available to accomplish other work while the device controller is performing the DMA transfer
CPU对通道的管理是通过I/O指令实现的。
–I/O指令属于特权指令,仅能由操作系统使用。
–在I/O指令中需指定通道号、设备号、以及通道程序的内存地址。
当CPU要完成一组相关的读(或写)操作及有关控制时,只需向I/O通 道发送一条I/O指令,以给出其所要执行的通道程序的首址和要访 问的I/O设备,通道接到该指令后,通过执行通道程序便可完成CPU 指定的I/O任务。
42
1.3 Computer-System Architecture (*)
Single-processor system
– One main CPU executing a general-purpose instruction set
– special-purpose processors run a limited instruction set and do not run user processes, such as controllers, I/O processors
Multiprocessor system/parallel system
– Two or more processors in close communication, sharing the computer bus and the clock, memory and I/O devices
– Advantages
• Increased throughput
• Economy of scale
• Increased reliability
– Symmetric(对称的) multiprocessing
• Each processor performs all tasks within the OS
• All processors are peers
– Asymmetric(非对称的) multiprocessing
• Each processor is assigned a specific task
• A boss processor controls the system
• The other worker processors look to the boss for instruction or have predefined tasks
• Boss processor schedules and allocate work to the worker processors
– Multi-core CPUs
• Multiple compute cores on a single chip
Clustered(集群) systems
– Clustered computers share storage and are closely linked via a LAN or a faster interconnect such as InfiniBand.
– Used to provide high-availability service
– A layer of cluster software runs on the cluster nodes
– Asymmetric clustering
• One machine is in hot-standby mode while the other is running the applications
• The hot-standby host machine does nothing but monitor the active server
– Symmetric clustering
• Two or more hosts are running applications and are monitoring each other
1.4 Operating-System Structure
Uniprogramming
– Problem: low Performance
Processor must wait for I/O instruction to complete before preceding
solution: Off-line operation (脱机操作)
– speed up computation by – loading jobs into memory from tapes
– card reading and line printing done off-line.
Spooling
Simultaneous Peripheral Operation On Line
Overlap I/O of one job with computation of another job.
While executing one job, the OS.
– Reads next job from card reader into a storage area on the disk (job queue).
– Outputs printout of previous job from disk to printer.
Job pool – data structure that allows the OS to select which job to run next in order to increase CPU utilization.
Multiprogramming needed for efficiency
One job selected and run via job scheduling
When it has to wait (for I/O for example), OS switches to another job.
Timesharing systems
Timesharing (multitasking) is logical extension in which CPU switches jobs so frequently that users can interact with each job while it is running, creating interactive computing
– Response time should be < 1 second
– Each user has at least one program executing in memory=> process
– If several jobs ready to run at the same time =>CPU scheduling
– If processes don’t fit in memory, swapping moves them in and out to run
– Virtual memory allows execution of processes not completely in memory
-
Using multiprogramming to handle multiple interactive jobs
-
The CPU is multiplexed(复用) among several jobs that are kept in memory and on disk
-
A job swapped in and out of memory to the disk.
-
Many users share the computer simultaneously.
-
On-line system must be available for users to access data and code.
1.5 Operating-System Operations
- Separate segments of code determine what action should be taken for each type of interrupt
Dual-mode operation
Allows OS to protect itself and other system components
– Provide hardware support to differentiate between at least two modes of operations.
- User mode – execution done on behalf of a user.
- Monitor mode (also kernel mode or system mode) – execution done on behalf of operating system.
- Mode bit provided by hardware
- Timer to prevent infinite loop / process hogging resources
– Set interrupt after specific period
– Operating system decrements counter
– When counter zero generate an interrupt
– Set up before scheduling process to regain control or terminate program that exceeds allotted time
– Instructions that modify the content of the timer are privileged. (I/O)
1.6 Process Management
Program is a passive entity, process is an active entity
Process needs resources to accomplish its task. – CPU, memory, I/O, files, Initialization data Process termination requires reclaim (归还) of any reusable resources.
Single-threaded process has one program counter specifying location of next instruction to execute.
– Process executes instructions sequentially, one at a time, until completion
Multi-threaded process has one program counter per thread.
1.7 Memory Management
Central to the operation of a modern computer system
The only large storage device that CPU is able to address and access directly
Memory management determines what is in memory when
– Optimizing CPU utilization and computer response to users
1.8 Storage Management
File-System management
- OS provides uniform, logical view of information storage
– Abstracts physical properties to logical storage unit - file
– Each medium is controlled by device (i.e., disk drive, tape drive) - Files usually organized into directories
Access control on most systems to determine who can access what
OS activities include
– Creating and deleting files
– Creating and deleting directories to organize files
– Supporting primitives(原语) for manipulating files and directories
– Mapping files onto secondary storage
– Backing up files onto stable (nonvolatile) storage media
Mass-Storage Management
Usually disk is used to store data that does not fit in main memory or data that must be kept for a “long” period of time.
Proper management is of central importance
Entire speed of computer operation hinges on disk subsystem and its algorithms
OS activities
– Free-space management
– Storage allocation
– Disk scheduling
Some storage need not be fast
Caching
Caching – copying information into faster storage system;
main memory can be viewed as a last cache for secondary storage.
Disk Cache
A portion of main memory used as a buffer to temporarily to hold data for the disk
Cache Memory(高速缓存)
Invisible to operating system
Increase the speed of memory
Processor speed is faster than memory speed
Coherency and Consistency (高速缓存一致性)
The same data may appear in different levels of the storage system.
I/O Subsystem
One purpose of OS is to hide peculiarities(特性) of hardware devices from the user
I/O subsystem responsible for
– Memory management of I/O, including
• buffering
• caching
• spooling
– General device-driver interface
– Drivers for specific hardware devices
1.9 Protection and Security
Protection – any mechanism for controlling access of processes or users to resources defined by the OS
Security – defense of the system against internal and external attacks
– Huge range, including denial-of-service, worms, viruses, identity theft, theft of service
Access control
– regulate user access to the system
Information flow control
– regulate flow of data within the system and its delivery to users
Certification
– proving that access and flow control perform according to specifications
Systems generally first distinguish among users, to determine who can do what
– User identities
– Group identifier (group ID)
– Privilege escalation allows user to change to effective ID with more rights
1.10 Kernel Data structures (*)
Lists, Stacks, and Queues
Hash Functions and Maps :[key:value] pairs
hash collision.
Bitmaps
1.11 Computing Environments (*)
Traditional computing
• PCs connected to a network, servers providing file and print services. Remote access was awkward, portability was achieved by use of laptop computers
• Terminals attached to mainframes were prevalent at many companies as well, with even fewer remote access and portability options.
Distributed computing
Collection of separate, possibly heterogeneous, systems networked together
• Local Area Network (LAN), Wide Area Network (WAN)
• Metropolitan Area Network (MAN), Personal Area Network (PAN) – Transport media
• Copper wires, fiber strands, wireless transmissions between satellites, microwave dishes, and radios.
Network Operating System provides features between systems across network
– Communication scheme allows systems to exchange messages
– provides file sharing across the network
– provides communication scheme allowing different processes on different computers to exchange messages.
– runs independently from other computers on the network
– less autonomy between computers
– gives the impression there is a single operating system controlling the network.
Client-Server Computing
Dumb terminals supplanted by smart PCs
Many systems now servers, responding to requests generated by clients-Server systems
– Compute-server system provides an interface to client to request services
– File-server system provides interface for clients to store and retrieve files (exp. web server)
Peer-to-Peer Computing
P2P does not distinguish clients and servers
– Registers its service with centralized lookup service on network
– Broadcast request for service and respond to requests for service via discovery protocol Examples:
– Napster, Gnutella
– Voice over IP (VoIP) such as Skype
Virtualization
a technology that allows operating systems to run as applications within other operating systems.
VMware Architecture
The Java Virtual Machine
Cloud computing
Delivers computing, storage, even apps as a service across a network
Logical extension of virtualization because it uses virtualization as the base for it functionality.
– Amazon EC2
Many types
– Public cloud – available via Internet to anyone willing to pay
– Private cloud – run by a company for the company’s own use
– Hybrid cloud – includes both public and private cloud
components
– Software as a Service (SaaS) – one or more applications available via the Internet (i.e., word processor)
– Platform as a Service (PaaS) – software stack ready for application use via the Internet (i.e., a database server)
– Infrastructure as a Service (IaaS) – servers or storage available over Internet (i.e., storage available for backup use)
Real-Time Embedded Systems
Used when there are rigid(严格的) time requirements on the operation of a processor or the flow of data.
Often used as a control device in a dedicated application, such as
– control scientific experiments
– medical imaging systems
– industrial control systems
– some display systems
The OS provide limited features
– Have little or no user interface
– Preferring to spend their time monitoring and managing hardware devices
There are two classes of real-time systems
– hard real-time system
– soft real-time system.
Hard real-time system
– goal: to guarantee critical tasks be completed on time.
– Secondary storage limited or absent, data stored in short-term memory, or read-only memory (ROM)
– Conflicts with time-sharing systems, not supported by general-purpose operating systems.
Soft real-time system
– a critical real-time task gets priority over other tasks, and retains that priority until it completes.
– Lack of deadline support, limited utility in industrial control or robotics.
– Useful in applications (multimedia, virtual reality, scientific projects) requiring advanced operating-system features.
1.12 Open-Source Operating Systems (*)
Operating systems made available in source-code format rather than just binary closed-source