From patchwork Sun Oct 7 07:43:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 12037 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 506A823EFF for ; Sun, 7 Oct 2012 07:44:43 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id E340AA19442 for ; Sun, 7 Oct 2012 07:44:42 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so6872053iej.11 for ; Sun, 07 Oct 2012 00:44:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=xBo+s1ddYM+5F5Im1uHcp6ZfQ56LNf1nUy8DKxZyiGM=; b=VnyMC4WF3+8p2Ty9zkbNKL4tO8sYAVFd4qUdV6PFRohwPkd3cRjOQaAmy8b790ZGfC Tji5vnnRhZ74mtrIHUWQP/qumI9KzWxvfykVyPQQvy57lv7nhbZtlLvLaG/VbU9KoGbW a8LlVVpB0Z0931MbStZgc0Hmt4P+pOTTu2lskr8m1aGHgjsIlZTNK24Iw5iTDyer485A 6zrqS8qwftlsOkN2/Exe7hrKv13LMpJKK9SCKIKTFhaOUda58/V9S3etF8iIavyFkKPN KD6lzpCIhAYr/Ky4tfBgXqn4RBrAaN1yjDFCx5cvdd4N+QO2XnyjVC15eTguUgDZxucu C5KQ== Received: by 10.42.84.69 with SMTP id k5mr10506856icl.5.1349595882703; Sun, 07 Oct 2012 00:44:42 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp39953igc; Sun, 7 Oct 2012 00:44:41 -0700 (PDT) Received: by 10.216.204.138 with SMTP id h10mr7915356weo.168.1349595881327; Sun, 07 Oct 2012 00:44:41 -0700 (PDT) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by mx.google.com with ESMTPS id d6si15682254wec.106.2012.10.07.00.44.40 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 07 Oct 2012 00:44:41 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.212.178 is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=209.85.212.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.178 is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) smtp.mail=vincent.guittot@linaro.org Received: by mail-wi0-f178.google.com with SMTP id hr7so1865545wib.13 for ; Sun, 07 Oct 2012 00:44:40 -0700 (PDT) Received: by 10.180.8.41 with SMTP id o9mr13361223wia.3.1349595880774; Sun, 07 Oct 2012 00:44:40 -0700 (PDT) Received: from lmenx30s.lme.st.com (pas72-1-88-161-60-229.fbx.proxad.net. [88.161.60.229]) by mx.google.com with ESMTPS id j8sm12495245wiy.9.2012.10.07.00.44.39 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 07 Oct 2012 00:44:40 -0700 (PDT) From: Vincent Guittot To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-dev@lists.linaro.org, peterz@infradead.org, mingo@redhat.com, pjt@google.com, linux@arm.linux.org.uk Cc: Vincent Guittot Subject: [RFC 4/6] sched: secure access to other CPU statistics Date: Sun, 7 Oct 2012 09:43:56 +0200 Message-Id: <1349595838-31274-5-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1349595838-31274-1-git-send-email-vincent.guittot@linaro.org> References: <1349595838-31274-1-git-send-email-vincent.guittot@linaro.org> X-Gm-Message-State: ALoCoQm1cxP6E7kTI7nzh7oxOHo0be8lYNutv1MFAEuzTGLzvDlxFAnt4ISdPnJgG9SqlTcWiWzI 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 --- 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)