From patchwork Fri Jan 17 09:04:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 23304 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f69.google.com (mail-oa0-f69.google.com [209.85.219.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 14EF520540 for ; Fri, 17 Jan 2014 09:04:51 +0000 (UTC) Received: by mail-oa0-f69.google.com with SMTP id h16sf12350982oag.8 for ; Fri, 17 Jan 2014 01:04:51 -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=iMDN5cJYlu+kddM8yBeIB952JGc72X4cXNzmMg8QVek=; b=TEVwJHRI8EX7lztvuyPJWiZOKZFtyFjXuaiT4uxG9s8NMWxFn/Ck22z9a5A7RIuAsX qY+KOL+0jpJTijQeZ7Z5jVXFT9IkU2DDHccGA9w2U4W63ACmR27XWrljhiaUtkzpQFhR VaSNuZ6Mp/1i9AHhiASAhWflUwsOwyf6BpeIXN4Lks/1DliDdmyHwqAoPhKN9bjy1UVX asAPpFkXINdBwhQ2VClsb7GhQMDzmGowVh2i3PqJP5LhOHcACv/6aYs/DC8SiPWg/r0/ MVx/cUvU+RueEifd1asKaQ1BEoYHwrlgVG+VudzIwCcX6E8mZuhhii/q+xSy+QwdEzgN k8NA== X-Gm-Message-State: ALoCoQnUKb60+lgOiqpwIQERmRosjrOL6UKmv9FzCsjLAn3KauEVuqbW7LdkIijTWR7Pcv7FFbHj X-Received: by 10.42.235.132 with SMTP id kg4mr260804icb.32.1389949491204; Fri, 17 Jan 2014 01:04:51 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.3.165 with SMTP id d5ls1110768qed.77.gmail; Fri, 17 Jan 2014 01:04:51 -0800 (PST) X-Received: by 10.52.166.6 with SMTP id zc6mr311339vdb.10.1389949491069; Fri, 17 Jan 2014 01:04:51 -0800 (PST) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id e9si4614610vct.34.2014.01.17.01.04.51 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 01:04:51 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hu8so1462610vcb.29 for ; Fri, 17 Jan 2014 01:04:50 -0800 (PST) X-Received: by 10.52.163.65 with SMTP id yg1mr311730vdb.14.1389949490918; Fri, 17 Jan 2014 01:04:50 -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.59.13.131 with SMTP id ey3csp4866ved; Fri, 17 Jan 2014 01:04:50 -0800 (PST) X-Received: by 10.67.14.231 with SMTP id fj7mr730237pad.115.1389949489887; Fri, 17 Jan 2014 01:04:49 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si4862305pbe.229.2014.01.17.01.04.49; Fri, 17 Jan 2014 01:04:49 -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 S1752218AbaAQJEd (ORCPT + 26 others); Fri, 17 Jan 2014 04:04:33 -0500 Received: from mail-we0-f174.google.com ([74.125.82.174]:39236 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751480AbaAQJEI (ORCPT ); Fri, 17 Jan 2014 04:04:08 -0500 Received: by mail-we0-f174.google.com with SMTP id x55so4222704wes.19 for ; Fri, 17 Jan 2014 01:04:07 -0800 (PST) X-Received: by 10.194.8.229 with SMTP id u5mr730165wja.80.1389949447463; Fri, 17 Jan 2014 01:04:07 -0800 (PST) Received: from localhost.localdomain (AToulouse-654-1-359-206.w90-60.abo.wanadoo.fr. [90.60.118.206]) by mx.google.com with ESMTPSA id ju6sm8671745wjc.1.2014.01.17.01.04.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 01:04:06 -0800 (PST) From: Daniel Lezcano To: peterz@infradead.org, mingo@kernel.org Cc: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, alex.shi@linaro.org Subject: [PATCH 2/4] sched: Fix race in idle_balance() Date: Fri, 17 Jan 2014 10:04:02 +0100 Message-Id: <1389949444-14821-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1389949444-14821-1-git-send-email-daniel.lezcano@linaro.org> References: <1389949444-14821-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.220.170 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. Signed-off-by: Daniel Lezcano --- kernel/sched/fair.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d601df3..502c51c 100644 --- 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