Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sched/fair: Rename cfs_rq::avg_vruntime to ::sum_w_vruntime, and helper functions

The ::avg_vruntime field is a misnomer: it says it's an
'average vruntime', but in reality it's the momentary sum
of the weighted vruntimes of all queued tasks, which is
at least a division away from being an average.

This is clear from comments about the math of fair scheduling:

* \Sum (v_i - v0) * w_i := cfs_rq->avg_vruntime

This confusion is increased by the cfs_avg_vruntime() function,
which does perform the division and returns a true average.

The sum of all weighted vruntimes should be named thusly,
so rename the field to ::sum_w_vruntime. (As arguably
::sum_weighted_vruntime would be a bit of a mouthful.)

Understanding the scheduler is hard enough already, without
extra layers of obfuscated naming. ;-)

Also rename related helper functions:

sum_vruntime_add() => sum_w_vruntime_add()
sum_vruntime_sub() => sum_w_vruntime_sub()
sum_vruntime_update() => sum_w_vruntime_update()

With the notable exception of cfs_avg_vruntime(), which
was named accurately.

Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://patch.msgid.link/20251201064647.1851919-7-mingo@kernel.org

+14 -14
+13 -13
kernel/sched/fair.c
··· 607 607 * Which we track using: 608 608 * 609 609 * v0 := cfs_rq->zero_vruntime 610 - * \Sum (v_i - v0) * w_i := cfs_rq->avg_vruntime 610 + * \Sum (v_i - v0) * w_i := cfs_rq->sum_w_vruntime 611 611 * \Sum w_i := cfs_rq->sum_weight 612 612 * 613 613 * Since zero_vruntime closely tracks the per-task service, these ··· 619 619 * As measured, the max (key * weight) value was ~44 bits for a kernel build. 620 620 */ 621 621 static void 622 - avg_vruntime_add(struct cfs_rq *cfs_rq, struct sched_entity *se) 622 + sum_w_vruntime_add(struct cfs_rq *cfs_rq, struct sched_entity *se) 623 623 { 624 624 unsigned long weight = scale_load_down(se->load.weight); 625 625 s64 key = entity_key(cfs_rq, se); 626 626 627 - cfs_rq->avg_vruntime += key * weight; 627 + cfs_rq->sum_w_vruntime += key * weight; 628 628 cfs_rq->sum_weight += weight; 629 629 } 630 630 631 631 static void 632 - avg_vruntime_sub(struct cfs_rq *cfs_rq, struct sched_entity *se) 632 + sum_w_vruntime_sub(struct cfs_rq *cfs_rq, struct sched_entity *se) 633 633 { 634 634 unsigned long weight = scale_load_down(se->load.weight); 635 635 s64 key = entity_key(cfs_rq, se); 636 636 637 - cfs_rq->avg_vruntime -= key * weight; 637 + cfs_rq->sum_w_vruntime -= key * weight; 638 638 cfs_rq->sum_weight -= weight; 639 639 } 640 640 641 641 static inline 642 - void avg_vruntime_update(struct cfs_rq *cfs_rq, s64 delta) 642 + void sum_w_vruntime_update(struct cfs_rq *cfs_rq, s64 delta) 643 643 { 644 644 /* 645 - * v' = v + d ==> avg_vruntime' = avg_runtime - d*sum_weight 645 + * v' = v + d ==> sum_w_vruntime' = sum_runtime - d*sum_weight 646 646 */ 647 - cfs_rq->avg_vruntime -= cfs_rq->sum_weight * delta; 647 + cfs_rq->sum_w_vruntime -= cfs_rq->sum_weight * delta; 648 648 } 649 649 650 650 /* ··· 654 654 u64 avg_vruntime(struct cfs_rq *cfs_rq) 655 655 { 656 656 struct sched_entity *curr = cfs_rq->curr; 657 - s64 avg = cfs_rq->avg_vruntime; 657 + s64 avg = cfs_rq->sum_w_vruntime; 658 658 long load = cfs_rq->sum_weight; 659 659 660 660 if (curr && curr->on_rq) { ··· 722 722 static int vruntime_eligible(struct cfs_rq *cfs_rq, u64 vruntime) 723 723 { 724 724 struct sched_entity *curr = cfs_rq->curr; 725 - s64 avg = cfs_rq->avg_vruntime; 725 + s64 avg = cfs_rq->sum_w_vruntime; 726 726 long load = cfs_rq->sum_weight; 727 727 728 728 if (curr && curr->on_rq) { ··· 745 745 u64 vruntime = avg_vruntime(cfs_rq); 746 746 s64 delta = (s64)(vruntime - cfs_rq->zero_vruntime); 747 747 748 - avg_vruntime_update(cfs_rq, delta); 748 + sum_w_vruntime_update(cfs_rq, delta); 749 749 750 750 cfs_rq->zero_vruntime = vruntime; 751 751 } ··· 819 819 */ 820 820 static void __enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se) 821 821 { 822 - avg_vruntime_add(cfs_rq, se); 822 + sum_w_vruntime_add(cfs_rq, se); 823 823 update_zero_vruntime(cfs_rq); 824 824 se->min_vruntime = se->vruntime; 825 825 se->min_slice = se->slice; ··· 831 831 { 832 832 rb_erase_augmented_cached(&se->run_node, &cfs_rq->tasks_timeline, 833 833 &min_vruntime_cb); 834 - avg_vruntime_sub(cfs_rq, se); 834 + sum_w_vruntime_sub(cfs_rq, se); 835 835 update_zero_vruntime(cfs_rq); 836 836 } 837 837
+1 -1
kernel/sched/sched.h
··· 678 678 unsigned int h_nr_runnable; /* SCHED_{NORMAL,BATCH,IDLE} */ 679 679 unsigned int h_nr_idle; /* SCHED_IDLE */ 680 680 681 - s64 avg_vruntime; 681 + s64 sum_w_vruntime; 682 682 u64 sum_weight; 683 683 684 684 u64 zero_vruntime;