Lines Matching +full:in +full:- +full:tree
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Hierarchical Budget Worst-case Fair Weighted Fair Queueing
4 * (B-WF2Q+): hierarchical scheduling algorithm by which the BFQ I/O
9 #include "bfq-iosched.h"
12 * bfq_gt - compare two timestamps.
20 return (s64)(a - b) > 0; in bfq_gt()
23 static struct bfq_entity *bfq_root_active_entity(struct rb_root *tree) in bfq_root_active_entity() argument
25 struct rb_node *node = tree->rb_node; in bfq_root_active_entity()
34 return bfqq ? bfqq->ioprio_class - 1 : in bfq_class_idx()
35 BFQ_DEFAULT_GRP_CLASS - 1; in bfq_class_idx()
40 return bfqd->busy_queues[0] + bfqd->busy_queues[1] + in bfq_tot_busy_queues()
41 bfqd->busy_queues[2]; in bfq_tot_busy_queues()
50 * bfq_update_next_in_service - update sd->next_in_service
56 * expiration of the in-service entity
58 * This function is called to update sd->next_in_service, which, in
65 * reposition an entity in its active tree; see comments on
66 * __bfq_activate_entity and __bfq_requeue_entity for details). In
67 * both the last two activation sub-cases, new_entity points to the
70 * Returns true if sd->next_in_service changes in such a way that
71 * entity->parent may become the next_in_service for its parent
78 struct bfq_entity *next_in_service = sd->next_in_service; in bfq_update_next_in_service()
85 * sd->next_in_service, then a full lookup in the active tree in bfq_update_next_in_service()
86 * can be avoided. In fact, it is enough to check whether the in bfq_update_next_in_service()
87 * just-modified entity has the same priority as in bfq_update_next_in_service()
88 * sd->next_in_service, is eligible and has a lower virtual in bfq_update_next_in_service()
89 * finish time than sd->next_in_service. If this compound in bfq_update_next_in_service()
93 if (new_entity && new_entity != sd->next_in_service) { in bfq_update_next_in_service()
96 * sd->next_in_service with new_entity. Tentatively in bfq_update_next_in_service()
98 * sd->next_in_service is NULL. in bfq_update_next_in_service()
105 * to replace sd->service_tree with new_entity. in bfq_update_next_in_service()
111 sd->service_tree + new_entity_class_idx; in bfq_update_next_in_service()
117 !bfq_gt(new_entity->start, st->vtime) in bfq_update_next_in_service()
119 bfq_gt(next_in_service->finish, in bfq_update_next_in_service()
120 new_entity->finish)); in bfq_update_next_in_service()
134 parent_sched_may_change = !sd->next_in_service || in bfq_update_next_in_service()
138 sd->next_in_service = next_in_service; in bfq_update_next_in_service()
146 * Returns true if this budget changes may let next_in_service->parent
156 group_sd = next_in_service->sched_data; in bfq_update_parent_budget()
162 * as it must never become an in-service entity. in bfq_update_parent_budget()
164 bfqg_entity = bfqg->my_entity; in bfq_update_parent_budget()
166 if (bfqg_entity->budget > next_in_service->budget) in bfq_update_parent_budget()
168 bfqg_entity->budget = next_in_service->budget; in bfq_update_parent_budget()
177 * next_in_service. In particular, this function is invoked for an
178 * entity that is about to be set in service.
182 * about to become the in-service queue. This function then returns
185 * In contrast, entity could still be a candidate for next service if
186 * it is not a queue, and has more than one active child. In fact,
187 * even if one of its children is about to be set in service, other
190 * non-queue entity is not a candidate for next-service only if it has
192 * function returns true for a non-queue entity.
206 * not account for the in-service entity in case the latter is in bfq_no_longer_next_in_service()
207 * removed from its active tree (which may get done after in bfq_no_longer_next_in_service()
208 * invoking the function bfq_no_longer_next_in_service in in bfq_no_longer_next_in_service()
210 * bfq_no_longer_next_in_service is not yet completed in in bfq_no_longer_next_in_service()
215 if (bfqg->active_entities == 1) in bfq_no_longer_next_in_service()
223 struct bfq_sched_data *sd = entity->sched_data; in bfq_inc_active_entities()
226 if (bfqg != bfqg->bfqd->root_group) in bfq_inc_active_entities()
227 bfqg->active_entities++; in bfq_inc_active_entities()
232 struct bfq_sched_data *sd = entity->sched_data; in bfq_dec_active_entities()
235 if (bfqg != bfqg->bfqd->root_group) in bfq_dec_active_entities()
236 bfqg->active_entities--; in bfq_dec_active_entities()
263 * service allowed in one timestamp delta (small shift values increase it),
264 * the maximum total weight that can be used for the queues in the system
274 if (!entity->my_sched_data) in bfq_entity_to_bfqq()
282 * bfq_delta - map service into the virtual time domain.
292 * bfq_calc_finish - assign the finish time to an entity.
300 entity->finish = entity->start + in bfq_calc_finish()
301 bfq_delta(service, entity->weight); in bfq_calc_finish()
304 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_calc_finish()
306 service, entity->weight); in bfq_calc_finish()
307 bfq_log_bfqq(bfqq->bfqd, bfqq, in bfq_calc_finish()
309 entity->start, entity->finish, in bfq_calc_finish()
310 bfq_delta(service, entity->weight)); in bfq_calc_finish()
315 * bfq_entity_of - get an entity from a node.
320 * conversion mechanism because, e.g., in the tree walking functions,
334 * bfq_extract - remove an entity from a tree.
335 * @root: the tree root.
340 entity->tree = NULL; in bfq_extract()
341 rb_erase(&entity->rb_node, root); in bfq_extract()
345 * bfq_idle_extract - extract an entity from the idle tree.
346 * @st: the service tree of the owning @entity.
355 if (entity == st->first_idle) { in bfq_idle_extract()
356 next = rb_next(&entity->rb_node); in bfq_idle_extract()
357 st->first_idle = bfq_entity_of(next); in bfq_idle_extract()
360 if (entity == st->last_idle) { in bfq_idle_extract()
361 next = rb_prev(&entity->rb_node); in bfq_idle_extract()
362 st->last_idle = bfq_entity_of(next); in bfq_idle_extract()
365 bfq_extract(&st->idle, entity); in bfq_idle_extract()
368 list_del(&bfqq->bfqq_list); in bfq_idle_extract()
372 * bfq_insert - generic tree insertion.
373 * @root: tree root.
376 * This is used for the idle and the active tree, since they are both
382 struct rb_node **node = &root->rb_node; in bfq_insert()
389 if (bfq_gt(entry->finish, entity->finish)) in bfq_insert()
390 node = &parent->rb_left; in bfq_insert()
392 node = &parent->rb_right; in bfq_insert()
395 rb_link_node(&entity->rb_node, parent, node); in bfq_insert()
396 rb_insert_color(&entity->rb_node, root); in bfq_insert()
398 entity->tree = root; in bfq_insert()
402 * bfq_update_min - update the min_start field of a entity.
407 * min_start due to updates to the active tree. The function assumes
417 if (bfq_gt(entity->min_start, child->min_start)) in bfq_update_min()
418 entity->min_start = child->min_start; in bfq_update_min()
423 * bfq_update_active_node - recalculate min_start.
434 entity->min_start = entity->start; in bfq_update_active_node()
435 bfq_update_min(entity, node->rb_right); in bfq_update_active_node()
436 bfq_update_min(entity, node->rb_left); in bfq_update_active_node()
440 * bfq_update_active_tree - update min_start for the whole active tree.
446 * changed in the path to the root. The only nodes that may have changed
447 * are the ones in the path or their siblings.
460 if (node == parent->rb_left && parent->rb_right) in bfq_update_active_tree()
461 bfq_update_active_node(parent->rb_right); in bfq_update_active_tree()
462 else if (parent->rb_left) in bfq_update_active_tree()
463 bfq_update_active_node(parent->rb_left); in bfq_update_active_tree()
470 * bfq_active_insert - insert an entity in the active tree of its
472 * @st: the service tree of the entity.
475 * The active tree is ordered by finish time, but an extra key is kept
478 * the eligible node with the lowest finish time in logarithmic time.
484 struct rb_node *node = &entity->rb_node; in bfq_active_insert()
486 bfq_insert(&st->active, entity); in bfq_active_insert()
488 if (node->rb_left) in bfq_active_insert()
489 node = node->rb_left; in bfq_active_insert()
490 else if (node->rb_right) in bfq_active_insert()
491 node = node->rb_right; in bfq_active_insert()
496 list_add(&bfqq->bfqq_list, &bfqq->bfqd->active_list[bfqq->actuator_idx]); in bfq_active_insert()
502 * bfq_ioprio_to_weight - calc a weight from an ioprio.
507 return (IOPRIO_NR_LEVELS - ioprio) * BFQ_WEIGHT_CONVERSION_COEFF; in bfq_ioprio_to_weight()
511 * bfq_weight_to_ioprio - calc an ioprio from a weight.
514 * To preserve as much as possible the old only-ioprio user interface,
521 IOPRIO_NR_LEVELS - weight / BFQ_WEIGHT_CONVERSION_COEFF); in bfq_weight_to_ioprio()
529 bfqq->ref++; in bfq_get_entity()
530 bfq_log_bfqq(bfqq->bfqd, bfqq, "get_entity: %p %d", in bfq_get_entity()
531 bfqq, bfqq->ref); in bfq_get_entity()
536 * bfq_find_deepest - find the deepest node that an extraction can modify.
539 * Do the first step of an extraction in an rb tree, looking for the
541 * the following modifications to the tree can touch. If @node is the
542 * last node in the tree return %NULL.
548 if (!node->rb_right && !node->rb_left) in bfq_find_deepest()
550 else if (!node->rb_right) in bfq_find_deepest()
551 deepest = node->rb_left; in bfq_find_deepest()
552 else if (!node->rb_left) in bfq_find_deepest()
553 deepest = node->rb_right; in bfq_find_deepest()
556 if (deepest->rb_right) in bfq_find_deepest()
557 deepest = deepest->rb_right; in bfq_find_deepest()
566 * bfq_active_extract - remove an entity from the active tree.
567 * @st: the service_tree containing the tree.
576 node = bfq_find_deepest(&entity->rb_node); in bfq_active_extract()
577 bfq_extract(&st->active, entity); in bfq_active_extract()
582 list_del(&bfqq->bfqq_list); in bfq_active_extract()
588 * bfq_idle_insert - insert an entity into the idle tree.
589 * @st: the service tree containing the tree.
596 struct bfq_entity *first_idle = st->first_idle; in bfq_idle_insert()
597 struct bfq_entity *last_idle = st->last_idle; in bfq_idle_insert()
599 if (!first_idle || bfq_gt(first_idle->finish, entity->finish)) in bfq_idle_insert()
600 st->first_idle = entity; in bfq_idle_insert()
601 if (!last_idle || bfq_gt(entity->finish, last_idle->finish)) in bfq_idle_insert()
602 st->last_idle = entity; in bfq_idle_insert()
604 bfq_insert(&st->idle, entity); in bfq_idle_insert()
607 list_add(&bfqq->bfqq_list, &bfqq->bfqd->idle_list); in bfq_idle_insert()
611 * bfq_forget_entity - do not consider entity any longer for scheduling
612 * @st: the service tree.
614 * @is_in_service: true if entity is currently the in-service entity.
616 * Forget everything about @entity. In addition, if entity represents
617 * a queue, and the latter is not in service, then release the service
618 * reference to the queue (the one taken through bfq_get_entity). In
619 * fact, in this case, there is really no more service reference to
620 * the queue, as the latter is also outside any service tree. If,
621 * instead, the queue is in service, then __bfq_bfqd_reset_in_service
631 entity->on_st_or_in_serv = false; in bfq_forget_entity()
632 st->wsum -= entity->weight; in bfq_forget_entity()
638 * bfq_put_idle_entity - release the idle tree ref of an entity.
639 * @st: service tree for the entity.
646 entity == entity->sched_data->in_service_entity); in bfq_put_idle_entity()
650 * bfq_forget_idle - update the idle tree if necessary.
651 * @st: the service tree to act upon.
654 * as the idle tree will not grow indefinitely this can be done safely.
658 struct bfq_entity *first_idle = st->first_idle; in bfq_forget_idle()
659 struct bfq_entity *last_idle = st->last_idle; in bfq_forget_idle()
661 if (RB_EMPTY_ROOT(&st->active) && last_idle && in bfq_forget_idle()
662 !bfq_gt(last_idle->finish, st->vtime)) { in bfq_forget_idle()
664 * Forget the whole idle tree, increasing the vtime past in bfq_forget_idle()
667 st->vtime = last_idle->finish; in bfq_forget_idle()
670 if (first_idle && !bfq_gt(first_idle->finish, st->vtime)) in bfq_forget_idle()
676 struct bfq_sched_data *sched_data = entity->sched_data; in bfq_entity_service_tree()
679 return sched_data->service_tree + idx; in bfq_entity_service_tree()
697 * invoked with update_class_too unset in the points in the code where
698 * entity may happen to be on some tree.
707 if (entity->prio_changed) { in __bfq_entity_update_weight_prio()
711 /* Matches the smp_wmb() in bfq_group_set_weight. */ in __bfq_entity_update_weight_prio()
713 old_st->wsum -= entity->weight; in __bfq_entity_update_weight_prio()
715 if (entity->new_weight != entity->orig_weight) { in __bfq_entity_update_weight_prio()
716 if (entity->new_weight < BFQ_MIN_WEIGHT || in __bfq_entity_update_weight_prio()
717 entity->new_weight > BFQ_MAX_WEIGHT) { in __bfq_entity_update_weight_prio()
719 entity->new_weight); in __bfq_entity_update_weight_prio()
720 if (entity->new_weight < BFQ_MIN_WEIGHT) in __bfq_entity_update_weight_prio()
721 entity->new_weight = BFQ_MIN_WEIGHT; in __bfq_entity_update_weight_prio()
723 entity->new_weight = BFQ_MAX_WEIGHT; in __bfq_entity_update_weight_prio()
725 entity->orig_weight = entity->new_weight; in __bfq_entity_update_weight_prio()
727 bfqq->ioprio = in __bfq_entity_update_weight_prio()
728 bfq_weight_to_ioprio(entity->orig_weight); in __bfq_entity_update_weight_prio()
732 bfqq->ioprio_class = bfqq->new_ioprio_class; in __bfq_entity_update_weight_prio()
738 if (!bfqq || bfqq->ioprio_class == bfqq->new_ioprio_class) in __bfq_entity_update_weight_prio()
739 entity->prio_changed = 0; in __bfq_entity_update_weight_prio()
746 * when entity->finish <= old_st->vtime). in __bfq_entity_update_weight_prio()
750 prev_weight = entity->weight; in __bfq_entity_update_weight_prio()
751 new_weight = entity->orig_weight * in __bfq_entity_update_weight_prio()
752 (bfqq ? bfqq->wr_coeff : 1); in __bfq_entity_update_weight_prio()
760 entity->weight = new_weight; in __bfq_entity_update_weight_prio()
762 * Add the entity, if it is not a weight-raised queue, in __bfq_entity_update_weight_prio()
765 if (prev_weight != new_weight && bfqq && bfqq->wr_coeff == 1) in __bfq_entity_update_weight_prio()
768 new_st->wsum += entity->weight; in __bfq_entity_update_weight_prio()
771 entity->start = new_st->vtime; in __bfq_entity_update_weight_prio()
778 * bfq_bfqq_served - update the scheduler status after selection for
789 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_served()
792 if (!bfqq->service_from_backlogged) in bfq_bfqq_served()
793 bfqq->first_IO_time = jiffies; in bfq_bfqq_served()
795 if (bfqq->wr_coeff > 1) in bfq_bfqq_served()
796 bfqq->service_from_wr += served; in bfq_bfqq_served()
798 bfqq->service_from_backlogged += served; in bfq_bfqq_served()
802 entity->service += served; in bfq_bfqq_served()
804 st->vtime += bfq_delta(served, st->wsum); in bfq_bfqq_served()
807 bfq_log_bfqq(bfqq->bfqd, bfqq, "bfqq_served %d secs", served); in bfq_bfqq_served()
811 * bfq_bfqq_charge_time - charge an amount of service equivalent to the length
812 * of the time interval during which bfqq has been in
823 * engine works in the service, and not in the time domain. The trick
830 * distortions in terms of bandwidth distribution, on devices with
840 struct bfq_entity *entity = &bfqq->entity; in bfq_bfqq_charge_time()
844 (bfqd->bfq_max_budget * bounded_time_ms) / timeout_ms; in bfq_bfqq_charge_time()
845 int tot_serv_to_charge = max(serv_to_charge_for_time, entity->service); in bfq_bfqq_charge_time()
848 if (tot_serv_to_charge > entity->budget) in bfq_bfqq_charge_time()
849 entity->budget = tot_serv_to_charge; in bfq_bfqq_charge_time()
852 max_t(int, 0, tot_serv_to_charge - entity->service)); in bfq_bfqq_charge_time()
862 * When this function is invoked, entity is not in any service in bfq_update_fin_time_enqueue()
863 * tree, then it is safe to invoke next function with the last in bfq_update_fin_time_enqueue()
867 bfq_calc_finish(entity, entity->budget); in bfq_update_fin_time_enqueue()
872 * lower than the system virtual time. In particular, if in bfq_update_fin_time_enqueue()
877 * the system virtual time. In fact, to serve the queues with in bfq_update_fin_time_enqueue()
879 * idle, the system virtual time may be pushed-up to much in bfq_update_fin_time_enqueue()
894 * worst-case fairness guarantees. in bfq_update_fin_time_enqueue()
896 * As a special case, if bfqq is weight-raised, push up in bfq_update_fin_time_enqueue()
899 * weight-raised queues to become higher than the backshifted in bfq_update_fin_time_enqueue()
900 * finish timestamps of non weight-raised queues. in bfq_update_fin_time_enqueue()
902 if (backshifted && bfq_gt(st->vtime, entity->finish)) { in bfq_update_fin_time_enqueue()
903 unsigned long delta = st->vtime - entity->finish; in bfq_update_fin_time_enqueue()
906 delta /= bfqq->wr_coeff; in bfq_update_fin_time_enqueue()
908 entity->start += delta; in bfq_update_fin_time_enqueue()
909 entity->finish += delta; in bfq_update_fin_time_enqueue()
916 * __bfq_activate_entity - handle activation of entity.
924 * inserts entity into its active tree, after possibly extracting it
925 * from its idle tree.
935 if (non_blocking_wait_rq && bfq_gt(st->vtime, entity->finish)) { in __bfq_activate_entity()
937 min_vstart = entity->finish; in __bfq_activate_entity()
939 min_vstart = st->vtime; in __bfq_activate_entity()
941 if (entity->tree == &st->idle) { in __bfq_activate_entity()
943 * Must be on the idle tree, bfq_idle_extract() will in __bfq_activate_entity()
947 entity->start = bfq_gt(min_vstart, entity->finish) ? in __bfq_activate_entity()
948 min_vstart : entity->finish; in __bfq_activate_entity()
952 * it is in the past for sure, otherwise the queue in __bfq_activate_entity()
953 * would have been on the idle tree. in __bfq_activate_entity()
955 entity->start = min_vstart; in __bfq_activate_entity()
956 st->wsum += entity->weight; in __bfq_activate_entity()
958 * entity is about to be inserted into a service tree, in __bfq_activate_entity()
959 * and then set in service: get a reference to make in __bfq_activate_entity()
961 * longer in service or scheduled for service. in __bfq_activate_entity()
965 entity->on_st_or_in_serv = true; in __bfq_activate_entity()
972 * __bfq_requeue_entity - handle requeueing or repositioning of an entity.
981 * Basically, this function: 1) removes entity from its active tree if
983 * entity back into its active tree (in the new, right position for
988 struct bfq_sched_data *sd = entity->sched_data; in __bfq_requeue_entity()
991 if (entity == sd->in_service_entity) { in __bfq_requeue_entity()
993 * We are requeueing the current in-service entity, in __bfq_requeue_entity()
996 * - entity represents the in-service queue, and the in __bfq_requeue_entity()
997 * in-service queue is being requeued after an in __bfq_requeue_entity()
999 * - entity represents a group, and its budget has in __bfq_requeue_entity()
1006 * In particular, before requeueing, the start time of in __bfq_requeue_entity()
1008 * service that the entity has received while in in __bfq_requeue_entity()
1014 bfq_calc_finish(entity, entity->service); in __bfq_requeue_entity()
1015 entity->start = entity->finish; in __bfq_requeue_entity()
1017 * In addition, if the entity had more than one child in __bfq_requeue_entity()
1018 * when set in service, then it was not extracted from in __bfq_requeue_entity()
1019 * the active tree. This implies that the position of in __bfq_requeue_entity()
1020 * the entity in the active tree may need to be in __bfq_requeue_entity()
1023 * time in a moment (the requeueing is then, more in __bfq_requeue_entity()
1024 * precisely, a repositioning in this case). To in __bfq_requeue_entity()
1029 if (entity->tree) in __bfq_requeue_entity()
1031 } else { /* The entity is already active, and not in service */ in __bfq_requeue_entity()
1033 * In this case, this function gets called only if the in __bfq_requeue_entity()
1039 * i.e., the position in the active tree, of this in __bfq_requeue_entity()
1044 * non-extracted-entity sub-case above. in __bfq_requeue_entity()
1057 if (entity->sched_data->in_service_entity == entity || in __bfq_activate_requeue_entity()
1058 entity->tree == &st->active) in __bfq_activate_requeue_entity()
1060 * in service or already queued on the active tree, in __bfq_activate_requeue_entity()
1066 * Not in service and not queued on its active tree: in __bfq_activate_requeue_entity()
1074 * bfq_activate_requeue_entity - activate or requeue an entity representing a
1083 * @expiration: true if this function is being invoked in the expiration path
1084 * of the in-service queue
1092 if (!bfq_update_next_in_service(entity->sched_data, entity, in bfq_activate_requeue_entity()
1099 * __bfq_deactivate_entity - update sched_data and service trees for
1103 * idle tree.
1105 * If necessary and allowed, puts entity into the idle tree. NOTE:
1106 * entity may be on no tree if in service.
1110 struct bfq_sched_data *sd = entity->sched_data; in __bfq_deactivate_entity()
1114 if (!entity->on_st_or_in_serv) /* in __bfq_deactivate_entity()
1124 * entity->sched_data has been set, and we can safely use it. in __bfq_deactivate_entity()
1127 is_in_service = entity == sd->in_service_entity; in __bfq_deactivate_entity()
1129 bfq_calc_finish(entity, entity->service); in __bfq_deactivate_entity()
1132 sd->in_service_entity = NULL; in __bfq_deactivate_entity()
1135 * Non in-service entity: nobody will take care of in __bfq_deactivate_entity()
1139 entity->service = 0; in __bfq_deactivate_entity()
1141 if (entity->tree == &st->active) in __bfq_deactivate_entity()
1143 else if (!is_in_service && entity->tree == &st->idle) in __bfq_deactivate_entity()
1146 if (!ins_into_idle_tree || !bfq_gt(entity->finish, st->vtime)) in __bfq_deactivate_entity()
1155 * bfq_deactivate_entity - deactivate an entity representing a bfq_queue.
1157 * @ins_into_idle_tree: true if the entity can be put into the idle tree
1158 * @expiration: true if this function is being invoked in the expiration path
1159 * of the in-service queue
1169 sd = entity->sched_data; in bfq_deactivate_entity()
1173 * entity is not in any tree any more, so in bfq_deactivate_entity()
1174 * this deactivation is a no-op, and there is in bfq_deactivate_entity()
1175 * nothing to change for upper-level entities in bfq_deactivate_entity()
1176 * (in case of expiration, this can never in bfq_deactivate_entity()
1182 if (sd->next_in_service == entity) in bfq_deactivate_entity()
1190 if (sd->next_in_service || sd->in_service_entity) { in bfq_deactivate_entity()
1204 * active entity in the parent entity, and 2) in bfq_deactivate_entity()
1221 * Also let parent be queued into the idle tree on in bfq_deactivate_entity()
1240 * already active, to requeue/reposition it in the in bfq_deactivate_entity()
1241 * active tree (because sd->next_in_service has in bfq_deactivate_entity()
1246 sd = entity->sched_data; in bfq_deactivate_entity()
1251 * any change in entity->parent->sd, and no in bfq_deactivate_entity()
1260 * bfq_calc_vtime_jump - compute the value to which the vtime should jump,
1262 * @st: the service tree to act upon.
1268 struct bfq_entity *root_entity = bfq_root_active_entity(&st->active); in bfq_calc_vtime_jump()
1270 if (bfq_gt(root_entity->min_start, st->vtime)) in bfq_calc_vtime_jump()
1271 return root_entity->min_start; in bfq_calc_vtime_jump()
1273 return st->vtime; in bfq_calc_vtime_jump()
1278 if (new_value > st->vtime) { in bfq_update_vtime()
1279 st->vtime = new_value; in bfq_update_vtime()
1285 * bfq_first_active_entity - find the eligible entity with
1287 * @st: the service tree to select from.
1291 * root of the tree and going on the left every time on this side there is
1300 struct rb_node *node = st->active.rb_node; in bfq_first_active_entity()
1305 if (!bfq_gt(entry->start, vtime)) in bfq_first_active_entity()
1308 if (node->rb_left) { in bfq_first_active_entity()
1309 entry = rb_entry(node->rb_left, in bfq_first_active_entity()
1311 if (!bfq_gt(entry->min_start, vtime)) { in bfq_first_active_entity()
1312 node = node->rb_left; in bfq_first_active_entity()
1318 node = node->rb_right; in bfq_first_active_entity()
1325 * __bfq_lookup_next_entity - return the first eligible entity in @st.
1326 * @st: the service tree.
1327 * @in_service: whether or not there is an in-service entity for the sched_data
1328 * this active tree belongs to.
1330 * If there is no in-service entity for the sched_data st belongs to,
1331 * then return the entity that will be set in service if:
1332 * 1) the parent entity this st belongs to is set in service;
1337 * In this first case, update the virtual time in @st too (see the
1340 * In contrast, if there is an in-service entity, then return the
1341 * entity that would be set in service if not only the above
1343 * in-service entity, on expiration,
1354 if (RB_EMPTY_ROOT(&st->active)) in __bfq_lookup_next_entity()
1364 * If there is no in-service entity for the sched_data this in __bfq_lookup_next_entity()
1365 * active tree belongs to, then push the system virtual time in __bfq_lookup_next_entity()
1367 * eligible. If, instead, there is an in-service entity, then in __bfq_lookup_next_entity()
1369 * eligible entity, namely the in-service one (even if the in __bfq_lookup_next_entity()
1370 * entity is not on st, because it was extracted when set in in __bfq_lookup_next_entity()
1382 * bfq_lookup_next_entity - return the first eligible entity in @sd.
1384 * @expiration: true if we are on the expiration path of the in-service queue
1386 * This function is invoked when there has been a change in the trees
1393 struct bfq_service_tree *st = sd->service_tree; in bfq_lookup_next_entity()
1394 struct bfq_service_tree *idle_class_st = st + (BFQ_IOPRIO_CLASSES - 1); in bfq_lookup_next_entity()
1401 * in idle class). This should also mitigate in bfq_lookup_next_entity()
1402 * priority-inversion problems in case a low priority task is in bfq_lookup_next_entity()
1405 if (time_is_before_jiffies(sd->bfq_class_idle_last_service + in bfq_lookup_next_entity()
1407 if (!RB_EMPTY_ROOT(&idle_class_st->active)) in bfq_lookup_next_entity()
1408 class_idx = BFQ_IOPRIO_CLASSES - 1; in bfq_lookup_next_entity()
1410 sd->bfq_class_idle_last_service = jiffies; in bfq_lookup_next_entity()
1414 * Find the next entity to serve for the highest-priority in bfq_lookup_next_entity()
1421 * of the in-service queue. In this case, even if in bfq_lookup_next_entity()
1422 * sd->in_service_entity is not NULL, in bfq_lookup_next_entity()
1423 * sd->in_service_entity at this point is actually not in bfq_lookup_next_entity()
1424 * in service any more, and, if needed, has already in bfq_lookup_next_entity()
1426 * tree. The reason why sd->in_service_entity is still in bfq_lookup_next_entity()
1428 * sd->in_service_entity is reset as a last step in the in bfq_lookup_next_entity()
1431 * sd->in_service_entity. in bfq_lookup_next_entity()
1434 sd->in_service_entity && in bfq_lookup_next_entity()
1446 struct bfq_sched_data *sd = &bfqd->root_group->sched_data; in next_queue_may_preempt()
1448 return sd->next_in_service != sd->in_service_entity; in next_queue_may_preempt()
1465 * serve. Set in service all the entities visited along the in bfq_get_next_queue()
1468 sd = &bfqd->root_group->sched_data; in bfq_get_next_queue()
1469 for (; sd ; sd = entity->my_sched_data) { in bfq_get_next_queue()
1471 * WARNING. We are about to set the in-service entity in bfq_get_next_queue()
1472 * to sd->next_in_service, i.e., to the (cached) value in bfq_get_next_queue()
1475 * service order in sd changed as a consequence of the in bfq_get_next_queue()
1476 * activation or deactivation of an entity. In this in bfq_get_next_queue()
1478 * in this very moment, it may, although with low in bfq_get_next_queue()
1480 * pointed to by sd->next_in_service. This rare event in bfq_get_next_queue()
1481 * happens in case there was no CLASS_IDLE entity to in bfq_get_next_queue()
1487 * such entity in CLASS_IDLE is postponed until the in bfq_get_next_queue()
1488 * service of the sd->next_in_service entity in bfq_get_next_queue()
1489 * finishes. In fact, when the latter is expired, in bfq_get_next_queue()
1491 * exactly to update sd->next_in_service. in bfq_get_next_queue()
1495 entity = sd->next_in_service; in bfq_get_next_queue()
1496 sd->in_service_entity = entity; in bfq_get_next_queue()
1501 * tree, so as to make sure that it won't be in bfq_get_next_queue()
1513 * extracted in one of the next iterations of this in bfq_get_next_queue()
1514 * loop. Such an event could cause a change in in bfq_get_next_queue()
1521 * the correct next-to-serve candidate entity for each in bfq_get_next_queue()
1523 * in service. In fact, only after we know which is in bfq_get_next_queue()
1524 * the next-to-serve leaf entity, we can discover in bfq_get_next_queue()
1526 * becomes the next-to-serve, and so on. in bfq_get_next_queue()
1533 * We can finally update all next-to-serve entities along the in bfq_get_next_queue()
1534 * path from the leaf entity just set in service to the root. in bfq_get_next_queue()
1537 struct bfq_sched_data *sd = entity->sched_data; in bfq_get_next_queue()
1546 /* returns true if the in-service queue gets freed */
1549 struct bfq_queue *in_serv_bfqq = bfqd->in_service_queue; in __bfq_bfqd_reset_in_service()
1550 struct bfq_entity *in_serv_entity = &in_serv_bfqq->entity; in __bfq_bfqd_reset_in_service()
1554 hrtimer_try_to_cancel(&bfqd->idle_slice_timer); in __bfq_bfqd_reset_in_service()
1555 bfqd->in_service_queue = NULL; in __bfq_bfqd_reset_in_service()
1558 * When this function is called, all in-service entities have in __bfq_bfqd_reset_in_service()
1564 entity->sched_data->in_service_entity = NULL; in __bfq_bfqd_reset_in_service()
1567 * in_serv_entity is no longer in service, so, if it is in no in __bfq_bfqd_reset_in_service()
1568 * service tree either, then release the service reference to in __bfq_bfqd_reset_in_service()
1571 if (!in_serv_entity->on_st_or_in_serv) { in __bfq_bfqd_reset_in_service()
1578 int ref = in_serv_bfqq->ref; in __bfq_bfqd_reset_in_service()
1590 struct bfq_entity *entity = &bfqq->entity; in bfq_deactivate_bfqq()
1597 struct bfq_entity *entity = &bfqq->entity; in bfq_activate_bfqq()
1607 struct bfq_entity *entity = &bfqq->entity; in bfq_requeue_bfqq()
1610 bfqq == bfqd->in_service_queue, expiration); in bfq_requeue_bfqq()
1616 struct bfq_entity *entity = &bfqq->entity; in bfq_add_bfqq_in_groups_with_pending_reqs()
1618 if (!entity->in_groups_with_pending_reqs) { in bfq_add_bfqq_in_groups_with_pending_reqs()
1619 entity->in_groups_with_pending_reqs = true; in bfq_add_bfqq_in_groups_with_pending_reqs()
1620 if (!(bfqq_group(bfqq)->num_queues_with_pending_reqs++)) in bfq_add_bfqq_in_groups_with_pending_reqs()
1621 bfqq->bfqd->num_groups_with_pending_reqs++; in bfq_add_bfqq_in_groups_with_pending_reqs()
1629 struct bfq_entity *entity = &bfqq->entity; in bfq_del_bfqq_in_groups_with_pending_reqs()
1631 if (entity->in_groups_with_pending_reqs) { in bfq_del_bfqq_in_groups_with_pending_reqs()
1632 entity->in_groups_with_pending_reqs = false; in bfq_del_bfqq_in_groups_with_pending_reqs()
1633 if (!(--bfqq_group(bfqq)->num_queues_with_pending_reqs)) in bfq_del_bfqq_in_groups_with_pending_reqs()
1634 bfqq->bfqd->num_groups_with_pending_reqs--; in bfq_del_bfqq_in_groups_with_pending_reqs()
1641 * the service tree. As a special case, it can be invoked during an
1646 struct bfq_data *bfqd = bfqq->bfqd; in bfq_del_bfqq_busy()
1652 bfqd->busy_queues[bfqq->ioprio_class - 1]--; in bfq_del_bfqq_busy()
1654 if (bfqq->wr_coeff > 1) in bfq_del_bfqq_busy()
1655 bfqd->wr_busy_queues--; in bfq_del_bfqq_busy()
1661 if (!bfqq->dispatched) { in bfq_del_bfqq_busy()
1676 struct bfq_data *bfqd = bfqq->bfqd; in bfq_add_bfqq_busy()
1683 bfqd->busy_queues[bfqq->ioprio_class - 1]++; in bfq_add_bfqq_busy()
1685 if (!bfqq->dispatched) { in bfq_add_bfqq_busy()
1687 if (bfqq->wr_coeff == 1) in bfq_add_bfqq_busy()
1691 if (bfqq->wr_coeff > 1) in bfq_add_bfqq_busy()
1692 bfqd->wr_busy_queues++; in bfq_add_bfqq_busy()
1695 if (!hlist_unhashed(&bfqq->woken_list_node) && in bfq_add_bfqq_busy()
1696 &bfqq->woken_list_node != bfqq->waker_bfqq->woken_list.first) { in bfq_add_bfqq_busy()
1697 hlist_del_init(&bfqq->woken_list_node); in bfq_add_bfqq_busy()
1698 hlist_add_head(&bfqq->woken_list_node, in bfq_add_bfqq_busy()
1699 &bfqq->waker_bfqq->woken_list); in bfq_add_bfqq_busy()