From patchwork Wed May 17 02:24:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 95012 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp839866vqo; Tue, 16 May 2023 19:57:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6prAw683i90GzBcA/jk5r4yo/qIg+OwrfTnZk+S4yB/+DCgBnyN66y0T+7bOF4bB6YLlMw X-Received: by 2002:a05:6a20:a122:b0:103:ef39:a832 with SMTP id q34-20020a056a20a12200b00103ef39a832mr26774219pzk.23.1684292234219; Tue, 16 May 2023 19:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684292234; cv=none; d=google.com; s=arc-20160816; b=aLl8D6EoIrt3nq44E7R2/O5Bt365d2JyFZYRaOdMb8Jqz0/qVjyEzf4v358ZKbvPEJ 1QNrD7+eIOqXJ6Or50G2ddi+hFXQyGF804k32eHddDb1HlCXew6MYmiFwuquJpKA6nwH 32klAxnbxYbZuSkxJ5p0+vlHiBvaDZYq1YblM1GzqA+j7S38sj5DdZen0UC8RzyvIIZX gbPXwARecP1odC+Ql3Z8eVKpy38MKpGPR1zbpoRcdf0CYRydNyVU9+sWgZoqo+uyZSI4 TV7MOd8zAL4gB54McIcKd1hZUeTA2F0qleQNvwifnADWgletJFChy9PahE/dmiD2k6fg Bo4w== 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=YJOkp+Ft2Nywi9cYi4xRHr3abT5R5H3DLqZ7fv53eLM=; b=KL9/g+sZdrZwpu8reMPkuN0/9V1IL1x59TkuPzuyYqTKrOwrpeDs05HGWA0fFs/eVh opUmYVZaNdwyrI7Wzb95tPKBgucH/h04IiIQJ4g/hlHYIOT2SRmazrVyLsIJUop9n2Ys FM8bVBXBdiIf/z5QgiyX0gpNxm20aJf/ZjSMY3wuQ7x/ta/nY9zq/vz91Vl34lqTpfL5 sTDyFxtH7K45Vicsa71Q5MRl1GfSkFmCl39HE4f5LzSsvDsjo1z4lN5A+AKRJCViPKJm Dao6HQOmeX1FaehaLqAiEUsXqdci+3Vm9fmrIknc6SuN5Swv5TCOZq4gzM4PADEwFmKX GDWw== 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 i133-20020a636d8b000000b005305ab8540asi17208016pgc.294.2023.05.16.19.57.02; Tue, 16 May 2023 19:57:14 -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 S232113AbjEQC0L (ORCPT + 99 others); Tue, 16 May 2023 22:26:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232111AbjEQCZv (ORCPT ); Tue, 16 May 2023 22:25:51 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 568691BD9; Tue, 16 May 2023 19:25:22 -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 EADD91FB; Tue, 16 May 2023 19:26:04 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.70.237]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3A2B93F793; Tue, 16 May 2023 19:25:14 -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 V10 10/10] arm64/perf: Implement branch records save on PMU IRQ Date: Wed, 17 May 2023 07:54:10 +0530 Message-Id: <20230517022410.722287-11-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230517022410.722287-1-anshuman.khandual@arm.com> References: <20230517022410.722287-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?1766108413778548813?= X-GMAIL-MSGID: =?utf-8?q?1766108413778548813?= 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 Signed-off-by: Anshuman Khandual --- drivers/perf/arm_brbe.c | 75 +++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/drivers/perf/arm_brbe.c b/drivers/perf/arm_brbe.c index 0678ebf0a896..9e441141a2c3 100644 --- a/drivers/perf/arm_brbe.c +++ b/drivers/perf/arm_brbe.c @@ -693,41 +693,45 @@ 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) { struct brbe_hw_attr *brbe_attr = (struct brbe_hw_attr *)cpuc->percpu_pmu->private; + 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; u64 brbfcr, brbcr; - int idx, loop1_idx1, loop1_idx2, loop2_idx1, loop2_idx2, count; brbcr = read_sysreg_s(SYS_BRBCR_EL1); brbfcr = read_sysreg_s(SYS_BRBFCR_EL1); @@ -739,36 +743,13 @@ void armv8pmu_branch_read(struct pmu_hw_events *cpuc, struct perf_event *event) write_sysreg_s(brbfcr | BRBFCR_EL1_PAUSED, SYS_BRBFCR_EL1); isb(); - /* Determine the indices for each loop */ - loop1_idx1 = BRBE_BANK0_IDX_MIN; - if (brbe_attr->brbe_nr <= BRBE_BANK_MAX_ENTRIES) { - loop1_idx2 = brbe_attr->brbe_nr - 1; - loop2_idx1 = BRBE_BANK1_IDX_MIN; - loop2_idx2 = BRBE_BANK0_IDX_MAX; - } else { - loop1_idx2 = BRBE_BANK0_IDX_MAX; - loop2_idx1 = BRBE_BANK1_IDX_MIN; - loop2_idx2 = brbe_attr->brbe_nr - 1; - } - - /* Loop through bank 0 */ - select_brbe_bank(BRBE_BANK_IDX_0); - for (idx = 0, count = loop1_idx1; count <= loop1_idx2; idx++, count++) { - if (!capture_branch_entry(cpuc, event, idx)) - goto skip_bank_1; - } - - /* Loop through bank 1 */ - select_brbe_bank(BRBE_BANK_IDX_1); - for (count = loop2_idx1; count <= loop2_idx2; idx++, count++) { - if (!capture_branch_entry(cpuc, event, idx)) - break; - } - -skip_bank_1: - cpuc->branches->branch_stack.nr = idx; - cpuc->branches->branch_stack.hw_idx = -1ULL; + nr_live = capture_brbe_regset(brbe_attr, live); + nr_store = task_ctx->nr_brbe_records; + nr_store = stitch_stored_live_entries(task_ctx->store, live, nr_store, + nr_live, brbe_attr->brbe_nr); + process_branch_entries(cpuc, event, task_ctx->store, nr_store); process_branch_aborts(cpuc); + task_ctx->nr_brbe_records = 0; /* Unpause the buffer */ write_sysreg_s(brbfcr & ~BRBFCR_EL1_PAUSED, SYS_BRBFCR_EL1);