Skip to contentSkip to conversation

Need information on elevator_dispatch_fn

DISCUSSION Philipp Gruber 3 participants 3 messages Oct 31, 2007

lore
Share & tools
lore
#0 lore raw

Hello everyone,

I'm just working on an I/O-scheduler that implements some QoS functionality.

Now I get some weird problems and need to know what triggers my elevator_dispatch_fn, and how the return value of it is handled. For now, I found that the dispatch function is called as long as there are requests in my queue, so probably as long as it returns 1. On the other hand, only every second dispatch call returns 1, the others 0, but still it's working. I couldn't find any documentation about that (but would like to write some, if I understood it). Could someone please explain me when and why exactly elevator_dispatch_fn is triggered?

A little background:
Now that I'm implementing my QoS, I have one queue for each process, and prioritized processes get a timeslice, where they can access the device exclusively.
A timeslice might be 400ms, but if a process is finished after 200ms and has no more requests, dispatch will return 0 and then it won't be triggered anymore. So, when the next process has his timeslice, even if it has requests, dispatch_fn is not triggered, so the process will starve and hang forever.
So I need to 'reactivate' the whole dispatching process again. The only way to to this is probably a timer, but I couldn't get this working since I don't understand what calls dispatch_fn.

thanks in advance,
Philipp

#1 lore raw
Quoted 5 lines · Philipp Gruber

Hello everyone,

I'm just working on an I/O-scheduler that implements some QoS functionality.

Quoted 8 lines

Now I get some weird problems and need to know what triggers my elevator_dispatch_fn, and how the return value of it is handled. For now, I found that the dispatch function is called as long as there are requests in my queue, so probably as long as it returns 1. On the other hand, only every second dispatch call returns 1, the others 0, but still it's working. I couldn't find any documentation about that (but would like to write some, if I understood it). Could someone please explain me when and why exactly elevator_dispatch_fn is triggered?

elevator_dispatch_fn() is in charge of putting request on the dispatch list. So it'll be called, if q->queue_head is empty to refill that. The core is __elv_next_request(), which is called when a block driver wants to queue more IO. The logic is essentially:

elv_next_request()

{
        while (1) {
                if (!list_empty(&q->queue_head))
                        return first rq of list
                if (!elevator_dispatch_fn())
                        return NULL;
        }
}

So if you queue_head is empty AND elevator_dispatch_fn returns 0, then no request is given to the driver. IF elevator_dispatch_fn returns non-zero, then it MUST have put request on the queue_head list.

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to Philipp Gruber
Quoted 3 lines · Philipp Gruber

So I need to 'reactivate' the whole dispatching process again. The only way to to this is probably a timer, but I couldn't get this working since I don't understand what calls dispatch_fn.

Hi Philipp,

Take a look how the AS and CFQ schedulers implement this. In fact, the CFQ scheduler implements policy similar to what you described. as_work_handler() in block/as-iosched.c might be a good starting point.

-- Aaron