案例教案成果modern_第1頁
案例教案成果modern_第2頁
案例教案成果modern_第3頁
案例教案成果modern_第4頁
案例教案成果modern_第5頁
已閱讀5頁,還剩113頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、Operating Systems DesignDept. of CS, ECNULi Dong2022/10/8ECNU-Operating Systems Design, Li Dong2Course OutlineIntroductionProcesses & ThreadsDeadlocksMemory ManagementInput / OutputFile SystemsMultimedia Operating SystemsMultiple Processor SystemsSecurity2022/10/8ECNU-Operating Systems Design, Li Do

2、ng3Chap. 5 Input/OutputBasic I/O hardware Devices and controllers ,Ports, BusesI/O Software User-Space I/O Software , Device-Independent Software, Interrupt Handlers, Device DriverReal I/O devices Disks, Character-Oriented Terminals, Graphical User Interfaces, Network Terminals, Power Management 202

3、2/10/8ECNU-Operating Systems Design, Li Dong4DevicesDevicesStorage devices (disk, tapes)Transmission devices (network card, modem)Human interface devices (screen, keyboard, mouse)Specialized device (joystick) 2022/10/8ECNU-Operating Systems Design, Li Dong5 puter / Device-Device CommunicationPhysica

4、lly: via signals over a cable or through air Logically: via a connection point - port (e.g., Serial port) Multiple devices are connected via a busA common set of wires and a rigidly defined protocol that specifies a set of messages that can be sent on the wires 2022/10/8ECNU-Operating Systems Design

5、, Li Dong6Device ControllerI/O units typically consist of a mechanical component and an electronic component. The electronic component is called the device controller or adapter. Example is a circuit board. The mechanical component is the device itself. Interface between controller and device is a v

6、ery low level interface. Example: Disks controller converts the serial bit stream, coming off the drive into a block of bytes, and performs error correction. The block of bytes is first assembled in a buffer inside the controller. After its checksum has been verified, the error-free block is copied

7、to main memory. Built-in controllers 2022/10/8ECNU-Operating Systems Design, Li Dong7I/O ControllerDisk controller - implements the disk side of the protocol that does: bad error mapping, prefetching, buffering, caching Controller has registers for data and control CPU and controllers communicate vi

8、a I/O instructions and registers Memory-mapped I/O 2022/10/8ECNU-Operating Systems Design, Li Dong8I/O Ports 4 registers - status, control, data-in, data-outStatus - states whether the current command is completed, byte is available, device has an error, etc Control - host determines to start a comm

9、and or change the mode of a device Data-in - host reads to get input Data-out - host writes to send output Size of registers - 1 to 4 bytes 2022/10/8ECNU-Operating Systems Design, Li Dong9Device ClassificationCharacter-stream or block devices Sequential or random access devices Synchronous or asynch

10、ronous devices Sharable or dedicated devices Speed of operation WO, RO, RW devices 2022/10/8ECNU-Operating Systems Design, Li Dong10Block Devices Block device - transfers blocks of data (e.g., Disk device) Commands: read, write, seek (if random access device) Memory-mapped files access can be layere

11、d on top of block-device drivers2022/10/8ECNU-Operating Systems Design, Li Dong11Character Devices Character device - transfers byte by byte (e.g., Keyboard) Commands: get, put one character Libraries can built on top of this device which provide line-at-a time access with buffering and editing serv

12、ices, etcQuestion: can block device be implemented using character device?2022/10/8ECNU-Operating Systems Design, Li Dong12Network Devices Network socket interface Commands: create socket, connect local socket to remote address, select information from a socket Other interfaces: half-duplex pipes, f

13、ull-duplex fifos, message queues, sockets (UNIX) 2022/10/8ECNU-Operating Systems Design, Li Dong13How to Perform I/O Operations?Programmed IO Interrupt-driven IOIO using DMA2022/10/8ECNU-Operating Systems Design, Li Dong14Programmed I/OEvery IO operation is programmed and controlled. Example: printi

