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: 1562121 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 9EC153FC1A for ; Sun, 7 Oct 2012 21:06:10 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TKy1T-00023T-EK; Sun, 07 Oct 2012 21:04:27 +0000 Received: from mail-wi0-f169.google.com ([209.85.212.169]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TKlXZ-0000dt-1W for linux-arm-kernel@lists.infradead.org; Sun, 07 Oct 2012 07:44:45 +0000 Received: by mail-wi0-f169.google.com with SMTP id hq4so2029273wib.0 for ; Sun, 07 Oct 2012 00:44:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=xBo+s1ddYM+5F5Im1uHcp6ZfQ56LNf1nUy8DKxZyiGM=; b=cDMPARyGVBZ0C18ugMN+c830gIffBCOsxOYk1DM388DmCOpXY6bsn+ILIrbr/dn/fN 7V6a4DJciZkI/sgeoRQocFUkJS7jtojcJUg73fZ2EeSf42iQ2QJv0oHUwjsKUT2Eg5Cx mw3fKryc0bYU05HvCG6c7THu+N5al08o7rFj+HealboJQWcHklY1ykPhWISuR6P4k+1u nGMKiK97zHd69xQ5Ga7d2KhgiD1jJbI3W8ZQUmQGcwFzRUxjcz1+RnzHVf8Jppn51E2C W6GcMuZceREilyRtAN87Xkyv6FGWdIJDqj7BDjnm8oZRYRxfDjr/Pssf05wplpJSxq3U 7XGA== 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 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: ALoCoQn9n8HEvK9wJrFgAMDEN+/H/AOYey9KjEMfRu3g6qhhZosu0pqCZd21ZV/CAVQJd/baFshX X-Bad-Reply: References and In-Reply-To but no 'Re:' in Subject. X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.169 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Mailman-Approved-At: Sun, 07 Oct 2012 17:03:37 -0400 Cc: Vincent Guittot X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 --- 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)