操作系統(tǒng)第五單元課件_第1頁(yè)
操作系統(tǒng)第五單元課件_第2頁(yè)
操作系統(tǒng)第五單元課件_第3頁(yè)
操作系統(tǒng)第五單元課件_第4頁(yè)
操作系統(tǒng)第五單元課件_第5頁(yè)
已閱讀5頁(yè),還剩109頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、Input/output Principles of I/O hardware Principles of I/O software I/O software layers Disk 輸入輸出 I/O硬件組成原理 I/O軟件組成原理 I/O軟件層次 盤(pán) EMPHASES (本章重點(diǎn)) DMA (直接存儲(chǔ)器訪問(wèn)) I/O software layers(I/O軟件層次) disk arm scheduling algorithms(磁盤(pán)調(diào)度算法) 出題方式 輸入輸出相關(guān)概念的選擇填空 I/O軟件層次及其功能的簡(jiǎn)答及畫(huà)圖 DMA的工作步驟簡(jiǎn)答 磁盤(pán)調(diào)度算法及與此相關(guān)的尋道時(shí)間的 計(jì)算及畫(huà)圖 Inp

2、ut/output One of the main functions of an operating system is to control all the computers I/O devices, it must: issue commands to the devices Catch interrupts Handle errors It should also provide an interface between the devices and the rest of the system that is simple and easy to use, the interfa

3、ce should be the same for all devices (device independence) Principles of I/O hardware 5.1 principles of I/O hardware 5.1.1 I/O devices I/O devices can be roughly divided into tow categories: block device, character device The essential property of a block device is that it is possible to read or wr

4、ite each block independently of all the other ones (disk) A character device delivers or accepts a stream of characters, without regard to any bock structure.it is not address-able and does not have any seek operation (printer) Another special device: clock Some typical device, network, and data bas

5、e rates Some typical device, network, and data base rates device controller and memory- mapped I/O 5.1.2 Device controller Device controller also is known as adapter Many controllers can handle two, four,or even eight identical devices (use a connector) The controllers job is to convert the serial b

6、it stream in to a block of bytes and perform any error correction necessary 5.1.3 memory-mapped I/O Each controller has a few registers that are used for communicating, by writing into these registers the operating system can command the device memory-mapped I/O In addition to the control registers,

7、 many devices have a data buffer that the operating system can read and write The issue thus arises of how the CPU communicates with the control registers and the device data buffers: First, each control register is assigned an I/O port, an 8- or 16-bit integer Second, to map all the control registe

8、rs into the memory space. Each control register is assigned a unique memory address to which no memory is assigned, this system is called memory-mapped I/O Hybrid Three kinds of I/O Separate I/O and memory space Memory-mapped I/O Hybrid memory-mapped I/O Advantage of memory-mapped I/O: First, an IO

9、device driver can be written entirely in c, without memory-mapped IO, some assembly code is needed ( there is no way to execute an IN or OUT instruction in C and C+) Second, with memory-mapped IO, no special protection mechanism is needed to keep user processes fro performing IO 1) Third, every inst

10、ruction that can reference memory can also reference control registers Disadvantage of memory- mapped I/O Disadvantage of memory-mapped I/O: First,most computers nowadays have some form of caching of memory words. Caching a device control register would be disastrous. To prevent this situation, the

11、hardware has to be equipped with the ability to selectively disable caching Second ,if there is only address space, then all memory modules and all I/O devices must examine all memory references to see which ones to respond to Bus architecture (a) A single-bus architecture (b) A dual-bus memory arch

12、itecture DMA 5.1.4 Direct memory access (DMA) The CPU can request data from an I/O controller one byte at a time but doing so wastes the CPUs time, so DMA is used. The OS can only use DMA if the hardware has a DMA controller No matter where it is physically located, the DMA controller has access to

13、the system bus independent of the CPU, as the figure in the following page. When DMA is used for read data from disk (detailed): 1)First the CPU programs the DMA controller by setting its registers so it knows what to transfer where DMA Second, the DMA controller initiates the transfer by issuing a

14、read request over the bus to the disk controller Third, the write to memory is another standard bus cycle Fourth, when the write is complete, the disk controller sends an acknowledgement signal to the DMA controller, also over the bus, the DMA controller then increments the memory address to use and

15、 decrements the byte count. If the byte count is still greater then 0, steps 2 to 4 are repeated Fifth, at that time, the DMA controller interrupts the CPU to let it know that the transfer is now complete Operation of a DMA transfer Operation of a DMA transfer: CPU programs the DMA controller. DMA r

16、equests transfer to memory. Data transferred from the buffer of disk controller to memory. Disk controller Acknowledge DMA controller. DMA controller interrupts CPU when done. 1)DMA controller can control the flow of bits between memory and some controller without CPU Operation of a DMA transfer Ope

17、ration of a DMA transfer DMA More complex DMA controller can be programmed to handle multiple transfers at once Some DMA controller can operate in two mode: Word-at-a-time mode: the DMA controller requests for the transfer of one word and gets it. If the CPU also wants the bus, it has to wait. The m