14、ng a file from user program to the printer means that data is first copied to the kernel, then the OS enters a tight loop outputting the characters one at a time. Essential aspect the CPU continuously polls the device to see if it is ready to accept another character. It uses polling (or busy waitin

15、g) behavior. Real life analogy?Cons & Pros?Pros: SimpleCons: required CPU full time until all the IO is done. 2022/10/8ECNU-Operating Systems Design, Li Dong15Host-Controller Interface: Polling Consider a producer-consumer relation between controller and host Controller indicates through busy bit (s

16、tatus bit) if it is busy to work or not Host signals its wishes via command-ready bit (command register) Polling behavior 2022/10/8ECNU-Operating Systems Design, Li Dong16Handshaking ProtocolHost reads busy bit (poll) until bit is clear Host sets write bit in command register and writes byte into th

17、e data-out register Host sets the command-ready bit in command register When controller notices command-ready bit, it sets busy bit and starts to workController reads the command register and sees the write command. It reads data-out and performs I/O Controller clears the command-ready bit, error bi

18、t and busy bit 2022/10/8ECNU-Operating Systems Design, Li Dong17A Programmed I/O Example(1)Steps in printing a string2022/10/8ECNU-Operating Systems Design, Li Dong18A Programmed I/O Example(2)Writing a string to the printer using programmed I/O2022/10/8ECNU-Operating Systems Design, Li Dong19Interr

19、upt-Driven IO CPU hardware has the interrupt report line that the CPU senses after executing every instruction. Device raises an interrupt CPU catches the interrupt and saves the state (e.g., instruction pointer) CPU dispatches the interrupt handler Interrupt handler determines the cause of the inte

20、rrupt, services the device and clears the interrupt. 2022/10/8ECNU-Operating Systems Design, Li Dong20Interrupts RevisitedHow interrupts happens. Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wires2022/10/8ECNU-Operating Systems De

21、sign, Li Dong21Interrupt-Driven I/OWriting a string to the printer using interrupt-driven I/O(a) Code executed when print system call is made(b)Interrupt service procedure2022/10/8ECNU-Operating Systems Design, Li Dong22Support for InterruptsNeed the ability to defer interrupt handling during critic

