From patchwork Tue Jan 28 17:16:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 23806 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f70.google.com (mail-pb0-f70.google.com [209.85.160.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7FF3B202B2 for ; Tue, 28 Jan 2014 17:34:22 +0000 (UTC) Received: by mail-pb0-f70.google.com with SMTP id rq2sf1369331pbb.9 for ; Tue, 28 Jan 2014 09:34:21 -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:message-id:user-agent :date:from:to:cc:subject:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe :content-disposition; bh=csIZMQdgq96vc1y/A/bjzfE4gcl09UZADx55LdHkOOs=; b=eAkqA04OoL5QZNBcj/U8GKh4HQfU6tmhmjEuyTAydagIbVEkkZmNx1Y53pAvA/c/nX ibM8mUjxbTcYYwkTAH5imwH3+bAQX+uMJ+fWtG5+Ip971AyHvoJW/BlJH3pi4tW+OmLZ LHBeAp+O4XCZG/HJvgMIXgTIds8xFKwU/9qcW4PNKI7iDt8+o93kaWa0ui6NuzzfQiYr 28rKUeql0g8WLDLnFJpP95oCPI77NQ+4TlOlzN8XY19XeVz6FCKpcONHOqc1URfB1tgq 33q6iaBqzF5kGWyQ3tcc6qMntn2fJDZvkF/88JUueGPR8sXHIiZ5n+Ry5r44gOg9KIeq lZ9g== X-Gm-Message-State: ALoCoQm5T88tjtFwERpoM8xxPgkpR5Gt3KSDA4T8S5657vPXiTNQERDuUb6DyM14TTTWvodqUvaA X-Received: by 10.68.133.164 with SMTP id pd4mr980078pbb.1.1390930461750; Tue, 28 Jan 2014 09:34:21 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.32.116 with SMTP id g107ls2206788qgg.49.gmail; Tue, 28 Jan 2014 09:34:21 -0800 (PST) X-Received: by 10.220.133.80 with SMTP id e16mr1966606vct.13.1390930461640; Tue, 28 Jan 2014 09:34:21 -0800 (PST) Received: from mail-vb0-f42.google.com (mail-vb0-f42.google.com [209.85.212.42]) by mx.google.com with ESMTPS id yt16si6562538vcb.117.2014.01.28.09.34.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Jan 2014 09:34:21 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.42; Received: by mail-vb0-f42.google.com with SMTP id i3so442531vbh.15 for ; Tue, 28 Jan 2014 09:34:21 -0800 (PST) X-Received: by 10.58.119.161 with SMTP id kv1mr1955534veb.21.1390930461557; Tue, 28 Jan 2014 09:34:21 -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 u4csp48493vcz; Tue, 28 Jan 2014 09:34:20 -0800 (PST) X-Received: by 10.66.197.135 with SMTP id iu7mr2683449pac.149.1390930460102; Tue, 28 Jan 2014 09:34:20 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fl7si16156762pad.258.2014.01.28.09.34.19; Tue, 28 Jan 2014 09:34:19 -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 S1755439AbaA1Rdw (ORCPT + 27 others); Tue, 28 Jan 2014 12:33:52 -0500 Received: from merlin.infradead.org ([205.233.59.134]:60571 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755356AbaA1Rds (ORCPT ); Tue, 28 Jan 2014 12:33:48 -0500 Received: from dhcp-077-248-225-117.chello.nl ([77.248.225.117] helo=twins) by merlin.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1W8CXc-0002v9-KT; Tue, 28 Jan 2014 17:33:40 +0000 Received: by twins (Postfix, from userid 0) id 22C1382785D1; Tue, 28 Jan 2014 18:33:38 +0100 (CET) Message-Id: <20140128171947.942449330@infradead.org> User-Agent: quilt/0.60-1 Date: Tue, 28 Jan 2014 18:16:36 +0100 From: Peter Zijlstra To: linux-kernel@vger.kernel.org Cc: mingo@kernel.org, daniel.lezcano@linaro.org, pjt@google.com, bsegall@google.com, Steven Rostedt , Vincent Guittot , Peter Zijlstra Subject: [PATCH 2/9] sched: Fix race in idle_balance() References: <20140128171634.974847076@infradead.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: peterz@infradead.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.42 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: , Content-Disposition: inline; filename=daniel_lezcano-2_sched-fix_race_in_idle_balance.patch From: Daniel Lezcano 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(+) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6417,6 +6417,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