80

I am learning about operating systems but there is a small concept I cannot grasp. Say a process 1 is running on the CPU and then it issues an I/O request to read from a disk. For efficiency, the CPU begins executing process 2 as this request is handled. That all makes sense but doesn't the I/O need to use the CPU?

enter image description here

My Question: Why isn't the CPU needed to service process 1's request?

1
  • 13
    Not really a programming question, but with a typical disc (for one example) the CPU gives the disc drive the address to read from, the memory address for the result, and the disc is smart enough to handle the job from there (and send the CPU an interrupt when the data is ready). Nov 28, 2012 at 2:56

2 Answers 2

158

It would help to understand the role of 3 important aspects of I/O in computer architecture: Interrupts, DMA, and Hardware Controllers.

When the CPU issues an I/O request to the hard disk, the hard disk has its own specialized chip called a device (or hardware) controller designed solely for processing commands from the CPU, such as reading from the disk. Originally these were simple chips that performed specific operations for the CPU, but modern hardware controllers are basically their own microprocessors with firmware and everything, so they are capable of very complex operations without the main CPU's help. While the hard drive's controller is busy performing the request, the main CPU is free to do whatever it wishes, such as execute process 2 in your example. The controller is able to read and write directly to and from system RAM using what is called a Direct Memory Access (DMA) controller, a special unit that transfers data from the hardware controller to main RAM without the CPU needing to do anything.

When the hard drive is done with the request and the relevant data has been loaded into RAM through DMA, it issues an interrupt request which informs the CPU that the data has been loaded into RAM. At this point the CPU can transfer control back to process 1. Thus, the CPU does not need to micromanage all tasks involved with I/O. At one time this used to be the case, but these tricks (interrupts, DMA, special controllers) were invented in order to improve CPU performance and make things more efficient.

2
  • 1
    @Dougvj As you said Hardware issues interrupt to inform CPU that IO operation is done. How does it work in case of REST/Network call? REST call is also a IO operation. Dec 19, 2019 at 7:30
  • 6
    @GovindaSakhare The same principles apply. WiFi and Ethernet devices also have their own controllers with DMA and Interrupts and are capable of informing the processor when data arrives from the network, including for a REST response.
    – Dougvj
    Dec 19, 2019 at 19:01
-10

Cpu is used to initiate every io request and then accept it when ready ...it is not the case that cpu is not involved in io operations.

E.g copy 2gb file from c drive to d drive and open task manager ..in performance tab u will see both disk utilization as well as cpu usage.

Proving my.point.

Ahsan

2
  • 2
    What new did your answer actually bring to that question and already an old existing answer? May 1, 2016 at 7:50
  • I think it brings a clarification on how much can be Cpu involvement in a IO operation. Oct 27, 2022 at 12:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.