720 likes | 1.77k Views
Input/Output Subsystem. I/O subsystem controls all I/O devices. Basic Functions include: - issuing commands to the devices - handling interrupts from devices - responding to errors from devices. Categories of devices. Block Devices Q. What are some examples of block devices?
E N D
Input/Output Subsystem I/O subsystem controls all I/O devices. Basic Functions include: - issuing commands to the devices - handling interrupts from devices - responding to errors from devices CPSC 451 Input/Output Susystem
Categories of devices • Block Devices • Q.What are some examples of block devices? • Character Devices • Q.What are some examples of character devices? CPSC 451 Input/Output Susystem
Device Controllers • Q. What are device controllers and where are they located? • Q. Why does the operating communicate with the device via a controller? CPSC 451 Input/Output Susystem
I/O Addresses • Most computers use a special address space for I/O. • clock uses addresses 040-043 on PC • floppy disk uses addresses 3F0-3F7 on PC • Controllers use these addresses to communicate with the CPU by accepting commands such as read, write, seek, format, etc. CPSC 451 Input/Output Susystem
Interrupt Request Lines (IRQs) • Controllers use interrupts to tell the CPU that they are ready to perform tasks. • A hardware Interrupt Request Line is an input to the interrupt controller chip. • IBM PC has 15 IRQs available for devices. • Each IRQ is mapped on an interrupt vector, which locates an interrupt service routine. • E.G IRQ 0 (CLOCK) corresponds to vector 8. CPSC 451 Input/Output Susystem
DMA • DMA - Direct Memory Access is supported by most controllers that work with block devices. • Q. How does DMA work and what is its main advantage? CPSC 451 Input/Output Susystem
Principles of I/O Software • Device independence (interface of the I/O software should not depend on the hardware design) • Uniform naming (device name should be a string of characters not dependent on the device itself) • Error handling (errors should be detected and corrected at the lowest possible layer of the system hierarchy). CPSC 451 Input/Output Susystem
Asynchronous I/O (CPU should be able to instruct the controller to perform specific I/O operations and go off to do something else until an interrupt arrives) • Sharable and dedicated devices. (The I/O subsystem should support both dedicated devices such as a keyboard and sharable devices such as disks.) CPSC 451 Input/Output Susystem
Layers of the I/O software User level software Device-independent o.s. software Device drivers Interrupt-level software CPSC 451 Input/Output Susystem
Interrupt Handlers • Interrupts are necessary for efficient use of the system resources. • The interrupt handler routines handle interrupts associated with device. • Interrupts ought to be completely transparent to user processes. • The user process should block until the requested I/O is completed. CPSC 451 Input/Output Susystem
Device Drivers • Contain all device dependent code. • Issue the commands to the device controllers and check if these commands are carried out properly. • Device drivers accept abstract requests from the device independent software and translate them into the language understood by the controller and the device. CPSC 451 Input/Output Susystem
Device-Independent Software • Device Independent Software usually is a part of the File System. • Its main function is to perform the I/O functions that are common to all devices and to provide a uniform interface to the user-level software such as naming, protection, defining device independent block size, buffering, device and storage allocation and de-allocation, and error reporting. CPSC 451 Input/Output Susystem
User Space Software • Library procedures and functions are used by application software to communicate with devices. (E.g. stdio.h header file is necessary to use library functions associated with standard I/O). • printf, scanf, read, write, seek are all library functions. • Another important feature of the I/O subsystem is spooling. CPSC 451 Input/Output Susystem
Interrupt Handlers in Minix • Interrupts generate messages and cause tasks switches. • Interrupt handlers generate messages and they frequently perform some I/O processing the lowest level. CPSC 451 Input/Output Susystem
Device Drivers in Minix • There is a separate I/O task (driver) for each device. • Device drivers communicate with other tasks and with the File System using message passing. • All device drivers are in the kernel. WHY? CPSC 451 Input/Output Susystem
Device Independent Software in Minix • In Minix the file system process contains all the device-independent I/O code. • The I/O independent code handles the interface with drivers, buffering, block allocation, protection and management of the I-nodes, directories and mounted file systems. CPSC 451 Input/Output Susystem
User-Level Software in Minix • Library procedures are available for making system calls as well as all the C functions required by the POSIX standard (such as scanf and printf) • Minix has one spooler daemon lpd, for spooling files to a printer. • Minix supports daemons for various network functions. CPSC 451 Input/Output Susystem
Terminals • There are three broad categories of terminals: • memory-mapped terminals (keyboard and displayed hardwired to the computer) • RS-232 terminals (they interface via a serial communication line, most frequently a modem). • X-terminals (connected to the computer via network). CPSC 451 Input/Output Susystem
Terminal Software • Consist of keyboard software and display software. • In Minix the keyboard and screen drivers are part of the same task. Q.What task is it? CPSC 451 Input/Output Susystem
Input Software • Its main function it is to collect input from the keyboard and pass it to user programs when they read from the terminal. • POSIX standard defined two modes of terminal operation: • canonical mode (line oriented) • non-canonical mode (character oriented) • Q. Give examples of apps that use non-canonical mode of terminal operation. CPSC 451 Input/Output Susystem
Keymaps/Code Pages • Keyboards usually deliver key numbers rather then the character codes used by applications. • The driver must convert the key number to the code (e.g. ASCII code) or another code for a different country. • Many o.s provide for load-able keyboard maps or code pages to facilitate different languages and applications. CPSC 451 Input/Output Susystem
Echoing • Echoing is a processing of displaying characters that are typed. • Echoing is done by the keyboard driver which must figure out where to put the new input without overwriting current output. • Wrapping around and scrolling must be handled. CPSC 451 Input/Output Susystem
Special Characters • When operating in canonical mode a number of characters have special meaning: • CTRL/D EOF • CTRL-H ERASE (Backspace one character) • CTRL-Q Start output • CTRL-S Stop output • CTRL-U KILL (Erase entire line being typed) CPSC 451 Input/Output Susystem
Termios Structure • Each terminal has a structure called termios associated with it: struct termios { tcflag_t c_iflag; /* input modes */ tcflag_t c_oflag; /*output modes */ tcflag_t c_cflag; /*control modes */ tcflag_t c_lflag; /*local modes*/ speed_t c_speed; /*input speed*/ speed_t c_ospeed; /*output speed*/ cc_t c_cc[NCCS]; /*control characters */ } CPSC 451 Input/Output Susystem
Values of the c_cc Array in Minix. • Q. Where are the values for the c_cc array defined in Minix? • Q. What are those values? Test them. CPSC 451 Input/Output Susystem
POSIX Terminal Functions • tcsetattr - sets a termios structure • tcgetattr -receives a termios structure • MINIX provides system call ioctl: • ioctl(file_descriptor, request, argp) to examine and set the value of termios. CPSC 451 Input/Output Susystem
Output Software • Output characters and echoed characters are buffered and then copied to the Video-RAM. • The driver must: • know where the next output goes • scroll the screen when necessary • interpret escape characters and execute the escape commands CPSC 451 Input/Output Susystem
Terminal Driver in MINIX • It handles both the keyboard and the display. • Opens and closes a device. • Accepts messages from FS and clock. • It uses a data structure called tty_table which is an array of tty structures. • It supports up to 8 virtual terminals. CPSC 451 Input/Output Susystem
Structure tty • Q. Where is structure tty defined? • Q. What is its contents? CPSC 451 Input/Output Susystem
How does the terminal input work? • User <--> FS<-->TTY <---clockInt<---ttyInt • User logs into the system. • A shell is created with dev/console as I/O • The shell does a read from console • Read sends a message to FS • FS locates i-node for console with major and minor device numbers for console. CPSC 451 Input/Output Susystem
FS identifies the task corresponding to the device. • FS sends a message to the task for which the task replies immediately that nothing has been typed yet. • The FS unblocks and goes off to do other things but it records the fact the user is expected input in the tty structure for this terminal. • The user’s shell remains blocked until the requested characters arrive. CPSC 451 Input/Output Susystem
A character pressed causes two interrupts • one when the key is depressed • one when the key is released • The keyboard interrupt stores character codes in ibuf. • The keyboard interrupt sets the tty_timeout variable which causes the clock handler to send a message to tty. CPSC 451 Input/Output Susystem
Upon receiving a message tty identifies the event and calls the event specific handler. • For keyboard input kb_read is called which converts keyboard codes to ASCII codes. • Kb_read calls then in_process which processes ASCII codes. • In_process processes ASCII codes, adds characters to the console’s input queue, (or removes them), etc. CPSC 451 Input/Output Susystem
When enough characters have come in, the tty task calls the assembly language procedure to copy the data to the user’s address space. • This is repeated until the whole request was completed. • After that the terminal driver sends a message to the file system informing it that the work has been done. CPSC 451 Input/Output Susystem
Note that unlike with block I/O, terminal driver does not go through the FS to copy the data to the user space. • Q. WHY? CPSC 451 Input/Output Susystem
Terminal Output • Simpler than input. • No interrupts are needed. • Copies data from one memory region to another. CPSC 451 Input/Output Susystem
How does the terminal output work? • User program wants to print something. • A message is passed to the FS with pointer to the buffer with characters to be printed. • The FS sends a message to tty (terminal deriver) which fetches the characters and copies them to the video RAM. CPSC 451 Input/Output Susystem