From patchwork Thu Jun 22 06:53:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13288395 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 47643EB64D8 for ; Thu, 22 Jun 2023 08:00:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=lEL5pL3/8Xq/V7dLlrlnfTXmGDfF6aWV00forpBB5kY=; b=ZMS46EPoDdiR44 UlsGfJCtHVeHykZuCo/0sFnUBQgc7gLdpMqrYTY37vmfGo1hobBhnYDmJAe+aZjTj+0Bpmd4rUAt0 yO2DjHpk9qO8X9jhGfqqQbRkxG1fqSRg++P+9XCSgAc9pdeqX6TcUP/hawdll9+eKAQOH8R9B1HBZ +CHEwTuA+bUk3MeAWgWgWmGYSTbcAJO3tNC8Bv7NfvN7lzbWp7rhP7MRSKpgQoccYsCV9DBwfqApt qY+LoH6ujh97wtvtXrt04M18ebxZ2tXKIAPycGfYrR6beIzmqeBh2CCnn1OSlbRLKTR+0I2Fz1cwP hGAZsxkWUSirTLuSh8iw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qCFF8-00HLiI-23; Thu, 22 Jun 2023 08:00:38 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qCEDe-00H7aU-0M for linux-arm-kernel@lists.infradead.org; Thu, 22 Jun 2023 06:55:04 +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 0A1A71063; Wed, 21 Jun 2023 23:55:45 -0700 (PDT) Received: from a077893.blr.arm.com (unknown [10.162.40.20]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A3ACB3F59C; Wed, 21 Jun 2023 23:54:56 -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 V13 10/10] arm64/perf: Implement branch records save on PMU IRQ Date: Thu, 22 Jun 2023 12:23:51 +0530 Message-Id: <20230622065351.1092893-11-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230622065351.1092893-1-anshuman.khandual@arm.com> References: <20230622065351.1092893-1-anshuman.khandual@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230621_235502_265098_9EADF349 X-CRM114-Status: GOOD ( 16.43 ) 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 This modifies armv8pmu_branch_read() to concatenate live entries along with task context stored entries and then process the resultant buffer to create perf branch entry array for perf_sample_data. It follows the same principle like task sched out. 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 Acked-by: Mark Rutland Signed-off-by: Anshuman Khandual --- drivers/perf/arm_brbe.c | 69 +++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/drivers/perf/arm_brbe.c b/drivers/perf/arm_brbe.c index 2177632befa6..cb765aaf1b52 100644 --- a/drivers/perf/arm_brbe.c +++ b/drivers/perf/arm_brbe.c @@ -647,41 +647,44 @@ void armv8pmu_branch_reset(void) isb(); } -static bool capture_branch_entry(struct pmu_hw_events *cpuc, - struct perf_event *event, int idx) +static void brbe_regset_branch_entries(struct pmu_hw_events *cpuc, struct perf_event *event, + struct brbe_regset *regset, int idx) { struct perf_branch_entry *entry = &cpuc->branches->branch_entries[idx]; - u64 brbinf = get_brbinf_reg(idx); - - /* - * There are no valid entries anymore on the buffer. - * Abort the branch record processing to save some - * cycles and also reduce the capture/process load - * for the user space as well. - */ - if (brbe_invalid(brbinf)) - return false; + u64 brbinf = regset[idx].brbinf; perf_clear_branch_entry_bitfields(entry); if (brbe_record_is_complete(brbinf)) { - entry->from = get_brbsrc_reg(idx); - entry->to = get_brbtgt_reg(idx); + entry->from = regset[idx].brbsrc; + entry->to = regset[idx].brbtgt; } else if (brbe_record_is_source_only(brbinf)) { - entry->from = get_brbsrc_reg(idx); + entry->from = regset[idx].brbsrc; entry->to = 0; } else if (brbe_record_is_target_only(brbinf)) { entry->from = 0; - entry->to = get_brbtgt_reg(idx); + entry->to = regset[idx].brbtgt; } capture_brbe_flags(entry, event, brbinf); - return true; +} + +static void process_branch_entries(struct pmu_hw_events *cpuc, struct perf_event *event, + struct brbe_regset *regset, int nr_regset) +{ + int idx; + + for (idx = 0; idx < nr_regset; idx++) + brbe_regset_branch_entries(cpuc, event, regset, idx); + + cpuc->branches->branch_stack.nr = nr_regset; + cpuc->branches->branch_stack.hw_idx = -1ULL; } void armv8pmu_branch_read(struct pmu_hw_events *cpuc, struct perf_event *event) { - int nr_hw_entries = brbe_get_numrec(cpuc->percpu_pmu->reg_brbidr); + struct arm64_perf_task_context *task_ctx = event->pmu_ctx->task_ctx_data; + struct brbe_regset live[BRBE_MAX_ENTRIES]; + int nr_live, nr_store, nr_hw_entries; u64 brbfcr, brbcr; - int idx = 0; brbcr = read_sysreg_s(SYS_BRBCR_EL1); brbfcr = read_sysreg_s(SYS_BRBFCR_EL1); @@ -693,25 +696,17 @@ void armv8pmu_branch_read(struct pmu_hw_events *cpuc, struct perf_event *event) write_sysreg_s(brbfcr | BRBFCR_EL1_PAUSED, SYS_BRBFCR_EL1); isb(); - /* Loop through bank 0 */ - select_brbe_bank(BRBE_BANK_IDX_0); - while (idx < nr_hw_entries && idx <= BRBE_BANK0_IDX_MAX) { - if (!capture_branch_entry(cpuc, event, idx)) - goto skip_bank_1; - idx++; - } - - /* Loop through bank 1 */ - select_brbe_bank(BRBE_BANK_IDX_1); - while (idx < nr_hw_entries && idx <= BRBE_BANK1_IDX_MAX) { - if (!capture_branch_entry(cpuc, event, idx)) - break; - idx++; + nr_hw_entries = brbe_get_numrec(cpuc->percpu_pmu->reg_brbidr); + nr_live = capture_brbe_regset(live, nr_hw_entries); + if (event->ctx->task) { + nr_store = task_ctx->nr_brbe_records; + nr_store = stitch_stored_live_entries(task_ctx->store, live, nr_store, + nr_live, nr_hw_entries); + process_branch_entries(cpuc, event, task_ctx->store, nr_store); + task_ctx->nr_brbe_records = 0; + } else { + process_branch_entries(cpuc, event, live, nr_live); } - -skip_bank_1: - cpuc->branches->branch_stack.nr = idx; - cpuc->branches->branch_stack.hw_idx = -1ULL; process_branch_aborts(cpuc); /* Unpause the buffer */