Skip to content

Commit

Permalink
sched: Make scale_rt_power() deal with backward clocks
Browse files Browse the repository at this point in the history
commit cadefd3 upstream.

Mike reported that, while unlikely, its entirely possible for
scale_rt_power() to see the time go backwards. This yields rather
'interesting' results.

So like all other sites that deal with clocks; make this one ignore
backward clock movement too.

Reported-by: Mike Galbraith <bitbucket@online.de>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20140227094035.GZ9987@twins.programming.kicks-ass.net
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
  • Loading branch information
Peter Zijlstra authored and Jiri Slaby committed Jun 27, 2014
1 parent dcc23f1 commit 5ff029e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion kernel/sched/fair.c
Original file line number Diff line number Diff line change
Expand Up @@ -4404,6 +4404,7 @@ static unsigned long scale_rt_power(int cpu)
{
struct rq *rq = cpu_rq(cpu);
u64 total, available, age_stamp, avg;
s64 delta;

/*
* Since we're reading these variables without serialization make sure
Expand All @@ -4412,7 +4413,11 @@ static unsigned long scale_rt_power(int cpu)
age_stamp = ACCESS_ONCE(rq->age_stamp);
avg = ACCESS_ONCE(rq->rt_avg);

total = sched_avg_period() + (rq_clock(rq) - age_stamp);
delta = rq_clock(rq) - age_stamp;
if (unlikely(delta < 0))
delta = 0;

total = sched_avg_period() + delta;

if (unlikely(total < avg)) {
/* Ensures that power won't end up being negative */
Expand Down

0 comments on commit 5ff029e

Please sign in to comment.