From patchwork Tue Jan 21 11:17:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 23432 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 87445203BE for ; Tue, 21 Jan 2014 11:30:58 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wp4sf13497795obc.1 for ; Tue, 21 Jan 2014 03:30:57 -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=RpA/QMb2dI8CbX7CM5KAh+XFVev04qOcMaTjnhYsMyw=; b=XhH9Kkdqc3Cqx1jtfmv4VXDT2qBknhyBJtyIKHXD47yxTUgmAnCFiliAgZXmwG6EkZ Dxuh1T0DFYtzwNwpwxJXWjje7aebt3SLspVQBR17QyY1rnMzj89fOGdAE31tI4wYE+yt nxgcGCNpqqYswqSx0azZH8BBid2J0jxMSCFyJ5nHebk+EAUNSiwbzCIbiIY/1AvYOiEa 9KuoeRAhbfX1xTZ9GKnTSH3rqz5zyGMZfYeAdWwxh6DArAQdNVC2UenD30tnlo+AGpIk hjihBf2ZdnxfbpP0k6mQ6A6BvitSM0Gk+Hjy4ZEfzBpxhYRaoT8kZd/l23T2U4W5YcwJ KlWA== X-Gm-Message-State: ALoCoQnrH8NL4a2B4EYZhel3QAr/Mslk0p8gHUcDKmoeuyxvIu9H/lY4soqF4MCYFEcnMskr5Eut X-Received: by 10.182.158.4 with SMTP id wq4mr8877826obb.18.1390303857675; Tue, 21 Jan 2014 03:30:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.131.202 with SMTP id oo10ls275553qeb.53.gmail; Tue, 21 Jan 2014 03:30:57 -0800 (PST) X-Received: by 10.58.227.38 with SMTP id rx6mr14505230vec.10.1390303857542; Tue, 21 Jan 2014 03:30:57 -0800 (PST) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id ru2si1849366vcb.29.2014.01.21.03.30.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 21 Jan 2014 03:30:57 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.169 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.169; Received: by mail-ve0-f169.google.com with SMTP id oy12so3089557veb.28 for ; Tue, 21 Jan 2014 03:30:57 -0800 (PST) X-Received: by 10.220.133.80 with SMTP id e16mr14147100vct.13.1390303857454; Tue, 21 Jan 2014 03:30:57 -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 u4csp111114vcz; Tue, 21 Jan 2014 03:30:56 -0800 (PST) X-Received: by 10.66.231.6 with SMTP id tc6mr24558913pac.68.1390303851858; Tue, 21 Jan 2014 03:30:51 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qx4si5064632pbc.165.2014.01.21.03.30.51; Tue, 21 Jan 2014 03:30:51 -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 S1754614AbaAUL37 (ORCPT + 27 others); Tue, 21 Jan 2014 06:29:59 -0500 Received: from merlin.infradead.org ([205.233.59.134]:51879 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754230AbaAUL30 (ORCPT ); Tue, 21 Jan 2014 06:29:26 -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 1W5ZWC-0002WS-Ab; Tue, 21 Jan 2014 11:29:20 +0000 Received: by twins (Postfix, from userid 0) id DFB68821E87B; Tue, 21 Jan 2014 12:29:03 +0100 (CET) Message-Id: <20140121112258.330689671@infradead.org> User-Agent: quilt/0.60-1 Date: Tue, 21 Jan 2014 12:17:56 +0100 From: Peter Zijlstra To: linux-kernel@vger.kernel.org Cc: mingo@kernel.org, daniel.lezcano@linaro.org, pjt@google.com, bsegall@google.com, Peter Zijlstra Subject: [PATCH 2/9] sched: Fix race in idle_balance() References: <20140121111754.580142558@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.128.169 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 Link: http://lkml.kernel.org/r/1389949444-14821-2-git-send-email-daniel.lezcano@linaro.org --- 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