From patchwork Fri Mar 22 12:25:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 2319381 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 B09F8400E6 for ; Fri, 22 Mar 2013 12:33:54 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UJ17m-0004T9-TZ; Fri, 22 Mar 2013 12:31:10 +0000 Received: from mail-wg0-f52.google.com ([74.125.82.52]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UJ16O-00045s-34 for linux-arm-kernel@lists.infradead.org; Fri, 22 Mar 2013 12:29:55 +0000 Received: by mail-wg0-f52.google.com with SMTP id 15so3114603wgd.19 for ; Fri, 22 Mar 2013 05:29:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=rekNo34cpZzqLqBpcZ4kG9ProHfTc9xG3EUU3kli3BA=; b=nbmZiWBJE8dD71O5zcPdRZ2QSlEc/FbtRpNGfJfmFWCPwo63v7R1qjVK3i2aAhfi0E cnptGdlifa/fVwG0+tL/sxSa8DnjRjpPqEVthbMVMIu/R2UCJgNsxB1s9HYrpQZtCVFE V7fQUvi+kCpclcJ/EICBD0mh4unDNDVd38URns1EaL1fn2KT24I/TsISzoHCLQxZPJaW 9DrZNh930eY33p4sr+RE62OpVy6Gdaou6YnWXcsKVcxMRhGFFcMG6MbS9tzm60O7tjQw yYCyPctDYeYjRgcyYfIjo70KTcqnDJXogZcGbz6VZdwJqNti+NjpygLShW9n8orNYr7F 2gBQ== X-Received: by 10.180.75.177 with SMTP id d17mr2714101wiw.16.1363955382062; Fri, 22 Mar 2013 05:29:42 -0700 (PDT) Received: from localhost.localdomain (LPuteaux-156-14-44-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by mx.google.com with ESMTPS id f1sm3237642wib.0.2013.03.22.05.29.39 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Mar 2013 05:29:40 -0700 (PDT) From: Vincent Guittot To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, peterz@infradead.org, mingo@kernel.org, linux@arm.linux.org.uk, pjt@google.com, santosh.shilimkar@ti.com, morten.rasmussen@arm.com, chander.kashyap@linaro.org, cmetcalf@tilera.com, tony.luck@intel.com Subject: [RFC PATCH v3 4/6] sched: secure access to other CPU statistics Date: Fri, 22 Mar 2013 13:25:53 +0100 Message-Id: <1363955155-18382-5-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1363955155-18382-1-git-send-email-vincent.guittot@linaro.org> References: <1363955155-18382-1-git-send-email-vincent.guittot@linaro.org> X-Gm-Message-State: ALoCoQnzH9jMWvRwIRAVfP9rK3wj6v0u1LxgCvgK1ZprVG78NyR4uNYf9PmXAy4qnpJv8akVqcMb X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130322_082944_850054_C2CC36E3 X-CRM114-Status: GOOD ( 11.57 ) 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 [74.125.82.52 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: len.brown@intel.com, alex.shi@intel.com, Vincent Guittot , corbet@lwn.net, amit.kucheria@linaro.org, preeti@linux.vnet.ibm.com, tglx@linutronix.de, paulmck@linux.vnet.ibm.com, arjan@linux.intel.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org If a CPU accesses the runnable_avg_sum and runnable_avg_period fields of its buddy CPU while the latter updates it, it can get the new version of a field and the old version of the other one. This can generate erroneous decisions. We don't want to use a lock mechanism for ensuring the coherency because of the overhead in this critical path. The previous attempt can't ensure coherency of both fields for 100% of the platform and use case as it will depend of the toolchain and the platform architecture. The runnable_avg_period of a runqueue tends to the max value in less than 345ms after plugging a CPU, which implies that we could use the max value instead of reading runnable_avg_period after 345ms. During the starting phase, we must ensure a minimum of coherency between the fields. A simple rule is runnable_avg_sum <= runnable_avg_period. Signed-off-by: Vincent Guittot Reviewed-by: Morten Rasmussen --- kernel/sched/fair.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 021c7b7..b636199 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3364,13 +3364,16 @@ done: static bool is_buddy_busy(int cpu) { struct rq *rq = cpu_rq(cpu); + u32 sum = rq->avg.runnable_avg_sum; + u32 period = rq->avg.runnable_avg_period; + + sum = min(sum, period); /* * A busy buddy is a CPU with a high load or a small load with a lot of * running tasks. */ - return (rq->avg.runnable_avg_sum > - (rq->avg.runnable_avg_period / (rq->nr_running + 2))); + return (sum > (period / (rq->nr_running + 2))); } static bool is_light_task(struct task_struct *p)