操作系统结构_第1页
操作系统结构_第2页
操作系统结构_第3页
操作系统结构_第4页
操作系统结构_第5页
已阅读5页,还剩49页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、1.2Operating System Concepts 6th EditionnComputer-system structuresl I/O structuresl Storage structures and hierarchy4 memory, secondary storage, tapel Hardware support for protectionnOperating-system structuresldifferent views: functional, components, services, structure1.3Operating System Concepts

2、 6th Edition1.4Operating System Concepts 6th Editionn Device controllersn I/O devices and the CPU can execute concurrently(并发).n Each device controller is in charge of a particular device type.n Each device controller has a local buffer.n CPU moves data from/to main memory to/from local buffersn I/O

3、 is from the device to local buffer of controller.n Device controller informs CPU that it has finished its operation by causing an interrupt. 1.5Operating System Concepts 6th EditionnInterrupts are “asynchronous(异步) requests for service”lsignal on a wire connecting the devicesnWhen an interrupt occu

4、rs, the CPUlpreserves the present CPU state4this includes its registers and program counterlforces execution of code at an interrupt address4this may be dependent on the source of the interrupt(中断源)4typically, table-driven: a table stores addresses of interrupt handlersindexed by the interrupt numbe

5、r (ISR 中断服务程序)linterrupt handlerslperform the requested servicelselective processing of other interruptse.g., only higher-priority interrupts may be handledlresumes the interrupted programnMost modern OSes are interrupt-driven1.6Operating System Concepts 6th Edition处理文档电话铃响暂停文档文档中作暂停记号电话交谈找出暂停记号位置继续

6、处理文档执行主程序(日常事务程序)中断申请信号有效(中断请求)暂停执行主程序响应中断当前PC及寄存器入栈(保护现场)处理外设要求(中断服务)寄存器及PC出栈(恢复现场及中断返回)继续执行主程序1.7Operating System Concepts 6th Edition1.8Operating System Concepts 6th EditionnInterruptslasynchronous(异步)(异步)4After I/O starts, control returns to user program without waiting for I/O completion lTrigg

7、ered(触发)(触发) by devices outside the CPUnTraps(陷阱)(陷阱)lsynchronous(同步)同步)4After I/O starts, control returns to user program only upon I/O completionltriggered by special instructions in user programnOther than the above, handling of interrupts and traps is identicalnTraps are the hardware mechanism f

8、or implementing system calls1.9Operating System Concepts 6th EditionnTwo approaches: Synchronous(同步) and Asynchronous(异步)1.10Operating System Concepts 6th Edition1.11Operating System Concepts 6th EditionnIN ALIPORT;从输入接口取中断信息;从输入接口取中断信息nTEST AL,80H;是;是0号设备请求吗号设备请求吗?nJNZ SEVO ;是,转;是,转0号设备服务程序号设备服务程序n

9、TEST AL40H;否,是;否,是1号设备请求吗号设备请求吗?nJNZ SEVl ;是,转;是,转1号设备服务程序号设备服务程序nTEST AL20H;否,是;否,是2号设备请求吗号设备请求吗?nJNZ SEV2 ;是,转;是,转2号设备服务程序号设备服务程序nTEST AL10H;否,是;否,是3号设备请求吗号设备请求吗?nJNZ SEV3 ;是,转;是,转3号设备服务程序号设备服务程序1.12Operating System Concepts 6th Edition1.13Operating System Concepts 6th Editionn中断的引入大大地提高了处理器处理中断的引

