Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3347645pxb; Fri, 4 Feb 2022 06:47:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvLhFNBwBx/9SpCw1GZbPJO0ZqPpC7DM38IGO8uBdtqSx7CTTLfAkcTUb7Y1tV2nIvJ8q9 X-Received: by 2002:a17:907:1612:: with SMTP id hb18mr2797975ejc.724.1643986046064; Fri, 04 Feb 2022 06:47:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643986046; cv=none; d=google.com; s=arc-20160816; b=snlExlXIi6ikaC03SGnlktxaU5LAhc0zxgkTWz4URnJLQcCRx7H3Z7J0/X37u4awYz hChdv0CNoN0e/FUiTiK2Kz/ZTAtIDZlXTEavydFFNkKXgzBpuj8VbQ2cHYLYJFGH1lji FfuDigWtb5rgJSFYgLGGopIodp/pEfvBdF9V4u3xZleL+vMOdz2ES6iuhPwMWUtzkoAu Bpfu5duaW7rN3bFAQUlud9qqTvLf3uK+oegE7YJHhgmpI+wxnXgD95BwUlBWxKCg+/rF h5z18kDSmhZh0cvmvDxqjv+B8OOjdnm8CrhGXJZXt+r5myAe9tbLegeyJYAjH0Lq1Q9F vbNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=10SQmPzyfVYsuAZxmGAvwhfgyuS2/nLnPVOk0ObKLMg=; b=KQ3bvt58t0S+mN/HD/XEaEf3FqCTrSDJsPdbcfrGMlZtzrbGDehXivI2AOfLh5/zJg Olx2T+Q9A8eiRQFkUHVjLL2cZo65qKAsylzI1CMhJ1IEaqf6PMPYSCrWtFJ3Wupk4xEV iYgqSUgpS5MYZHH5ggEpldmo3w4bjTTWEoFrX785HnyUZhPL5ABlMaEWgkOEvIs1+akf jHcZzQjbZTi2SddJIjWWMymyMXVcCsIOJACoel0WoXbekIilM9nRzW2XYGYzvWb6ko6b RLjBtWvmVZFePVCP3qrdWjSZL3LoHUi6OO+vE2FZwXMiRomSs1D9lrnC9I6ecopSxR8S DvuQ== 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 l6si1452759ejo.623.2022.02.04.06.47.00; Fri, 04 Feb 2022 06:47:26 -0800 (PST) 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 S1358476AbiBDLsm (ORCPT + 99 others); Fri, 4 Feb 2022 06:48:42 -0500 Received: from foss.arm.com ([217.140.110.172]:38584 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbiBDLsl (ORCPT ); Fri, 4 Feb 2022 06:48:41 -0500 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 255CE1480; Fri, 4 Feb 2022 03:48:41 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.89.15]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D5C8C3F40C; Fri, 4 Feb 2022 03:48:39 -0800 (PST) Date: Fri, 4 Feb 2022 11:48:35 +0000 From: Mark Rutland To: Stephane Eranian Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, will@kernel.org, ashoks@broadcom.com Subject: Re: [PATCH] perf/arm64: fix mapping for HW_BRANCH_INSTRUCTIONS on PMUv3 Message-ID: References: <20220204073940.1258263-1-eranian@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220204073940.1258263-1-eranian@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Stephane, On Thu, Feb 03, 2022 at 11:39:40PM -0800, Stephane Eranian wrote: > With the existing code, the following command: > > $ perf stat -e branches sleep 0 > Performance counter stats for 'sleep 0': > branches > > on N1 core (pmuv3). This is definitely not ideal. :( > This is due to the fact that the mapping for the generic event is wrong. I don't think that's quite true; more detail below. This is certainly *messy* though. > It is using ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED which is not implemented > on N1 (and most likely on any PMUv3 implementations). However, there is > another supported event ARMV8_PMUV3_PERFCTR_BR_RETIRED measuring the same > condition. I have a couple of concerns here: 1) Both PC_WRITE_RETIRED and BR_RETIRED are OPTIONAL (though the Arm strongly recommends that BR_RETIRED is implemented), so CPUs may exist which only support one of the two, or both. So as-is, this patch may break working support for CPUs which have PC_WRITE_RETIRED but not BR_RETIRED. IIUC we should be able to detect whether either are implemented by looking at PMCEID, and we could take that into account when mapping the event. 2) IIUC (even with ARMv8.6) there is a potential semantic difference between PC_WRITE_RETIRED and BR_RETIRED, in that e.g. PC_WRITE_RETIRED must include exception returns while this is IMPLEMENTATION DEFINED for BR_RETIRED. I guess this might not matter all that much given the precise definition of "Software change of the PC" is IMPLEMENTATION DEFINED, but I don't think it's true that the two events count "the same condition", and we should be more explicit about that. > This patch switches the mapping to ARMV8_PMUV3_PERFCTR_BR_RETIRED so that > the perf stat command above works. > > Signed-off-by: Stephane Eranian > --- > arch/arm64/kernel/perf_event.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c > index cab678ed6618..ec2b98343a0b 100644 > --- a/arch/arm64/kernel/perf_event.c > +++ b/arch/arm64/kernel/perf_event.c > @@ -45,7 +45,7 @@ static const unsigned armv8_pmuv3_perf_map[PERF_COUNT_HW_MAX] = { > [PERF_COUNT_HW_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_INST_RETIRED, > [PERF_COUNT_HW_CACHE_REFERENCES] = ARMV8_PMUV3_PERFCTR_L1D_CACHE, > [PERF_COUNT_HW_CACHE_MISSES] = ARMV8_PMUV3_PERFCTR_L1D_CACHE_REFILL, > - [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_PC_WRITE_RETIRED, > + [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = ARMV8_PMUV3_PERFCTR_BR_RETIRED, As above, I don't think we can unconditionally make this change, and instead should have the mapping function take PMCEID into account to map the event (or bail out if we don't know a suitable event is implemented). Thanks, Mark. > [PERF_COUNT_HW_BRANCH_MISSES] = ARMV8_PMUV3_PERFCTR_BR_MIS_PRED, > [PERF_COUNT_HW_BUS_CYCLES] = ARMV8_PMUV3_PERFCTR_BUS_CYCLES, > [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = ARMV8_PMUV3_PERFCTR_STALL_FRONTEND, > -- > 2.35.0.263.gb82422642f-goog >