Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2469846ybz; Sun, 3 May 2020 01:42:02 -0700 (PDT) X-Google-Smtp-Source: APiQypIXlB3SIFk8WkefMQnx8Qh+x37k/dOs/agBtDvbHeyy78acxY8PmF5qLl4UQyl5EbM50XbP X-Received: by 2002:a17:906:90c1:: with SMTP id v1mr9606192ejw.322.1588495322715; Sun, 03 May 2020 01:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588495322; cv=none; d=google.com; s=arc-20160816; b=Q2zw7reOiduj2552rh7VfCpOjvc1v7EmQxwaCZckEUuUNJSTwtdTFZSPRcxwug8BPR DTQeGOghz+9lIBhcr843iw8MTNn02+inv41YnQHTHGtqFTxAQYAeaHh4AlDRrueQqVBB UKyV6IA6jiLiRtIHPng7Z5Qcxqc3t5M9O/n+nEgr4HIqh0dBpiq259cUiIpVu9QFvSXB M0lRc5W6suTup4+fSH0jqFRGRE6/a5/1HWVo752etv7s0B2PZzYtc3OdzExi/K69Z9Z2 0T81pNfE8VpOhP0Ke2r4OSo8V4SOrsWQPd+DGdGWOmgm1ulDb0inXtp2XywJtLENRR7U 2DUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=xq7ysiUAMlkm14lElNH6IyCeagfNa1BwRcWSHMY71S4=; b=H+3s81c9LBZqiIvHssqjR9B6V5V/L72eQIt1DmOu6fSpUNWA3i4s1vNJ5EaAmnNMRn JtSy1/f9wUwg+EomamsSN0gZ31kjtriGE37iY4GezPDfMOGb3fn+akH73qaIyEsT8Ahl SCFCh9CDDaDzN3lwHjVFTJ/t5USXzAZWx+iB21cOkwjgrI6XnjeXRpidpycCzYVWGU79 EjPi/1TVXNBm2j8jn6y5j5ALj/BO0ea6qXAuLyeLIU04MIjhsUuPHAcAeKqZrrc232wG vF93gMTR5FR8CYpIo8/ZgetcHLXPkbs/g00V+rz1TSJLT2OPa0yppV94nKriJY22yK+Z LAWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WeUBmeun; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q24si4354828ejb.184.2020.05.03.01.41.27; Sun, 03 May 2020 01:42:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WeUBmeun; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727806AbgECIeN (ORCPT + 99 others); Sun, 3 May 2020 04:34:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726751AbgECIeN (ORCPT ); Sun, 3 May 2020 04:34:13 -0400 Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65F4CC061A0C for ; Sun, 3 May 2020 01:34:13 -0700 (PDT) Received: by mail-pl1-x643.google.com with SMTP id u22so5536578plq.12 for ; Sun, 03 May 2020 01:34:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=xq7ysiUAMlkm14lElNH6IyCeagfNa1BwRcWSHMY71S4=; b=WeUBmeunP+BaYBQxSQXOd3ZqZuEHFwx/eav9KYkB6G+cFG3yYWvzN9vlYFQAzLYNo8 cR6czhtUjgQ3opUhVVKLx1ZL8mOG443lxlYfeuiTyhoklpHQ2Zn0mDrfrvGxClJ4UUk4 q5pIwtyXKoU1mLbVgYh37z6V+LQmjbREiN8AztXlw8GCyzGg0GenaciXp9R7neU0XsF3 fHx/4v9clzIEry9iM5v06A8pH7QiCQkMb6K16ucVyHPPLaLbPEwCbnImzmY1+J13f55q 6xhnPZ4p5EgcGuWU+YtHnu7GXYXDmxH9YqKwF/QRorFKAoqefPIHG40VYNMnfJziiy8e JBSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=xq7ysiUAMlkm14lElNH6IyCeagfNa1BwRcWSHMY71S4=; b=q2UN7sWIx3ovWiIGHj8tB6is4CyFMpk0FHdZwuatVqbCNBp/V64cwy3wSpkVphFqBJ FZs1koOdZLEkEK3Ql6aqRHDnEwVNRkJ9q7V4WWojPzWFuiX+WKXTqtJTn1vE9Jcgu7m2 JjB0yQd31OUQVH2TVEeZFDlOE8xowEN8xCpi6Xc3+x8dtPXXvlGpccPihJEUGcPRv+KK cYjGXMdKqopKWyqB37weibalUCF4ydPQLenExjeW2izWIFSKms2EdOcCozqyekRRea9j QAN8h9Lsc1vQ+gcca7HiTKn1Djhe726axSQqgHYMr9yElk7btTCPJ6AJSdHZ6d4DAlGW JBpg== X-Gm-Message-State: AGi0Pubd/NUeBpBSeLd+WYaB5AUlyTfsTh5flyNJq1jOmDXIHe9z9rNP 8JS+ez7oGmWujVh2LNDOhN5ltrG7 X-Received: by 2002:a17:90a:2b8f:: with SMTP id u15mr10739930pjd.137.1588494852331; Sun, 03 May 2020 01:34:12 -0700 (PDT) Received: from iZj6chx1xj0e0buvshuecpZ ([47.75.1.235]) by smtp.gmail.com with ESMTPSA id p62sm6002043pfb.93.2020.05.03.01.34.09 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 03 May 2020 01:34:11 -0700 (PDT) Date: Sun, 3 May 2020 16:34:07 +0800 From: Peng Liu To: linux-kernel@vger.kernel.org Cc: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, valentin.schneider@arm.com, iwtbavbm@gmail.com Subject: [PATCH] sched/fair: Fix nohz.next_balance update Message-ID: <20200503083407.GA27766@iZj6chx1xj0e0buvshuecpZ> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org commit c5afb6a87f23 ("sched/fair: Fix nohz.next_balance update") During idle load balance, this_cpu(ilb) do load balance for the other idle CPUs, also gather the earliest (nohz.)next_balance. Since commit: 'b7031a02ec75 ("sched/fair: Add NOHZ_STATS_KICK")' We update nohz.next_balance like this: _nohz_idle_balance() { for_each_cpu(nohz.idle_cpus_mask) { rebalance_domains() { update nohz.next_balance <-- compare and update } } rebalance_domains(this_cpu) { update nohz.next_balance <-- compare and update } update nohz.next_balance <-- unconditionally update } For instance, nohz.idle_cpus_mask spans {cpu2,3,5,8}, and this_cpu is cpu5. After the above loop we could gather the earliest *next_balance* among {cpu2,3,8}, then rebalance_domains(this_cpu) update nohz.next_balance with this_rq->next_balance, but finally overwrite nohz.next_balance with the earliest *next_balance* among {cpu2,3,8}, we may end up with not getting the earliest next_balance. Since we can gather all the updated rq->next_balance, including this_cpu, in _nohz_idle_balance(), it's safe to remove the extra lines in rebalance_domains() which are originally intended for this_cpu. And finally the updating only happen in _nohz_idle_balance(). Signed-off-by: Peng Liu Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Juri Lelli Cc: Vincent Guittot Cc: Dietmar Eggemann Cc: Steven Rostedt Cc: Ben Segall Cc: Mel Gorman Cc: Valentin Schneider --- kernel/sched/fair.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 02f323b85b6d..1d0cf33fefad 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9943,22 +9943,8 @@ 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 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 - } } static inline int on_null_domain(struct rq *rq) @@ -10321,9 +10307,15 @@ static bool _nohz_idle_balance(struct rq *this_rq, unsigned int flags, has_blocked_load |= this_rq->has_blocked_load; } - if (flags & NOHZ_BALANCE_KICK) + if (flags & NOHZ_BALANCE_KICK) { rebalance_domains(this_rq, CPU_IDLE); + if (time_after(next_balance, this_rq->next_balance)) { + next_balance = this_rq->next_balance; + update_next_balance = 1; + } + } + WRITE_ONCE(nohz.next_blocked, now + msecs_to_jiffies(LOAD_AVG_PERIOD)); -- 2.17.1