From nobody Wed Sep 10 09:23:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC4D1C00528 for ; Tue, 1 Aug 2023 21:25:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232531AbjHAVZa (ORCPT ); Tue, 1 Aug 2023 17:25:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbjHAVY4 (ORCPT ); Tue, 1 Aug 2023 17:24:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 062492708 for ; Tue, 1 Aug 2023 14:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=2Fw/6pc13hFz4431UNCf/XS3M9fAIWcYfqPnXE09Ku4=; b=jf7h3twPdz2DT1GCwfUgdsHWvl 6gJ6KV5WtDzaSrLPLVmGcSsNI/aPU6YuG/xgdRcISp/8cdMuxLDYSSOACzvce0Xin0ei5eurCCVW6 pKhIniOu3a6lY3JXgczXG8BA4bNwQ7ibysONv7Fklk9bZ4pMTaX6+Jhxsn/5ua9oyqgzxNHtotBA2 m+Rej9y/VI678MskQgPdCshVY4X6Qmnwpqj76M6A/AW1o7OgItWsLTAKeedBx6E19GFALEo58HwfS 6ZyZ0DSbdXMfYqFv4nb7aPil+r8I1F8t7OlD0qIUnWQHwn4lbg194c89YhUGFLlx1PCBGeyPtrqCd QdZAOqSg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qQwqm-00B5yX-0o; Tue, 01 Aug 2023 21:24:17 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 569F43002D3; Tue, 1 Aug 2023 23:24:15 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 389C52028A2D8; Tue, 1 Aug 2023 23:24:15 +0200 (CEST) Message-ID: <20230801211811.828443100@infradead.org> User-Agent: quilt/0.66 Date: Tue, 01 Aug 2023 22:41:22 +0200 From: Peter Zijlstra To: mingo@redhat.com Cc: peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org Subject: [PATCH 1/9] sched: Simplify get_nohz_timer_target() References: <20230801204121.929256934@infradead.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use guards to reduce gotos and simplify control flow. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Joel Fernandes (Google) --- kernel/sched/core.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1097,25 +1097,22 @@ int get_nohz_timer_target(void) =20 hk_mask =3D housekeeping_cpumask(HK_TYPE_TIMER); =20 - rcu_read_lock(); + guard(rcu)(); + for_each_domain(cpu, sd) { for_each_cpu_and(i, sched_domain_span(sd), hk_mask) { if (cpu =3D=3D i) continue; =20 - if (!idle_cpu(i)) { - cpu =3D i; - goto unlock; - } + if (!idle_cpu(i)) + return i; } } =20 if (default_cpu =3D=3D -1) default_cpu =3D housekeeping_any_cpu(HK_TYPE_TIMER); - cpu =3D default_cpu; -unlock: - rcu_read_unlock(); - return cpu; + + return default_cpu; } =20 /*