10、入大大地提高了处理器处理I/O的效率的效率n当处理器和当处理器和I/O间传送数据时,效率仍旧不高间传送数据时,效率仍旧不高n解决方法:解决方法:n直接存储器访问(直接存储器访问(DMA:Direct Memory Access)l通过系统总线中一独立控制单元通过系统总线中一独立控制单元DMA控制器,自动控制控制器,自动控制成块数据(成块数据(blocks of data),在内存和在内存和I/O单元间的传送,单元间的传送, without CPU intervention,大大提高处理大大提高处理I/O的效能的效能1.14Operating System Concepts 6th Editio

11、nnDMA方式一般用于高速传送成组的数据。方式一般用于高速传送成组的数据。DMA控制器将向内存发出地控制器将向内存发出地址和控制信号,修改地址,对传送的字的个数计数,并且以中断方式址和控制信号,修改地址,对传送的字的个数计数,并且以中断方式向向CPU报告传送操作的结束。报告传送操作的结束。DMA方式速度非常快。方式速度非常快。 nDMA能够执行的一些基本操作:能够执行的一些基本操作: 1.从外围设备发出从外围设备发出DMA请求;请求; 2.CPU响应请求,把响应请求,把CPU工作改成工作改成DMA操作方式,操作方式,DMA控制器从控制器从CPU接管接管总线的控制;总线的控制; 3.由由DMA控

12、制器对内存寻址,即决定数据传送的内存单元地址及数据传送个控制器对内存寻址,即决定数据传送的内存单元地址及数据传送个数的计数,并执行数据传送的操作;数的计数,并执行数据传送的操作; 4.向向CPU报告报告DMA操作的结束。操作的结束。处理器只在开始传送和传送结束时关注一下就可处理器只在开始传送和传送结束时关注一下就可1.15Operating System Concepts 6th Editionn处理器和处理器和DMA传送不完全并行传送不完全并行n因为有时会有总线竞争的情况发生因为有时会有总线竞争的情况发生n处理器用总线时可能稍作等待处理器用总线时可能稍作等待n通常过程只有一个总线周期通常过程

13、只有一个总线周期n在在DMA传送时,处理器访问总线速度会变慢传送时,处理器访问总线速度会变慢n对于大量数据对于大量数据I/O传送,传送,DMA技术是很有价值技术是很有价值1.16Operating System Concepts 6th EditionnMain memory lonly large storage media that the CPU can access directly.nSecondary storage(辅存) lextension of main memory that provides large nonvolatile storage capacity.nMag

14、netic disks lrigid metal or glass(玻璃) platters(磁盘片) covered with magnetic recording material (磁性记录材料)lDisk surface is logically divided into tracks, which are subdivided into sectors.lThe disk controller determines the logical interaction between the device and the computer. 1.17Operating System Con

15、cepts 6th Edition1.18Operating System Concepts 6th EditionFast SlowVolatileCommentsManaged by Computer SystemPrice dropping; Few gig/Server max.Erase Slower; Limited 1M writes.400 Gig max; Must move to RAM.CD640 Meg.DVD5-17 Gig.R/W Slower; Jukeboxes.40-300 Gig. Jukeboxes;Sequential Access.lSpeedlCos

16、tlVolatility1.19Operating System Concepts 6th EditionnImportant principle, performed at many levels in a computer (in hardware, operating system, software) nInformation in use copied from slower to faster storage temporarily (信息使用时会被临时复制到高速缓存中)(信息使用时会被临时复制到高速缓存中)nFaster storage (cache) checked first

17、 to determine if information is therelIf it is, information used directly from the cache (fast)lIf not, data copied to cache and used therenCache smaller than storage being cachedlCache management important design problemlCache size and replacement policy(置换策略)(置换策略)1.21Operating System Concepts 6th

18、 EditionnGoal: Prevent user processes from accidentally/maliciously damaginglthe OS structureslparts of other processs memory spacelother users I/O devicesnMechanisms address different ways in which protection breaks downlDual-Mode OperationlI/O ProtectionlMemory ProtectionlCPU Protection1.22Operati

19、ng System Concepts 6th EditionnProvide 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 supervisor mode or system mode) execution done on behalf of operating system. 1.23Operating System Concepts 6th Edit

20、ionnMode bit added to computer hardware to indicate the current mode: monitor (0) or user (1).nWhen an interrupt or fault occurs hardware switches to monitor mode.nPrivileged instructions can be issued only in monitor mode. monitoruserInterrupt/faultset user mode1.24Operating System Concepts 6th Edi

21、tion n特权指令:只能由操作系统使用的指令特权指令:只能由操作系统使用的指令n使用多道程序设计技术的计算机指令系统必须要区分为特使用多道程序设计技术的计算机指令系统必须要区分为特权指令和非特权指令权指令和非特权指令n特权指令一般引起处理器状态的切换特权指令一般引起处理器状态的切换l处理器通过特殊的机制将处理器状态切换到操作系统运行的特权状处理器通过特殊的机制将处理器状态切换到操作系统运行的特权状态(管态态(管态,又称核心态、系统态)又称核心态、系统态)l然后将处理权移交给操作系统中的一段特殊代码,这一个过程称为然后将处理权移交给操作系统中的一段特殊代码,这一个过程称为陷入陷入nCPU如何知

22、道当前运行的是操作系统还是一般应用软件?如何知道当前运行的是操作系统还是一般应用软件?有赖于处理器状态的标识有赖于处理器状态的标识1.25Operating System Concepts 6th Editionn386、486、Pentium系列都支持系列都支持4个处理器特权级别个处理器特权级别(特权环:(特权环:R0、R1、R2和和R3)n从从R0到到R3特权能力依次降低特权能力依次降低nR0相当于双状态系统的管态相当于双状态系统的管态nR3相当于目态相当于目态nR1和和R2则介于两者之间,它们能够运行的指令集合具则介于两者之间,它们能够运行的指令集合具有包含关系:有包含关系:1.26Op

23、erating System Concepts 6th Editionn各个级别有保护性检查(地址校验、各个级别有保护性检查(地址校验、I/O限制)限制)n特权级别之间的转换方式不尽相同特权级别之间的转换方式不尽相同n四个级别运行不同类别的程序:四个级别运行不同类别的程序:lR0-运行操作系统核心代码运行操作系统核心代码lR1-运行关键设备驱动程序和运行关键设备驱动程序和I/O处理例程处理例程lR2-运行其他受保护共享代码,如语言系统运行环境运行其他受保护共享代码,如语言系统运行环境lR3-运行各种用户程序运行各种用户程序n现有基于现有基于x86处理器的操作系统,多数处理器的操作系统,多数UN

24、IX、Linux以及以及Windows系列大都只用了系列大都只用了R0和和R3两个特权级别两个特权级别1.27Operating System Concepts 6th Editionn处理器处于管态时:处理器处于管态时:l全部指令(包括特权指令)可以执行全部指令(包括特权指令)可以执行l可使用所有资源可使用所有资源l并具有改变处理器状态的能力并具有改变处理器状态的能力n处理器处于目态时:处理器处于目态时:l只有非特权指令能执行只有非特权指令能执行n特权级别不同,可运行指令集合也不同特权级别不同,可运行指令集合也不同n特权级别越高,可以运行指令集合越大特权级别越高,可以运行指令集合越大n高特权

25、级别对应的可运行指令集合包含低特权级的高特权级别对应的可运行指令集合包含低特权级的1.28Operating System Concepts 6th Editionn在在PSW中专门设置一位,根据运行程序使用指令的权中专门设置一位,根据运行程序使用指令的权限而设置限而设置CPU状态状态nCPU的工作状态码的工作状态码指明管态还是目态,用来说明指明管态还是目态,用来说明当前在当前在CPU上执行的是操作系统还是一般用户,从而上执行的是操作系统还是一般用户,从而决定其是否可以使用特权指令或拥有其他的特殊权力决定其是否可以使用特权指令或拥有其他的特殊权力1.29Operating System Con

26、cepts 6th Edition1.30Operating System Concepts 6th Editionn目态目态管态管态 唯一途径是中断唯一途径是中断n管态管态目态目态设置设置PSW(修改程序状态字修改程序状态字) 可实现可实现1.31Operating System Concepts 6th EditionnWhen executing in monitor mode, the operating system has unrestricted access to both monitor and users memory.nThe load instructions for

27、the base and limit registers are privileged instructions.1.32Operating System Concepts 6th EditionnTimer interrupts computer after specified period to ensure operating system maintains control.lTimer is decremented every clock tick.lWhen timer reaches the value 0, an interrupt occurs.l设置时间间隔初值,每经过一个

28、单位时间,时钟值减设置时间间隔初值,每经过一个单位时间,时钟值减1,直到该,直到该值为负时,则触发时钟中断,并进行相应中断处理值为负时,则触发时钟中断,并进行相应中断处理nTimer commonly used to implement time sharing(分时).nTimer also used to compute the current time.nLoad-timer is a privileged instruction.1.33Operating System Concepts 6th Edition1.34Operating System Concepts 6th Edit

29、ionnWhat are the functions performed by an OS?nExplicit operationslprogram execution and handlinglI/O operationslfile-system managementlinter-process communication(进程间的通信)(进程间的通信)lexception detection and handling4e.g., notifying user that printer is out of papernImplicit operationslresource allocati

30、on资源分配资源分配 - 把资源分配给多个用户或多个同时运行的作业把资源分配给多个用户或多个同时运行的作业lAccounting帐务帐务 - 跟踪和记录用户对资源的使用,用于帐单和统计跟踪和记录用户对资源的使用,用于帐单和统计lProtection 保护保护 - 确保对资源的所有访问均在控制中确保对资源的所有访问均在控制中4e.g., maintaining data integrity, logging invalid login attempts1.35Operating System Concepts 6th EditionnProcesses: run-time representat

31、ions of user programslcreate, terminate, suspend, resume(创建,终止,暂停,重启)创建,终止,暂停,重启)laccess to shared resources (e.g., printers)nStoragelallocation of memory among resident processesldisk management (e.g., scheduling of disk accesses)nI/Oldevice drivers, handling of device interruptslfiles and director

32、iesnProtectionluser access to system resourcesnCourse organization follows this view1.36Operating System Concepts 6th EditionnTwo issueslWhat services does an OS provide? (same as functional view)lHow do users and user programs access these services?nInterface between the user and the OS: Command In

33、terpreterltypical commands4process creation and (implicitly) destruction (阻塞)(阻塞)4I/O handling and file system manipulation4communication: interact with remote devices4protection management: changing file/directory access control, etc.lIn some operating systems, the command interpreter is called the

34、 shell1.37Operating System Concepts 6th EditionnInterface between a user program and the OS: System Callslarguments passed in registers, a memory block, or on the stacklentry into the kernel using the trap mechanismnSystem call the method used by a process to request action by the operating system.l

35、process controllfile manipulationldevice manipulationlinformation maintenance4get/set system data (time, memory/cpu usage), process and device attributeslcommunications1.38Operating System Concepts 6th EditionStandard system calls (P66)1.39Operating System Concepts 6th EditionnHow to structure OS fu

36、nctionalitylLayering(分层)(分层)lMicrokernels(微内核)(微内核)lVirtual machines(虚拟机)(虚拟机)nDesigning and implementing an OS1.40Operating System Concepts 6th Edition 在早期开发操作系统时,设计者只是把他的注在早期开发操作系统时,设计者只是把他的注意力放在功能的实现和获得高的效率上,缺乏意力放在功能的实现和获得高的效率上,缺乏首尾一致的设计思想。这种首尾一致的设计思想。这种OSOS是无结构的。是无结构的。 主要是编制紧凑程序,便于利用内存,对主要是编制紧凑程

37、序,便于利用内存,对go go toto无限制,无限制,缺乏清晰的程序结构,缺乏清晰的程序结构,难以维护和难以维护和理解,理解,增加了维护人员的负担。增加了维护人员的负担。 1.41Operating System Concepts 6th Edition 模块化程序设计技术,是基于模块化程序设计技术,是基于“分解分解”和和“模块化模块化”原则来原则来控制大型软件的复杂度的。将控制大型软件的复杂度的。将OSOS按其功能划分为若干个具有一定按其功能划分为若干个具有一定独立性和大小的模块。并规定好各模块间的接口,独立性和大小的模块。并规定好各模块间的接口, 各模块之间能各模块之间能通过该接口实现交

38、互。通过该接口实现交互。1.42Operating System Concepts 6th EditionlThe operating system is divided into a number of layers (levels), each built on top of lower layers. The bottom layer (layer 0), is the hardware; the highest (layer N) is the user interface. (操作系统划分为若干层,在低层上构建高层。底层(操作系统划分为若干层,在低层上构建高层。底层(0层)为硬件;层

39、)为硬件; 最高层(最高层( N层)为用户层层)为用户层)lWith modularity, layers are selected such that each uses functions (operations) and services of only lower-level layers. ( 考虑模块化,层的选择是每层只使用考虑模块化,层的选择是每层只使用 低层次的功能和服务低层次的功能和服务)1.43Operating System Concepts 6th Editionn被调用功能被调用功能在低层:在低层:l如文件系统管理设备管理设备驱动程序如文件系统管理设备管理设备驱动程序

40、n活跃功能活跃功能在低层:提高运行效率在低层:提高运行效率n资源管理的资源管理的公用模块公用模块放在最低层:如缓冲区队列、堆栈操作放在最低层:如缓冲区队列、堆栈操作n存储器管理存储器管理放在次低层:便于利用虚拟存储功能放在次低层:便于利用虚拟存储功能n最低层的最低层的硬件抽象层硬件抽象层:与机器特点紧密相关的软件放在最低层。:与机器特点紧密相关的软件放在最低层。l 如如Windows NT中的中的HAL(Hardware Abstraction Layer)单处理、多处理)单处理、多处理n资源分配策略资源分配策略放在最外层,便于修改或适应不同环境放在最外层,便于修改或适应不同环境1.45Ope

