From patchwork Mon Aug 3 09:55:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 51858 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id C2FD9229FD for ; Mon, 3 Aug 2015 09:56:10 +0000 (UTC) Received: by labjm1 with SMTP id jm1sf9438299lab.0 for ; Mon, 03 Aug 2015 02:56:09 -0700 (PDT) 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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=Mgk8gxeLA4bkWzXIM3BIpKBRTn6j1xKvkaG4GLqv8VA=; b=FLmIKzRF0bjxarUHuEqvhIPTtk1e3ppKrSHPtW7FhjqZi7JOEuW63Q/0NJ8hqzgbvO 8xrd23cdrpFkrekuvOLDMcgNv2Ge1aq/9BO12eF0miyY5Qk15OYLXBASdgOrGBgYdMvU bCdnMVFZtYJLP0Xan3/LE9ff2vdZE1WMhayel/ZPyU/fdrZT5eQRHPe5MZy/d0YWbxVi Zvo/u/qoE4oI5DawykQEHbslcCIpMiIv6CLdXJkOXiBDzJuzsb1gkj6CM+mhGzXgO9Gy HZjBIT3IGPOTdovT2bQ3KRbs3IFuryB156xteNeDve2Up+6TBwevWOJNI2JpohcY8dtq ZAtg== X-Gm-Message-State: ALoCoQlsPVBgYo6AkHJK+knUltjocD0RSEdNeCMc6rqWNRvzbA8KDZ5hOUWervm8TswL1B1fjLX7 X-Received: by 10.152.9.99 with SMTP id y3mr5337333laa.10.1438595769754; Mon, 03 Aug 2015 02:56:09 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.99 with SMTP id p3ls481048laj.57.gmail; Mon, 03 Aug 2015 02:56:09 -0700 (PDT) X-Received: by 10.152.10.237 with SMTP id l13mr6188226lab.97.1438595769506; Mon, 03 Aug 2015 02:56:09 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id f1si11530905lab.6.2015.08.03.02.56.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Aug 2015 02:56:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbbpo9 with SMTP id po9so958847lbb.2 for ; Mon, 03 Aug 2015 02:56:09 -0700 (PDT) X-Received: by 10.152.18.162 with SMTP id x2mr16003628lad.73.1438595769395; Mon, 03 Aug 2015 02:56:09 -0700 (PDT) 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.112.7.198 with SMTP id l6csp1771517lba; Mon, 3 Aug 2015 02:56:08 -0700 (PDT) X-Received: by 10.68.219.73 with SMTP id pm9mr22126975pbc.84.1438595768050; Mon, 03 Aug 2015 02:56:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si393565pas.122.2015.08.03.02.56.06; Mon, 03 Aug 2015 02:56:08 -0700 (PDT) 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 S1752715AbbHCJ4E (ORCPT + 28 others); Mon, 3 Aug 2015 05:56:04 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:33353 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751982AbbHCJ4C (ORCPT ); Mon, 3 Aug 2015 05:56:02 -0400 Received: by wicmv11 with SMTP id mv11so128415164wic.0 for ; Mon, 03 Aug 2015 02:56:00 -0700 (PDT) X-Received: by 10.180.84.230 with SMTP id c6mr32304925wiz.32.1438595759978; Mon, 03 Aug 2015 02:55:59 -0700 (PDT) Received: from lmenx30s.lme.st.com (LPuteaux-656-1-48-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by smtp.gmail.com with ESMTPSA id ec19sm12677605wic.0.2015.08.03.02.55.57 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Aug 2015 02:55:58 -0700 (PDT) From: Vincent Guittot To: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org, preeti@linux.vnet.ibm.com, jason.low2@hp.com Cc: linaro-kernel@lists.linaro.org, Vincent Guittot Subject: [PATCH v2] sched: fix nohz.next_balance update Date: Mon, 3 Aug 2015 11:55:50 +0200 Message-Id: <1438595750-20455-1-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.9.1 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: vincent.guittot@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) 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: , Since commit d4573c3e1c99 ("sched: Improve load balancing in the presence of idle CPUs"), the ILB CPU starts with the idle load balancing of other idle CPUs and finishes with itself in order to speed up the spread of tasks in all idle CPUs. The this_rq->next_balance is still used in nohz_idle_balance as an intermediate step to gather the shortest next balance before updating nohz.next_balance. But the former has not been updated yet and is likely to be set with the current jiffies. As a result, the nohz.next_balance will be set with current jiffies instead of the real next balance date. This generates spurious kicks of nohz ilde balance. nohz_idle_balance must set the nohz.next_balance without taking into account this_rq->next_balance which is not updated yet. Then, this_rq will update nohz.next_update with its next_balance once updated and if necessary. Signed-off-by: Vincent Guittot --- change since v1: - add #ifdef CONFIG_NO_HZ_COMMON for accessing nohz structure - fix some typos kernel/sched/fair.c | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 587a2f6..581378a 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7779,8 +7779,23 @@ static void rebalance_domains(struct rq *rq, enum cpu_idle_type idle) * When the cpu is attached to null domain for ex, it will not be * updated. */ - if (likely(update_next_balance)) + if (likely(update_next_balance)) { rq->next_balance = next_balance; + +#ifdef CONFIG_NO_HZ_COMMON + /* + * If this cpu has been elected to perform the nohz idle + * balance. Other idle cpus have already rebalanced with + * nohz_idle_balance and the nohz.next_balance has been + * updated accordingly. This cpu is now running the idle load + * balance for itself and we need to update the + * nohz.next_balance accordingly. + */ + if ((idle == CPU_IDLE) && + time_after(nohz.next_balance, rq->next_balance)) + nohz.next_balance = rq->next_balance; +#endif + } } #ifdef CONFIG_NO_HZ_COMMON @@ -7793,6 +7808,9 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) int this_cpu = this_rq->cpu; struct rq *rq; int balance_cpu; + /* Earliest time when we have to do rebalance again */ + unsigned long next_balance = jiffies + 60*HZ; + int update_next_balance = 0; if (idle != CPU_IDLE || !test_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu))) @@ -7824,10 +7842,19 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) rebalance_domains(rq, CPU_IDLE); } - if (time_after(this_rq->next_balance, rq->next_balance)) - this_rq->next_balance = rq->next_balance; + if (time_after(next_balance, rq->next_balance)) { + next_balance = rq->next_balance; + update_next_balance = 1; + } } - nohz.next_balance = this_rq->next_balance; + + /* + * next_balance will be updated only when there is a need. + * When the cpu is attached to null domain for ex, it will not be + * updated. + */ + if (likely(update_next_balance)) + nohz.next_balance = next_balance; end: clear_bit(NOHZ_BALANCE_KICK, nohz_flags(this_cpu)); }