18、echanism is called cycle stealing because the device controller sneaks in and steals and occasional bus cycle from the CPU once in a while, delaying it slightly Block mode: the DMA controller tells the device to acquire the bus, issue a series of transfers, the release the bus the form of operation

19、is called burst mode DMA Why does a DMA controller needs a internal buffer: First, by doing internal buffering, the disk controller can verify the checksum before starting a transfer Second, once a disk transfer has started, the bits keep arriving from the disk at a constant rate, whether the contro

20、ller is ready for them of not. If the controller tried to write data directly to memory, it would have to go over the system bus for each word transferred. If the bus were busy due to some other device using it, the controller would have to wait Interrupt revisited When a I/O device has finished the

21、 work given to it ,it causes an interrupt. It does this by asserting a signal on a bus line that it has been assigned. This signal is detected by the interrupt controller chip on the parent-board, which then decides what to do: Device is finished Controller issues interrupt 1) CPU ACKs interrupt Int

22、errupts Revisited How interrupts happens. Connections between devices and interrupt controller actually use interrupt lines on the bus rather than dedicated wires interrupt Shortly after it starts running, the interrupt service procedure acknowledges the interrupt by writing a certain value to one o

23、f the interrupt controllers I/O ports. This acknowledgement tells the controller that it is free to issue another interrupt The hardware always saves certain information before starting the service procedure. So one issue is where to save this information: In internal registers Most CPUs save the in

24、formation on the stack: In the User process stack 1)In the Kernel stack Interrupt revisited The model makes implicit assumption that if an interrupt occurs just after some instruction, all the instructions up to and including that instruction have been executed completely, and no instructions after

25、it have executed. But on modern machines it may not be because the pipeline and the super-scalar CPU is used,so an interrupt that leaves the machine in a well-defined state is called a precise interrupt: The PC is saved in a known place; All instructions before the one pointed to by the PC have full

26、y executed; No instruction beyond the one pointed to by the PC has been executed; The execution state of the instruction pointed to by the PC is known. Principles of I/O software 5.2 principles of I/O software 5.2.1 Goals of the I/O software: A key concept in the design of I/O software is known as d

27、evice-independence.what it means is that it should be possible to write programs that can access any I/O device without having to specify the device in advance 1.It is up to the operating system to take care of the problems caused by the fact that these devices really are different command sequences

28、 to read or write Principles of I/O software Closely related to device independence is the goal of uniform naming: the name of a file or a device should be same. In this way, all files and devices are addressed the same way:a path name Another important issue for I/O software is error handling: In g

29、eneral, errors should be handled as close to the hardware as possible Principles of I/O software Still another key issue is synchronous (clocking) versus asynchronous (interrupt-driven) transfers It is up to the operating system to make operations that are actually interrupt-driven look blocking the

30、 user programs Another issue for the I/O software is buffering: often data that come off a device cannot be stored directly in its final destination Buffering involves considerable copying and often has a major impact on I/O performance Principles of I/O software The final concept that we will menti

31、on here is sharable versus dedicated device: Some I/O devices, such as disks, can be used by many users at the same time Other devices, such as tape drives, have to be dedicated to a single user until that user is finished Introducing dedicated devices also introduces a variety of problems, such as

32、deadlocks. Again the operating system must be able to handle both shared and dedicated devices in a way that avoid problems Programmed I/O 5.2.2 programmed I/O The simplest form of I/O is to have the CPU do all the work. This method is called programmed I/O: First the data are coped to the kernel. T

33、hen the operating system enters a tight-loop outputting the characters one at a time The essential aspect of programmed I/O is that after outputting a character, the CPU continuously polls the device to see if it is ready to accept another. This behavior is called polling or busy waiting Programmed

34、I/O Steps in printing a string Writing a string to the printer using programmed I/O Writing a string to the printer using programmed I/O Programmed I/O and interrupt- driven I/O disadvantage :Programmed I/O is simple but has the disadvantage of tying up the CPU full time until all the I/O is done 5.

35、2.3 Interrupt-driven I/O The way to allow the CPU to do something else while waiting for the printer to become ready is to use interrupts When the printer has printed the character and is prepared to accept the next one ,it generates an interrupt. Interrupt-driven I/O and DMA Disadvantage: an interr

36、upt occurs on every character. Interrupts take time, so this scheme wastes a certain amount of CPU time 5.2.4 I/O using DMA Here the idea is to let the DMA controller feed the characters to the printer one at time, without the CPU being bothered Reducing the number of interrupts from one per charact

37、er to one per buffer printed Disadvantage: the DMA controller is usually much slower than the main CPU Writing a string to the printer using interrupt-driven I/O Writing a string to the printer using interrupt-driven I/O Code executed when print system call is made Interrupt service procedure I/O Us

38、ing DMA Printing a string using DMA code executed when the print system call is made interrupt service procedure Layers of the I/O Software System Layers of the I/O Software System 5.3 Layers of the I/O Software System Interrupt handlers 5.3.1 Interrupt handlers: Save registers not already saved by

