Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "1 Device Management The von Neumann Architecture System Architecture Device Management Polling Interrupts DMA operating systems."— Presentation transcript:

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

2 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 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 4 bus cpu address lines data lines ALU Control Unit General Purpose & Status Registers operating systems The CPU and the Bus

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

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

7 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 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 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 10 Do an ls command on a terminal device $ ls –al /dev/ttyp1 operating systems crw - - w - - - - 1 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 11 Do an ls command on a terminal device $ ls –al /dev/tty1 operating systems crw - - w - - - - 1 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 12 operating systems crw - - w - - - - 1 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 13 At the API, all devices support a common set of commands: open close read write... operating systems

14 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 34 Single Bus Architecture bus cpu memory device All addresses and data go on the same bus operating systems

35 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 36 Polling vs. Interrupts operating systems

37 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 55 ExampleExample process Text to print user space kernel space print user process makes a print request operating systems

56 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 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 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 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 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 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 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 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 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 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 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


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

Similar presentations


Ads by Google