Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2499798rdb; Wed, 15 Nov 2023 02:32:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEx/8N7sViw/XM/iLok6MFIkSfsanWE35aQXCVgLIZvrbKQtLwvFHOUPrAvv+II2P/1xS6R X-Received: by 2002:aa7:8550:0:b0:6c5:7a6:e1d with SMTP id y16-20020aa78550000000b006c507a60e1dmr10595383pfn.29.1700044328885; Wed, 15 Nov 2023 02:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700044328; cv=none; d=google.com; s=arc-20160816; b=CFaN3chyUNXLTroZ8y5HZzHrtvpy184FhRmCCeRdeRr4VygJ5N3gDeJgK8JByvJ8uy jqwOetdE6cVK4u5D2kVAGSBET7EYVi8GfIrT0gohc1ks4eDOpEnlUMG/KNyPV+Ov9rei 2omJTSHNRNUxkRIatVHsGXR8H157HRLzQeg5gPyjyxGT2jL90jr8awf0iDhjxIy7II5u PM06tPCc2sJ3UCkGcDyQuM1XT7nIzWbxZujXQLkzHRpXPh/v9w4iZtI7/ViuWf8rzDjd thoxV/uM6GWkeYE4tLNpOFm+DRpBm6gEVxxM/VW6Lv9XopfN9pSZ8QTdq8ZHIeDnyGmP rN8Q== 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=jTrB25zqHJmxKcPSZ4NVPi2QdcQQymDkA2ryGwWdzXk=; fh=XADYNn1vVluOwXCvm1n/GRoDLd2WqPH2PC/ADmArqps=; b=rMaslAIrgZ5v3AdmM8MJ0/YXSFjLbEA+bSJLuQaMSyTnWAFKuiDJt0KEuvAdISRlJa 71+44I0Bv1Dt9h5ucug39L396WmJka99oUfAU9tj5AgV5O0+cDz9rozzSrprbCohO6Vv agA9uSf2Y7nhMBwhEME+D2cWK7NPmeFWfosdG5S2Ek1S+/iY/5QVBNezjRHh12wfS1Xo Hb16kr33JWM2XZAE1XkSp5UTn/cUr47nyS0+d7a5h9TlZOfxDfE9MIDFObbdaaD0Jyqa rf5xwb3V8ZfzJirCDOc4SY6dmzdzSu+BPtnORWR9PnhRKDUcjKnnL1Vx4e+OQr/hRXaM fmFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="XG5/pDn6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id fj26-20020a056a003a1a00b0068fe0f46f27si10048020pfb.171.2023.11.15.02.32.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 02:32:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="XG5/pDn6"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 177E6802F259; Wed, 15 Nov 2023 02:32:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234688AbjKOKbu (ORCPT + 99 others); Wed, 15 Nov 2023 05:31:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234116AbjKOKbt (ORCPT ); Wed, 15 Nov 2023 05:31:49 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E64A109 for ; Wed, 15 Nov 2023 02:31:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=jTrB25zqHJmxKcPSZ4NVPi2QdcQQymDkA2ryGwWdzXk=; b=XG5/pDn6qbSbCKS9i8clrqH1LL scQH0R82gbwHNmmRMqdu1ySh0zjVC/fFaF5Rr+L9AiInehj2xHUSWXpLebQOVyV0ONPesgyZTpid5 N3qJMi5Kd9DUzBM6RtZB8upyRXddqqgVoF1UEHooWZtUthDN20B+JlWlnWjL5SGh9QsFq3zL3unqT Q/7yp43NLHVuL3AnXXQNXB8OJ5i4nKnI4scA80BkvkLxJzCHKzODLmCOGfOrtnqm5xSh449Q0bfV9 wkoYbi4KjWAiq9SXl+KTesQKZ8Fq8lw+vLP4piyitYSlbja66Ummmt7QcPWzM7nBZkpT5rEkYEIPV FaeL9P1g==; 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 1r3DBB-00DeWB-Hu; Wed, 15 Nov 2023 10:31:29 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 38D62300427; Wed, 15 Nov 2023 11:31:29 +0100 (CET) Date: Wed, 15 Nov 2023 11:31:29 +0100 From: Peter Zijlstra To: Namhyung Kim Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com Subject: Re: [PATCH 11/13] perf: Simplify perf_adjust_freq_unthr_context() Message-ID: <20231115103129.GC3818@noisy.programming.kicks-ass.net> References: <20231102150919.719936610@infradead.org> <20231102152018.986157891@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=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 15 Nov 2023 02:32:06 -0800 (PST) On Fri, Nov 03, 2023 at 06:14:32PM -0700, Namhyung Kim wrote: > On Thu, Nov 2, 2023 at 8:32 AM Peter Zijlstra wrote: > > > > > > Signed-off-by: Peter Zijlstra (Intel) > > --- > > kernel/events/core.c | 51 +++++++++++++++++++++++---------------------------- > > 1 file changed, 23 insertions(+), 28 deletions(-) > > > > --- a/kernel/events/core.c > > +++ b/kernel/events/core.c > > @@ -4090,7 +4090,7 @@ perf_adjust_freq_unthr_context(struct pe > > if (!(ctx->nr_freq || unthrottle)) > > return; > > > > - raw_spin_lock(&ctx->lock); > > + guard(raw_spinlock)(&ctx->lock); > > > > list_for_each_entry_rcu(event, &ctx->event_list, event_entry) { > > if (event->state != PERF_EVENT_STATE_ACTIVE) > > @@ -4100,7 +4100,7 @@ perf_adjust_freq_unthr_context(struct pe > > if (!event_filter_match(event)) > > continue; > > > > - perf_pmu_disable(event->pmu); > > + guard(perf_pmu_disable)(event->pmu); > > > > hwc = &event->hw; > > > > @@ -4110,34 +4110,29 @@ perf_adjust_freq_unthr_context(struct pe > > event->pmu->start(event, 0); > > } > > > > - if (!event->attr.freq || !event->attr.sample_freq) > > - goto next; > > + if (event->attr.freq && event->attr.sample_freq) { > > Any reason for this change? I think we can just change the > 'goto next' to 'continue', no? Linus initially got confused about the life-time of for-loop scopes, but yeah, this could be continue just fine. > Also I think this code needs changes to optimize the access. > A similar reason for the cgroup switch, it accesses all the > pmu/events in the context even before checking the sampling > frequency. This is bad for uncore PMUs (and KVM too). > > But this is a different issue.. Right, lets do that in another patch. Also, there seems to be a problem with the cgroup thing :/