I/O, Devices & Device Drivers I/O subsystem It is the responsibility of the I/O subsystem of an OS to schedule, manage, & control the interactions between.

Slides:



Advertisements
Similar presentations
System Integration and Performance
Advertisements

I/O Organization popo.
INPUT-OUTPUT ORGANIZATION
Input and Output CS 215 Lecture #20.
CS-334: Computer Architecture
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
1 Lecture 2: Review of Computer Organization Operating System Spring 2007.
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)
1 Computer System Overview OS-1 Course AA
Chapter 1 and 2 Computer System and Operating System Overview
Computer-System Structures
Mehmet Can Vuran, Instructor University of Nebraska-Lincoln Acknowledgement: Overheads adapted from those provided by the authors of the textbook.
INPUT/OUTPUT ORGANIZATION INTERRUPTS CS147 Summer 2001 Professor: Sin-Min Lee Presented by: Jing Chen.
Chapter 2: Computer-System Structures
1 Computer System Overview Chapter 1 Review of basic hardware concepts.
Copyright ©: Nahrstedt, Angrave, Abdelzaher
INPUT-OUTPUT ORGANIZATION
Input/Output. Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower.
Chapter 7 Input/Output Luisa Botero Santiago Del Portillo Ivan Vega.
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.
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
1 Computer System Overview Chapter 1. 2 n An Operating System makes the computing power available to users by controlling the hardware n Let us review.
Chapter 1 Computer System Overview Dave Bremer Otago Polytechnic, N.Z. ©2008, Prentice Hall Operating Systems: Internals and Design Principles, 6/E William.
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
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.
Chapter 2: Computer-System Structures
1 CSE Department MAITSandeep Tayal Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection.
2: Computer-System Structures
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
The Functions of Operating Systems Interrupts. Learning Objectives Explain how interrupts are used to obtain processor time. Explain how processing of.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage Structure Storage Hierarchy Hardware Protection Network Structure.
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
CH10 Input/Output DDDData Transfer EEEExternal Devices IIII/O Modules PPPProgrammed I/O IIIInterrupt-Driven I/O DDDDirect Memory.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
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.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Lecture 1: Review of Computer Organization
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
Input/Output Problems Wide variety of peripherals —Delivering different amounts of data —At different speeds —In different formats All slower than CPU.
IT3002 Computer Architecture
Input Output Techniques Programmed Interrupt driven Direct Memory Access (DMA)
بسم الله الرحمن الرحيم MEMORY AND I/O.
Time Management.  Time management is concerned with OS facilities and services which measure real time.  These services include:  Keeping track of.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
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.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Overview: Using Hardware.
Chapter 2: Computer-System Structures
Operating Systems (CS 340 D)
Computer Architecture
Module 2: Computer-System Structures
Operating Systems Chapter 5: Input/Output Management
Module 2: Computer-System Structures
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 2: Computer-System Structures
Chapter 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 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

I/O, Devices & Device Drivers

I/O subsystem It is the responsibility of the I/O subsystem of an OS to schedule, manage, & control the interactions between processes and devices.

In a single/process user system if a program requests access to an I/O device it gains control of that device immediately, and the I/O subsystem manages the transfer of data In a multiprogramming environment, many processes can be requesting service from the same device. The I/O subsystem is then responsible for: –Determining if the device is available If it is the operation is initiated and handled by the I/O subsystem –If the device is unavailable The request is preserved in a device queue When the device becomes available, the next pending operation is initiated.

What is a device driver A device driver is software that manages communications with a specific I/O device or type of I/O device. Device drivers are one of the most frequently written type of OS software Implementing device drivers can be complex because of the characteristics of the individual device

DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Initialize Seek to Sector, Track, Cyl. Seek Home Position Read block Write block Magnetic Tape Rewind Forward Space Record Backspace Record Read Record Write Record Read Backwards Printer Initialize Load or select font Select paper tray Print character Load font Initialize Terminal** Read Character Write Character Mouse Read position Read button status ** Control operations are normally invoked by special characters in the data stream Figure 9--1: I/O Operations for Typical Devices

Character Devices These devices transfer one character at a time between the device and the computer. –Keyboards –Printers

Block Storage Devices Usually magnetic storage devices: magnetic tape and disks. These are devices that transfer large groups of bytes called blocks. Once an operation is started, it proceeds without further intervention by the OS.

Magnetic tapes are a continuous strip of storage medium which contains a # of parallel tracks. 8 bits of data are written in parallel on 8 tracks with a 9 th track used for a parity bit. In this form, data may be written densely, maybe up to thousands of bytes per block. However and inch or more may be required between blocks for control information. Usefulness of tape is limited by it serial nature.

