Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4479603rwo; Tue, 25 Jul 2023 06:47:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlHNLjlhZIb494fbU/rxFw192ygK75evYDS7VnezvXT+LjHiXgnRndi29k1kpG2ka7U7iSFi X-Received: by 2002:a17:902:ce83:b0:1bb:25bd:d091 with SMTP id f3-20020a170902ce8300b001bb25bdd091mr16124899plg.30.1690292853397; Tue, 25 Jul 2023 06:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690292853; cv=none; d=google.com; s=arc-20160816; b=adeqiAposneSlB84pMdNCRl2EjTYg4Dhm2dQTcjLXleyduvQj/idw4N0BdOdHp3HxJ uiNa/Nj+YlHh0GYbQ694g37HusQkGS9o6y6HyufcytGInKxGl78oCzRwV5TejTfX7KuP /QGl0FEFKZpj/x1ASejdobZlwk1q7tCsi7UCZZv3gEPHBzoHkAkMlEm30YBJ+JH5V0IH Gux5zOo/cqtHX96ltMxOjyte0ZM0hAN87LajmGqg1PuFuF42C0Pq03q6M+qiKk0307VJ GxGSClWGNxM1rT3lLQ2/dEqT9kW8MfscC1Y/wzCi+jGw/JrN47tJZiJKOLXCX+VHE7BF 30Cw== 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:subject:user-agent:mime-version:date:message-id; bh=2ReSu6MxiAsJEttFTIRtn6/PQyMvtNLFcrUHOV3PdGE=; fh=E0KnOdx5uQ8LMjP97NlD9ATO4rL/u+cmJ/05lnv4nNo=; b=oHfLnb89NSMpHBhyHlDm/1rOlQLR5rrE+aAz91/QcmUsVVY35yNFFN/Nje58trGxiy I/o6K5WLEfr+/ANDjNmVYS9KOYF+mo1itbwFYbCzg1HDh1FIbE7ga/ip1GDH43tyMqxN GAQcJ66z8/KdjfcaQmBM7ej1q3XnXElprMbQy23tjQDuDu7ukKxpJfzljdObb2BW+Pom vNyUV8swPlkMLkE66MnOiUttmRjzdMSdUReMo41JlRFhDDj8EMopWthd9wz7hxwWb4XT 7a1JLn7QQ4sxuD3T02bbH0IvPPjOgCCjPFSIni3YPidozI+xsdwNyaqLTR0hTbSgA+52 bvgw== 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 n17-20020a170902e55100b001bb8f59aca3si7119759plf.583.2023.07.25.06.47.21; Tue, 25 Jul 2023 06:47:33 -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 S230370AbjGYN3r (ORCPT + 99 others); Tue, 25 Jul 2023 09:29:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230344AbjGYN3q (ORCPT ); Tue, 25 Jul 2023 09:29:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D705F1BD8; Tue, 25 Jul 2023 06:29:44 -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 AED3E15BF; Tue, 25 Jul 2023 06:30:27 -0700 (PDT) Received: from [10.57.89.166] (unknown [10.57.89.166]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E0BC33F5A1; Tue, 25 Jul 2023 06:29:41 -0700 (PDT) Message-ID: <3873f3b6-5e0b-360f-2f01-4584e15e960a@arm.com> Date: Tue, 25 Jul 2023 14:29:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH V13 - RESEND 06/10] arm64/perf: Enable branch stack events via FEAT_BRBE To: Anshuman Khandual , Yang Shen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com Cc: Mark Brown , James Clark , Rob Herring , Marc Zyngier , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org References: <20230711082455.215983-1-anshuman.khandual@arm.com> <20230711082455.215983-7-anshuman.khandual@arm.com> <5c7c1ff3-1e2a-1258-7fa0-c82a9ab62646@huawei.com> <9d07e82a-06fb-a5f8-6f4f-f3c16784b9b7@arm.com> From: Suzuki K Poulose In-Reply-To: <9d07e82a-06fb-a5f8-6f4f-f3c16784b9b7@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed 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 25/07/2023 12:42, Anshuman Khandual wrote: > Hello Yang, > > On 7/25/23 12:42, Yang Shen wrote: >>> +    if (!(branch_type & PERF_SAMPLE_BRANCH_NO_CYCLES)) >>> +        brbcr |= BRBCR_EL1_CC; >> >> Hi Anshuman, >> >> Here is problem about enable CYCLES_COUNT. The SPEC defines that the CYCLES_COUNT is only >> >> valid when the BRECR_EL1.CC & BRBCR_EL2.CC is true. And here the SPEC also defines that >> >> when PSTATE.EL == EL2 and HCR_EL2.E2h == '1', 'MSR BRBCR_EL1, ' means writing to >> >> BRBCR_EL2 actually. So 'armv8pmu_branch_enable' can only set the BRBCR_EL2.CC, while the >> >> BRECR_EL1.CC is still 0. The CYCLES_COUNT will be always 0 in records. > > > Agreed, this is a valid problem i.e BRBCR_EL1.CC and BRBCR_EL2.CC both needs to be set > for valid cycle count information regardless if the kernel runs in EL1 or EL2. A simple > hack in the current code setting BRBCR_EL12.C, which in turn sets BRBCR_EL1.CC when the > kernel runs in EL2 solves the problem. > >> >> As a solution, maybe BRBCR_EL12 should be added for driver according to the registers definition. > > Right, will add the definition for BRBCR_EL12 in arch/arm64/tools/sysreg > >> >> Or, do you have a more standard solution? > > Right, there are some nuances involved here. > > Kernel could boot > > a. Directly into EL2 and stays in EL2 for good > b. Directly into EL2 but switches into EL1 > c. Directly into EL1 without ever going into EL2 > > In all the above cases BRBCR_EL1.CC and BRBCR_EL2.CC needs to be set when cycle count > is requested in the perf event interface (event->attr.branch_sample_type) via clearing > PERF_SAMPLE_BRANCH_NO_CYCLES. > > > - For the case as in (c) where kernel boots into EL1 directly and hence cannot ever set > EL2 register, BRBCR_EL2.CC would be a booting requirement - updated in booting.rst > > - For the cases as in (a) and (b) kernel boots via EL2, hence there is an opportunity > to set both BRBCR_EL1.CC (via accessed BRBCR_EL12.CC) and BRBCR_EL2.CC. Depending on You don't need to use BRBCR_EL12, if you do it early enough, before HCR_EL2.E2H == 1 is applied. Suzuki