Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp221735rdb; Thu, 19 Oct 2023 02:26:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkywX72stVdy+Ye1LolnkqhGvdiTrNiYHc5CKky065v2HyNDcUK3zDGvBMQjAJhgiVUxAu X-Received: by 2002:a17:902:d4cb:b0:1c9:ece9:53d2 with SMTP id o11-20020a170902d4cb00b001c9ece953d2mr2086497plg.61.1697707610252; Thu, 19 Oct 2023 02:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697707610; cv=none; d=google.com; s=arc-20160816; b=u9U/KwE22/ptzMTWr2DwObJxM0NCvS2lW2jFMKocqMUYJXJ89cqPRXU8ncTLk8boHW /tFQ0Pe1bxSwX1Rjk5rwc3dgNst3iCwasRbb7EDHvqKOZi0Yz/H7CaE94Bv1/GRqCg+L vKTh2UHsHU0fP+kyFP0uyWkF70leTPdOmSsbu8bn/ZVSq9SajexemoF/Vcuwg3BaxXv3 JtcqSX5eCAng1Md7m8bAfXRtOSUARSpoBlwP+mtm8o0EHOtcyJcXRPnS92LW8QmOj72H 4tPvs9eaL9Y50s28R0zmEFkltYxJG9UcFkTKLH1/IQA9Ve/R4K5id7Q2EbbVHCpm8RNX P8Lg== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=UlxhvUEUF3jyB3xsMCTtxKubVCjk9HjCcypqzOC3zrM=; fh=3kTKsv2cAw/HzpZ5MwS0/6eqzVbNIR0k/WjaGE2kPn8=; b=q6cHIr/dIjg3odlCGKdPdnmdrrDEAg9YA+x2csgobVwnXDKuyNmyEK08D1bvtiu0as yVw6FXJ97nvCfn0UU9dkyIVUF8kgGF9q+whggsBnY2XDU6GcqrvbbHUtwdmLuDQCg+Nv jPgVINQcMD9BWxySAZvYGWtNugWOLlf8fZe/jH/sRSuCOvtWM+RZsejzPtg8pGwg5CxF /qmO/ZQ7rtFMDhI+tWiGc6+5WecmqqhmNhgpn+Xt8T/BncOBPI5NWSe7NxtisJLWfSCp +94p58Mf5vJS0xEVnLOZHXDjwjhwXkO1lNtcDOafHe1BoV18iyPezqfdAmH1khvlDd03 x+ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=PIMGnUSv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id b11-20020a170902bd4b00b001c77a0c5a61si1658167plx.551.2023.10.19.02.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 02:26:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=PIMGnUSv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 8D2278181B90; Thu, 19 Oct 2023 02:26:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231792AbjJSJ0F (ORCPT + 99 others); Thu, 19 Oct 2023 05:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345034AbjJSJ0D (ORCPT ); Thu, 19 Oct 2023 05:26:03 -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 EB526106 for ; Thu, 19 Oct 2023 02:26:00 -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-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=UlxhvUEUF3jyB3xsMCTtxKubVCjk9HjCcypqzOC3zrM=; b=PIMGnUSv9gxzl+YwuJSeyVfXtq N3a+gPgY4M49fvWiariT6/2tZ6wjPoG0dc9Vt1U9sDm9LLUxYSyNEPzOI4fj0enRZPvL6CV0wgPdK w/WXE884xeJMm5gDtw0ddV5Oy9A3LG32HhTtN2HNv+Rgs261t07eI1VrxDIRlKOF0BWvRivEvf/cb YccBQ2CCb06GHBhKB581+ynnCHXMxGw9LtfrlbpHFwWBLqL1VF4lSC4Rke7LiGkanK22b8A89Spbj ecw5AxGVzn8+S6+VjfePpn4Ck9s2nSvqmn1+htAW5cVKMsn1iycG4goYMWkTSxc7oOjcz+H/L3S8M XF86vp5Q==; 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 1qtPFm-009kcL-0r; Thu, 19 Oct 2023 09:25:42 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 8E53E300585; Thu, 19 Oct 2023 11:23:41 +0200 (CEST) Date: Thu, 19 Oct 2023 11:23:41 +0200 From: Peter Zijlstra To: kan.liang@linux.intel.com Cc: mingo@redhat.com, acme@kernel.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, ak@linux.intel.com, eranian@google.com, alexey.v.bayduraev@linux.intel.com, tinghao.zhang@intel.com Subject: Re: [PATCH V4 4/7] perf/x86/intel: Support LBR event logging Message-ID: <20231019092341.GE36211@noisy.programming.kicks-ass.net> References: <20231004184044.3062788-1-kan.liang@linux.intel.com> <20231004184044.3062788-4-kan.liang@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231004184044.3062788-4-kan.liang@linux.intel.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Thu, 19 Oct 2023 02:26:35 -0700 (PDT) On Wed, Oct 04, 2023 at 11:40:41AM -0700, kan.liang@linux.intel.com wrote: > diff --git a/arch/x86/events/intel/lbr.c b/arch/x86/events/intel/lbr.c > index c3b0d15a9841..1e80a551a4c2 100644 > --- a/arch/x86/events/intel/lbr.c > +++ b/arch/x86/events/intel/lbr.c > @@ -676,6 +676,21 @@ void intel_pmu_lbr_del(struct perf_event *event) > WARN_ON_ONCE(cpuc->lbr_users < 0); > WARN_ON_ONCE(cpuc->lbr_pebs_users < 0); > perf_sched_cb_dec(event->pmu); > + > + /* > + * The logged occurrences information is only valid for the > + * current LBR group. If another LBR group is scheduled in > + * later, the information from the stale LBRs will be wrongly > + * interpreted. Reset the LBRs here. > + * For the context switch, the LBR will be unconditionally > + * flushed when a new task is scheduled in. If both the new task > + * and the old task are monitored by a LBR event group. The > + * reset here is redundant. But the extra reset doesn't impact > + * the functionality. It's hard to distinguish the above case. > + * Keep the unconditionally reset for a LBR event group for now. > + */ I found this really hard to read, also should this not rely on !cpuc->lbr_users ? As is, you'll reset the lbr for every event in the group. > + if (is_branch_counters_group(event)) > + intel_pmu_lbr_reset(); > }