Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4172299rwl; Mon, 3 Apr 2023 00:33:25 -0700 (PDT) X-Google-Smtp-Source: AKy350ZAvyeuxubFO8vftnY7i9HcJHpl5Up+IdB1U0x1zBgyP3NmOGTWaTRj829JUbZWbDkaEvcT X-Received: by 2002:a17:906:b16:b0:92a:3709:e872 with SMTP id u22-20020a1709060b1600b0092a3709e872mr34524472ejg.19.1680507205559; Mon, 03 Apr 2023 00:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680507205; cv=none; d=google.com; s=arc-20160816; b=YFp8mx39swVE7eZUtu5YiYdPgZMKYFQLbBbH0F5Nxr5ZrfTqgAErzBXrhPWrg+8RQa w5YtZ6sqpkm+gOfBzLmVoTXckqWMijSlI0dQFN9PnnopbpjvfMzWYAcZ44ntyuBvUKbD piBmkNyiy7beJtQ5XmLN0NcbwL4VV/lmqPfGrFzgyjRU85vl5BTNKqiSb2SUFh1QY4os 6HQwUvdkvN/WGicUBKLXEzHaw9IWHBWi0FoL3hX0RK0StMVsjwxSxhY09cFB3tUHG7Q9 fIcVC42RJLcopbNbVQcf9zIlpXEoPxGH+X2ZMr4eq9Ym9/0uNtdWFdSrtBvsgfK1ZRPT WR5Q== 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; bh=ZDBAwO9vPKKk0A0DP/NhhrwczRgWQaQTKNHpuDG7VhQ=; b=jzO10SClxT0SMQ5aE3bWoFf47Q9i4b6CUeB0yQH6M38CnrnKI/7TXh3wwEP8OJ0f/1 SWFE22b9Sx8g1lIy0JfO+BZ0qw2RgBCMi/uen2pX0nRcy1lf2AYEhxlHWoZel8rdb6Xh 3uDvDIE16XqXOwWhwItoccUawgb3r+8jkac95m0F5tc/MhYkeXd2rFviCKtw5BFemULI cmmsEIeZ3aIdZHgtc0j1exwvnPiWctRJPlbivEBq8JtjJqP91kf4v5LxGk1M8j2WA+oc CHdm/k0MOOo9eGaAkat2t807CYIS1MB1N9ue59yK9/DdVeJZh5VohXYtAL6zCoQopQfj HXTA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b26-20020aa7c91a000000b004ff91698e31si3996043edt.81.2023.04.03.00.33.01; Mon, 03 Apr 2023 00:33:25 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231492AbjDCHYZ (ORCPT + 99 others); Mon, 3 Apr 2023 03:24:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229659AbjDCHYY (ORCPT ); Mon, 3 Apr 2023 03:24:24 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 32D98769D; Mon, 3 Apr 2023 00:24:21 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1665BFEC; Mon, 3 Apr 2023 00:25:06 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.57.89]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EAB463F6C4; Mon, 3 Apr 2023 00:24:18 -0700 (PDT) Date: Mon, 3 Apr 2023 08:24:13 +0100 From: Mark Rutland To: Peter Newman Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, will@kernel.org, catalin.marinas@arm.com, eranian@google.com Subject: Re: [PATCH v4] arm64: pmuv3: dynamically map PERF_COUNT_HW_BRANCH_INSTRUCTIONS Message-ID: References: <20230327122527.3913496-1-peternewman@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230327122527.3913496-1-peternewman@google.com> X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 Mon, Mar 27, 2023 at 02:25:27PM +0200, Peter Newman wrote: > From: Stephane Eranian > > The mapping of perf_events generic hardware events to actual PMU events on > ARM PMUv3 may not always be correct. This is in particular true for the > PERF_COUNT_HW_BRANCH_INSTRUCTIONS event. Although the mapping points to an > architected event, it may not always be available. This can be seen with a > simple: > > $ perf stat -e branches sleep 0 > Performance counter stats for 'sleep 0': > > branches > > 0.001401081 seconds time elapsed > > Yet the hardware does have an event that could be used for branches. > > Dynamically check for a supported hardware event which can be used for > PERF_COUNT_HW_BRANCH_INSTRUCTIONS at mapping time. > > And with that: > > $ perf stat -e branches sleep 0 > > Performance counter stats for 'sleep 0': > > 166,739 branches > > 0.000832163 seconds time elapsed > > Based-on: https://lore.kernel.org/all/YvunKCJHSXKz%2FkZB@FVFF77S0Q05N > Based-on-patch-by: Mark Rutland > Signed-off-by: Stephane Eranian > Signed-off-by: Peter Newman Thanks for reworking the patch; the patch itself and commit message look good to me. I'd like to keep my S-o-b here for the code itself; could we please make the tags: Co-Developed-by: Stephane Eranian Signed-off-by: Stephane Eranian Co-Developed-by: Mark Rutland Signed-off-by: Mark Rutland Co-Developed-by: Peter Newman Signed-off-by: Peter Newman Link: https://lore.kernel.org/all/YvunKCJHSXKz%2FkZB@FVFF77S0Q05N That follow the conventions documented in: https://www.kernel.org/doc/html/latest/process/submitting-patches.html Thanks, Mark. > --- > v3->v4: > - splice Mark's patch with Stephane's problem statement > v2->v3: > - removed prints per Will's suggestion > > [v3] https://lore.kernel.org/all/20220816130221.885920-1-peternewman@google.com/ > [v2] https://lore.kernel.org/lkml/20220324181458.3216262-1-eranian@google.com/ > > arch/arm64/kernel/perf_event.c | 27 +++++++++++++++++++++++---- > 1 file changed, 23 insertions(+), 4 deletions(-) > > diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c > index dde06c0f97f3..ee63f8e719ea 100644 > --- a/arch/arm64/kernel/perf_event.c > +++ b/arch/arm64/kernel/perf_event.c > @@ -45,7 +45,6 @@ static const unsigned armv8_pmuv3_perf_map[PERF_COUNT_HW_MAX] = { > [PERF_COUNT_HW_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_INST_RETIRED, > [PERF_COUNT_HW_CACHE_REFERENCES] = ARMV8_PMUV3_PERFCTR_L1D_CACHE, > [PERF_COUNT_HW_CACHE_MISSES] = ARMV8_PMUV3_PERFCTR_L1D_CACHE_REFILL, > - [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED, > [PERF_COUNT_HW_BRANCH_MISSES] = ARMV8_PMUV3_PERFCTR_BR_MIS_PRED, > [PERF_COUNT_HW_BUS_CYCLES] = ARMV8_PMUV3_PERFCTR_BUS_CYCLES, > [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = ARMV8_PMUV3_PERFCTR_STALL_FRONTEND, > @@ -1048,6 +1047,28 @@ static void armv8pmu_reset(void *info) > armv8pmu_pmcr_write(pmcr); > } > > +static int __armv8_pmuv3_map_event_id(struct arm_pmu *armpmu, > + struct perf_event *event) > +{ > + if (event->attr.type == PERF_TYPE_HARDWARE && > + event->attr.config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) { > + > + if (test_bit(ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED, > + armpmu->pmceid_bitmap)) > + return ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED; > + > + if (test_bit(ARMV8_PMUV3_PERFCTR_BR_RETIRED, > + armpmu->pmceid_bitmap)) > + return ARMV8_PMUV3_PERFCTR_BR_RETIRED; > + > + return HW_OP_UNSUPPORTED; > + } > + > + return armpmu_map_event(event, &armv8_pmuv3_perf_map, > + &armv8_pmuv3_perf_cache_map, > + ARMV8_PMU_EVTYPE_EVENT); > +} > + > static int __armv8_pmuv3_map_event(struct perf_event *event, > const unsigned (*extra_event_map) > [PERF_COUNT_HW_MAX], > @@ -1059,9 +1080,7 @@ static int __armv8_pmuv3_map_event(struct perf_event *event, > int hw_event_id; > struct arm_pmu *armpmu = to_arm_pmu(event->pmu); > > - hw_event_id = armpmu_map_event(event, &armv8_pmuv3_perf_map, > - &armv8_pmuv3_perf_cache_map, > - ARMV8_PMU_EVTYPE_EVENT); > + hw_event_id = __armv8_pmuv3_map_event_id(armpmu, event); > > /* > * CHAIN events only work when paired with an adjacent counter, and it > -- > 2.40.0.348.gf938b09366-goog >