39、interrupt hardware Set up context for interrupt service procedure Set up stack for interrupt service procedure Acknowledge interrupt controller, re-enable interrupts Copy registers from where saved Run service procedure Choose which process run next Set up MMU context for process to run next Load ne

40、w process registers 1.Start running the new process Device drivers 5.3.2 device drivers each I/O device attached to a computer needs some device-specific code for controlling it, the code, called the device driver, is generally written by the devices manufacturer and delivered along with the device,

41、 since each operating system needs its own drivers, device manufacturers commonly supply drivers for several popular operating systems Device drivers In order to access the device hardware, meaning the controllers registers, the device driver normally has to be part of the operating system kernel, a

42、t least with current architectures Since the designers of every operating system know that pieces of code (drivers) written by outsiders will be installed in it, it needs to have an architecture that allows such installation. This means having a well-defined model of that a driver does and how it in

43、teracts with the rest of the operating system Device drivers Operating systems, starting with MS-DOS, went over to a model in which drivers were dynamically loaded into the system during execution. Different systems handle loading drives in different ways Drivers are not allowed to make system calls

44、, but they often need to interact with the rest of the kernel, usually, calls to certain kernel procedures are permitted Device driver A device driver has several functions: Accept abstract read and write requests from the device-independent software Initialize device Manage its power requirements a

45、nd log events Set up device registers Check status 1)And so on Device drivers working flow Device drivers working flow: A typical driver starts out by checking the input parameters to see if they are valid. If they are valid, a translation from abstract to concrete terms may be needed. (converting l

46、inear block number into the head, track,sector, and cylinder numbers) 1)Next the driver may check if the device is currently in use.(start a motor if necessary) Device drivers working flow After the driver knows which commands it is going to issue, it starts writing them into the controllers device

47、registers. Check to see if the controller accepted the command and is prepared to accept the next one. After the commands have been issued, the driver will blocks itself or not Device drivers working flow In the former case (block itself), the blocked driver will be awakened by the interrupt. In the

48、 latter case it will never go to sleep. Either way after the operation has been completed, the driver must check for errors. If every thing is all right, the driver may have data to pass to the device-independent software Finally, it returns some status information for error reporting back to it cal

49、ler Device Drivers Logical position of device drivers is shown here Communications between drivers and device controllers goes over the bus Device-independent I/O software 5.3.3 Device-independent I/O software (OS) Although some of the I/O software is device specific, other parts of it are device in

50、dependent Functions of the device-independent I/O software: Uniform interfacing for device drivers Buffering Error reporting Allocating and releasing dedicated devices 1) Providing a device-independent block size Device-Independent I/O Software (a) Without a standard driver interface (b) With a stan

51、dard driver interface Uniform interfacing for device drivers Uniform interfacing for device drivers: On aspect of this issue is the interface between the device drivers and the rest of the operating system it becomes much easier to plug in a new driver, providing it conforms to the driver interface.

52、 It also means that driver writers know what is expected of them (e.g., what functions they must provide and what kernel functions they may call) Another aspect of having a uniform interface is how I/O devices are named. The device-independent software takes care of mapping symbolic device names ont

53、o the proper driver buffering Buffering Buffering is also an issue, both for block and character devices for a variety of reasons: It is important for input It is important for output Buffering is a widely-used technique, but it has a downside as well, if data get buffered too many times, performanc

54、e suffer buffering (a) Un-buffered input: the user process has to be started for every incoming character (b) Buffering in user space: what happens if the buffer is paged out when a character arrives? (c) Buffering in the kernel followed by copying to user space: what happens to characters that arri

55、ve while the page with the user buffer is being brought in from the disk? (d) Double buffering in the kernel: it is very excellent Networking may involve many copies Networking may involve many copies Error reporting Error reporting One class of I/O errors are programming errors: Writing to an input

56、 device; Providing an invalid buffer address; Specifying an invalid device The action to take on these errors in straightforward: just report back an error code to the caller Another class of errors is the class of actual I/O errors: A disk block that has been damaged; Read from a camcorder that has

57、 been switched off It is up to the driver to determine what to do. If the driver does not know what to do, it may pass the problem back up to device-independent software Allocating and releasing dedicated devices Allocating and releasing dedicated devices: First method: a simple way to handle these

58、requests is to require processes to perform opens on the special files for devices directly. If the device is unavailable, the open fails, closing such a dedicated device then releases it Second method: having special mechanisms for requesting and releasing dedicated devices. An attempt to acquire a

59、 device that is not available blocks the caller instead of failing Device-independent block size Device-independent block size: Different disks may have different sector sizes. It is up to the device-independent software to hide this fact and provide a uniform block size to higher layers, for exampl

60、e, by treating several sectors as a single logical block the higher layers only deal with abstract devices that all use the same logical block size User-space I/O software 5.3.4 User-space I/O software Although most of the I/O software is within the operating system, a small portion of it consists o

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論