Skip to content

Commit 328fefa

Browse files
committed
Merge branch 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull scheduler fixes from Ingo Molnar: "Two fixes: a guest-cputime accounting fix, and a cgroup bandwidth quota precision fix" * 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: sched/vtime: Fix guest/system mis-accounting on task switch sched/fair: Scale bandwidth quota and period without losing quota/period ratio precision
2 parents 465a7e2 + 68e7a4d commit 328fefa

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

kernel/sched/cputime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ void vtime_account_system(struct task_struct *tsk)
740740

741741
write_seqcount_begin(&vtime->seqcount);
742742
/* We might have scheduled out from guest path */
743-
if (current->flags & PF_VCPU)
743+
if (tsk->flags & PF_VCPU)
744744
vtime_account_guest(tsk, vtime);
745745
else
746746
__vtime_account_system(tsk, vtime);
@@ -783,7 +783,7 @@ void vtime_guest_enter(struct task_struct *tsk)
783783
*/
784784
write_seqcount_begin(&vtime->seqcount);
785785
__vtime_account_system(tsk, vtime);
786-
current->flags |= PF_VCPU;
786+
tsk->flags |= PF_VCPU;
787787
write_seqcount_end(&vtime->seqcount);
788788
}
789789
EXPORT_SYMBOL_GPL(vtime_guest_enter);
@@ -794,7 +794,7 @@ void vtime_guest_exit(struct task_struct *tsk)
794794

795795
write_seqcount_begin(&vtime->seqcount);
796796
vtime_account_guest(tsk, vtime);
797-
current->flags &= ~PF_VCPU;
797+
tsk->flags &= ~PF_VCPU;
798798
write_seqcount_end(&vtime->seqcount);
799799
}
800800
EXPORT_SYMBOL_GPL(vtime_guest_exit);

kernel/sched/fair.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4926,20 +4926,28 @@ static enum hrtimer_restart sched_cfs_period_timer(struct hrtimer *timer)
49264926
if (++count > 3) {
49274927
u64 new, old = ktime_to_ns(cfs_b->period);
49284928

4929-
new = (old * 147) / 128; /* ~115% */
4930-
new = min(new, max_cfs_quota_period);
4931-
4932-
cfs_b->period = ns_to_ktime(new);
4933-
4934-
/* since max is 1s, this is limited to 1e9^2, which fits in u64 */
4935-
cfs_b->quota *= new;
4936-
cfs_b->quota = div64_u64(cfs_b->quota, old);
4937-
4938-
pr_warn_ratelimited(
4939-
"cfs_period_timer[cpu%d]: period too short, scaling up (new cfs_period_us %lld, cfs_quota_us = %lld)\n",
4940-
smp_processor_id(),
4941-
div_u64(new, NSEC_PER_USEC),
4942-
div_u64(cfs_b->quota, NSEC_PER_USEC));
4929+
/*
4930+
* Grow period by a factor of 2 to avoid losing precision.
4931+
* Precision loss in the quota/period ratio can cause __cfs_schedulable
4932+
* to fail.
4933+
*/
4934+
new = old * 2;
4935+
if (new < max_cfs_quota_period) {
4936+
cfs_b->period = ns_to_ktime(new);
4937+
cfs_b->quota *= 2;
4938+
4939+
pr_warn_ratelimited(
4940+
"cfs_period_timer[cpu%d]: period too short, scaling up (new cfs_period_us = %lld, cfs_quota_us = %lld)\n",
4941+
smp_processor_id(),
4942+
div_u64(new, NSEC_PER_USEC),
4943+
div_u64(cfs_b->quota, NSEC_PER_USEC));
4944+
} else {
4945+
pr_warn_ratelimited(
4946+
"cfs_period_timer[cpu%d]: period too short, but cannot scale up without losing precision (cfs_period_us = %lld, cfs_quota_us = %lld)\n",
4947+
smp_processor_id(),
4948+
div_u64(old, NSEC_PER_USEC),
4949+
div_u64(cfs_b->quota, NSEC_PER_USEC));
4950+
}
49434951

49444952
/* reset count so we don't come right back in here */
49454953
count = 0;

0 commit comments

Comments
 (0)