22、al processing CPUs have two interrupt request lines non-maskable interrupt (reserved for unrecoverable memory errors) maskable interrupt (can be turned off by cpus before the execution of critical instructions Need efficient way to dispatch the proper serviceInterrupt comes with an addressNeed multi

23、level interrupts - interrupt priority level 2022/10/8ECNU-Operating Systems Design, Li Dong23Interrupt HandlerAt boot time, OS probes the hardware buses to determine what devices are present and installs corresponding interrupt handlers into the interrupt vector During I/O interrupt, controller sign

24、als that device is ready 2022/10/8ECNU-Operating Systems Design, Li Dong24Other Types of InterruptsInterrupt mechanisms are used to handle wide variety of exceptions: Division by zero, wrong address Virtual memory paging System calls (software interrupts, trap) 2022/10/8ECNU-Operating Systems Design

25、, Li Dong25Direct Memory Access (DMA) use a special purpose processor, called a DMA controller Host writes a DMA command block into memory pointer to source, pointer to destination, count of bytes to be transferredCPU writes the address of this command block to the DMA controller and goes on with ot

26、her work DMA controller proceeds to operate the memory bus directly without help of main CPUCons & Pros?2022/10/8ECNU-Operating Systems Design, Li Dong26Direct Memory Access (DMA)DMA controller feeds the characters to the printer one at the time, without CPU being bothered. DMA is actually the progr

27、ammed IO, only with DMA controller doing the work.2022/10/8ECNU-Operating Systems Design, Li Dong27I/O Using DMAPrinting a string using DMA(a) code executed when the print system call is made(b) interrupt service procedure2022/10/8ECNU-Operating Systems Design, Li Dong28DMA IssuesHandshaking between

28、 DMA controller and the device controller Cycle stealing DMA controller takes away CPU cycles when it uses CPU memory bus, hence blocks the CPU from accessing the memory In general DMA controller improves the total system performance 2022/10/8ECNU-Operating Systems Design, Li Dong29DiscussionTradeof

29、fs betweenProgrammed I/OInterrupt-driven I/OI/O using DMA2022/10/8ECNU-Operating Systems Design, Li Dong30Memory-Mapped I/O (1)(a) Separate I/O and memory space(b) Memory-mapped I/O(c) Hybrid2022/10/8ECNU-Operating Systems Design, Li Dong31Memory-Mapped I/O (2)(a) A single-bus architecture(b) A dual

30、-bus memory architecture2022/10/8ECNU-Operating Systems Design, Li Dong32I/O Software Layers of the I/O system and the main functions of each layer2022/10/8ECNU-Operating Systems Design, Li Dong33I/O Software: Principles device independencepossible to write programs that can access any IO device wit

31、hout having to specify the device in advance. read file as input on a floppy, hard disk, or CD-ROM, without modifying the program for each device uniform namingthe name of a file or a device should simply be a string or an integer and not depend on the device in any way Example: In Unix all files an

32、d devices are addressed the same way by a path name. Synchronous (blocking) vs asynchronous (interrupt-driven) transfers Example: most devices are asynchronous. User programs are easier to write if the IO operations are synchronous. Hence, it is up to OS to make asynchronous operations look like syn

33、chronous to the user programs. 2022/10/8ECNU-Operating Systems Design, Li Dong34Principles (cont.)Buffering data might need to be buffered because they might not be stored immediately Example: Network packets come in off the network, and need to be buffered for protocol processing, audio buffering b

34、etween audio speakers and network. shared vs dedicated devicesallowing for sharing, considering two users having open files on the same device, or allowing dedicated devices and deal with deadlock problems. Example: Disk, audio devices. 2022/10/8ECNU-Operating Systems Design, Li Dong35Detailed Princ

35、iple (*)Interrupts are facts of life, but should be hidden away, so that as little of the OS as possible knows about them. The best way to hide interrupts is to have the driver starting an IO operation block until IO has completed and the interrupt occurs. When interrupt happens, the interrupt handl

36、er handles the interrupt. Once the handling of interrupt is done, the interrupt handler unblocks the device driver that started it. This model works if drivers are structures as kernel processes with their own states, stacks and program counters. 2022/10/8ECNU-Operating Systems Design, Li Dong36Devi

37、ce DriversDevice-specific code to control an IO device, is usually written by devices manufacturerEach controller has some device registers used to give it commands. The number of device registers and the nature of commands vary from device to device (e.g., mouse driver accepts information from the

38、mouse how far it has moved, disk driver has to know about sectors, tracks, heads, etc). A device driver is usually part of the OS kernelCompiled with the OSDynamically loaded into the OS during executionEach device driver handles one device type (e.g., mouse) one class of closely related devices (e.

39、g., SCSI disk driver to handle multiple disks of different sizes and different speeds.). Categories:Block devicesCharacter devices2022/10/8ECNU-Operating Systems Design, Li Dong37Functions in Device Drivers(*)Accept abstract read and write requests from the device-independent layer above; Initialize

40、 the device; Manage power requirements and log events Check input parameters if the are valid Translate valid input from abstract to concrete terms e.g., convert linear block number into the head, track, sector and cylinder number for disk accessCheck the device if it is in use Control the device by

41、 issuing a sequence of commands. The driver determines what commands will be issued. 2022/10/8ECNU-Operating Systems Design, Li Dong38Device Driver Protocol (*)After driver knows which commands to issue, it starts to write them into controllers device registers After writing each command, it checks

42、to see if the controller accepted the command and is prepared to accept the next one. After command have been issues, either (a) the device waits until the controller does some work and it blocks itself until interrupt comes to unblock it; or (b) the device doesnt wait because the command finished w

43、ithout any delay. 2022/10/8ECNU-Operating Systems Design, Li Dong39Device-Independent IO Software Functions : Uniform interfacing for device driversBufferingError reporting Allocating and releasing dedicated devicesproviding a device-independent block size 2022/10/8ECNU-Operating Systems Design, Li

44、Dong40Uniform Interfacing for Device DriversGoal: how to make all IO devices and drivers look similarProblem: write a complete new code for each new device?Solution: device types. Example: block and character devices, but they also have many functions common 2022/10/8ECNU-Operating Systems Design, L

45、i Dong41Naming of IO devices The device-independent software takes care of mapping symbolic device names onto the proper driver. Examplein UNIX, the symbolic device name dev/disk0 uniquely specifies the disk2022/10/8ECNU-Operating Systems Design, Li Dong42BufferingBuffer is a memory area that stores

46、 data while they are transferred between two devices or between a device and an application. Reasons of buffering: cope with speed mismatch between the producer and consumer of a data stream - use double buffering adapt between devices that have different data-transfer sizes support of copy semantic

47、s for application I/O - application writes to an application buffer and the OS copies it to the kernel buffer and then writes it to the disk. Unbuffered input strategy is ineffective, as the user process must be started up with every ing character. Buffering is also important on output. Caching cach

48、e is region of fast memory that holds copies of data and it allows for more efficient access. Difference?2022/10/8ECNU-Operating Systems Design, Li Dong43Buffering IssuesPros:Unbuffered input strategy is ineffective, as the user process must be started up with every ing character. Buffering in user

49、spaceif the buffer is paged out, where should the character be put? One solution would be to pin the pages into the real memory, but this could degrade performance if many processes start to lock pages in memory. Buffering in kernel followed by copying to user space:far more efficient than the previ

50、ous methods, but again the problem occurs if the kernel buffer es full and the user buffer page is paged out. In this case again there is no space to put the ing data. Double buffering in the kernelas long as one kernel buffer takes ing data, the other buffer is copied to the user space. Note: if da

51、ta get buffered too many times, performance suffers. 2022/10/8ECNU-Operating Systems Design, Li Dong44Error Reporting Programming IO Errorsthese errors occur when a process asks for something impossible (e.g., write to an input device such as keyboard, or read from output device such as printer). Ac

52、tual IO Errorserrors occur at the device level (e.g., read disk block that has been damaged, or try to read from video camera which is switched off) The device-independent IO software detects the errors and responds to them by reporting to the user-space IO software. 2022/10/8ECNU-Operating Systems

53、Design, Li Dong45Allocating and releasing Dedicated Devices (*) Some devices can be used only by single process at any given time e.g., CD-ROM recorders, some audio devices Two approaches:perform open on the special file for devices directly. If device is not available, open fails. A process request

54、s a device. If it is not available, the process is blocked, instead failing, and waits until the device e available. 2022/10/8ECNU-Operating Systems Design, Li Dong46Device Independent Block Size (*) Different disks have different sector sizes. The device independent IP software should hide this fac

55、t and provide uniform block size to higher layers. introduce the same logical block at the user-space IO level and do the mapping between the logical block size and the underlying several sectors in the device independent IO software. 2022/10/8ECNU-Operating Systems Design, Li Dong47User-Space IO So

56、ftwareApplications in user space call IO system calls to access IO. IO system calls are normally made by library procedures. Steps to perform an IO system call:User-space library calls the device-independent IO softwareDevice-independent I/O software calls the corresponding device driverDevice drive

57、r accesses the device controller and through it the corresponding device. 2022/10/8ECNU-Operating Systems Design, Li Dong48SpoolingAnother way to do IO is the spooling system. Spooling is an approach to deal with IO devices in a multiprogramming systemExample: printer (spooled device) Spooling inclu

58、des a special process, called daemon, and special directory, called spooling directory. Example: To print a file, the printing process creates the entire file, puts it in the spooling directory, and the daemon then takes out the file and prints it. 2022/10/8ECNU-Operating Systems Design, Li Dong49Mo

59、re on System Calls (*)Interface between running application and operating system Assembly language macros or subroutines Need to use an SVC instruction Pass parameters through registers, in memory tables, or on stackUnix has about 32 system calls: Read(), write(), open(), close(), fork(), exec(), io

60、ctl(),2022/10/8ECNU-Operating Systems Design, Li Dong50How System Calls Work1.SVC Causes a Trap2.System Privilege Mode Entered3.Trap Handler Decodes Which SVC4.Branch to System Function5.Access Arguments From the Stack2022/10/8ECNU-Operating Systems Design, Li Dong51AnimationProcess StackSVC Argumen

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論