第二讲 计算机系统结构 本讲主要内容: 计算机系统操作 I/O 结构 存储系统的结构 分级的存储体系 硬件保护 一般的系统结构 作业: 第二章 2, 3, 4, 5,6,7,8,9,10 Operating System Concepts
计算机系统结构 Operating System Concepts
计算机系统操作 I/O设备和CPU可以并行地执行。 每一个设备控制器负责管理一种特定的设备。 设备控制器通常都有本地的缓冲。 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. 设备控制器在完成I/O操作后通过中断通知CPU . Operating 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. 中断一般来说通过中断向量将CPU的控制转移给中断服务程序。中断向量包含有所有的服务程序的地址。 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. 操作系统都是中断驱动的。 Operating 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 单独的代码段决定对每一种中断类型要采取什么操作。 Operating System Concepts
Interrupt Time Line For a Single Process Doing Output 单个进程做输出操作的时序图 Operating System Concepts
I/O Structure I/O结构 After I/O starts, control returns to user program only upon I/O completion. I/O操作开始后,CPU的控制只有在I/O操作完成后才返回用户程序。 Wait instruction idles the CPU until the next interrupt 等待指令在下一次中断开始之前使CPU处于空等状态。 Wait loop (contention for memory access). 当访问存储器冲突时,就插入等待节拍。 At most one I/O request is outstanding at a time, no simultaneous I/O processing. 任何时候最多只有一个中断请求处于处理状态。 After I/O starts, control returns to user program without waiting for I/O completion. I/O操作开始后,CPU的控制不等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. 操作系统访问I/O设备表决定设备的状态,修改表项以加入中断。 Operating System Concepts
Two I/O Methods 两种方法 Synchronous同步 Asynchronous异步 Operating System Concepts
Device-Status Table 设备状态表 Operating System Concepts
Direct Memory Access Structure 直接访问存储器的结构 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. 每个数据块只产生一个中断,而不是每个字节产生一个中断。 Operating System Concepts
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 磁盘-硬金属或玻璃上覆盖磁记录材料。 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. 磁盘控制器决定设备和计算机之间逻辑上相互作用。 Operating System Concepts
Moving-Head Disk Mechanism 磁盘磁头移动的机制 Operating System Concepts
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. 高速缓存-将信息拷贝到快速的存储系统。主存可以二级存储器的上一级的高速缓冲。 Operating System Concepts
Storage-Device Hierarchy 分级存储设备 Operating System Concepts
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. Operating System Concepts
Migration of A From Disk to Register 将A从磁盘迁移到寄存器 Operating System Concepts
Hardware Protection 硬件保护 Dual-Mode Operation 双模式操作 I/O Protection I/O保护 Memory Protection 存储保护 CPU Protection CPU保护 Operating System Concepts
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) – execution done on behalf of operating system. Operating System Concepts
Dual-Mode Operation (Cont.) 双模式操作(续) 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 mode. 中断或异常 monitor user 设置用户模式 特权指令只有在管态或核心模式下才能执行。 Operating System Concepts
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 (I.e., a user program that, as part of its execution, stores a new address in the interrupt vector). 必须确保用户程序不能获得核心模式(即用户程序不能将中断向量表修改成用户程序的地址) Operating System Concepts
Use of A System Call to Perform I/O 使用系统调用执行I/O操作 Operating System Concepts
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. 存储器超出定义的范围就受到保护。 Operating System Concepts
Use of A Base and Limit Register 使用基址寄存器和界限寄存器 Operating System Concepts
Hardware Address Protection 硬件地址保护 Operating 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. 装载基址寄存器和界限寄存器的指令为特权指令。 Operating System Concepts
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. 时间中断用来实现分时系统。 Timer also used to compute the current time. 时间中断还用来计算系统的时间。 Load-timer is a privileged instruction. 设置系统时间是特权指令。 Operating System Concepts
Network Structure 网络结构 Local Area Networks (LAN) 局域网 Wide Area Networks (WAN) 广域网 Operating System Concepts
Local Area Network Structure 局域网结构 Operating System Concepts
Wide Area Network Structure 广域网结构 Operating System Concepts