0

From what I have understood so far about the Linux CFS is that scheduling entities are indexed by their virtual runtime (vruntime) inside the RB-tree.

The scheduler regularly updates this vruntime by calling the update_curr function which basically increase the vruntime value of the current running entity.

What I don't understand is how does the scheduler keeps the RB-tree always well ordered. The update_curr function increases the value of vruntime but does not seem to check whether the entity should be moved back into the right of RB-tree. Which function performs this check?

Tyrann
  • 61
  • 7

2 Answers2

1

While Ahmed is right about update_curr, I was still confused about the fact the tree could be unbalanced between the moment vruntime is updated and the eventual call to resched_curr. As a matter of fact, it turns out that the task that is currently scheduled is not part of the tree.

It is removed from the tree in set_next_entity(cfs_rq_of(se), se); which is called when pick_next_task_fair is invoked. So the tree is always balanced and the only function performing the balancing are enqueue_entity and dequeue_entity

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Tyrann
  • 61
  • 7
0

update_curr doesn't just increase the value of vruntime it also calls account_cfs_rq_runtime which in turn eventually calls resched_curr which will fix the RB-tree (eventually)

Ahmed Masud
  • 21,655
  • 3
  • 33
  • 58