1 Device Management The von Neumann Architecture System Architecture Device Management Polling Interrupts DMA operating systems.

Slides:



Advertisements
Similar presentations
CT213 – Computing system Organization
Advertisements

1 (Review of Prerequisite Material). Processes are an abstraction of the operation of computers. So, to understand operating systems, one must have a.
Slide 3-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter 3 3 Operating System Organization.
Input and Output CS 215 Lecture #20.
CS4315A. Berrached:CMS:UHD1 Operating Systems and Computer Organization Chapter 4.
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
1 Lecture 2: Review of Computer Organization Operating System Spring 2007.
1 CS 333 Introduction to Operating Systems Class 2 – OS-Related Hardware & Software The Process Concept Jonathan Walpole Computer Science Portland State.
© 2004, D. J. Foreman 1 Computer Organization. © 2004, D. J. Foreman 2 Basic Architecture Review  Von Neumann ■ Distinct single-ALU & single-Control.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
Computer System Structures memory memory controller disk controller disk controller printer controller printer controller tape-drive controller tape-drive.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output – 3 I/O Software CS 342 – Operating Systems Ibrahim Korpeoglu.
1 Input/Output Chapter 3 TOPICS Principles of I/O hardware Principles of I/O software I/O software layers Disks Clocks Reference: Operating Systems Design.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
General System Architecture and I/O.  I/O devices and the CPU can execute concurrently.  Each device controller is in charge of a particular device.
System Calls 1.
1 I/O and Filesystems. 2 How to provide interfaces Rough reading guide (no exam guarantee): Tanenbaum Ch. 5.1 – 5.5 & Silberschatz Ch. 13 & ,
OPERATING SYSTEM OVERVIEW. Contents Basic hardware elements.
Input and Output Computer Organization and Assembly Language: Module 9.
Cpr E 308 Input/Output Recall: OS must abstract out all the details of specific I/O devices Today –Block and Character Devices –Hardware Issues – Programmed.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-1: I/O Management Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Segmentation & O/S Input/Output Chapter 4 & 5 Tuesday, April 3, 2007.
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
Windows Operating System Internals - by David A. Solomon and Mark E. Russinovich with Andreas Polze Unit OS6: Device Management 6.1. Principles of I/O.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 2: Computer-System Structures Computer System Operation I/O Structure.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
1 CSE Department MAITSandeep Tayal Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
2: Computer-System Structures
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Input/Output CS 342 – Operating Systems Ibrahim Korpeoglu Bilkent University.
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
© 2004, D. J. Foreman 1 Computer Organization. © 2004, D. J. Foreman 2 Basic Architecture Review  Von Neumann ■ Distinct single-ALU & single-Control.
© 2004, D. J. Foreman 1 Computer Organization. © 2004, D. J. Foreman 2 Basic Architecture Review  Von Neumann ■ Distinct single-ALU & single-Control.
Fall 2000M.B. Ibáñez Lecture 25 I/O Systems. Fall 2000M.B. Ibáñez Categories of I/O Devices Human readable –used to communicate with the user –video display.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
Silberschatz, Galvin and Gagne  Applied Operating System Concepts Chapter 2: Computer-System Structures Computer System Architecture and Operation.
Lecture 1: Review of Computer Organization
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
OSes: 2. Structs 1 Operating Systems v Objective –to give a (selective) overview of computer system architectures Certificate Program in Software Development.
C HAPTER 4 OS: C OMPUTER O RGANIZATION TOPICS: The Von Neumann Architecture The CPU.
Device Driver Concepts Digital UNIX Internals II Device Driver Concepts Chapter 13.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 I/O through system calls Protection.
CS4315A. Berrached:CMS:UHD1 Operating Systems and Computer Organization Chapter 4.
بسم الله الرحمن الرحيم MEMORY AND I/O.
I/O Software CS 537 – Introduction to Operating Systems.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
Part IVI/O Systems Chapter 13: I/O Systems. I/O Hardware a typical PCI bus structure 2.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
CSCE451/851 Introduction to Operating Systems
Introduction to Operating Systems Concepts
Input/Output (I/O) Important OS function – control I/O
I/O Management.
Protection of System Resources
CS703 - Advanced Operating Systems
Module 2: Computer-System Structures
Operating Systems Chapter 5: Input/Output Management
Operating System Concepts
Chapter 5: I/O Systems.
Computer Organization
Module 2: Computer-System Structures
Module 2: Computer-System Structures
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Module 2: Computer-System Structures
Chapter 1: Introduction CSS503 Systems Programming
Module 12: I/O Systems I/O hardwared Application I/O Interface
Presentation transcript:

1 Device Management The von Neumann Architecture System Architecture Device Management Polling Interrupts DMA operating systems

