From patchwork Wed May 31 04:04:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 101229 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2634859vqr; Tue, 30 May 2023 21:41:54 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69TcajxZC2x/bnzCwwkWm8mhUP8jU/wYFpbnvXN/+JndSeV6ZUlMFGLtGbCCwsH5qm7UH4 X-Received: by 2002:a05:6808:3025:b0:398:29ce:81f7 with SMTP id ay37-20020a056808302500b0039829ce81f7mr2791414oib.11.1685508113472; Tue, 30 May 2023 21:41:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685508113; cv=none; d=google.com; s=arc-20160816; b=v3ppQHBclNTbVkrMpMLfv5zHxCg9INLlLRxBafekfuN5wsOe6SWnboRq0ywmZYlgW2 3icYQ+ScfnjrITQe8+xWa8eD4VcyOTws11aXiXc2Pq835+MtJc2T08e98W+VQs4gA5Ph kI7lPJ4Wt9yQHk/TDxmHpyTMjuFSyMvWW7JF8TdN3DmpCejDhzcCWiuUYAbMrML9mXk4 1rCLJ3ZnYGEbE3wMZWd6M0JfFIqqZzy20i41tFHNtN5jsL1uG3p63+17RgYqUglx82lt DSIM9vjUhcKbOOlJxUu8er2y85CAJIAMUobaS28UpSvaWiCwf3cfm9UnXlf9zGTePwLN CvWQ== 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=n3+m5C1RzAdusOr8unmcOZz1ysqV38JhqFjcUJ8hLjw=; b=QPSDXWE0ftOK21+84wduzND58dUvwITtc1VzAoknBKfS7e00BDrhE7IvgZMlTed87x EH+ofqTwZWjfAqzFGpFts7IB4cYwT/2TXdjzXq+MnAjgF3zaTWWnEAZa8R589uLxyfqY V2scril1a8cwZfS2luU/Dze8gA+phKCFyGh0xLlz0SQBIb4ntsleI+2xIZ8C99SNQOwU HJWiZETob9WHcnoqhIaMUC1rdZrpjjRNRfcrsAvysKaFyFy52ljT9o6fkx+8cCBPM0OJ XA8ko1tA8DtCvg3kmoABxHcbxeWqnrix60lFA03ajIPyawo8rPQx7BeRfce6I+VqB9Rd B1NQ== 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 q30-20020a638c5e000000b0053fb32e621bsi271328pgn.896.2023.05.30.21.41.39; Tue, 30 May 2023 21:41:53 -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 S234256AbjEaEGe (ORCPT + 99 others); Wed, 31 May 2023 00:06:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234119AbjEaEFy (ORCPT ); Wed, 31 May 2023 00:05:54 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C17A0E5D; Tue, 30 May 2023 21:05:38 -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 89A9C15BF; Tue, 30 May 2023 21:06:23 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.73.163]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 05EA33F6C4; Tue, 30 May 2023 21:05:32 -0700 (PDT) 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 V11 07/10] arm64/perf: Add PERF_ATTACH_TASK_DATA to events with has_branch_stack() Date: Wed, 31 May 2023 09:34:25 +0530 Message-Id: <20230531040428.501523-8-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230531040428.501523-1-anshuman.khandual@arm.com> References: <20230531040428.501523-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,T_SCC_BODY_TEXT_LINE 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?1767383356031529464?= X-GMAIL-MSGID: =?utf-8?q?1767383356031529464?= Short running processes i.e those getting very small cpu run time each time when they get scheduled on, might not accumulate much branch records before a PMU IRQ really happens. This increases possibility, for such processes to loose much of its branch records, while being scheduled in-out of various cpus on the system. There is a need to save all occurred branch records during the cpu run time while the process gets scheduled out. It requires an event context specific buffer for such storage. This adds PERF_ATTACH_TASK_DATA flag unconditionally, for all branch stack sampling events, which would allocate task_ctx_data during its event init. This also creates a platform specific task_ctx_data kmem cache which will serve such allocation requests. This adds a new structure 'arm64_perf_task_context' which encapsulates brbe register set for maximum possible BRBE entries on the HW along with a valid records tracking element. Cc: Catalin Marinas Cc: Will Deacon Cc: Mark Rutland Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Tested-by: James Clark Signed-off-by: Anshuman Khandual --- drivers/perf/arm_brbe.c | 13 +++++++++++++ drivers/perf/arm_brbe.h | 13 +++++++++++++ drivers/perf/arm_pmuv3.c | 8 ++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/drivers/perf/arm_brbe.c b/drivers/perf/arm_brbe.c index 34547ad750ad..484842d8cf3e 100644 --- a/drivers/perf/arm_brbe.c +++ b/drivers/perf/arm_brbe.c @@ -109,20 +109,33 @@ bool armv8pmu_branch_valid(struct perf_event *event) return true; } +static inline struct kmem_cache * +arm64_create_brbe_task_ctx_kmem_cache(size_t size) +{ + return kmem_cache_create("arm64_brbe_task_ctx", size, 0, 0, NULL); +} + int armv8pmu_private_alloc(struct arm_pmu *arm_pmu) { struct brbe_hw_attr *brbe_attr = kzalloc(sizeof(struct brbe_hw_attr), GFP_KERNEL); + size_t size = sizeof(struct arm64_perf_task_context); if (!brbe_attr) return -ENOMEM; arm_pmu->private = brbe_attr; + arm_pmu->pmu.task_ctx_cache = arm64_create_brbe_task_ctx_kmem_cache(size); + if (!arm_pmu->pmu.task_ctx_cache) { + kfree(arm_pmu->private); + return -ENOMEM; + } return 0; } void armv8pmu_private_free(struct arm_pmu *arm_pmu) { kfree(arm_pmu->private); + kmem_cache_destroy(arm_pmu->pmu.task_ctx_cache); } static int brbe_attributes_probe(struct arm_pmu *armpmu, u32 brbe) diff --git a/drivers/perf/arm_brbe.h b/drivers/perf/arm_brbe.h index a47480eec070..4a72c2ba7140 100644 --- a/drivers/perf/arm_brbe.h +++ b/drivers/perf/arm_brbe.h @@ -80,12 +80,25 @@ * --------------------------------- ------ */ #define BRBE_BANK_MAX_ENTRIES 32 +#define BRBE_MAX_BANK 2 +#define BRBE_MAX_ENTRIES (BRBE_BANK_MAX_ENTRIES * BRBE_MAX_BANK) #define BRBE_BANK0_IDX_MIN 0 #define BRBE_BANK0_IDX_MAX 31 #define BRBE_BANK1_IDX_MIN 32 #define BRBE_BANK1_IDX_MAX 63 +struct brbe_regset { + unsigned long brbsrc; + unsigned long brbtgt; + unsigned long brbinf; +}; + +struct arm64_perf_task_context { + struct brbe_regset store[BRBE_MAX_ENTRIES]; + int nr_brbe_records; +}; + struct brbe_hw_attr { int brbe_version; int brbe_cc; diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c index fef1bc6067cc..29672ff20026 100644 --- a/drivers/perf/arm_pmuv3.c +++ b/drivers/perf/arm_pmuv3.c @@ -1022,8 +1022,12 @@ static int __armv8_pmuv3_map_event(struct perf_event *event, hw_event_id = __armv8_pmuv3_map_event_id(armpmu, event); - if (has_branch_stack(event) && !armv8pmu_branch_valid(event)) - return -EOPNOTSUPP; + if (has_branch_stack(event)) { + if (!armv8pmu_branch_valid(event)) + return -EOPNOTSUPP; + + event->attach_state |= PERF_ATTACH_TASK_DATA; + } /* * CHAIN events only work when paired with an adjacent counter, and it