track sector Circular base of support material on which a magnetic film is deposited. Arm

CPU I/O Interface controller Device Driver Data Status Control Processors view of I/O

Separate and protected, accessed through special instructions ie: Inport and Outport

Memory mapped I/O

Implementation strategies for handling devices Simple I/O –AKA Programmed I/O –Used on small and medium sized computers to handle character devices Block transfer –Used on small and medium sized computers to handle block devices I/O processors – used on large computers

Polling.vs. Interrupts Once an I/O operation is initiated, the OS must tract the operation until it is complete. There are two techniques that can be used to monitor device activity: Polling or Interrupts

Simple Polling algorithm /* initialize pointer and index */ ix=0; count = BUFLEN; /* begin polling loop */ while ((count > 0) && (no device error)) { /* wait while device is busy */ while (device is busy) {} /* process character if no error */ if (no device error) { write buffer[ix]; /* write next character */ count = count - 1; /* decrement count */ ix = ix + 1; /* increment index */ } }

Using interrupts for device management: –Starting I/O –Returning to the process or OS –Device generates an interrupt signal

Interrupts MAIN PROGRAM: /* initialize index, count, and device flag */ ix = 0; count = BUFLEN; dev_flag = 0;... enable interrupts for device and initiate operation... /* loop until all characters are written */ while (dev_flag == 0) {}... INTERRUPT HANDLER: save registers /* check for errors */ if (error) { dev_flag = -1;/* set flag to error code */ disable interrupts for device restore registers return from interrupt }

Interrupts continued /* check for completion */ if (count==0) { /* operation completed */ dev_flag = 1; /* set flag to completion code */ disable interrupts for device restore registers return from interrupt } /* no error, not complete; process character */ write buffer[ix]; /* write next character */ ix = ix + 1;/* increment index */ count = count - 1; /* decrement count */ restore registers return from interrupt

Buffering Buffering is a technique that can be used to improve device as well as CPU throughput Buffering is the use of temporary storage areas in memory to store data that is read from an input device before it is needed. Process can also use buffering to store data before it is sent to the output device

Buffering with character devices

Ring Buffer

Buffering with DMA devices and blocking

BUFFER1 BUFFER2 DISK1 CPU/PROCESS READ MORE DATA PROCESS Device Driver

BUFFER1 BUFFER2 CPU/PROCESS Read Last logical record from buffer 1 DISK1 Start read from device to fill buffer 2

Software Caching

Data structures for Device Management I/O operations that are in progress need to be represented by some type of data structures in every operating system This data structure can be called by various names DCB, IOB, IOCB It represents a device, channel or controller, and the activity of the device

Data structures for device management: I/OCB Channel (port ) Number Controller Address Device Name Device Address Interrupt Vector Address Address of Interrupt Handler Device Type Address of Open Procedure Address of Close Procedure Address of Start I/O Procedure Address of Cancel I/O Procedure Buffer Address Buffer Length Current Buffer Pointer Current Data Count Current I/O Operation Address of PCB of Process which requested the Operation Address of I/O Request Parameters Address of ECB for Current Operation Figure : Information Stored in an I/O Control Block & DCB

Device Driver Organization Every device driver & I/O supervisor must provide services to support the basic activities for each device, including: –Preparing for and starting I/O –Servicing interrupts –Completion of I/O –Cancellation of I/O –Error detection and recovery The I/O system call interface includes procedures to service common operations such as: –Open, close, read, write, and control operations Which when called for a specific device, invoke the corresponding component of a device driver.

Device driver organization: structure and functions of device drivers Figure : Structure and Functions of Device Drivers

Figure : Flow of Control in a Device Driver

Parameters Individual standards for system calls and device drivers for a specific OS will determine how parameters are passed to device drivers. Most systems create a parameter list, using a register to point to the address of this list. Part of the responsibility of the I/O scheduler is to access these parameters, validate them, and make them available to later components of the device driver.

