From patchwork Thu Feb 6 23:10:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 24269 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0BB3C20445 for ; Thu, 6 Feb 2014 23:11:31 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id c14sf6345805vea.7 for ; Thu, 06 Feb 2014 15:11:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=FlzZYG7Aq6KKUU9jsqLFgR7e/V0ffiG+icYeQGbhy74=; b=dR2nkX3n1u6/3F5WFgF6GK0Gf8IFkwoUbu/SNyY6q/GYVhnvENAV9IUZbLZVHFShbX IoYN4WHPa2tnhfgoC7r+DCLguzynLNsl13BRczjxtkxUgI4qel3oRdjR9bJGm0GSd5iO cO7/CTSyGsYfph5JFLiXMCmjz8C1Odwmn5oydxsx8I1JEo0G8CR9PimJsX2KlXBJrM9U dnzE2QPvb2+3yr+PFnvvxTNq/bFiT2THNKkOhuK789RBJfVrynyGCjyNoxnfM2w/HlTS AhdIoZPHkyptxSenPdmDCDRZOfsB3HOR7f4dRL9OW6iifigEOVNh5Q/szW2r3OCnmanB +zaQ== X-Gm-Message-State: ALoCoQnh6MVlMo89irUhmf2+mJ2FqLLFPQFKBOzZNrno78kKJzfzuk57GUI73eCueYXbKu5ocRmc X-Received: by 10.58.155.36 with SMTP id vt4mr2843024veb.31.1391728291118; Thu, 06 Feb 2014 15:11:31 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.5 with SMTP id r5ls744162qga.22.gmail; Thu, 06 Feb 2014 15:11:31 -0800 (PST) X-Received: by 10.52.68.106 with SMTP id v10mr1015472vdt.59.1391728291036; Thu, 06 Feb 2014 15:11:31 -0800 (PST) Received: from mail-ve0-f180.google.com (mail-ve0-f180.google.com [209.85.128.180]) by mx.google.com with ESMTPS id we7si677930vcb.7.2014.02.06.15.11.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Feb 2014 15:11:31 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.180; Received: by mail-ve0-f180.google.com with SMTP id db12so2070195veb.25 for ; Thu, 06 Feb 2014 15:11:31 -0800 (PST) X-Received: by 10.52.107.35 with SMTP id gz3mr6451216vdb.8.1391728290899; Thu, 06 Feb 2014 15:11:30 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp52596vcz; Thu, 6 Feb 2014 15:11:30 -0800 (PST) X-Received: by 10.66.25.101 with SMTP id b5mr3643286pag.101.1391728289193; Thu, 06 Feb 2014 15:11:29 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si2676701pav.74.2014.02.06.15.11.28; Thu, 06 Feb 2014 15:11:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754816AbaBFXLO (ORCPT + 27 others); Thu, 6 Feb 2014 18:11:14 -0500 Received: from mail-wi0-f179.google.com ([209.85.212.179]:45078 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754692AbaBFXKr (ORCPT ); Thu, 6 Feb 2014 18:10:47 -0500 Received: by mail-wi0-f179.google.com with SMTP id hn9so321632wib.12 for ; Thu, 06 Feb 2014 15:10:46 -0800 (PST) X-Received: by 10.180.206.172 with SMTP id lp12mr1415043wic.46.1391728246045; Thu, 06 Feb 2014 15:10:46 -0800 (PST) Received: from mai.arqiva.lan (host-231-197-68-109.arq1.ldn.uk.sharedband.net. [109.68.197.231]) by mx.google.com with ESMTPSA id fm3sm2675334wib.8.2014.02.06.15.10.44 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Feb 2014 15:10:45 -0800 (PST) From: Daniel Lezcano To: peterz@infradead.org, mingo@kernel.org Cc: alex.shi@linaro.org, linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org Subject: [PATCH V2 2/3] sched: Fix race in idle_balance() Date: Thu, 6 Feb 2014 23:10:36 +0000 Message-Id: <1391728237-4441-3-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1391728237-4441-1-git-send-email-daniel.lezcano@linaro.org> References: <1391728237-4441-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.180 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The scheduler main function 'schedule()' checks if there are no more tasks on the runqueue. Then it checks if a task should be pulled in the current runqueue in idle_balance() assuming it will go to idle otherwise. But the idle_balance() releases the rq->lock in order to lookup in the sched domains and takes the lock again right after. That opens a window where another cpu may put a task in our runqueue, so we won't go to idle but we have filled the idle_stamp, thinking we will. This patch closes the window by checking if the runqueue has been modified but without pulling a task after taking the lock again, so we won't go to idle right after in the __schedule() function. Cc: alex.shi@linaro.org Cc: peterz@infradead.org Cc: mingo@kernel.org Signed-off-by: Daniel Lezcano Signed-off-by: Peter Zijlstra --- kernel/sched/fair.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 428bc9d..5ebc681 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6589,6 +6589,13 @@ void idle_balance(struct rq *this_rq) raw_spin_lock(&this_rq->lock); + /* + * While browsing the domains, we released the rq lock. + * A task could have be enqueued in the meantime + */ + if (this_rq->nr_running && !pulled_task) + return; + if (pulled_task || time_after(jiffies, this_rq->next_balance)) { /* * We are going idle. next_balance may be set based on