Skip to contentSkip to conversation

sched/fair: fix incorrect calculation of capacity in scale_rt_capacity

PATCH In review Chao Yu 2 participants 2 messages Sep 23, 2015 – Sep 30, 2015 Scheduler

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 sched/fair: fix incorrect calculation of capacity in scale_rt_capacity

div_u64 can only handle 32-bits divisor, if our divisor is with type of 64-bits, we should use div64_u64 instead, otherwise value of divisor will be cast to 32-bits, resulting in wrong calculation.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
index 9176f7c..ee268ef 100644
@@ -6086,7 +6086,7 @@ static unsigned long scale_rt_capacity(int cpu)
 
 	total = sched_avg_period() + delta;
 
-	used = div_u64(avg, total);
+	used = div64_u64(avg, total);
 
 	if (likely(used < SCHED_CAPACITY_SCALE))
 		return SCHED_CAPACITY_SCALE - used;
Signature · 1 line
2.5.2
maintainer
#1 lore raw
Quoted 14 lines · Chao Yu

div_u64 can only handle 32-bits divisor, if our divisor is with type of 64-bits, we should use div64_u64 instead, otherwise value of divisor will be cast to 32-bits, resulting in wrong calculation.

---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +0 -0
index 9176f7c..ee268ef 100644

kernel/sched/fair.c static unsigned long scale_rt_capacity(int cpu) · line 6089

Quoted 5 lines
kernel/sched/fair.c +1 -1
@@ -6086,7 +6086,7 @@ static unsigned long scale_rt_capacity(int cpu)
 
 	total = sched_avg_period() + delta;
 
-	used = div_u64(avg, total);
+	used = div64_u64(avg, total);

total here should not exceed 2*sched_avg_period() 'much', with the defaults this would end up being around 1e9.

So unless you prod at sysctl_sched_time_avg it should all work out fine with the 32bit divisor.

Have you seen problems here?