From patchwork Wed Dec 12 13:31:30 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 13508 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 CF36C23E2A for ; Wed, 12 Dec 2012 13:32:35 +0000 (UTC) Received: from mail-ia0-f180.google.com (mail-ia0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 784A6A199A3 for ; Wed, 12 Dec 2012 13:32:35 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id t4so848636iag.11 for ; Wed, 12 Dec 2012 05:32:35 -0800 (PST) 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=uV3W7NvS1g38Dv9PGnA9kxVHrdhFvUheINIlZ4culQI=; b=ZwLJp3acI8wTPvSfE/NQLyJO1vWZe5KVINqQaK6KvOqZGvW6uR9lSGRN1EihsJg7JM zg9N0EfvXPZ8Efqg+nv0ovLDTMryI/45gvMMyTa7gfG1dgcp3A3KTFM+s3kuJbtf4M56 P5oxQ3gpTNqcFvxT4eLBYDghkmNySUrQdxuI889/tM1a6b7L71Wm3FRj2flnIdr7UOaW apjKxDd7aV9+REwOIzZJnc1SRoIMQ82nGIhYFltpo+Lai/wtwT7159nSPQQjI1dr7R1a 7zvCTzDrfIIy4KnWeSNIYupLayVDPs/KKGpiEaFRF/mkXuwPeMhdRWzIYI8Pg/4KF2Zq MJOA== Received: by 10.43.49.199 with SMTP id vb7mr730512icb.6.1355319154925; Wed, 12 Dec 2012 05:32:34 -0800 (PST) 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.67.148 with SMTP id n20csp199597igt; Wed, 12 Dec 2012 05:32:34 -0800 (PST) Received: by 10.180.88.99 with SMTP id bf3mr1933059wib.22.1355319153808; Wed, 12 Dec 2012 05:32:33 -0800 (PST) Received: from mail-wi0-f170.google.com (mail-wi0-f170.google.com [209.85.212.170]) by mx.google.com with ESMTPS id s8si3802889wic.36.2012.12.12.05.32.33 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 12 Dec 2012 05:32:33 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.170 is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=209.85.212.170; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.170 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-f170.google.com with SMTP id hq7so3050208wib.1 for ; Wed, 12 Dec 2012 05:32:33 -0800 (PST) Received: by 10.194.118.229 with SMTP id kp5mr2005661wjb.2.1355319153340; Wed, 12 Dec 2012 05:32:33 -0800 (PST) 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 t17sm21269650wiv.6.2012.12.12.05.32.31 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 12 Dec 2012 05:32:32 -0800 (PST) From: Vincent Guittot To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-dev@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 Cc: alex.shi@intel.com, preeti@linux.vnet.ibm.com, paulmck@linux.vnet.ibm.com, tglx@linutronix.de, len.brown@intel.com, arjan@linux.intel.com, amit.kucheria@linaro.org, viresh.kumar@linaro.org, Vincent Guittot Subject: [RFC PATCH v2 4/6] sched: secure access to other CPU statistics Date: Wed, 12 Dec 2012 14:31:30 +0100 Message-Id: <1355319092-30980-5-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1355319092-30980-1-git-send-email-vincent.guittot@linaro.org> References: <1355319092-30980-1-git-send-email-vincent.guittot@linaro.org> X-Gm-Message-State: ALoCoQnLaIJXlKKjTvvNqdlRlFPUdAWRc1FZB+r5ya3w5CWLQEypkW668z+KEECLTSzBjv5xDAnY 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 --- 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 fc93d96..f1a4c24 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -5153,13 +5153,16 @@ static bool numa_allow_migration(struct task_struct *p, int prev_cpu, int new_cp 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->nr_running) > - rq->avg.runnable_avg_period); + return ((sum << rq->nr_running) > period); } static bool is_light_task(struct task_struct *p)