2 Von Neumann Architecture Born 28 December 1903, Budapest, Hungary; Died 8 February 1957, Washington DC; Brilliant mathematician, synthesizer, and promoter of the stored program concept which became the prototype of most of its successors - the von Neumann Architecture operating systems

3 Von Neumann Architecture bus cpu memory device Machine has a fixed set of electronic parts Actions are determined by a program stored in the computer memory. Instructions and Data operating systems Prior to this time programming was done with switches & plugboards

4 bus cpu address lines data lines ALU Control Unit General Purpose & Status Registers operating systems The CPU and the Bus

5 cpu ALU Control Unit General Purpose & Status Registers fetch unit decode unit execution unit instruction reg program ctr address instruction operating systems

6 bus Memory unit memory MAR MDR Command Memory Address register Memory Data register operating systems The Memory Unit

7 bus Memory unit memory MAR MDR CMD REG Writing to Memory Address to write to Data to write Write command operating systems Memory Address register Memory Data register

8 DevicesDevices In a Unix system, every device is treated just like a file. In fact, all devices have a file name in the file system operating systems Files that represent devices are in the /dev directory $ ls –C /dev You can list the terminal device you are attached to $ tty You can copy a file to the terminal $ cp myFile.txt /dev/tty2

9 Block Devices Stores data in fixed size blocks. Blocks can be read/written independently Character Devices Delivers or accepts a stream of characters. DevicesDevices operating systems

10 Do an ls command on a terminal device $ ls –al /dev/ttyp1 operating systems crw - - w debry tty 4, 1 Aug 4 4:18 /dev/tty1 A character device this is usually where the file size goes. What’s up?

11 Do an ls command on a terminal device $ ls –al /dev/tty1 operating systems crw - - w debry tty 4, 1 Aug 4 4:18 /dev/tty1 A character device The i-node in this case does not contain the address of a disk block, but the address of a device driver. In this case, 4 is the “address” of the device driver, and 1 is an argument passed to the device driver.

12 operating systems crw - - w debry tty 4, 1 Aug 4 4:18 /dev/tty1 A character device only the terminal owner can read from the terminal. any other terminal user can write to the terminal

13 At the API, all devices support a common set of commands: open close read write... operating systems

