From: vincent.guittot@linaro.org (Vincent Guittot)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC 4/6] sched: secure access to other CPU statistics
Date: Sun, 7 Oct 2012 09:43:56 +0200 [thread overview]
Message-ID: <1349595838-31274-5-git-send-email-vincent.guittot@linaro.org> (raw)
In-Reply-To: <1349595838-31274-1-git-send-email-vincent.guittot@linaro.org>
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>
---
kernel/sched/fair.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 8c9d3ed..6df53b5 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3133,13 +3133,28 @@ static int select_idle_sibling(struct task_struct *p, int target)
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)
--
1.7.9.5
next prev parent reply other threads:[~2012-10-07 7:43 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-07 7:43 [RFC 0/6] sched: packing small tasks Vincent Guittot
2012-10-07 7:43 ` [RFC 1/6] Revert "sched: introduce temporary FAIR_GROUP_SCHED dependency for load-tracking" Vincent Guittot
2012-10-07 7:43 ` [RFC 2/6] sched: add a new SD SHARE_POWERLINE flag for sched_domain Vincent Guittot
2012-10-24 15:17 ` Santosh Shilimkar
2012-10-29 9:40 ` Vincent Guittot
2012-10-29 9:50 ` Vincent Guittot
2012-11-02 10:27 ` Santosh Shilimkar
2012-10-07 7:43 ` [RFC 3/6] sched: pack small tasks Vincent Guittot
2012-10-24 15:20 ` Santosh Shilimkar
2012-10-29 13:12 ` Vincent Guittot
2012-11-02 10:53 ` Santosh Shilimkar
2012-11-09 16:46 ` Morten Rasmussen
2012-11-12 13:13 ` Vincent Guittot
2012-11-12 9:30 ` Vincent Guittot
2012-11-09 17:13 ` Morten Rasmussen
2012-11-12 13:51 ` Vincent Guittot
2012-11-20 14:28 ` Morten Rasmussen
2012-11-20 16:59 ` Vincent Guittot
2012-10-07 7:43 ` Vincent Guittot [this message]
2012-10-24 15:21 ` [RFC 4/6] sched: secure access to other CPU statistics Santosh Shilimkar
2012-10-29 13:18 ` Vincent Guittot
2012-10-07 7:43 ` [RFC 5/6] sched: pack the idle load balance Vincent Guittot
2012-10-24 15:21 ` Santosh Shilimkar
2012-10-29 13:27 ` Vincent Guittot
2012-11-02 10:59 ` Santosh Shilimkar
2012-10-07 7:43 ` [RFC 6/6] ARM: sched: clear SD_SHARE_POWERLINE Vincent Guittot
2012-10-24 15:21 ` Santosh Shilimkar
2012-10-29 13:28 ` Vincent Guittot
2012-11-02 11:00 ` Santosh Shilimkar
2012-11-12 8:23 ` Vincent Guittot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349595838-31274-5-git-send-email-vincent.guittot@linaro.org \
--to=vincent.guittot@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).