Commit b3d99f4
Peter Zijlstra
sched/fair: Fix zero_vruntime tracking
It turns out that zero_vruntime tracking is broken when there is but a single
task running. Current update paths are through __{en,de}queue_entity(), and
when there is but a single task, pick_next_task() will always return that one
task, and put_prev_set_next_task() will end up in neither function.
This can cause entity_key() to grow indefinitely large and cause overflows,
leading to much pain and suffering.
Furtermore, doing update_zero_vruntime() from __{de,en}queue_entity(), which
are called from {set_next,put_prev}_entity() has problems because:
- set_next_entity() calls __dequeue_entity() before it does cfs_rq->curr = se.
This means the avg_vruntime() will see the removal but not current, missing
the entity for accounting.
- put_prev_entity() calls __enqueue_entity() before it does cfs_rq->curr =
NULL. This means the avg_vruntime() will see the addition *and* current,
leading to double accounting.
Both cases are incorrect/inconsistent.
Noting that avg_vruntime is already called on each {en,de}queue, remove the
explicit avg_vruntime() calls (which removes an extra 64bit division for each
{en,de}queue) and have avg_vruntime() update zero_vruntime itself.
Additionally, have the tick call avg_vruntime() -- discarding the result, but
for the side-effect of updating zero_vruntime.
While there, optimize avg_vruntime() by noting that the average of one value is
rather trivial to compute.
Test case:
# taskset -c -p 1 $$
# taskset -c 2 bash -c 'while :; do :; done&'
# cat /sys/kernel/debug/sched/debug | awk '/^cpu#/ {P=0} /^cpu#2,/ {P=1} {if (P) print $0}' | grep -e zero_vruntime -e "^>"
PRE:
.zero_vruntime : 31316.407903
>R bash 487 50787.345112 E 50789.145972 2.800000 50780.298364 16 120 0.000000 0.000000 0.000000 /
.zero_vruntime : 382548.253179
>R bash 487 427275.204288 E 427276.003584 2.800000 427268.157540 23 120 0.000000 0.000000 0.000000 /
POST:
.zero_vruntime : 17259.709467
>R bash 526 17259.709467 E 17262.509467 2.800000 16915.031624 9 120 0.000000 0.000000 0.000000 /
.zero_vruntime : 18702.723356
>R bash 526 18702.723356 E 18705.523356 2.800000 18358.045513 9 120 0.000000 0.000000 0.000000 /
Fixes: 79f3f9b ("sched/eevdf: Fix min_vruntime vs avg_vruntime")
Reported-by: K Prateek Nayak <kprateek.nayak@amd.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: Shubhang Kaushik <shubhang@os.amperecomputing.com>
Link: https://patch.msgid.link/20260219080624.438854780%40infradead.org1 parent 6de23f8 commit b3d99f4
1 file changed
Lines changed: 57 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
589 | 589 | | |
590 | 590 | | |
591 | 591 | | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
592 | 607 | | |
593 | 608 | | |
594 | 609 | | |
| |||
676 | 691 | | |
677 | 692 | | |
678 | 693 | | |
679 | | - | |
| 694 | + | |
680 | 695 | | |
681 | 696 | | |
682 | | - | |
| 697 | + | |
683 | 698 | | |
684 | 699 | | |
| 700 | + | |
685 | 701 | | |
686 | 702 | | |
687 | 703 | | |
688 | | - | |
| 704 | + | |
689 | 705 | | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
690 | 714 | | |
691 | 715 | | |
692 | 716 | | |
693 | 717 | | |
694 | | - | |
695 | | - | |
| 718 | + | |
| 719 | + | |
696 | 720 | | |
697 | | - | |
698 | | - | |
| 721 | + | |
| 722 | + | |
699 | 723 | | |
700 | | - | |
701 | | - | |
702 | | - | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
703 | 733 | | |
704 | | - | |
705 | 734 | | |
706 | | - | |
707 | | - | |
708 | | - | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
709 | 744 | | |
710 | 745 | | |
711 | | - | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
712 | 749 | | |
713 | 750 | | |
714 | 751 | | |
| |||
777 | 814 | | |
778 | 815 | | |
779 | 816 | | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | 817 | | |
791 | 818 | | |
792 | 819 | | |
| |||
856 | 883 | | |
857 | 884 | | |
858 | 885 | | |
859 | | - | |
860 | 886 | | |
861 | 887 | | |
862 | 888 | | |
| |||
868 | 894 | | |
869 | 895 | | |
870 | 896 | | |
871 | | - | |
872 | 897 | | |
873 | 898 | | |
874 | 899 | | |
| |||
5524 | 5549 | | |
5525 | 5550 | | |
5526 | 5551 | | |
| 5552 | + | |
| 5553 | + | |
| 5554 | + | |
| 5555 | + | |
| 5556 | + | |
5527 | 5557 | | |
5528 | 5558 | | |
5529 | 5559 | | |
| |||
0 commit comments