Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 6: Device Drivers


drivers/block/ll_rw_blk.c
void blk_plug_device(request_queue_t *q)
{
...
if (!test_and_set_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags)) {
mod_timer(&q->unplug_timer, jiffies + q->unplug_delay);
...
}
}

This section of code ensures that the unplug timer of the queue is enabled afterq->unplug_delayjiffies
[typically(3 * HZ) / 1000, or 3 milliseconds]; in turn, this invokesblk_unplug_timeoutto unplug the
queue.

A second mechanism is also available to unplug the queue. If the number of current read and write
requests (stored in the two entries of thecountarray of the request list) corresponds to the threshold
specified byunplug_thresh,__generic_unplug_deviceis invoked inelv_insert^14 to trigger unplug-
ging so that waiting requests are processed.

__generic_unplug_deviceis not very complicated.

block/ll_rw_blk.c
void __generic_unplug_device(request_queue_t *q)
{
...
if (!blk_remove_plug(q))
return;

q->request_fn(q);
}

request_fnis invoked to process the waiting requests afterblk_remove_plughas removed the plug of
the queue and the timer used for automatic unplugging (unplug_timer) is set. That’s all that need be
done!

The kernel is also able to perform unplugging manually when important I/O operations are pending.
This ensures that important read operations, for example, are carried out immediately if data are urgently
required. This situation arises when synchronous requests (mentioned briefly above) need to be satisfied.

ExecutingRequests


The device-specificrequest_fnfunction is invoked when the requests in the request queue are ready to
be processed. This is a very hardware-specific task so the kernel does not provide a default implementa-
tion. Instead, it always uses the method passed when the queue was registered withblk_dev_init.

Nevertheless, the structure of therequestfunction described below is similar in most device drivers. I
assume a situation in which there are several requests in the request queue.

(^14) elv_insertis an internal function of the elevator implementation and is called at various points in the kernel.

Free download pdf