From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A09E2C27C77 for ; Mon, 17 Jun 2024 04:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rwUPYjMmuYZFCmO+guxQunSczfeYP49IjaMjsc3zCFM=; b=013ONdJlfvhNBtmfsnZ6HdBwAf sMSXTvpR7jA4ChzWU77y4fnGtB/mSUVr7F6qImzrOx0R5F+6CNiz7FF5ZKUhcY3bPD+QLtNJR/boB bH4hACcCzcSQg2ALLgOmSgpN5Z94wFoQ5CWXQGbRW355Mf/XsbHrK0YvS9oYWc3dscc27EvESzpuu zldXhPv/gI4oQhbldCtewPMLPtNtE4DOgamoqP8pNSBUWp2cBtTqsC/2d5hb0eYy1+7fUXjis/fXw OsfDgiCP1u1Kpi/YkiaTunC7uW7NwWr2rf9VnpoYbGuvzGo2KbjWYGbTFvz8BJQvSOKZbWupDQXYO 54YUynww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJ48A-000000098Xa-2hcQ; Mon, 17 Jun 2024 04:38:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sJ486-000000098Wg-3qUS for linux-arm-kernel@lists.infradead.org; Mon, 17 Jun 2024 04:38:08 +0000 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 98B96DA7; Sun, 16 Jun 2024 21:38:28 -0700 (PDT) Received: from [10.162.16.42] (a077893.blr.arm.com [10.162.16.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2DDAC3F64C; Sun, 16 Jun 2024 21:37:59 -0700 (PDT) Message-ID: Date: Mon, 17 Jun 2024 10:07:57 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH V18 3/9] drivers: perf: arm_pmu: Add infrastructure for branch stack sampling Content-Language: en-US To: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, Mark Brown , James Clark , Rob Herring , Marc Zyngier , Suzuki Poulose , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org References: <20240613061731.3109448-1-anshuman.khandual@arm.com> <20240613061731.3109448-4-anshuman.khandual@arm.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240616_213807_123067_EB1AB14D X-CRM114-Status: GOOD ( 25.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 6/14/24 20:31, Mark Rutland wrote: > On Thu, Jun 13, 2024 at 11:47:25AM +0530, Anshuman Khandual wrote: >> @@ -289,6 +289,23 @@ static void armpmu_start(struct perf_event *event, int flags) >> { >> struct arm_pmu *armpmu = to_arm_pmu(event->pmu); >> struct hw_perf_event *hwc = &event->hw; >> + struct pmu_hw_events *cpuc = this_cpu_ptr(armpmu->hw_events); >> + int idx; >> + >> + /* >> + * Merge all branch filter requests from different perf >> + * events being added into this PMU. This includes both >> + * privilege and branch type filters. >> + */ >> + if (armpmu->has_branch_stack) { >> + cpuc->branch_sample_type = 0; >> + for (idx = 0; idx < ARMPMU_MAX_HWEVENTS; idx++) { >> + struct perf_event *event_idx = cpuc->events[idx]; >> + >> + if (event_idx && has_branch_stack(event_idx)) >> + cpuc->branch_sample_type |= event_idx->attr.branch_sample_type; >> + } >> + } > > When we spoke about this, I meant that we should do this under armpmu::start(), > or a callee or caller thereof once we know all the events are configured, just > before we actually enable the PMU. > > For example, this could live in armv8pmu_branch_enable(), which'd allow > all the actual logic to be added in the BRBE enablement patch. > > Doing this in armpmu_start() doesn't work as well because it won't handle > events being removed. Sure, will move this filter aggregation inside armv8pmu_branch_enable() instead which is being added via the BRBE driver. diff --git a/drivers/perf/arm_brbe.c b/drivers/perf/arm_brbe.c index d795e8fd646f..9cf824bdc8b7 100644 --- a/drivers/perf/arm_brbe.c +++ b/drivers/perf/arm_brbe.c @@ -856,6 +856,22 @@ void armv8pmu_branch_enable(struct arm_pmu *arm_pmu) { struct pmu_hw_events *cpuc = this_cpu_ptr(arm_pmu->hw_events); u64 brbfcr, brbcr; + int idx; + + /* + * Merge all branch filter requests from different perf + * events being added into this PMU. This includes both + * privilege and branch type filters. + */ + if (arm_pmu->has_branch_stack) { + cpuc->branch_sample_type = 0; + for (idx = 0; idx < ARMPMU_MAX_HWEVENTS; idx++) { + struct perf_event *event_idx = cpuc->events[idx]; + + if (event_idx && has_branch_stack(event_idx)) + cpuc->branch_sample_type |= event_idx->attr.branch_sample_type; + } + } if (!(cpuc->branch_sample_type && cpuc->branch_users)) return; > > [...] > >> diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h >> index b3b34f6670cf..9eda16dd684e 100644 >> --- a/include/linux/perf/arm_pmu.h >> +++ b/include/linux/perf/arm_pmu.h >> @@ -46,6 +46,18 @@ static_assert((PERF_EVENT_FLAG_ARCH & ARMPMU_EVT_63BIT) == ARMPMU_EVT_63BIT); >> }, \ >> } >> >> +/* >> + * Maximum branch record entries which could be processed >> + * for core perf branch stack sampling support, regardless >> + * of the hardware support available on a given ARM PMU. >> + */ >> +#define MAX_BRANCH_RECORDS 64 >> + >> +struct branch_records { >> + struct perf_branch_stack branch_stack; >> + struct perf_branch_entry branch_entries[MAX_BRANCH_RECORDS]; >> +}; >> + >> /* The events for a given PMU register set. */ >> struct pmu_hw_events { >> /* >> @@ -66,6 +78,17 @@ struct pmu_hw_events { >> struct arm_pmu *percpu_pmu; >> >> int irq; >> + >> + struct branch_records *branches; >> + >> + /* Active context for task events */ >> + void *branch_context; > > Using 'void *' here makes this harder to reason about and hides type > safety issues. > > Give this a real type. IIUC it should be 'perf_event_context *'. Sure, will change the type. > >> + >> + /* Active events requesting branch records */ >> + unsigned int branch_users; >> + >> + /* Active branch sample type filters */ >> + unsigned long branch_sample_type; >> }; >> >> enum armpmu_attr_groups { >> @@ -96,8 +119,15 @@ struct arm_pmu { >> void (*stop)(struct arm_pmu *); >> void (*reset)(void *); >> int (*map_event)(struct perf_event *event); >> + void (*sched_task)(struct perf_event_pmu_context *pmu_ctx, bool sched_in); >> + bool (*branch_stack_init)(struct perf_event *event); >> + void (*branch_stack_add)(struct perf_event *event, struct pmu_hw_events *cpuc); >> + void (*branch_stack_del)(struct perf_event *event, struct pmu_hw_events *cpuc); >> + void (*branch_stack_reset)(void); > > The reset callback isn't used in this series; s > > Subsequent patches call armv8pmu_branch_stack_reset() directly from > PMUv3 and the BRBE driver, and arm_pmu::branch_stack_reset() is never > used, so we can delete it. Sure, will drop branch_stack_reset() callback.