Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3727815ybz; Mon, 4 May 2020 08:36:21 -0700 (PDT) X-Google-Smtp-Source: APiQypLwkJiDbrH8ciPSJVIV9COyz1FvplVBRDAUBm9+GjzcuZGgqlzrQtVwLVGtgqRju4IMwuNq X-Received: by 2002:a17:906:bce4:: with SMTP id op4mr14254761ejb.174.1588606580922; Mon, 04 May 2020 08:36:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588606580; cv=none; d=google.com; s=arc-20160816; b=mFvku4sAsHtELI0yyfUX7PuW6Uf0owi+fg/8PPJbaHb9DHAeBl3G2eetFnaaZjG+s9 Cab3BLFxjE0f7q1c8y/2b+Nrgvpx4GyNJRYB2Y0Bg1mKb8XoQBm9shLhA46rIkD0DH5K VtnYsMwS74II0J/j96kDk9VZDA6mCAD3nIy+MeZ6dJpEgZ1UJcPdpsFEi2LbWA5Kl5gY 25NH60aCFyvH8e2CBProXO2rgl3waOSC9HdIfsibtHGr0oANGZPDnB/jrIqjCmN4b3M2 S8JJoxK+S56PrnKljx55UT3os/Eb+hwll6CSzmP0lW+XTusryUjxr/azGJPfkeT+RGg5 rZJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=CR1034a54R7krWBlR+Wwz8ASr1KEH3BC6Ga1BqQA9Do=; b=hjpurUNATYj06cHwzu8pq2rwPgXutqVoUOFmyt2iWYr7dD/Qrs4pD9BuWUTRulGoyp HIn5RBFaB63in+oU8oUvy2FtZmPtNmnavqEpgMx7jB1jhLMdRQbMo+G4KnOn7Qz2hiyq sWR9hArnq+FWkpvXRlb8ScnjiELMXmRDEA0j44xmuV/OVIsKOMJB0qWTOGTEenMDUM0D K/Gr+NrX5BWEaeXx9EW28NCQMhn28v0GiEHd1a7zQ9uKOXqj8FI1wmhI5Mq4d8Eq2S4J Y989ksJ0oWx8DfxuxK5enKnEUxyd/ObhksZ8CrfpwWG84T+SPoVzvu92C4LMp6PbePYS 8ntA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=O0VcoZTI; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c10si7147741eds.107.2020.05.04.08.35.57; Mon, 04 May 2020 08:36:20 -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=@linaro.org header.s=google header.b=O0VcoZTI; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728899AbgEDPRZ (ORCPT + 99 others); Mon, 4 May 2020 11:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728165AbgEDPRY (ORCPT ); Mon, 4 May 2020 11:17:24 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47017C061A0E for ; Mon, 4 May 2020 08:17:24 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id g4so10068590ljl.2 for ; Mon, 04 May 2020 08:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CR1034a54R7krWBlR+Wwz8ASr1KEH3BC6Ga1BqQA9Do=; b=O0VcoZTIHJm3q5Yhecj6iKf2QFe7hNfQjYJu3Oz4R4Y11TxpaQqzs7ySTskuftcNyJ +c91jxsHAJK3xvfPdnI88Wyc7FWEB0w6Cb2vkBCCAmlO7IanAGpEF44Z+n4ay96piosC WF9YyC/Ho0xromMA4OZ1T0ugLKPHm+swMvSkjkbXkBafalVHGXOQd28r25oqMxHrAtid 4LJMOyRGDda+h8r5ou8H71MFgXEWXeyPrt2n2ppRJSaw3et6S65YqYd1EqMGEBYBK1W4 GpD4RP2p6tLA7y+tDsJ6r1BywQlNXFW+gFqb/fki18j3VnI+cSTAZ7PGnUPoq34ekhym dccQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CR1034a54R7krWBlR+Wwz8ASr1KEH3BC6Ga1BqQA9Do=; b=EJTI0YM8MfHFKcjqQierqNI97P0sqR2lcMJsesZeo02SO7l6CZ6NDGB9qYb0oy/t15 KR/47fpIDyo4LpB/oZvWiMTWgFlRXHGh1wFldahKXaShJpY2OMYcZcoW0bnjDkdR5EKq BCZ8Iwjzx9oRF7jFE1rfha+pviJIUdAZlHnxomfdTP4l0ZnlclvSLnfbo+Jzju3SUXx6 dek6PT9vvKobCMcX/soKODO3GZxgSeGa9kwCVkEnIRGrQZbmC/M9tE+w50bzMf2l1K0i 5BQ3Ddr26OgvmEK7gHQXosCXQZto6rjud8T3UzlKgwkAWiyNWRuU+XeUfAM0W6wS/629 GNxw== X-Gm-Message-State: AGi0PubfS+yXU3ZdMREMNRNqZTXxcwcjpmiNWec316Uht5qA+W2L1kbT XW9OxTO6zwHh5Gjji5idc3iqmcjbl+gdsub8af2m5A== X-Received: by 2002:a2e:740f:: with SMTP id p15mr10731103ljc.151.1588605442680; Mon, 04 May 2020 08:17:22 -0700 (PDT) MIME-Version: 1.0 References: <20200503083407.GA27766@iZj6chx1xj0e0buvshuecpZ> In-Reply-To: <20200503083407.GA27766@iZj6chx1xj0e0buvshuecpZ> From: Vincent Guittot Date: Mon, 4 May 2020 17:17:11 +0200 Message-ID: Subject: Re: [PATCH] sched/fair: Fix nohz.next_balance update To: Peng Liu Cc: linux-kernel , Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 3 May 2020 at 10:34, Peng Liu wrote: > > 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(). I'm not sure that's always true. Nothing prevents nohz_idle_balance() to return false . Then run_rebalance_domains() calls rebalance_domains(this_rq ,SCHED_IDLE) outside _nohz_idle_balance(). In this case we must keep the code in rebalance_domains(). For example when the tick is not stopped when entering idle. Or when need_resched() returns true. So instead of removing the code from rebalance_domains, you should move the one in _nohz_idle_balance() to make sure that the "if (likely(update_next_balance)) ..." is called before calling rebalance_domains for the local cpu > > 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 >