chapter 2: computer-system structures 计算机系统结构

36
2.1 Operating System Concepts Chapter 2: Computer-System Structures 计计计计 计计 2.1 Computer System Operation 计计计计 计计 2.2 I/O Structure I/O 计计 2.3 Storage Structure 计计计计 2.4 Storage Hierarchy 计计计计 2.5 Hardware Protection 计计计计 2.6 Network Structure 计计计计

Upload: natalie-lucas

Post on 13-Mar-2016

177 views

Category:

Documents


19 download

DESCRIPTION

Chapter 2: Computer-System Structures 计算机系统结构. 2.1 Computer System Operation 计算机系统运行 2.2 I/O Structure I/O 结构 2.3 Storage Structure 存储构造 2.4 Storage Hierarchy 存储层次 2.5 Hardware Protection 硬件保护 2.6 Network Structure 网络 结构. 2.1 Computer-System Operation 计算机系统运行. - PowerPoint PPT Presentation

TRANSCRIPT

2.1Operating System Concepts

Chapter 2: Computer-System Structures计算机系统结构 2.1 Computer System Operation 计算机系统运行 2.2 I/O Structure I/O 结构 2.3 Storage Structure 存储构造 2.4 Storage Hierarchy 存储层次 2.5 Hardware Protection 硬件保护 2.6 Network Structure 网络结构

2.2Operating System Concepts

2.1 Computer-System Operation 计算机系统运行 I/O devices and the CPU can execute concurrently.

I/O 设备与 CPU 可并行运行 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 local

buffers .CPU 通过局部缓存与主存交换数据 I/O is from the device to local buffer of controller.  I/O 是从设备到设备控制器的局部缓存 Device controller informs CPU that it has finished its

operation by causing an interrupt. 设备控制器通过引起中断通知 CPU 操作已完成

2.3Operating System Concepts

Fig 2.1 Computer-System Architecture计算机系统体系结构

2.4Operating System Concepts

Common Functions of Interrupts 中断的常见功能 Interrupt transfers control to the interrupt service

routine generally, through the interrupt vector, which 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. 当另一个中断正在处理时,刚进入的中断不能响应,以免丢失中断

2.5Operating System Concepts

Common Functions of Interrupts (Cont.)

A trap is a software-generated interrupt caused either by an error or a user request.

 陷阱是由于出错或用户请求引起的软件生成的中断 An operating system is interrupt driven. 操作系统是中断驱动的

2.6Operating System Concepts

Interrupt Handling中断处理 The operating system preserves the state of the

CPU by storing registers and the program counter.操作系统通过保存寄存器和程序计数器而保留了 CPU的状态 Determines which type of interrupt has occurred: 确定哪一种中断发生了:

polling 轮询 vectored interrupt system 矢量化中断系统

Separate segments of code determine what action should be taken for each type of interrupt

 对每一类中断分离代码段,以确定应该采取什么反应

2.7Operating System Concepts

Fig 2.2 Interrupt Time Line For a Single Process Doing Output单进程处理输出的中断时间线

2.8Operating System Concepts

2.2 I/O Structure I/O 结构

SynchronousI/O:After I/O starts, control returns to user program only upon I/O completion. 同步 I/O :在 I/O 开始之后,仅当 I/O 完成之后控制才返回用户程序Wait instruction idles the CPU until the next interrupt 等待指令空转 CPU ( cpu 等待)直至下一个中断Wait loop (contention for memory access). 等候循环At most one I/O request is outstanding at a time, no

simultaneous I/O processing. 每一时刻最多一个 I/O 请求,无并行 I/O 处理

2.9Operating System Concepts

I/O Structure (Cont.) AsynchronousI/O: After I/O starts, control returns to user

program without waiting for I/O completion. 异步 I/O :在 I/O 开始之后,不等 I/O 完成控制就返回用户程序 System call – request to the operating system to allow

user to wait for I/O completion. 系统调用-请求操作系统允许用户等待 I/O 完成Device-status table contains entry for each I/O device

indicating its type, address, and state. 设备状态表-包括每个 I/O 设备的类型、地址和状态Operating system indexes into I/O device table to

determine device status and to modify table entry to include interrupt. 操作系统引用设备状态表以确定设备状态并修改表入口加入中断

2.10Operating System Concepts

Fig 2.3 Two I/O Methods两种 I/O 方法Synchronous 同步 Asynchronous 异步

2.11Operating System Concepts

Fig 2.4 Device-Status Table设备状态表

2.12Operating System Concepts

2.2.2 Direct Memory Access Structure 直接内存访问 (DMA) 结构 Used for high-speed I/O devices able to transmit

information at close to memory speeds. 用于高速 I/O 设备能够以接近存储器的速率传送信息 Device controller transfers blocks of data from buffer

storage directly to main memory without CPU intervention.无须 CPU 的介入,设备控制器直接把数据块从缓冲区存储传送到主存

Only on interrupt is generated per block, rather than the one interrupt per byte.

每数据块只要一个中断,而不是每个字节一个中断

2.13Operating System Concepts

2.3 Storage Structure存储构造 Main memory– only large storage media that the

CPU can access directly. 主存 --CPU 可以直接访问的唯一大型存储介质 Secondary storage– extension of main memory that

provides large nonvolatile storage capacity. 二级 ( 辅助、外 ) 存储器 - 主存的扩展提供了非易失的存储容量 Magnetic disks– rigid metal or glass platters covered