Preparing for I/O Preparation for I/O is the first activity of a device driver when invoked via one of the device system calls. I/O system call parameters must: –specify the type of operation requested (read, write, control), –the address of the data buffer to be used, –the size of the data area, –and other relevant information. (font, or paper tray) –Additionally, device-dependent parameters, such as track and sector numbers for disk operations, may also be required. This component of a device driver validates device-specific parameters of an I/O request. Appropriate error return codes must be provided to the user for any errors detected in the service request parameters. The preparation for I/O might include: – temporary buffer allocation or initialization, –formatting of data, –placing information in the appropriate location(s) in some I/O control block that is accessible to the device interrupt handler and the operating system. Once the I/O request parameters are validated, the device status must be checked. If the device is busy or not ready, the device driver must take an appropriate system dependent action. –If an error condition or problem such as "device not ready" is detected, the driver might take action causing the application process to terminate, or it might simply provide a return code to be passed back to the process, which then must deal with the problem in a suitable way depending on the application. –In a multiprogramming operating system, the response may include queuing the I/O request for a shared device that is presently busy with another operation.

Starting I/O DEVICEREQUIRED I/O INFORMATION Disk Operation Code Memory Transfer Address Number of Bytes to Transfer Track Address Sector Address Tape Operation Code Memory Transfer Address Number of Bytes to Transfer Printer Terminal Serial Device Operation Code (read/write) Character to Transfer TimerTime interval

Interrupt Servicing The most complicated part of most I/O drivers or I/O supervisor modules is the interrupt handler. Much of the device control is embedded in the interrupt handler, which is given control asynchronously when the device needs service. –This could involve processing the next character for a device in the case of a non-DMA device, –starting a second or third phase of an I/O operation for DMA devices (for example, a read after a seek to sector on some disks). Information needed by the interrupt handler must be provided by the main portion of the device driver. Such information is usually contained in the control blocks that represent the current I/O operation, just as PCBs represent process execution to the dispatcher. –Device interrupt handlers must save all registers and hardware status of the interrupted program and restoring it before returning to the interrupted program. –Certainly the most complex part of interrupt handler service is error recovery –Error recovery routines can be either resident or dynamically loaded when needed, depending on operating system design and requirements.

Possible errors for devices DEVICEPOSSIBLE ERRORS Disk Invalid Track, Sector Wrong Density Power Unsafe Data error Tape Data error End of tape Printer Paper out Paper jam Off Line

Sample Error Handler ERROR HANDLER: /* initialize counter and flag */ loop = 0; tape_error = TRUE; /* repeat entire process up to ten times */ while ((loop < 10) && tape_error) { /* backspace and reread up to nine times */ count = 0; while ((count < 9) && tape_error) { backspace record read record again if (read is ok) tape_error = FALSE; else count = count + 1; }

/* if error still present, backup further */ if (tape_error) { /* backspace ten records */ count = 0; while (count < 10) { backspace record count = count + 1; } /* skip forward nine records */ count = 0; while (count < 9) { forward space record count = count + 1; } /* try reading again */ read record if (read is ok) tape_error = FALSE; loop = loop + 1; /* prepare for retry */ } /* repeat if necessary */

I/O completion Once the requested operation is finished, some cleanup must still occur –Setting the status of the process requesting the operation –Clearing the device busy status, and disabling interrupts –Search a device queue, for the next operation

Scheduling I/O process1process2process3 I/O event 1 I/O event 3 I/O event 2 Device or I/O queue

Multiple I/O queues Figure : A Single I/O Queue Figure : Multiple I/O Queues

PCB 0 Priority 60 Running Process Ready Q IO_Active Q IO_Init Q PCB 9 Priority 32 PCB 8 Priority 40 PCB 5 Disk Read PCB 4 Printer Write PCB 3 Disk Write PCB 2 Disk Read PCB1 Printer Write PRINTER_IOCB PCB7 Address ECB Address DISK_IOCB PCB6 Address ECB Address Modified figure 10-25

Running Process Ready Q IO_Active Q IO_Init Q PCB 8 Priority 40 PCB 6 Priority 42 PCB 5 Disk Read PCB 4 Printer Write PCB 3 Disk Write PCB1 Printer Write PRINTER_IOCB PCB7 Address ECB Address DISK_IOCB PCB2 Address ECB Address PCB 0 Priority 60 PCB 9 Priority32 Modified Figure 1--27

IO_COMPLETE: /* Cleanup after disk operation, switch waiting process to ready state */ if (operation is complete) { Save context of current process in PCB Insert PCB in ReadyQ Set Disk ECB for disk I/O just completed Move PCB address in Disk IOCB to ReadyQ Set Disk IOCB to idle state } /* setup next disk operation, if any */ Search IO_WaitQ for another disk request if (disk request found) { Move PCB address of next disk I/O request to Disk IOCB Move DIsk ECB address to Disk IOCB Start requested disk I/O operation } Invoke dispatcher to dispatch next process Figure : Handling an I/O Request Complete Interrupt