Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp213300rwl; Wed, 9 Aug 2023 13:24:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJUiu1UWKr+UBR1Attkb2fP1OUMOQMhBY/6w3NIluO3sTXclgp7ZCvSJ4npzgOFJG8MXdF X-Received: by 2002:a17:902:7449:b0:1bb:a122:4886 with SMTP id e9-20020a170902744900b001bba1224886mr143168plt.64.1691612667980; Wed, 09 Aug 2023 13:24:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691612667; cv=none; d=google.com; s=arc-20160816; b=DHEiIDtpas3Y730aIMEpljUcag/D+Q79viNyvdYboHJ4jZoNsXKgvbZSNZ6g/caQTi vGqYja3TeQHPv3wIeK/KhN1zeCrs1EBNgoBA3bJPG4LNwi1TzuHiFT/fZpmdZQ/eiVC3 4xaAbT1aFFLQ28verf01K5XGQXOCyaW24lBDAsk1wDJ2Zr/4UYzyIq01MKEOnWzUhXiy ipmJpkbPidwWBnSNAWQT3MzcbjSnAC0z6Y7tA36OhdJ+SbEWmNctZJO6P5cxdLmJO9kd 4M7VNVKTW7U/b6AsPJjak78XIVPseOAxFH2FfQQsimZBF6AhFK+Pvqzr381tQlXPSpHs 7pOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=sFRRM464Bt6MEnb3WIeAuQysrD/M+qVRQwMUi036qMI=; fh=WSM5HPXYb7OBUyYzBQlm+pMZsUpHD8ByWddwAo6tl9I=; b=NOtJVf4uKV7VCLKnFfjuvUccs0QL4KPMXV/AsISjEwfRouN/29LsIOMfnYJtVFmM1X l+qMKQEzu8ir3iueC3zceIMD5zJPTXCER7hQqQX8oaDoSlBSCvAUy+XSDDVMzmWSZ6V1 MEivDXrI8Syc/wtcX89axBxWFD8I4u5bdkwMl6JPU+C9C5ftvXEl3olp485D0Uh+VZGV +03PeJ3UJwmJQb5Y8Xw5BsKc9KYC0ypV0sBj5StJXnmKDfo7K9x9TA4vvE/cchwpC9VH HrBaHnQAcKSf8zcf7lJryLEJU/wzJJZWbNg7tUkXA6emN7QY8q5LjKxF9YryHmFbAjYi xFjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=THzT725c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m12-20020a170902e40c00b001bbcc4e0211si7202201ple.239.2023.08.09.13.24.15; Wed, 09 Aug 2023 13:24:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=THzT725c; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234197AbjHITts (ORCPT + 99 others); Wed, 9 Aug 2023 15:49:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234128AbjHITtc (ORCPT ); Wed, 9 Aug 2023 15:49:32 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB03510DC for ; Wed, 9 Aug 2023 12:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=sFRRM464Bt6MEnb3WIeAuQysrD/M+qVRQwMUi036qMI=; b=THzT725cTZnBJWe0mx4wYStpmZ J0qBz142+KC+QdO5jeLkEyt7Kd2v4Jbn/D18Wk7cv+oMMEGet5+BVxcawjNRhESMl5p3+yt2KUPuK UtRS+Bn1SXMUMxWfPisaC0egopFfhrY7/ol+oUJ3epuZgckIMHcrIbU3PSHt34MQOSA7SjqPcG2Vy 9zInh+nuBX5OYIiUMy+YGVmEYXogXCy0ztdWPyc4Hd9T6jMvBtA1QrOFYfGo74+Pn3BQz7o+rFY3k cu+eFmOyfRkcYtNcWz077Bt8IoxbtIO0f1ZTvZm5YL0Ob4V0VmKEPjND3v7PRF+Y4CEieeCnjlTuY Pa8A40Hg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1qTpAN-005s4m-1p; Wed, 09 Aug 2023 19:48:25 +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)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id D7E4630026C; Wed, 9 Aug 2023 21:48:22 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B49A220B32279; Wed, 9 Aug 2023 21:48:22 +0200 (CEST) Date: Wed, 9 Aug 2023 21:48:22 +0200 From: Peter Zijlstra To: Joel Fernandes Cc: mingo@redhat.com, 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: Re: [PATCH 1/9] sched: Simplify get_nohz_timer_target() Message-ID: <20230809194822.GV212435@hirez.programming.kicks-ass.net> References: <20230801204121.929256934@infradead.org> <20230801211811.828443100@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 06, 2023 at 05:39:24PM -0400, Joel Fernandes wrote: > On Sun, Aug 6, 2023 at 9:52 AM Peter Zijlstra wrote: > > > > Use guards to reduce gotos and simplify control flow. > > > > Signed-off-by: Peter Zijlstra (Intel) > > --- > > 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) > > > > hk_mask = housekeeping_cpumask(HK_TYPE_TIMER); > > > > - rcu_read_lock(); > > + guard(rcu)(); > > + > > for_each_domain(cpu, sd) { > > for_each_cpu_and(i, sched_domain_span(sd), hk_mask) { > > if (cpu == i) > > continue; > > > > - if (!idle_cpu(i)) { > > - cpu = i; > > - goto unlock; > > - } > > + if (!idle_cpu(i)) > > + return i; > > } > > } > > > > if (default_cpu == -1) > > default_cpu = housekeeping_any_cpu(HK_TYPE_TIMER); > > - cpu = default_cpu; > > -unlock: > > - rcu_read_unlock(); > > - return cpu; > > + > > + return default_cpu; > > } > > Reviewed-by: Joel Fernandes (Google) > > I haven't looked into the actual implementation of the guard stuff, > but rcu_read_lock_guarded() is less of an eyesore to me than > guard(rcu)(); TBH. I readily admit it isn't the prettiest construct, my brain is warped by many years of C++ and I can read it as: guard(), but I'm not sure that's actually better :-) The advantage of all this is that you also get: scoped_guard (rcu) { } for 'free'.