41、rating System Concepts 6th Edition1.46Operating System Concepts 6th Editionn优点:优点:l功能明确,功能明确,调用关系清晰调用关系清晰(高层对低层单向依赖),(高层对低层单向依赖),有利于保证设计和实现的正确性有利于保证设计和实现的正确性l低层和高层可分别实现(低层和高层可分别实现(便于扩充便于扩充);高层错误不);高层错误不会影响到低层;避免递归调用会影响到低层;避免递归调用n缺点:降低了缺点:降低了运行效率运行效率各系统对具体划分各系统对具体划分多少层次多少层次有有不同的看法不同的看法。1.47Operating

42、System Concepts 6th Edition内核内核,是实现操作系统最基本功能的程序模块的集合是实现操作系统最基本功能的程序模块的集合,在机器的系统态在机器的系统态(或者或者说核心态说核心态)下运行下运行;外壳外壳,指的是运行在内核之上的指的是运行在内核之上的,完成完成OS外层功能外层功能(如命令解释如命令解释,机器诊断等机器诊断等)的程序的程序,它们运行在机器的用户态下它们运行在机器的用户态下,是一种开放式结构是一种开放式结构,其功能可方便地修其功能可方便地修改和增删。改和增删。微内核技术的引入微内核技术的引入 通过划分系统程序和用户程序,把所有不必要的部件移出内核,形成通过划分系

