操作系统 2014 春 第 9 章其他类型的操作系统 授课人 : 孙海龙 2014 年 5 月 21 日 多处理机系统 内容提要 实时操作系统 嵌入式操作系统 2 1
多处理机系统的三种模型 (a) 共享存储的多处理机. (b) 基于消息传递的多处理机. (c) 广域分布式系统. 统一存储器访问 UMA 的总线型多处理机体系结构 (a) 无缓存. (b) 有缓存. (c) 有缓存和私有存储 2
统一存储器访问 UMA 的交叉开关型多处理机体系结构 (a) 8 8 交叉开关. (b) 打开的交叉点. (c) 闭合的交叉点. 使用多阶段交换网络的 UMA 多处理机 (1) Figure 8-4. (a) A 2 2 switch with two input lines, A and B, and two output lines, X and Y. (b) A message format. Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639 3
使用多阶段交换网络的 UMA 多处理机 (2) Figure 8-5. An omega switching network. 非一致内存访问 NUMA 的多处理机 Figure 8-6. (a) A 256-node directorybased multiprocessor. 访问远程内存比访问本地内存要慢 4
每个 CPU 拥有各自的操作系统 每个 CPU 具有自己的内存, 用于保存私有数据 ; 操作系统的代码被所有 CPU 进行共享 主从式多处理机 Figure 8-8. A master-slave multiprocessor model. 所有的系统调用都由主 CPU 处理, 从 CPU 只负责运行用户进程 5
对称多处理机 Figure 8-9. The SMP multiprocessor model. 互斥访问 死锁处理 多处理机同步与互斥 TSL 指令 : 必须锁住总线, 否则会失效 6
多处理机的调度 - 分时系统 使用一个数据结构进行调度 ( 线程之间无依赖关系 ) 多处理机调度 - 空间共享 32 个 CPU 分成 4 个区域, 两个 CPU 可用 ( 某些线程需要同时进行调度 ) 7
群调度 Gang Scheduling (1) Figure 8-14. Communication between two threads belonging to thread A that are running out of phase. 空间共享与分时的结合, 让一个进程的所有线程一起调度运行 Gang Scheduling (2) The three parts of gang scheduling: 1.Groups of related threads are scheduled as a unit, a gang. 2.All members of a gang run simultaneously, on different timeshared CPUs. 3.All gang members start and end their time slices together. 8
Gang Scheduling (3) Figure 8-15. Gang scheduling. 多计算机之间的互联 : Interconnection Technology (1) Figure 8-16. Various interconnect topologies. (a) A single switch. (b) A ring. (c) A grid. 9
Interconnection Technology (2) Figure 8-16. Various interconnect topologies. (d) A double torus. (e) A cube. (f) A 4D hypercube. Network Interfaces Figure 8-18. Position of the network interface boards in a multicomputer. 10
阻塞与非阻塞调用 (1) (a) 阻塞的 send 调用. 阻塞与非阻塞调用 (2) 非阻塞的 send 调用 问题 : 直到消息发送出去才能修改其消息缓冲区, 否则消息会丢失, 发送进程仍然无法连续发送消息 三种方法 : 复制消息到内核缓冲区 发送结束之后中断发送者 缓冲区写时复制 11
阻塞与非阻塞调用 (3) 因此发送方有四种选择 : 1.Blocking send (CPU idle during message transmission). 2.Nonblocking send with copy (CPU time wasted for the extra copy). 3.Nonblocking send with interrupt (makes programming difficult). 4.Copy on write (extra copy probably needed eventually). 远程过程调用 :Remote Procedure Call 屏蔽 I/O 层的细节 12
分布式共享内存 (1) 不同层次实现存储器共享 分布式共享内存 (2) (a) Pages of the address space distributed among four machines. 13
多计算机间的调度算法 : 基于图论的确定性调度算法 Figure 8-24. Two ways of allocating nine processes to three nodes. 目标 : 最小网络流 A Sender-Initiated Distributed Heuristic Algorithm 过载的节点主动询问空闲节点 14
虚拟化技术 系统虚拟化 : 实现操作系统与物理计算机的分离, 使得在一台物理计算机上可以同时安装和运行一个或多个虚拟的操作系统 虚拟机 : 使用系统虚拟化技术, 运行在一个隔离环境中 具有完整硬件功能的逻辑计算机系统, 包括操作系统和其中的应用程序 最早在 IBM 370 中提出 IBM Systems Journal, vol. 18, no. 1, 1979, pp. 4 17. Concurrent execution of multiple production operating systems Testing and development of experimental systems Adoption of new systems with continued use of legacy systems Ability to accommodate applications requiring specialpurpose OS Introduced notions of handshake and virtual-equals-real mode to allow sharing of resource control information with CP Leveraged ability to co-design hardware, VMM, and guestos 15
计算机系统结构与接口 API ABI ISA Libraries Operating System System Calls System ISA Applications User ISA Hardware API application programming interface ABI application binary interface ISA instruction set architecture 系统级 VMM 类型 Provides ABI interface Efficient execution Can add OS-independent services (e.g., migration, intrustion detection) 进程级 Provdes API interface Easier installation Leverage OS services (e.g., device drivers) Execution overhead (possibly mitigated by justin-time compilation) 16
系统级的虚拟化设计 完全虚拟化 (direct execution) Exact hardware exposed to OS Efficient execution OS runs unchanged Requires a virtualizable architecture Example: VMWare 半虚拟化 Paravirtualization OS modified to execute under VMM Requires porting OS code Execution overhead Necessary for some (popular) architectures (e.g., x86) Examples: Xen, Denali Design Space (level vs. ISA) API interface ABI interface Variety of techniques and approaches available Critical technology space highlighted 17
系统级 VMM Type 1 Structure Type 1: runs directly on host hardware Type 2: runs on HostOS Primary goals Type 1: High performance Type 2: Ease of construction/installation/acceptability Examples Type 1: VMWare ESX Server, Xen, OS/370 Type 2: User-mode Linux Type 2 Structure Hybrid between Type1 and Type2 Core VMM executes directly on hardware I/O services provided by code running on HostOS Goals Improve performance overall leverages I/O device support on the HostOS Hosted VMMs Disadvantages Incurs overhead on I/O operations Lacks performance isolation and performance guarantees Example: VMWare (Workstation) 18
Whole-system VMMs Challenge: GuestOS ISA differs from HostOS ISA Requires full emulation of GuestOS and its applications Example: VirtualPC CS5204 Operating Systems VMM machine 虚拟机环境下的内存管理 OS physical process virtual entity address space VMM shadow page tables GuestOS page tables Isolation/protection of Guest OS address spaces Efficient MM address translation 19
分布式系统 小结 : 多处理机系统. 20
内容提要 多处理机系统 实时操作系统 嵌入式操作系统 41 实时操作系统 满足实时应用需求的操作系统, 其关键的指标是实际处理时间与所指定时间的一致性程度 分为 : 软实时和硬实时 调度算法 : 协作型调度 抢先式调度 最早截止时间优先调度 随机有向图调度 http://en.wikipedia.org/wiki/real time_operating_system 21
内容提要 多处理机系统 实时操作系统 嵌入式操作系统 43 嵌入式操作系统 嵌入式系统 : 具有专用功能的机电系统, 通常具有实时需求 能耗优化 CPU 消耗 内存使用 网络带宽 22
问题? 23