Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp650939rwb; Wed, 26 Jul 2023 00:02:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEFbuzBvx18s1KrAXn/tqv2PKAzR+4Z6oVZib8QEKb5pgupHbJ6TonrwwYZJ96ODPG6UiU X-Received: by 2002:aa7:cd6a:0:b0:522:5932:57ec with SMTP id ca10-20020aa7cd6a000000b00522593257ecmr768743edb.41.1690354964545; Wed, 26 Jul 2023 00:02:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690354964; cv=none; d=google.com; s=arc-20160816; b=ceVGi4+HpCviF3w8z9KRDLC64BmMmNq++t9bUN1J69bFVdShrLyCmOj3Zlosj1oH9S sllaxF8eunZj7O00qku1LtDGTejnUMjIcRmIZaSHQqnFBmfDh+FeH/XFSlAHdjvSJJ+J 9FfXyG6sBOqyeoL25WhhJuWagzq4rtwndmCzOkiqA/+zsoNjJAshHUHNTkVgRkMG9nPz tdL5SFCadRD8mKyy+VdWDOGLIycAfnWb8RTe1zbxK6bSS2eNL0Rt4kBV9GYSdgj1j5xx EYgVHgOvg2wKD0U5bUatvcynh+Nlde16gjU4G0KGTw+IMZl6hEcZOrHclkzC4YCVS6HS 5u4Q== 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=MhBKcddJWsSKYAL+qVaQVV18nKZwIUqW9ZM1VXJpmW4=; fh=rBKIYYaeKaffpB5VZNGuRoUpkvOduBK9GD1e1zpw3mI=; b=P7hU5BxwD1+B4W9rUKnXXKJ40jcijIQa40dN0jcXqDj/Go5tKXS11V4qsUl3emUpaF IQHeHcR7u9kc6aJst7g5yAxqJP7RtFxJO3sLJKU8Z4eRpIRAJiMNGbQUKuFlzfucgr6N nslWxFpptlm58cMEpOa29YtW6yfHc0i9nDhKivng2UM1mwnhufE7vC/qRJRV9SgcfzwA c83pq8zuVyCnTITX0pPdYKT69VInFpRcCXzvaWIeDG2H5mrE+hyImlkxuMtBRT9msgAj varrPxdb4dY12VJo1K0+vjXbDgUcnCCVBEsIdlqFSpqHwkRh+UicQ2rrF9ZzLuJrH/E9 186A== 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 g12-20020aa7c58c000000b0051e23250f88si691483edq.349.2023.07.26.00.02.19; Wed, 26 Jul 2023 00:02:44 -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 S231166AbjGZG0Y (ORCPT + 99 others); Wed, 26 Jul 2023 02:26:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbjGZG0X (ORCPT ); Wed, 26 Jul 2023 02:26:23 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2569D13E; Tue, 25 Jul 2023 23:26: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 D02BF11FB; Tue, 25 Jul 2023 23:27:04 -0700 (PDT) Received: from [10.162.40.16] (unknown [10.162.40.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7AB723F5A1; Tue, 25 Jul 2023 23:26:17 -0700 (PDT) Message-ID: Date: Wed, 26 Jul 2023 11:56:14 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; 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 Content-Language: en-US To: 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 , Suzuki Poulose , 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> From: Anshuman Khandual In-Reply-To: <20230711082455.215983-7-anshuman.khandual@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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, URIBL_BLOCKED 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 7/11/23 13:54, Anshuman Khandual wrote: > +static void capture_brbe_flags(struct perf_branch_entry *entry, struct perf_event *event, > + u64 brbinf) > +{ > + if (branch_sample_type(event)) > + brbe_set_perf_entry_type(entry, brbinf); > + > + if (!branch_sample_no_cycles(event)) > + entry->cycles = brbe_get_cycles(brbinf); Just revisiting the branch records cycle capture process in BRBE. 'cycles' field is a 16 bit field in struct perf_branch_entry. struct perf_branch_entry { __u64 from; __u64 to; __u64 mispred:1, /* target mispredicted */ predicted:1,/* target predicted */ in_tx:1, /* in transaction */ abort:1, /* transaction abort */ cycles:16, /* cycle count to last branch */ type:4, /* branch type */ spec:2, /* branch speculation info */ new_type:4, /* additional branch type */ priv:3, /* privilege level */ reserved:31; }; static inline int brbe_get_cycles(u64 brbinf) { /* * Captured cycle count is unknown and hence * should not be passed on to the user space. */ if (brbinf & BRBINFx_EL1_CCU) return 0; return FIELD_GET(BRBINFx_EL1_CC_MASK, brbinf); } capture_brbe_flags() { ..... if (!branch_sample_no_cycles(event)) entry->cycles = brbe_get_cycles(brbinf); ..... } BRBINF_EL1.CC[45:32] is a 14 bits field which gets assigned into perf_branch_entry->cycles field which is 16 bits wide. Although the cycle count representation here is mantissa and exponent based one. CC bits[7:0] indicate the mantissa M CC bits[13:8] indicate the exponent E The actual cycle count is based on the following formula as the per the spec [1], which needs to be derived from BRBINF_EL1.CC field. ------------------------------------------------------------------- The cycle count is expressed using the following function: if IsZero(E) then UInt(M) else UInt('1':M:Zeros(UInt(E)-1)) If required, the cycle count is rounded to a multiple of 2(E-1) towards zero before being encoded. A value of all ones in both the mantissa and exponent indicates the cycle count value exceeded the size of the cycle counter. ------------------------------------------------------------------- Given that there is only 16 bits in perf_branch_entry structure for cycles count, I assume that it needs to be derived in the user perf tool (per the above calculation) before being interpreted ? [1] https://developer.arm.com/documentation/ddi0601/2023-06/AArch64-Registers/BRBINF-n--EL1--Branch-Record-Buffer-Information-Register--n-?lang=en - Anshuman