43、统程序和用户程序,把所有不必要的部件移出内核,形成一个一个能实现现代能实现现代OSOS核心功能的小型内核,它运行在核心态,且开机后常驻核心功能的小型内核,它运行在核心态,且开机后常驻内存。内存。微内核的基本功能微内核的基本功能 (1) (1) 进程管理。进程管理。 (2) (2) 存储器管理。存储器管理。 (3) (3) 进程通信管理。进程通信管理。 (4) I/O(4) I/O设备管理。设备管理。1.48Operating System Concepts 6th Editionn优点:优点:l良好的良好的扩充性扩充性:只需添加支持新功能的服务进程即可:只需添加支持新功能的服务进程即可l可靠性

44、可靠性好:调用关系明确,执行转移不易混乱好:调用关系明确,执行转移不易混乱l便于网络服务便于网络服务,实现分布式处理:以同样的调用形式,在下层可通过,实现分布式处理:以同样的调用形式,在下层可通过核心中的网络传送到远方服务器上核心中的网络传送到远方服务器上 (远地过程调用远地过程调用 RPC, Remote Procedure Call)n缺点:缺点:l消息传递比直接调用消息传递比直接调用效率效率要低一些要低一些 (但可以通过提高硬件性能来补偿但可以通过提高硬件性能来补偿 )RPC的过程:的过程:RPC应用程序应用程序RPC Stub(client)NetworkRPC Server进行本地调

45、用进行本地调用Structure of Windows 2000Structure of Linux1.51Operating System Concepts 6th EditionnA virtual machine takes the layered approach to its logical conclusion. It treats hardware and the operating system kernel as though they were all hardware. (虚拟机是层次化的逻辑结果。它把硬件和操作系统看成都是硬件)(虚拟机是层次化的逻辑结果。它把硬件和操作

46、系统看成都是硬件)nA virtual machine provides an interface identical to the underlying bare hardware. (虚拟机为裸机提供了统一的接口)(虚拟机为裸机提供了统一的接口)nThe operating system creates the illusion of multiple processes, each executing on its own processor with its own (virtual) memory. (操作系统创建了多个进程,每一个进程有自己的处理器和(虚拟)内存)(操作系统创建了多个进程,每

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论