When a process is waiting for I/O, how is the task state updated to TASK_INTERRUPTIBLE (that is, blocked)?
Imagine this case, a process issues an I/O request to a block device. According to my previous thread, the process finally invokes elv_add_request()
to add the request to the I/O queue. So I guess in this elv_add_request()
call, the implementation will something like:
elv_add_request(){
// Register IO_CALLBACK()
set_task_state(task, TASK_INTERRUPTABLE); // blocked
// flush IO request to disk
...
}
IO_CALLBACK(){
set_task_state(task, TASK_RUNNING); // IO completed, ready to run
}
The logic is like this: When the I/O request is finished, it will use the call back function to notify the kernel that the process is ready now. Does it make sense?
If that's the case, how is the callback mechanism implemented? Is it a CPU/hardware feature?