with magnetic recording material 磁盘 - 覆盖了磁记录材料的硬金属或玻璃盘片

2.14Operating System Concepts

Storage Structure (Cont.)

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. 磁盘驱动器确定设备和计算机之间的相互作用

2.15Operating System Concepts

Fig 2.5 Moving-Head Disk Mechanism磁头移动机制

2.16Operating System Concepts

2.4 Storage Hierarchy存储层次 Storage systems organized in hierarchy. 存储系统分层组织

Speed 速度Cost 成本Volatility 易失性

Caching 缓存– copying information into faster storage system; main memory can be viewed as a last cache for secondary storage.

缓存 - 把信息复制进较快的存储系统;主存可看作为二级存储器的最后一个缓存

2.17Operating System Concepts

Fig 2.6 Storage-Device Hierarchy存储设备层次寄存器

缓存主存储器电子盘

磁盘光盘磁带

2.18Operating System Concepts

2.4.1 Caching 缓存 Use of high-speed memory to hold recently-

accessed data.用高速存储器保存最近访问的数据 Requires a cache management policy.需要缓存管理策略 Caching introduces another level in storage

hierarchy. This requires data that is simultaneously stored in more than one level to be consistent.在存储层次中缓存引入另一级,则要求在更多层次上一致协调被存储的数据

2.19Operating System Concepts

Fig 2.7 Migration of A From Disk to Register

2.20Operating System Concepts

2.5 Hardware Protection硬件保护 2.5.1 Dual-Mode Operation-- 两状态运行 2.5.2 I/O Protection-- I/O 保护 2.5.3 Memory Protection-- 内存保护 2.5.4 CPU Protection-- CPU 保护

2.21Operating System Concepts

2.5.1 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.

至少在两个不同运行状态之间提供硬件支持 1.User mode– execution done on behalf of a user.用户态—代表用户的执行2.Monitor mode (also kernel mode or system mode or supervisor) --execution done on behalf of operating system.管态(核心态或系统态)–代表操作系统的执行

2.22Operating System Concepts

Dual-Mode Operation (Cont.-1)

Mode bit added to computer hardware to indicate the current mode: monitor (0) or user (1).计算机硬件中增加状态位,指示正确的状态:管态(0) 或用户态( 1 )

When an interrupt or fault occurs hardware switches to monitor mode.

当中断或错误出现,硬件切换至管态

2.23Operating System Concepts

Dual-Mode Operation (Cont.-2)

Privileged instructions can be issued only in monitor mode. 特权指令只能在管态下使用

Monitor管态 User用户态

Interrupt/fault

中断 / 错误

set user mode

置用户态

2.24Operating System Concepts

2.5.2 I/O Protection I/O 保护

All I/O instructions are privileged instructions. 所有 I/O 指令是特权指令 Must ensure that a user program could never gain

control of the computer in monitor mode在管态模式下必须确保用户程序决不能控制计算机

Given the I/O instructions are privileged, how does the user program perform I/O? I/O 指令是要特权的,用户程序如何完成 I/O ?

2.25Operating System Concepts

I/O Protection System call – 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. 控制通过中断向量传递给 OS 中的服务程序,状态位设为管态

The monitor verifies that the parameters are correct and legal, executes the request, and returns control to the instruction following the system call. 监控程序验证参数正确合法,执行请求,返回控制给系统调用后的指令

2.26Operating System Concepts

Fig 2.8 Use of A System Call to Perform I/O使用系统调用完成 I/O

2.27Operating System Concepts

2.5.3 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:为了进行存储保护,增加 2 个寄存器用于确定一个程序的合法地址范围 Base register– holds the smallest legal physical memory

address.基址寄存器 - 存有最小的合法物理存储器地址

Limit register– contains the size of the range 限长寄存器 - 存有允许范围的大小

Memory outside the defined range is protected.在定义范围之外的存储器受到保护

2.28Operating System Concepts

Fig 2.9 Use of A Base and Limit Register基址与限长寄存器使用

2.29Operating System Concepts

Fig2.10 Hardware Address Protection 硬件地址保护

2.30Operating System Concepts

Hardware Protection

When executing in monitor mode, the operating system has unrestricted access to both monitor and user’s memory.

在管态下运行时,操作系统对监控和用户存储空间有不受限制的访问权 The load instructions for the base and limit

registers are privileged instructions. 用于基址和限长寄存器的装载指令是特权指令

2.31Operating System Concepts

2.5.4 CPU Protection CPU 保护 Timer– interrupts computer after specified period to

ensure operating system maintains control.定时器 - 在指定的时间段之后中断计算机,以确认操作系统保持控制 Timer is decremented every clock tick. 每一时钟滴答定时器减少When timer reaches the value 0, an interrupt

occurs. 定时器为零时中断发生 Timer commonly used to implement time sharing. 定时器通常用于实现时间共享 Time also used to compute the current time. 定时器也用于计算当前时间 Load-timer is a privileged instruction. 装载定时器是特权指令

2.32Operating System Concepts

2.6 Network Structure网络结构 2.6.1 Local Area Networks (LAN) 局域网 2.6.2 Wide Area Networks (WAN)广域网

2.33Operating System Concepts

Fig2.11 Local Area Network Structure局域网结构

2.34Operating System Concepts

Fig 2.12 Wide Area Network Structure广域网结构

2.35Operating System Concepts

2.7 Summary

2.36Operating System Concepts

Exercises

2.3 2.8