From patchwork Mon Jan 23 12:59:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 47137 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1593948wrn; Mon, 23 Jan 2023 05:01:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXslM9wUOp5JhqQy5OoCfqMPzp1vBgMVLoOtjuWkTRQs7HFRNXNkLupcZy3mkglq4TlpQhKA X-Received: by 2002:a17:90b:4f81:b0:229:ecf1:f2ba with SMTP id qe1-20020a17090b4f8100b00229ecf1f2bamr16313964pjb.31.1674478881103; Mon, 23 Jan 2023 05:01:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674478881; cv=none; d=google.com; s=arc-20160816; b=c/94zL4umAhaDG5KKNn81WR9ApEvdu2l57wKvvJaklV1jMH1C6YEmc1YrfWU7Y3Rn1 mkKYMOKXc0j77JpHeqNLHBZOagSO4DMmN7lVMmbpzGuy8GA2yw/G9HvvWtqtpMd0eqYA zG2FtsY7N7j2spET0o6CTCkvOr9pLkarORWzUpJvYSONaBQYORISP00IJ0HlWbQ4IvvE G2QsieQhQx3s+11giZ2HPSX3QSFE8UnhW5Mcfv4f5bbvdU16jJMcQOrFjHc9nbHdc+0a thi6kvAGFjdtqQ0DFdJ/EFxNEigpLKdokLqF6cMlbrHiTf5zuwyzdzasPCEzpfGulnzu Kr+A== 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=PGAZ7UuQDx3o6DdQUzfhmuTBVJkypG5S5+v5DyEvUB4=; b=dtWMB/VlYG8DUIjaihBglgmUB15/tgA91vxKbhNHARz4ydjLc4rtNZVj8NtRyZErTh dD2yfSNcPYLQjmBLQrjETtcFwohq7gRFdtdsxfGRmNfN4KAyFL7IVQnOFjkRAKfaZ17P 1vQtIEF5jWRLUkP3qBeXLQrZmxLbEP6/MV4ZvdGxvqKMxkQhggz3i/pK8shR0zo9ImR/ lJ5F9hqW9DggD1MfYvVssxhZjwqb1NbQyBDYW2mS15CF87pxhuxTlGL+79fpEdHKPgOY HPh2EzwBS/mBS/yoRGwomsE2A7VXlFZQmfMRPrUxxhNTyrsdtsY1vpUdqeMhn0I+3BZL BvDw== 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 mt18-20020a17090b231200b002290a7e6896si11359334pjb.137.2023.01.23.05.01.07; Mon, 23 Jan 2023 05:01:21 -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 S232101AbjAWNAm (ORCPT + 99 others); Mon, 23 Jan 2023 08:00:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbjAWNAd (ORCPT ); Mon, 23 Jan 2023 08:00:33 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5ECAA241E4; Mon, 23 Jan 2023 05:00:28 -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 CBE77C14; Mon, 23 Jan 2023 05:01:09 -0800 (PST) Received: from a077893.arm.com (unknown [10.163.50.146]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 61C563F64C; Mon, 23 Jan 2023 05:00:22 -0800 (PST) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com Cc: Anshuman Khandual , Mark Brown , James Clark , Rob Herring , Marc Zyngier , Suzuki Poulose , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org Subject: [PATCH V8 3/6] arm64/perf: Add branch stack support in struct arm_pmu Date: Mon, 23 Jan 2023 18:29:53 +0530 Message-Id: <20230123125956.1350336-4-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230123125956.1350336-1-anshuman.khandual@arm.com> References: <20230123125956.1350336-1-anshuman.khandual@arm.com> MIME-Version: 1.0 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755818367101805934?= X-GMAIL-MSGID: =?utf-8?q?1755818367101805934?= This updates 'struct arm_pmu' for branch stack sampling support later. This adds a new 'features' element in the structure to track supported features, and another 'private' element to encapsulate implementation attributes on a given 'struct arm_pmu'. These updates here will help in tracking any branch stack sampling support, which is being added later. This also adds a helper arm_pmu_branch_stack_supported(). This also enables perf branch stack sampling event on all 'struct arm pmu', supporting the feature but after removing the current gate that blocks such events unconditionally in armpmu_event_init(). Instead a quick probe can be initiated via arm_pmu_branch_stack_supported() to ascertain the support. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Anshuman Khandual --- drivers/perf/arm_pmu.c | 3 +-- include/linux/perf/arm_pmu.h | 12 +++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c index 14a3ed3bdb0b..a85b2d67022e 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -510,8 +510,7 @@ static int armpmu_event_init(struct perf_event *event) !cpumask_test_cpu(event->cpu, &armpmu->supported_cpus)) return -ENOENT; - /* does not support taken branch sampling */ - if (has_branch_stack(event)) + if (has_branch_stack(event) && !arm_pmu_branch_stack_supported(armpmu)) return -EOPNOTSUPP; return __hw_perf_event_init(event); diff --git a/include/linux/perf/arm_pmu.h b/include/linux/perf/arm_pmu.h index 2a9d07cee927..78cb1c895ab9 100644 --- a/include/linux/perf/arm_pmu.h +++ b/include/linux/perf/arm_pmu.h @@ -103,7 +103,9 @@ struct arm_pmu { bool (*filter)(struct pmu *pmu, int cpu); void (*sched_task)(struct perf_event_pmu_context *pmu_ctx, bool sched_in); int num_events; - bool secure_access; /* 32-bit ARM only */ + unsigned int secure_access : 1, /* 32-bit ARM only */ + has_branch_stack: 1, /* 64-bit ARM only */ + reserved : 30; #define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40 DECLARE_BITMAP(pmceid_bitmap, ARMV8_PMUV3_MAX_COMMON_EVENTS); #define ARMV8_PMUV3_EXT_COMMON_EVENT_BASE 0x4000 @@ -119,8 +121,16 @@ struct arm_pmu { /* Only to be used by ACPI probing code */ unsigned long acpi_cpuid; + + /* Implementation specific attributes */ + void *private; }; +static inline bool arm_pmu_branch_stack_supported(struct arm_pmu *armpmu) +{ + return armpmu->has_branch_stack; +} + #define to_arm_pmu(p) (container_of(p, struct arm_pmu, pmu)) u64 armpmu_event_update(struct perf_event *event);