aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Guittot <vincent.guittot@linaro.org>2012-10-07 09:43:56 +0200
committerViresh Kumar <viresh.kumar@linaro.org>2012-11-14 09:20:43 +0530
commit2aa14d0379cc54bc0ec44adb7a2e0ad02ae293d0 (patch)
tree9625d83329894a09dac4db519fba949925d5c1fa
parent1def6d2091d38a09e9e7c8f46244f74fb9ce8b51 (diff)
sched: secure access to other CPU statistics
The atomic update of runnable_avg_sum and runnable_avg_period are ensured by their size and the toolchain. But we must ensure to not read an old value for one field and a newly updated value for the other field. As we don't want to lock other CPU while reading these fields, we read twice each fields and check that no change have occured in the middle. Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
-rw-r--r--kernel/sched/fair.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index d0f5f04baef..e4cd3fd9cca 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3155,13 +3155,28 @@ done:
static inline bool is_buddy_busy(int cpu)
{
struct rq *rq = cpu_rq(cpu);
+ volatile u32 *psum = &rq->avg.runnable_avg_sum;
+ volatile u32 *pperiod = &rq->avg.runnable_avg_period;
+ u32 sum, new_sum, period, new_period;
+ int timeout = 10;
+
+ while (timeout) {
+ sum = *psum;
+ period = *pperiod;
+ new_sum = *psum;
+ new_period = *pperiod;
+
+ if ((sum == new_sum) && (period == new_period))
+ break;
+
+ timeout--;
+ }
/*
* A busy buddy is a CPU with a high load or a small load with a lot of
* running tasks.
*/
- return ((rq->avg.usage_avg_sum << rq->nr_running) >
- rq->avg.runnable_avg_period);
+ return ((new_sum << rq->nr_running) > new_period);
}
static inline bool is_light_task(struct task_struct *p)