From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D80F634DCDE for ; Tue, 6 Jan 2026 15:50:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767714621; cv=none; b=DM42aEFy7nq1VmsPp/A/huEj1r7G+KfD2VhH+z+K57J0nmdZvPwGuuiTCS9d4DF5xHUp0q47OPtSDJUZxJX8BqwlHbwOtLnHfAXS7L8qBK+PRvaRgTpLPx6llar4GbaB5ZsC/+BNGBL9NkSTBxlOCmH2j6HmLx3TuG1+AmGZado= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767714621; c=relaxed/simple; bh=XeETfUuh7NZol6JqzvPEdmFeL40NoRNb0HvtJH5+lJY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XvnsGJJu3VPMPObZNnSGwU8PkHRIDuAfvGQBS3gYwa6jFxosN7DDtNjrLl90Imxan8ezTOkI68VWrtGD8aVvUdOy4QWhhigdukKWFe0u6QWOndm/NOAuyZ640yujR68ZfI/oeSGLXQN6C32cr6AzutT012q1Q4fZKAMjlW4z8zk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=KsO9oZNJ; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="KsO9oZNJ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=jrA/Cw18CsElchMswtlE3EcXZhJc2pLVVQOjHkqRYWw=; b=KsO9oZNJ4KoG3oiEyBnoKI0M/R ikFlp7qnRSPf9zpU8geV4x28xpESjLiX1zWQcjsKInm5w3rKrc+3dslnUtOnFjXflYIRhMhTF0RjQ f+wmdHh6OuRWNvIS6m/PPFeKl5FpIOO600CTnXKQzMpDGyWTtrVgmI+T/3BcuMEZj0csaVcX3GVOn 3TNxuhpHiO9zM8K64BiRsEpRUVjjPDKgGgGWXUw0PTLsSRTv1hctbTaeYpDvJh/e7cdGI51cH1zc7 khh1rxa9MWyl9Fy8bd2l4sGb5XRCH1teof3yFtlS+OQAs2w9Fv0nSHgww5yWQXRc4laLW7bP/P0pO bq5pdv/g==; Received: from 2001-1c00-8d85-5700-266e-96ff-fe07-7dcc.cable.dynamic.v6.ziggo.nl ([2001:1c00:8d85:5700:266e:96ff:fe07:7dcc] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vd9Jz-0000000C0M7-3zmV; Tue, 06 Jan 2026 15:50:12 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id D720E30056B; Tue, 06 Jan 2026 16:50:10 +0100 (CET) Date: Tue, 6 Jan 2026 16:50:10 +0100 From: Peter Zijlstra To: Shrikanth Hegde Cc: mingo@kernel.org, vincent.guittot@linaro.org, linux-kernel@vger.kernel.org, kprateek.nayak@amd.com, juri.lelli@redhat.com, vschneid@redhat.com, tglx@linutronix.de, dietmar.eggemann@arm.com, anna-maria@linutronix.de, frederic@kernel.org, wangyang.guo@intel.com Subject: Re: [PATCH v2 1/3] sched/fair: Move checking for nohz cpus after time check Message-ID: <20260106155010.GC3707837@noisy.programming.kicks-ass.net> References: <20260102124744.360872-1-sshegde@linux.ibm.com> <20260102124744.360872-2-sshegde@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260102124744.360872-2-sshegde@linux.ibm.com> On Fri, Jan 02, 2026 at 06:17:42PM +0530, Shrikanth Hegde wrote: > Idle load balancer is kicked off only after time check. So move > the atomic read after the time check to avoid the overhead. Presumably this is because the nr_cpus field is more contended than the next_balance field; but aren't they in the same cacheline? That is, *what* !??! > If there are no nohz CPUs and next_blocked has passed, then there > will be one additional stats based load balancing which would set the > has_blocked_load to 0. It shouldn't make a difference. > > Signed-off-by: Shrikanth Hegde > --- > kernel/sched/fair.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 7377f9117501..cd1c78d2c272 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -12447,13 +12447,6 @@ static void nohz_balancer_kick(struct rq *rq) > */ > nohz_balance_exit_idle(rq); > > - /* > - * None are in tickless mode and hence no need for NOHZ idle load > - * balancing: > - */ > - if (likely(!atomic_read(&nohz.nr_cpus))) > - return; > - > if (READ_ONCE(nohz.has_blocked_load) && > time_after(now, READ_ONCE(nohz.next_blocked))) > flags = NOHZ_STATS_KICK; > @@ -12461,6 +12454,13 @@ static void nohz_balancer_kick(struct rq *rq) > if (time_before(now, nohz.next_balance)) > goto out; > > + /* > + * None are in tickless mode and hence no need for NOHZ idle load > + * balancing: > + */ > + if (likely(!atomic_read(&nohz.nr_cpus))) > + return; > + > if (rq->nr_running >= 2) { > flags = NOHZ_STATS_KICK | NOHZ_BALANCE_KICK; > goto out; > -- > 2.47.3 >