operating system os

OS Interrupt Driven Input/Output

« Previous Tutorial Next Tutorial »

Interrupt-driven input/output is another way to perform input/output.

In case of printing on a printer that doesn't buffer the characters but prints each character when it arrives.

If the printer can print 100 characters per seconds, each character takes 10 msec to print. It means that after every character is written to the data register of the printer, the central processing unit will sit in an idle loop for 10 msec waiting to be allowed to output the next character.

This 10 msec is much more time to do a context switch and run some other process which would be wasted.

Now, the way to allow the central processing unit to do or to run some other process while waiting for printer to become read is to use interrupts.

When the computer system call to print the string is made then the buffer is copied to the kernel space and first character is copied to printer as soon as it is willing to accept a character. Now, at that point, the central processing unit (CPU) calls scheduler and then some other process is run. And, here the process that was called for the required string to be printed on the printer is blocked until the total string has printed.

The code given below shows the work done on the system call.

copy_from_user(buffer, p, count);
while(*printer_status_reg != READY);
*printer_data_register = p[0];

Now, when the printer has printed the character and then is prepared to accept the next character from the string, it generates an interrupt.

Here, the interrupt now stops the current process and saves its state. And the printer interrupt service procedure is run. Here is the code that shows this process of printing the string on the printer:

if(count == 0)
*printer_data_register = p[i];

Now, in case if none characters remains to print from the required string, then the interrupt handler takes an action to unblock the user. Otherwise, it outputs the next remaining character from the string, acknowledges the interrupts, and returns to the process that was running just before the interrupt, that continues from where it left off.

A big disadvantage of interrupt-driven input/output is that an interrupt occurs on each and every character of the string. And as you know that interrupt takes time therefore this method wastes a lot amount of central processing unit (CPU) time. Therefore, a solution to this problem is to use DMA. We will learn about input/output using DMA (Direct Memory Access) in next tutorial.

« Previous Tutorial Next Tutorial »


Quick Links
Signup - Login - Give Online Test