Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1267038rwb; Sun, 6 Nov 2022 22:38:55 -0800 (PST) X-Google-Smtp-Source: AMsMyM4tx7SiooIwWxHmj3VHbV/fTJVkW3dm9ss8qnACh4gz0gkcnlqBqjyOvdJl29dDlxeuxBm5 X-Received: by 2002:a17:906:8a63:b0:7ad:95cf:726a with SMTP id hy3-20020a1709068a6300b007ad95cf726amr46795924ejc.82.1667803135625; Sun, 06 Nov 2022 22:38:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667803135; cv=none; d=google.com; s=arc-20160816; b=tOd+B7Ojw3wOMNfQpZNLVjAXgVB6qCsMdByGYdul3oTqzZDVMWEA3MnKoECsXgM4Ng TeTimem2w6iN8CIAAx/oSul+xjmGCj5mTagt9kUMK3ENKJc/gf1VcAZ959XFaSc1JkMw IndZoJsOvoiEkAc+5r6ASh4jijqsS+kej/doc8FKvJNOGAnitm50gGeGVE7TgWK/P2hn dgRwPvDWgX3cqWUmoUYsYRNUydB6jmeZbczUD96y414WSPO2jU8kbsEbSLgcRmaaBxJ7 4g7vaek7yR7heAI82csoMCqj0XUHVXmJeUUov/eaN3w8seDuZbpYR9JqZh36Fq406WV9 Z8qw== 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 :message-id:date:subject:cc:to:from; bh=gyqlv2IOogYln/VylhivP6fsoP5uu5csDUVztzwQv94=; b=rsUZJsvTIz3jnJFcBVSdLG1/uGYyxnxN4D271zPqT4JQpnLuGKJn9Q7oXVgBlOAsnY 1jvnkt10tfGyaz2YDp9rTUC5k/MJ33Yf8ezHc+M+u+3ZYRstUy7rAWrtvImdEeEDujG5 RyofYDfhtzsL9HP89F1et+4J+KxR8EUb6DyiPmig9jcwSfK+poEO+lbIJ+3GvJxdAidT f93C3oXC7BbO8SWr48ALwic1mGeGU4z2SssOUQ30AbLgZHuX8x1Qyww63Nz6mYrbQQWI Ya4hOcHbmp84uS5HJeI1FypSAnIkDfGUmfW3N20f9StMaDkz6Zk4slDrLXFtj+S1wEem VMYg== 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 gu20-20020a170906f29400b007ae29da29d9si6467061ejb.131.2022.11.06.22.38.30; Sun, 06 Nov 2022 22:38:55 -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 S231268AbiKGGZk (ORCPT + 96 others); Mon, 7 Nov 2022 01:25:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229768AbiKGGZi (ORCPT ); Mon, 7 Nov 2022 01:25:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1F23110551; Sun, 6 Nov 2022 22:25:37 -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 B15B81FB; Sun, 6 Nov 2022 22:25:42 -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 9FCC13F534; Sun, 6 Nov 2022 22:25:31 -0800 (PST) From: Anshuman Khandual 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 , Mark Brown , James Clark , Rob Herring , Marc Zyngier , Suzuki Poulose , Ingo Molnar Subject: [PATCH V5 0/7] arm64/perf: Enable branch stack sampling Date: Mon, 7 Nov 2022 11:55:07 +0530 Message-Id: <20221107062514.2851047-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 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: X-Mailing-List: linux-kernel@vger.kernel.org This series enables perf branch stack sampling support on arm64 platform via a new arch feature called Branch Record Buffer Extension (BRBE). All relevant register definitions could be accessed here. https://developer.arm.com/documentation/ddi0601/2021-12/AArch64-Registers This series applies on v6.1-rc4. Changes in V5: - Changed BRBCR_EL1.VIRTUAL from 0b1 to 0b01 - Changed BRBFCR_EL1.EnL into BRBFCR_EL1.EnI - Changed config ARM_BRBE_PMU from 'tristate' to 'bool' Changes in V4: https://lore.kernel.org/all/20221017055713.451092-1-anshuman.khandual@arm.com/ - Changed ../tools/sysreg declarations as suggested - Set PERF_SAMPLE_BRANCH_STACK in data.sample_flags - Dropped perfmon_capable() check in armpmu_event_init() - s/pr_warn_once/pr_info in armpmu_event_init() - Added brbe_format element into struct pmu_hw_events - Changed v1p1 as brbe_v1p1 in struct pmu_hw_events - Dropped pr_info() from arm64_pmu_brbe_probe(), solved LOCKDEP warning Changes in V3: https://lore.kernel.org/all/20220929075857.158358-1-anshuman.khandual@arm.com/ - Moved brbe_stack from the stack and now dynamically allocated - Return PERF_BR_PRIV_UNKNOWN instead of -1 in brbe_fetch_perf_priv() - Moved BRBIDR0, BRBCR, BRBFCR registers and fields into tools/sysreg - Created dummy BRBINF_EL1 field definitions in tools/sysreg - Dropped ARMPMU_EVT_PRIV framework which cached perfmon_capable() - Both exception and exception return branche records are now captured only if the event has PERF_SAMPLE_BRANCH_KERNEL which would already been checked in generic perf via perf_allow_kernel() Changes in V2: https://lore.kernel.org/all/20220908051046.465307-1-anshuman.khandual@arm.com/ - Dropped branch sample filter helpers consolidation patch from this series - Added new hw_perf_event.flags element ARMPMU_EVT_PRIV to cache perfmon_capable() - Use cached perfmon_capable() while configuring BRBE branch record filters Changes in V1: https://lore.kernel.org/linux-arm-kernel/20220613100119.684673-1-anshuman.khandual@arm.com/ - Added CONFIG_PERF_EVENTS wrapper for all branch sample filter helpers - Process new perf branch types via PERF_BR_EXTEND_ABI Changes in RFC V2: https://lore.kernel.org/linux-arm-kernel/20220412115455.293119-1-anshuman.khandual@arm.com/ - Added branch_sample_priv() while consolidating other branch sample filter helpers - Changed all SYS_BRBXXXN_EL1 register definition encodings per Marc - Changed the BRBE driver as per proposed BRBE related perf ABI changes (V5) - Added documentation for struct arm_pmu changes, updated commit message - Updated commit message for BRBE detection infrastructure patch - PERF_SAMPLE_BRANCH_KERNEL gets checked during arm event init (outside the driver) - Branch privilege state capture mechanism has now moved inside the driver Changes in RFC V1: https://lore.kernel.org/all/1642998653-21377-1-git-send-email-anshuman.khandual@arm.com/ Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: Mark Brown Cc: James Clark Cc: Rob Herring Cc: Marc Zyngier Cc: Suzuki Poulose Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Arnaldo Carvalho de Melo Cc: linux-arm-kernel@lists.infradead.org Cc: linux-perf-users@vger.kernel.org Cc: linux-kernel@vger.kernel.org Anshuman Khandual (7): arm64/perf: Add BRBE registers and fields arm64/perf: Update struct arm_pmu for BRBE arm64/perf: Update struct pmu_hw_events for BRBE driver/perf/arm_pmu_platform: Add support for BRBE attributes detection arm64/perf: Drive BRBE from perf event states arm64/perf: Add BRBE driver arm64/perf: Enable branch stack sampling arch/arm64/include/asm/sysreg.h | 103 ++++++++ arch/arm64/kernel/perf_event.c | 49 ++++ arch/arm64/tools/sysreg | 161 ++++++++++++ drivers/perf/Kconfig | 11 + drivers/perf/Makefile | 1 + drivers/perf/arm_pmu.c | 66 ++++- drivers/perf/arm_pmu_brbe.c | 441 ++++++++++++++++++++++++++++++++ drivers/perf/arm_pmu_brbe.h | 259 +++++++++++++++++++ drivers/perf/arm_pmu_platform.c | 34 +++ include/linux/perf/arm_pmu.h | 68 +++++ 10 files changed, 1190 insertions(+), 3 deletions(-) create mode 100644 drivers/perf/arm_pmu_brbe.c create mode 100644 drivers/perf/arm_pmu_brbe.h -- 2.25.1