14 For example, to read from a tape drive, you might write code that looks like the following: int fd; fd = open(“dev/tape”,O_RDONLY); lseek(fd, long (4096, SEEK_SET); n = read(fd, buffer_length); close(fd);

15 Note that all devices do not support all of the file system commands. For example, you cannot do a seek on a terminal.

16 I/O Layers User Program User Space Operating System Device Driver Kernel Space Device Controller Device Driver Device Controller Device Driver Device Controller API operating systems Standard I/F open close read write ioctl

17 Layers of the I/O system and the main functions of each layer User Process Device Independent Layer Device Dependent Layer Interrupt Handler LOGICAL I/O: open, read, write, … Naming, protection, blocking, allocation Write to device registers, read status Driver Wake up driver when I/O completes Device Controller Perfom the physical I/O operation data status command operating systems

18 Device Controllers I/O devices have two major components: A mechanical component An electronic component The electronic component is the device controller. It may be able to handle multiple devices Controller's tasks convert serial bit stream to block of bytes perform error correction as necessary make data available to main memory continuously monitor the state of the device Control the device I/O devices have two major components: A mechanical component An electronic component The electronic component is the device controller. It may be able to handle multiple devices Controller's tasks convert serial bit stream to block of bytes perform error correction as necessary make data available to main memory continuously monitor the state of the device Control the device operating systems

19 Control and status registers Data buffer Device Controller I/O Bus Put an address on the address line of the I/O bus the address selects the device put the command to be executed on the control line operating systems

20 A Device Controller Example: Reading Data From Disk CPU Controller buffer Memory operating systems 1.The cpu issues a read command to the disk controller read

21 Reading Data From Disk CPU ControllerMemory 1.The cpu issues a read command to the disk controller 2.The disk controller reads the required data from the device and stores it in it’s internal buffer operating systems |||||||||||| buffer

22 Reading Data From Disk CPU Controller buffer Memory 1.The cpu issues a read command to the disk controller 2.The disk controller reads the required data from the device and stores it in it’s buffer 3.The controller sends an interrupt to the cpu indicating that data is ready to be read INT operating systems

23 Reading Data From Disk CPU Controller buffer Memory 1.The cpu issues a read command to the disk controller 2.The disk controller reads the required data from the device and stores it in it’s buffer 3.The controller sends an interrupt to the cpu indicating that data is ready to be read 4. The cpu reads one byte of data from the controller buffer reg operating systems a

24 Reading Data From Disk CPU Controller buffer Memory 1.The cpu issues a read command to the disk controller 2.The disk controller reads the required data from the device and stores it in it’s buffer 3. The controller sends an interrupt to the cpu indicating that data is ready to be read 4. The cpu reads one byte of data from the controller buffer 5.The cpu writes the byte to memory. This process continues until all data is transferred reg operating systems a

25 Using Direct Memory Access CPU Controller buffer Memory DMA Controller A DMA controller is like a mini-cpu. It can read And write data to memory without involving The CPU. operating systems

26 Using Direct Memory Access CPU Controller buffer Memory 1. The cpu programs the dma controller, giving it a beginning address in memory, a byte count,and a command to execute. It also sends a read command to the disk controller. The cpu can now go on and do other work. DMA Controller read operating systems pgm

27 Using Direct Memory Access CPU Controller buffer Memory 1.The cpu programs the dma controller, giving it a beginning address in memory, a byte count, and a command to execute. It also sends a read command to the disk controller. 2.The disk controller reads the data from the disk and stores it in its data buffer, just as it did before. DMA Controller operating systems ||||||||||

28 Using Direct Memory Access CPU Controller buffer Memory 1.The cpu programs the dma controller, giving it a beginning address in memory, a byte count, and a command to execute. It also sends a read command to the disk controller. 2.The disk controller reads the data from the disk and stores it in its data buffer, just as it did before. 3.The DMA controller sends a command to the disk controller requesting a byte of data. DMA Controller operating systems

29 Using Direct Memory Access CPU Controller buffer Memory 1.The cpu programs the dma controller, giving it a beginning address in memory, a byte count, and a command to execute. It also sends a read command to the disk controller. 2.The disk controller reads the data from the disk and stores it in its data buffer, just as it did before. 3.The DMA controller sends a command to the disk controller requesting a byte of data. 4. The disk controller sends a byte of data to the dma controller DMA Controller operating systems a

30 Using Direct Memory Access CPU Controller buffer Memory 1.The cpu programs the dma controller, giving it a beginning address in memory, a byte count, and a command to execute. It also sends a read command to the disk controller. 2.The disk controller reads the data from the disk and stores it in its data buffer, just as it did before. 3.The DMA controller sends a command to the disk controller requesting a byte of data. 4. The disk controller sends a byte of data to the dma controller 5. The dma controller writes the byte to memory. DMA Controller operating systems a

31 Using Direct Memory Access CPU Controller buffer Memory 6. The disk controller sends an acknowledgement signal to the dma controller. This continues until all of the data has been transferred. All of this happens without the cpu being involved. When all of the data has been transferred, then the cpu is interrupted. DMA Controller ack operating systems int

32 Memory-Mapped I/O Primary memory device 0 device 1 device 2 memory addresses device addresses Traditional approach uses special I/O instructions to get at device registers copy_in R3, 0x012, 4 Copy the contents of register 4 in the device at address 012 into cpu register 3 operating systems

33 Memory-Mapped I/O Primary memory device 0 device 1 device 2 memory addresses With memory mapped I/O no special instructions are needed. Device registers are mapped by the hardware into memory addresses. Load R3, 0xFFF0124 Load register 3 from memory Address 0xFFF0124 operating systems

34 Single Bus Architecture bus cpu memory device All addresses and data go on the same bus operating systems

35 Multiple Bus Architecture bus cpu memory device All device addresses and data go on another bus The cpu uses one bus to access memory operating systems

36 Polling vs. Interrupts operating systems

37PollingPolling Because there is a tremendous difference in speed between an I/O device and the computer, the computer must wait until the device is ready to process the next byte of data. Instruction Register Accumulator Status Register Control lines and address lines Data lines Status lines operating systems

38 ExampleExample Instruction Register Accumulator Status Register Control lines and address lines Data lines Status lines character to be printed print instruction device address character print printed! operating systems

39 PollingPolling Issue Write Command Load character into accumulator Is the printer done? no Load character into accumulator yes What is wrong with this approach ? If the printer can print 100 characters a second, then it takes 10ms to print each character. Thus this polling loop runs for 10 ms between each character. Clear the status register operating systems

40 Direct I/O with Polling User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 1.Application issues a read( ) call. The OS blocks the application. operating systems An example of a device driver using polling

41 Direct I/O with Polling 2. User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 2. The device driver queries the status register in the controller to determine whether or not the device is busy. It polls until it is not. BLOCKED operating systems

42 Direct I/O with Polling 2. User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 3. The driver stores a command in the command register of the device controller. BLOCKED operating systems

43 Direct I/O with Polling 2. User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 4. The controller reads from the device. Since this involves mechanical parts, the read can take some time. BLOCKED operating systems

44 Direct I/O with Polling 2. User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space BLOCKED operating systems 5. Meanwhile, the device driver queries the status register in the controller to see if the operation is complete. It polls until it is. The CPU cannot be used for anything else.

45 Direct I/O with Polling 2. User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 7. The device driver reads the data register(s) in the device controller to get the data that has been read from the device. BLOCKED operating systems

46 Direct I/O with Polling 2. User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 8. The device driver copies the data into user space. The OS unblocks the application program. BLOCKED operating systems

47 InterruptsInterrupts Handling interrupts on machines that do look-ahead or on super- scalar machines is quite complicated. This discussion is simplified. bus cpumemory Interrupt controller device Device finishes it operation. It writes its status to the Interrupt controller cpu The Interrupt controller issues the interrupt to the CPU. The interrupt includes a number which is used to index into an interrupt table. The CPU stops whatever it is doing, and executes the interrupt handler pointed to by the interrupt. operating systems

48 Direct I/O with Interrupts User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 1.Application issues a read( ) call. The OS blocks the application. operating systems A Device Driver Using Interrupts

49 Direct I/O with Interrupts User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 2. The device driver queries status registers in the device controller to see if the device is busy. If it is, it waits. BLOCKED operating systems

50 Direct I/O with Interrupts User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 3. When the device is ready, the device driver stores a command in the command register of the device controller. This starts the device. BLOCKED operating systems

51 Direct I/O with Interrupts User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 3. The driver then issues a wait(). BLOCKED operating systems wait means “I will voluntarily give up the cpu and wait for an interrupt to occur.

52 Direct I/O with Interrupts User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 4. The OS schedules another process. 5. Meanwhile, the device controller reads from the device. Some other process is using the CPU BLOCKED Another Process BLOCKED operating systems

53 operating systems Direct I/O with Interrupts User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 6. The read is complete. The device controller interrupts the CPU. 7. The interrupt handler determines which device caused the interrupt. It does its clean up and then sends a signal to the device driver to wake it up. Interrupt Handler BLOCKED signal

54 Direct I/O with Interrupts User Program Operating System Device Driver Kernel Space Device Controller Device Interface (API) User Space 8. The device driver copies the data from the data registers in the device controller into the user’s address space. It then does a return to the application. operating systems

55 ExampleExample process Text to print user space kernel space print user process makes a print request operating systems

56 Code executed when the system call is made copy (userBuffer, kernelBuffer, count); enable interrupts; while (printerStatusReg != READY); printerDataReg = kernelBuffer[0]; run scheduler; Prints the first character // Block the user and run some other process

57 ExampleExample process Text to print user space kernel space blocked The user process is blocked. the print data is transferred to the kernel. process Another user process is scheduled to run. operating systems

58 ExampleExample process Text to print user space kernel space blocked the first character is sent to the printer process while the printer works, this process can run. operating systems

59 ExampleExample process Text to print user space kernel space blocked The printer sends an interrupt. It is ready for another character. process This process is interrupted. operating systems

60 ExampleExample process Text to print user space kernel space blocked the next character is sent to the printer process while the printer works, this process can run again. operating systems

61 ExampleExample process user space kernel space When all of the data has been printed, the process is unblocked. It will now be scheduled to run. process operating systems

62 Interrupt Handlers operating systems Interrupt handlers are best hidden deep in the O/S. In the best case, drivers are kernel processes – they use privileged instructions. have the driver starting an I/O operation block until an interrupt notifies it of completion Interrupt procedure does its work - when finished it unblocks driver that started it

63 Handling an Interrupt operating systems Save any registers not saved by the interrupt hardware Set up the context for the interrupt to run in Copy saved registers to the process table Set up stack for interrupt service procedure Ack interrupt controller, re-enable interrupts Run the interrupt handler Determine which process to run next Set up context for the next process to run Load new process' registers Start running the new process

64 Print Driver Interrupt Service Routine if (count == 0) done so unblock user; else { i = i + 1; count = count -1; printerDataReg = kernelBuffer[i]; } Acknowledge interrupt; Return from interrupt;

65 operating systems Device Manager Design User Program Operating System Kernel Space Device Interface (API) User Space read( device_x, … ) Trap Table read( device_x ) read( deviceID, …) { switch(deviceID) { case dev0: dev0_read( … ); break; case dev1: dev1_read( …); break; … This design requires that the kernel be recompiled every time a new device is added.

66 Reconfigurable Drivers Device 01 Device 02 Device 03 Device 04 … open( ) read( ) write( ) ioctl( ) When a new device is added, fill in entries in the table using a device “Registration” procedure. operating systems