Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5079349rwd; Sun, 4 Jun 2023 20:17:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7u50yEr1zsE6YajLPq5Y9Q1Y0lzb5SIjuwyvLtnvkHeapS0TuwmXN+Lbq472sa71Xmb6lT X-Received: by 2002:a05:6a20:a31a:b0:114:6390:db06 with SMTP id x26-20020a056a20a31a00b001146390db06mr2128390pzk.32.1685935073497; Sun, 04 Jun 2023 20:17:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685935073; cv=none; d=google.com; s=arc-20160816; b=J6GgLLw6CqernOo1PL3uZhRGGpNG6h4H0uGwU0aWcLDWThTexGPxTtRdvUlsCKe4z1 5Ckp9He7u7J6HpiENqAzgLRBjsK8h1VBuz8eFvBTOb6Vhe6Rxawyy9nXbB9xSJTgP1Vh dZZlqJ0gwUYJDKTjlots587svTYlgC1r8H8ZpSVre0WVUGYY08AbV2TX28l1WH0a0gSA kbOlVTUEQkj5bBck2hfGbKwuyWcDMaeW2k4PCVfHoLD6Ieas9IuPkfueipT7imsLPZd3 DtR9/eqlN2o0dFYFe3FQ23t8UAs+jVw0FGf/NfittearltrTRrpl9AbG4Gg6IrfpTIZ1 IJUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=XEmnm28AFMxlyGbyKFrAx8VzqeLWUZ1lYCBVd+RPrZw=; b=I+B1o67b6APMiYxDnbOyJso1n/i6MKL8arJrHRaosoAHSWO9hv5dF9Zaw8oIgC2aiK rcUMFk7uBXGehz9BMPNaEKT0NTUXtIedha9jU5I25/KhFdx3XvZkcrtHDXlVu5fm1vUb f39FQUrTwKGqzmtQA+o5pBnJVB6gh2aibSzKysfhpfaT7sTQOrylUGTOcA2YqnXbmGfU DnbpkeCv/g3PXEr48nxjvgZtK2nCv0Mj7zm3cVXvd7hvgzsEDKUb9u30AM5s3ATC5cm9 uU82BHpf5NMqaJHz6LyX97gN70VLXRtHXwm8UPkDMh577sEYXVrfmSO9oeFmjgqNYRl1 Phlw== 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 u11-20020a170902714b00b001a6dba52e52si4635298plm.390.2023.06.04.20.17.39; Sun, 04 Jun 2023 20:17: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 S232606AbjFEDBI (ORCPT + 99 others); Sun, 4 Jun 2023 23:01:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232619AbjFEDBH (ORCPT ); Sun, 4 Jun 2023 23:01:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AC45DBD; Sun, 4 Jun 2023 20:01:03 -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 EAC13D75; Sun, 4 Jun 2023 20:01:48 -0700 (PDT) Received: from [10.162.41.6] (a077893.blr.arm.com [10.162.41.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 969373F663; Sun, 4 Jun 2023 20:00:58 -0700 (PDT) Message-ID: Date: Mon, 5 Jun 2023 08:30:55 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH V11 06/10] arm64/perf: Enable branch stack events via FEAT_BRBE Content-Language: en-US To: Namhyung Kim Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, Mark Brown , James Clark , Rob Herring , Marc Zyngier , Suzuki Poulose , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org References: <20230531040428.501523-1-anshuman.khandual@arm.com> <20230531040428.501523-7-anshuman.khandual@arm.com> From: Anshuman Khandual In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 On 6/2/23 07:15, Namhyung Kim wrote: > Hello, > > On Tue, May 30, 2023 at 9:21 PM Anshuman Khandual > wrote: >> >> This enables branch stack sampling events in ARMV8 PMU, via an architecture >> feature FEAT_BRBE aka branch record buffer extension. This defines required >> branch helper functions pmuv8pmu_branch_XXXXX() and the implementation here >> is wrapped with a new config option CONFIG_ARM64_BRBE. >> >> 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 >> --- > > [SNIP] >> +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; >> + 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); >> + >> + /* Ensure pause on PMU interrupt is enabled */ >> + WARN_ON_ONCE(!(brbcr & BRBCR_EL1_FZP)); >> + >> + /* Pause the buffer */ >> + 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; > > Is this to disable the bank1? Maybe need a comment. Sure, will add a comment. > > >> + } else { >> + loop1_idx2 = BRBE_BANK0_IDX_MAX; >> + loop2_idx1 = BRBE_BANK1_IDX_MIN; >> + loop2_idx2 = brbe_attr->brbe_nr - 1; >> + } > > The loop2_idx1 is the same for both cases. Maybe better > to move it out of the if statement. Sure, will do the following change as suggested but wondering whether should the change be implemented from this patch onwards or in the later patch that adds capture_brbe_regset(). --- a/drivers/perf/arm_brbe.c +++ b/drivers/perf/arm_brbe.c @@ -56,13 +56,14 @@ static int capture_brbe_regset(struct brbe_hw_attr *brbe_attr, struct brbe_regse int idx, count; loop1_idx1 = BRBE_BANK0_IDX_MIN; + loop2_idx1 = BRBE_BANK1_IDX_MIN; if (brbe_attr->brbe_nr <= BRBE_BANK_MAX_ENTRIES) { loop1_idx2 = brbe_attr->brbe_nr - 1; - loop2_idx1 = BRBE_BANK1_IDX_MIN; + + /* Disable capturing the bank 1 */ 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; }