-static struct cfq_queue *cfq_get_best_queue(struct cfq_data *cfqd)
-{
- struct cfq_queue *cfqq = NULL, *__cfqq;
- sector_t best = -1, first = -1, dist;
-
- list_for_each_entry(__cfqq, &cfqd->cur_rr, cfq_list) {
- if (!__cfqq->next_rq || !cfq_cfqq_sync(__cfqq))
- continue;
-
- dist = cfq_dist_from_last(cfqd, __cfqq->next_rq);
- if (first == -1)
- first = dist;
- if (dist < best) {
- best = dist;
- cfqq = __cfqq;
- }
- }
-
- /*
- * Only async queue(s) available, grab first entry. Do the same
- * if the difference between the first and best isn't more than
- * twice, to obey fairness.
- */
- if (!cfqq || (best && first != best && ((first / best) < 4)))
- cfqq = list_entry_cfqq(cfqd->cur_rr.next);
-
- return cfqq;
-}
-
-static struct cfq_queue *cfq_get_next_queue(struct cfq_data *cfqd)
-{
- struct cfq_queue *cfqq = NULL;
-
- if (!list_empty(&cfqd->cur_rr) || cfq_get_next_prio_level(cfqd) != -1) {
- /*
- * if current list is non-empty, grab first entry. if it is
- * empty, get next prio level and grab first entry then if any
- * are spliced
- */
- cfqq = cfq_get_best_queue(cfqd);
- } else if (!list_empty(&cfqd->idle_rr)) {
- /*
- * if we have idle queues and no rt or be queues had pending
- * requests, either allow immediate service if the grace period
- * has passed or arm the idle grace timer
- */
- unsigned long end = cfqd->last_end_request + CFQ_IDLE_GRACE;
-
- if (time_after_eq(jiffies, end))
- cfqq = list_entry_cfqq(cfqd->idle_rr.next);
- else
- mod_timer(&cfqd->idle_class_timer, end);
- }
-
- return cfqq;
-}
-
-static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd)
-{
- struct cfq_queue *cfqq;
-
- do {
- long prio;
-
- cfqq = cfq_get_next_queue(cfqd);
- if (!cfqq)
- break;
-
- prio = cfq_prio_to_slice(cfqd, cfqq);
- if (cfqq->slice_resid > -prio)
- break;
-
- cfqq->slice_resid += prio;
- list_del_init(&cfqq->cfq_list);
- list_add_tail(&cfqq->cfq_list, &cfqd->rr_list[cfqq->ioprio]);
- cfqq = NULL;
- } while (1);
-
- __cfq_set_active_queue(cfqd, cfqq);
- return cfqq;
-}