Message ID | 20221107062514.2851047-3-anshuman.khandual@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1868956wru; Sun, 6 Nov 2022 22:27:41 -0800 (PST) X-Google-Smtp-Source: AMsMyM7iDsK79Q1Sb9ziLSnXCRXNtHkKjeUZw7ONLRw62NXqquaDPTuNHsl5ehpFGL2dFJQu/71w X-Received: by 2002:a17:907:31c3:b0:770:852b:71a2 with SMTP id xf3-20020a17090731c300b00770852b71a2mr46261639ejb.557.1667802461004; Sun, 06 Nov 2022 22:27:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667802460; cv=none; d=google.com; s=arc-20160816; b=KPMcrp9fHMs6zA83OZA6gDPaofyWUgEWmM9/Y/8HPp4bAxdQooj4ih/Slfw+jpHObd edgijVaprnCzwz026EqYRGY6XvVwHsW3VHOYJ7HgZP70fI60HG2xbqN1bSKYn9fX5g/3 x18jPo0efin0UR3bDp/pemnPWr4xqu6mxsGlhYELekiMzcOiejlRTavHZ6GjM15kzOl9 uUROy2uEMYlMrX+jFNcZcxvhz/Ra9c3zMACZaawlJnraGQEpFmdRVxZgQr4tx4S5egPe V7vsvtfaD0ZkFmdQUaBGhq8O6R0dRurIp4RlJrEtrxKZx7upx3QTbUF7pK3Hebiot72E diOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=aSxaEu9kpiMVce3FRDbVv1l6xBJNcUGiSLhfr+B59ZI=; b=FUpdVhOQxRFw+Xtn7U/o+OHiCLJlWBUOcexiXR31en+La6pY5mGH1hX1/LgQYDEC2c X8EaRGzkkVMZh1CDTANwSVreDtadsorL0MZ7Ogjhp5ahWSDaieC5u3ai0XoefKp9IXMq j0wf5VGaBu9JAWN24k0IIYt3pSFGYkZkUimrARmuTl+pw7sanXWctWZ5Wls8gFB/a+UT KK2aFFlXz5HY6fNUIO9blDeP3k9WPXplM6BU5g4SJw8Vfcg9tnkrxbgybfHvtRqBr5KZ DWNnZQteVUkC3MTxVuj6hm20eCjR6OGfsy/13DcylPlGAxX/1TqqwsbIymItpSRcoslj J+yA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020aa7cf10000000b0045b50cee511si7340782edy.122.2022.11.06.22.27.17; Sun, 06 Nov 2022 22:27:40 -0800 (PST) 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 S231292AbiKGGZu (ORCPT <rfc822;hjfbswb@gmail.com> + 99 others); Mon, 7 Nov 2022 01:25:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231277AbiKGGZs (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 7 Nov 2022 01:25:48 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C7CC1275D; Sun, 6 Nov 2022 22:25:47 -0800 (PST) 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 8C2F3113E; Sun, 6 Nov 2022 22:25:53 -0800 (PST) Received: from a077893.blr.arm.com (unknown [10.162.42.7]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 951C43F534; Sun, 6 Nov 2022 22:25:42 -0800 (PST) From: Anshuman Khandual <anshuman.khandual@arm.com> To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-arm-kernel@lists.infradead.org, peterz@infradead.org, acme@kernel.org, mark.rutland@arm.com, will@kernel.org, catalin.marinas@arm.com Cc: Anshuman Khandual <anshuman.khandual@arm.com>, Mark Brown <broonie@kernel.org>, James Clark <james.clark@arm.com>, Rob Herring <robh@kernel.org>, Marc Zyngier <maz@kernel.org>, Suzuki Poulose <suzuki.poulose@arm.com>, Ingo Molnar <mingo@redhat.com> Subject: [PATCH V5 2/7] arm64/perf: Update struct arm_pmu for BRBE Date: Mon, 7 Nov 2022 11:55:09 +0530 Message-Id: <20221107062514.2851047-3-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221107062514.2851047-1-anshuman.khandual@arm.com> References: <20221107062514.2851047-1-anshuman.khandual@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748817633308874273?= X-GMAIL-MSGID: =?utf-8?q?1748817633308874273?= |
Series |
arm64/perf: Enable branch stack sampling
|
|
Commit Message
Anshuman Khandual
Nov. 7, 2022, 6:25 a.m. UTC
Although BRBE is an armv8 speciifc HW feature, abstracting out its various
function callbacks at the struct arm_pmu level is preferred, as it cleaner
, easier to follow and maintain.
Besides some helpers i.e brbe_supported(), brbe_probe() and brbe_reset()
might not fit seamlessly, when tried to be embedded via existing arm_pmu
helpers in the armv8 implementation.
Updates the struct arm_pmu to include all required helpers that will drive
BRBE functionality for a given PMU implementation. These are the following.
- brbe_filter : Convert perf event filters into BRBE HW filters
- brbe_probe : Probe BRBE HW and capture its attributes
- brbe_enable : Enable BRBE HW with a given config
- brbe_disable : Disable BRBE HW
- brbe_read : Read BRBE buffer for captured branch records
- brbe_reset : Reset BRBE buffer
- brbe_supported: Whether BRBE is supported or not
A BRBE driver implementation needs to provide these functionalities.
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-perf-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
arch/arm64/kernel/perf_event.c | 36 ++++++++++++++++++++++++++++++++++
include/linux/perf/arm_pmu.h | 21 ++++++++++++++++++++
2 files changed, 57 insertions(+)
Comments
On 07/11/2022 06:25, Anshuman Khandual wrote: > Although BRBE is an armv8 speciifc HW feature, abstracting out its various > function callbacks at the struct arm_pmu level is preferred, as it cleaner > , easier to follow and maintain. > > Besides some helpers i.e brbe_supported(), brbe_probe() and brbe_reset() > might not fit seamlessly, when tried to be embedded via existing arm_pmu > helpers in the armv8 implementation. > > Updates the struct arm_pmu to include all required helpers that will drive > BRBE functionality for a given PMU implementation. These are the following. > > - brbe_filter : Convert perf event filters into BRBE HW filters > - brbe_probe : Probe BRBE HW and capture its attributes > - brbe_enable : Enable BRBE HW with a given config > - brbe_disable : Disable BRBE HW > - brbe_read : Read BRBE buffer for captured branch records > - brbe_reset : Reset BRBE buffer > - brbe_supported: Whether BRBE is supported or not > > A BRBE driver implementation needs to provide these functionalities. Could these not be hidden from the generic arm_pmu and kept in the arm64 pmu backend ? It looks like they are quite easy to simply move these to the corresponding hooks in arm64 pmu. Suzuki
On 11/9/22 17:00, Suzuki K Poulose wrote: > On 07/11/2022 06:25, Anshuman Khandual wrote: >> Although BRBE is an armv8 speciifc HW feature, abstracting out its various >> function callbacks at the struct arm_pmu level is preferred, as it cleaner >> , easier to follow and maintain. >> >> Besides some helpers i.e brbe_supported(), brbe_probe() and brbe_reset() >> might not fit seamlessly, when tried to be embedded via existing arm_pmu >> helpers in the armv8 implementation. >> >> Updates the struct arm_pmu to include all required helpers that will drive >> BRBE functionality for a given PMU implementation. These are the following. >> >> - brbe_filter : Convert perf event filters into BRBE HW filters >> - brbe_probe : Probe BRBE HW and capture its attributes >> - brbe_enable : Enable BRBE HW with a given config >> - brbe_disable : Disable BRBE HW >> - brbe_read : Read BRBE buffer for captured branch records >> - brbe_reset : Reset BRBE buffer >> - brbe_supported: Whether BRBE is supported or not >> >> A BRBE driver implementation needs to provide these functionalities. > > Could these not be hidden from the generic arm_pmu and kept in the > arm64 pmu backend ? It looks like they are quite easy to simply > move these to the corresponding hooks in arm64 pmu. We have had this discussion multiple times in the past [1], but I still believe, keeping BRBE implementation hooks at the PMU level rather than embedding them with other PMU events handling, is a much better logical abstraction. [1] https://lore.kernel.org/all/c3804290-bdb1-d1eb-3526-9b0ce4c8e8b1@arm.com/ -------------------------------------------------------------------------- > > One thing to answer in the commit msg is why we need the hooks here. > Have we concluded that adding BRBE hooks to struct arm_pmu for what is > an armv8 specific feature is the right approach? I don't recall > reaching that conclusion. Although it might be possible to have this implementation embedded in the existing armv8 PMU implementation, I still believe that the BRBE functionalities abstracted out at the arm_pmu level with a separate config option is cleaner, easier to follow and to maintain as well. Besides some helpers i.e brbe_supported(), brbe_probe() and brbe_reset() might not fit seamlessly, when tried to be embedded via existing arm_pmu helpers in the armv8 implementation. Nonetheless if arm_pmu based additional BRBE helpers is absolutely a no go for folks here in general, will explore arm64 based implementation. ---------------------------------------------------------------------------- I am still waiting for maintainer's take on this issue. I will be happy to rework this series to move all these implementation inside arm64 callbacks instead, if that is required or preferred by the maintainers. But according to me, this current abstraction layout is much better. - Anshuman
Hi Anshuman, Apologies for the delayi n reviewing this. On Fri, Nov 18, 2022 at 12:09:07PM +0530, Anshuman Khandual wrote: > On 11/9/22 17:00, Suzuki K Poulose wrote: > > On 07/11/2022 06:25, Anshuman Khandual wrote: > >> Although BRBE is an armv8 speciifc HW feature, abstracting out its various > >> function callbacks at the struct arm_pmu level is preferred, as it cleaner > >> , easier to follow and maintain. > >> > >> Besides some helpers i.e brbe_supported(), brbe_probe() and brbe_reset() > >> might not fit seamlessly, when tried to be embedded via existing arm_pmu > >> helpers in the armv8 implementation. > >> > >> Updates the struct arm_pmu to include all required helpers that will drive > >> BRBE functionality for a given PMU implementation. These are the following. > >> > >> - brbe_filter : Convert perf event filters into BRBE HW filters > >> - brbe_probe : Probe BRBE HW and capture its attributes > >> - brbe_enable : Enable BRBE HW with a given config > >> - brbe_disable : Disable BRBE HW > >> - brbe_read : Read BRBE buffer for captured branch records > >> - brbe_reset : Reset BRBE buffer > >> - brbe_supported: Whether BRBE is supported or not > >> > >> A BRBE driver implementation needs to provide these functionalities. > > > > Could these not be hidden from the generic arm_pmu and kept in the > > arm64 pmu backend ? It looks like they are quite easy to simply > > move these to the corresponding hooks in arm64 pmu. > > We have had this discussion multiple times in the past [1], but I still > believe, keeping BRBE implementation hooks at the PMU level rather than > embedding them with other PMU events handling, is a much better logical > abstraction. > > [1] https://lore.kernel.org/all/c3804290-bdb1-d1eb-3526-9b0ce4c8e8b1@arm.com/ > > -------------------------------------------------------------------------- > > > > One thing to answer in the commit msg is why we need the hooks here. > > Have we concluded that adding BRBE hooks to struct arm_pmu for what is > > an armv8 specific feature is the right approach? I don't recall > > reaching that conclusion. > > Although it might be possible to have this implementation embedded in > the existing armv8 PMU implementation, I still believe that the BRBE > functionalities abstracted out at the arm_pmu level with a separate > config option is cleaner, easier to follow and to maintain as well. > > Besides some helpers i.e brbe_supported(), brbe_probe() and brbe_reset() > might not fit seamlessly, when tried to be embedded via existing arm_pmu > helpers in the armv8 implementation. > > Nonetheless if arm_pmu based additional BRBE helpers is absolutely a no > go for folks here in general, will explore arm64 based implementation. > ---------------------------------------------------------------------------- > > I am still waiting for maintainer's take on this issue. I will be happy to > rework this series to move all these implementation inside arm64 callbacks > instead, if that is required or preferred by the maintainers. But according > to me, this current abstraction layout is much better. To be honest, I'm not sure what's best right now; but at the moment it's not clear to me why this couldn't fit within the existing hooks. Above you say brbe_supported() / brbe_probe() / brbe_reset() didn't fit seamlessly; can you give an example of problem? I think I'm missing something obvious. Thanks, Mark.
On 11/18/22 23:17, Mark Rutland wrote: > > Hi Anshuman, > > Apologies for the delayi n reviewing this. > > On Fri, Nov 18, 2022 at 12:09:07PM +0530, Anshuman Khandual wrote: >> On 11/9/22 17:00, Suzuki K Poulose wrote: >>> On 07/11/2022 06:25, Anshuman Khandual wrote: >>>> Although BRBE is an armv8 speciifc HW feature, abstracting out its various >>>> function callbacks at the struct arm_pmu level is preferred, as it cleaner >>>> , easier to follow and maintain. >>>> >>>> Besides some helpers i.e brbe_supported(), brbe_probe() and brbe_reset() >>>> might not fit seamlessly, when tried to be embedded via existing arm_pmu >>>> helpers in the armv8 implementation. >>>> >>>> Updates the struct arm_pmu to include all required helpers that will drive >>>> BRBE functionality for a given PMU implementation. These are the following. >>>> >>>> - brbe_filter : Convert perf event filters into BRBE HW filters >>>> - brbe_probe : Probe BRBE HW and capture its attributes >>>> - brbe_enable : Enable BRBE HW with a given config >>>> - brbe_disable : Disable BRBE HW >>>> - brbe_read : Read BRBE buffer for captured branch records >>>> - brbe_reset : Reset BRBE buffer >>>> - brbe_supported: Whether BRBE is supported or not >>>> >>>> A BRBE driver implementation needs to provide these functionalities. >>> >>> Could these not be hidden from the generic arm_pmu and kept in the >>> arm64 pmu backend ? It looks like they are quite easy to simply >>> move these to the corresponding hooks in arm64 pmu. >> >> We have had this discussion multiple times in the past [1], but I still >> believe, keeping BRBE implementation hooks at the PMU level rather than >> embedding them with other PMU events handling, is a much better logical >> abstraction. >> >> [1] https://lore.kernel.org/all/c3804290-bdb1-d1eb-3526-9b0ce4c8e8b1@arm.com/ >> >> -------------------------------------------------------------------------- >>> >>> One thing to answer in the commit msg is why we need the hooks here. >>> Have we concluded that adding BRBE hooks to struct arm_pmu for what is >>> an armv8 specific feature is the right approach? I don't recall >>> reaching that conclusion. >> >> Although it might be possible to have this implementation embedded in >> the existing armv8 PMU implementation, I still believe that the BRBE >> functionalities abstracted out at the arm_pmu level with a separate >> config option is cleaner, easier to follow and to maintain as well. >> >> Besides some helpers i.e brbe_supported(), brbe_probe() and brbe_reset() >> might not fit seamlessly, when tried to be embedded via existing arm_pmu >> helpers in the armv8 implementation. >> >> Nonetheless if arm_pmu based additional BRBE helpers is absolutely a no >> go for folks here in general, will explore arm64 based implementation. >> ---------------------------------------------------------------------------- >> >> I am still waiting for maintainer's take on this issue. I will be happy to >> rework this series to move all these implementation inside arm64 callbacks >> instead, if that is required or preferred by the maintainers. But according >> to me, this current abstraction layout is much better. > > To be honest, I'm not sure what's best right now; but at the moment it's not > clear to me why this couldn't fit within the existing hooks. > > Above you say brbe_supported() / brbe_probe() / brbe_reset() didn't fit > seamlessly; can you give an example of problem? I think I'm missing something > obvious. I tried to move them inside armv8 implementation callbacks. arm64_pmu_brbe_supported() can be moved inside __armv8_pmuv3_map_event(), so that event viability can be validated during armpmu_event_init(). arm64_pmu_brbe_probe() can be moved inside __armv8pmu_probe_pmu() as you have suggested earlier on another thread. arm64_pmu_brbe_reset() can also be moved inside armv8pmu_enable_event(), and also armv8pmu_reset(). The only problem being armpmu_sched_task() where earlier we had BRBE reset, but I guess it can be replaced with entire PMU reset which does the BRBE reset as well ? static void armpmu_sched_task(struct perf_event_context *ctx, bool sched_in) { struct arm_pmu *armpmu = to_arm_pmu(ctx->pmu); if (sched_in) armpmu->reset(armpmu); }
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c index 7b0643fe2f13..c97377e28288 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -1025,6 +1025,35 @@ static int armv8pmu_filter_match(struct perf_event *event) return evtype != ARMV8_PMUV3_PERFCTR_CHAIN; } +static void armv8pmu_brbe_filter(struct pmu_hw_events *hw_event, struct perf_event *event) +{ +} + +static void armv8pmu_brbe_enable(struct pmu_hw_events *hw_event) +{ +} + +static void armv8pmu_brbe_disable(struct pmu_hw_events *hw_event) +{ +} + +static void armv8pmu_brbe_read(struct pmu_hw_events *hw_event, struct perf_event *event) +{ +} + +static void armv8pmu_brbe_probe(struct pmu_hw_events *hw_event) +{ +} + +static void armv8pmu_brbe_reset(struct pmu_hw_events *hw_event) +{ +} + +static bool armv8pmu_brbe_supported(struct perf_event *event) +{ + return false; +} + static void armv8pmu_reset(void *info) { struct arm_pmu *cpu_pmu = (struct arm_pmu *)info; @@ -1257,6 +1286,13 @@ static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name, cpu_pmu->pmu.event_idx = armv8pmu_user_event_idx; + cpu_pmu->brbe_filter = armv8pmu_brbe_filter; + cpu_pmu->brbe_enable = armv8pmu_brbe_enable; + cpu_pmu->brbe_disable = armv8pmu_brbe_disable; + cpu_pmu->brbe_read = armv8pmu_brbe_read; + cpu_pmu->brbe_probe = armv8pmu_brbe_probe; + cpu_pmu->brbe_reset = armv8pmu_brbe_reset; + cpu_pmu->brbe_supported = armv8pmu_brbe_supported; cpu_pmu->name = name; cpu_pmu->map_event = map_event; cpu_pmu->attr_groups[ARMPMU_ATTR_GROUP_EVENTS] = events ? diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index 0356cb6a215d..67a6d59786f2 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -101,6 +101,27 @@ struct arm_pmu { void (*reset)(void *); int (*map_event)(struct perf_event *event); int (*filter_match)(struct perf_event *event); + + /* Convert perf event filters into BRBE HW filters */ + void (*brbe_filter)(struct pmu_hw_events *hw_events, struct perf_event *event); + + /* Probe BRBE HW and capture its attributes */ + void (*brbe_probe)(struct pmu_hw_events *hw_events); + + /* Enable BRBE HW with a given config */ + void (*brbe_enable)(struct pmu_hw_events *hw_events); + + /* Disable BRBE HW */ + void (*brbe_disable)(struct pmu_hw_events *hw_events); + + /* Process BRBE buffer for captured branch records */ + void (*brbe_read)(struct pmu_hw_events *hw_events, struct perf_event *event); + + /* Reset BRBE buffer */ + void (*brbe_reset)(struct pmu_hw_events *hw_events); + + /* Check whether BRBE is supported */ + bool (*brbe_supported)(struct perf_event *event); int num_events; bool secure_access; /* 32-bit ARM only */ #define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40