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: 15537 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 5685323DEE for ; Fri, 22 Mar 2013 12:29:44 +0000 (UTC) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by fiordland.canonical.com (Postfix) with ESMTP id 152C6A18211 for ; Fri, 22 Mar 2013 12:29:43 +0000 (UTC) Received: by mail-vc0-f178.google.com with SMTP id hz11so3153276vcb.9 for ; Fri, 22 Mar 2013 05:29:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=rekNo34cpZzqLqBpcZ4kG9ProHfTc9xG3EUU3kli3BA=; b=pvbZfpYPhYOh4mbzOWwmMD7eU6uNBNTiemotPrMftx/OfOkCy/Afipk28RXl+BZF4R Bl6E0BnrwnFinIrk/jgEHboPm/InlrFXrvwPnymE6mjP91bgrSgV9szlGXj5+mUfwO2y hPiTrcLsgSx0G+WSsPr1rZDLj+NAXJch0z7NsTzK7ugiu67lCEenBkr65Gd0tzA26dxV a8/1mYFTjiefdYW9jNVZH+COq3qES+gZCkb5wRn+DRMdetg6W9nkhRNcsQV1XuLpzJ0s Jg6VToff1Cz9J01knsNwrIGm0QB5RtJSePCBQgHakL4xf+5h5Jkb474rnqKyDQ0SsZXk WjRw== X-Received: by 10.220.154.199 with SMTP id p7mr1894097vcw.46.1363955383591; Fri, 22 Mar 2013 05:29:43 -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.58.233.198 with SMTP id ty6csp102073vec; Fri, 22 Mar 2013 05:29:43 -0700 (PDT) X-Received: by 10.181.12.103 with SMTP id ep7mr11010823wid.12.1363955382561; Fri, 22 Mar 2013 05:29:42 -0700 (PDT) Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]) by mx.google.com with ESMTPS id be5si847632wjb.111.2013.03.22.05.29.42 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 22 Mar 2013 05:29:42 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c05::22b is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=2a00:1450:400c:c05::22b; Authentication-Results: mx.google.com; spf=neutral (google.com: 2a00:1450:400c:c05::22b 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-f171.google.com with SMTP id hn17so7726680wib.4 for ; Fri, 22 Mar 2013 05:29:42 -0700 (PDT) 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 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, corbet@lwn.net, Vincent Guittot 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: ALoCoQn7s0mytp9+FGKVWHHWy/cOh5F5p6yJ06UttAKYDMX2JRDegSvXwXo5OwAE5BYszrLrwGJA 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)