From patchwork Wed Jun 5 08:13:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 17539 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f200.google.com (mail-ye0-f200.google.com [209.85.213.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C3CEF20F5A for ; Wed, 5 Jun 2013 08:13:27 +0000 (UTC) Received: by mail-ye0-f200.google.com with SMTP id r9sf1248416yen.7 for ; Wed, 05 Jun 2013 01:13:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=CrGuUrw3tpDElJnl2HQp0aVuefhe9TabgD8LzBemG4E=; b=FCV7nqQtaq2MqGmJQwoWJuFQYeF0SAaZ56pMW9mdfNtCfJZ6MeXCYgTM/B8/5Ad2UD hbXtJVHSjgaog0tLgR9Xv7EMvgF7OntXkVrSHM5lY+7R+OiEKqmt0dBXtb0tiDZhk76e erMv5Q4EuwIX3nrwGoG6/i+M74L91v2bJnDg49LmQ58GcmzhnXB7Wf39fOf1lNS8angW lTr2L8Zu0uFBVMYj6DYpEUxK0wYThZrr6aN5LdYMFiYPnoYxlVzpGxIrP6a5gn6Lnq1q 73U31p73uZYmSo8INu6mVD7Z/jQHrVPGaVCUSjpQNnGE6dJ3paw/O2YiDkcyM1oknlGh ds0g== X-Received: by 10.224.215.68 with SMTP id hd4mr4329383qab.5.1370420007164; Wed, 05 Jun 2013 01:13:27 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.119.1 with SMTP id kq1ls661656qeb.26.gmail; Wed, 05 Jun 2013 01:13:27 -0700 (PDT) X-Received: by 10.52.20.77 with SMTP id l13mr17194304vde.21.1370420006969; Wed, 05 Jun 2013 01:13:26 -0700 (PDT) Received: from mail-ve0-x22f.google.com (mail-ve0-x22f.google.com [2607:f8b0:400c:c01::22f]) by mx.google.com with ESMTPS id f17si19638791vci.2.2013.06.05.01.13.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Jun 2013 01:13:26 -0700 (PDT) Received-SPF: neutral (google.com: 2607:f8b0:400c:c01::22f is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=2607:f8b0:400c:c01::22f; Received: by mail-ve0-f175.google.com with SMTP id da11so984477veb.34 for ; Wed, 05 Jun 2013 01:13:26 -0700 (PDT) X-Received: by 10.220.59.131 with SMTP id l3mr5540344vch.14.1370420006602; Wed, 05 Jun 2013 01:13:26 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.10.206 with SMTP id pb14csp7803vcb; Wed, 5 Jun 2013 01:13:25 -0700 (PDT) X-Received: by 10.180.188.141 with SMTP id ga13mr5429395wic.9.1370420005304; Wed, 05 Jun 2013 01:13:25 -0700 (PDT) Received: from mail-wg0-x229.google.com (mail-wg0-x229.google.com [2a00:1450:400c:c00::229]) by mx.google.com with ESMTPS id br2si1644518wib.31.2013.06.05.01.13.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Jun 2013 01:13:25 -0700 (PDT) Received-SPF: neutral (google.com: 2a00:1450:400c:c00::229 is neither permitted nor denied by best guess record for domain of vincent.guittot@linaro.org) client-ip=2a00:1450:400c:c00::229; Received: by mail-wg0-f41.google.com with SMTP id k13so4654435wgh.4 for ; Wed, 05 Jun 2013 01:13:24 -0700 (PDT) X-Received: by 10.180.99.232 with SMTP id et8mr5310290wib.17.1370420004798; Wed, 05 Jun 2013 01:13:24 -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 ESMTPSA id e5sm8620676wiy.5.2013.06.05.01.13.23 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Jun 2013 01:13:24 -0700 (PDT) From: Vincent Guittot To: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, peterz@infradead.org, mingo@kernel.org, fweisbec@gmail.com Cc: Vincent Guittot Subject: [PATCH v2] sched: fix clear NOHZ_BALANCE_KICK Date: Wed, 5 Jun 2013 10:13:11 +0200 Message-Id: <1370419991-13870-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQkTzQcdQxLJozPHioBv3KJsrtvrnxIMyg3uqmPQqdWeL4UypzN34xHgJjlBeB81y8xo8HAm X-Original-Sender: vincent.guittot@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 2607:f8b0:400c:c01::22f 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , I have faced a sequence where the Idle Load Balance was sometime not triggered for a while on my platform. CPU 0 and CPU 1 are running tasks and CPU 2 is idle CPU 1 kicks the Idle Load Balance CPU 1 selects CPU 2 as the new Idle Load Balancer CPU 2 sets NOHZ_BALANCE_KICK for CPU 2 CPU 2 sends a reschedule IPI to CPU 2 While CPU 3 wakes up, CPU 0 or CPU 1 migrates a waking up task A on CPU 2 CPU 2 finally wakes up, runs task A and discards the Idle Load Balance task A quickly goes back to sleep (before a tick occurs on CPU 2) CPU 2 goes back to idle with NOHZ_BALANCE_KICK set Whenever CPU 2 will be selected as the ILB, no reschedule IPI will be sent because NOHZ_BALANCE_KICK is already set and no Idle Load Balance will be performed. We must wait for the sched softirq to be raised on CPU 2 thanks to another part the kernel to come back to clear NOHZ_BALANCE_KICK. The proposed solution clears NOHZ_BALANCE_KICK in schedule_ipi if we can't raise the sched_softirq for the Idle Load Balance. Change since V1: - move the clear of NOHZ_BALANCE_KICK in got_nohz_idle_kick if the ILB can't run on this CPU (as suggested by Peter) Signed-off-by: Vincent Guittot --- kernel/sched/core.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 58453b8..919bee6 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -633,7 +633,19 @@ void wake_up_nohz_cpu(int cpu) static inline bool got_nohz_idle_kick(void) { int cpu = smp_processor_id(); - return idle_cpu(cpu) && test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu)); + + if (!test_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu))) + return false; + + if (idle_cpu(cpu) && !need_resched()) + return true; + + /* + * We can't run Idle Load Balance on this CPU for this time so we + * cancel it and clear NOHZ_BALANCE_KICK + */ + clear_bit(NOHZ_BALANCE_KICK, nohz_flags(cpu)); + return false; } #else /* CONFIG_NO_HZ_COMMON */ @@ -1393,8 +1405,9 @@ static void sched_ttwu_pending(void) void scheduler_ipi(void) { - if (llist_empty(&this_rq()->wake_list) && !got_nohz_idle_kick() - && !tick_nohz_full_cpu(smp_processor_id())) + if (llist_empty(&this_rq()->wake_list) + && !tick_nohz_full_cpu(smp_processor_id()) + && !got_nohz_idle_kick()) return; /* @@ -1417,7 +1430,7 @@ void scheduler_ipi(void) /* * Check if someone kicked us for doing the nohz idle load balance. */ - if (unlikely(got_nohz_idle_kick() && !need_resched())) { + if (unlikely(got_nohz_idle_kick())) { this_rq()->idle_balance = 1; raise_softirq_irqoff(SCHED_SOFTIRQ); }