From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 740DFC433B4 for ; Fri, 30 Apr 2021 12:36:03 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E51D66142A for ; Fri, 30 Apr 2021 12:36:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E51D66142A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aFR9iraRfJf53XnzPwaLes8MPk0yYJ4BE4BvukvkYo8=; b=h0KdzvL07K3CUjbh2UQqSmejT LiTU/b5LbQM2GA1s2MIQ3fN9GxWnM8lJXofFka/D0mlGGFmBMdac1CuNj9Us1ix5gn4c1VHzI4iUH wJFXm7XZMKS8Witwz9WsPiIxIscVkQUIdmPL7HL/PPjiV8LlQIU4qsXtSws+DIp4xdmYZI3Zsa6Ks /wYb+0jrIuOq2o8Qj+m/vfvC6e+Vzbvdzb9p+1anMRU7SkB72sc6BjXmIkm4Jl6TuGazEk/ZqSufQ gi/18obwJdPhUDxNXw/HMzWHcRmu61/A2s1N/ML+vcQeVPmSdv+e7PTxmI22s2rv9wokqOjlrS6Ua 0SKycQalQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lcSLi-007nNo-PD; Fri, 30 Apr 2021 12:34:26 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lcSLe-007nMp-BF for linux-arm-kernel@desiato.infradead.org; Fri, 30 Apr 2021 12:34:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2vAkLuZeYPz81FIWYKU3kTyfSBZqc2YiV09MBWGPwfw=; b=ZKMkqNz2NiL44nla1gsr95b1q1 9QyZt6FRmyYr45uX0Yaw9fNqq313NWZuYTJ8C7p/k7xCmy0h50Ao9tQZFtSm9yxzY2GRTeD5InwuQ 9q4/1XP7qmX6QKpqaPAtEhc2gYuem1jN7cTDRu68TKzpCw9tL1To4OxQQIsZXz7sMConF3pWQ+FnD Bt+Y1wYS65z3Hu0xulmtFmYaIv0Ce6zGvLMBdJNHBfLx0z4xt9nOmCMrjR2Lx4+Ti+veDFRQ/B/1m XoKe2dHFhZ7rHBOLic/QygHrGhcLVoyxms50Gd+uxVzALEnf5Jx+mSMsYBucbEEGsfpvQTGU1LlHL HpurHXww==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lcSLb-001Mnq-8F for linux-arm-kernel@lists.infradead.org; Fri, 30 Apr 2021 12:34:20 +0000 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 C8AA61063; Fri, 30 Apr 2021 05:34:14 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.5.252]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 02A183F70D; Fri, 30 Apr 2021 05:34:10 -0700 (PDT) Date: Fri, 30 Apr 2021 13:34:08 +0100 From: Mark Rutland To: Yang Jihong , will@kernel.org Cc: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org, linux@armlinux.org.uk, suzuki.poulose@arm.com, julien.thierry.kdev@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm_pmu: Fix write counter incorrect in ARMv7 big-endian mode Message-ID: <20210430123408.GD53304@C02TD0UTHF1T.local> References: <20210430012659.232110-1-yangjihong1@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210430012659.232110-1-yangjihong1@huawei.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210430_053419_415549_49CBEAD1 X-CRM114-Status: GOOD ( 21.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Apr 30, 2021 at 09:26:59AM +0800, Yang Jihong wrote: > Commit 3a95200d3f89a ("arm_pmu: Change API to support 64bit counter values") > changes the input "value" type from 32-bit to 64-bit, > which introduces the following problem: > ARMv7 PMU counters is 32-bit width, in big-endian mode, write counter uses > high 32-bit, which writes an incorrect value. It might be worth noting that the reason for this is that when a 64-bit value is split across two 32-bit registers, the high/low halves are split to match how LDRD would load a 64-bit quantity (and so differs across big/little endian), but the "r" constraint consistently uses the first of the two regiseters. Given that, this patch makes sense to me (and I didn't spot any related issues), so: Acked-by: Mark Rutland Will, I assume you'll pick this up. Mark. > > Before: > > Performance counter stats for 'ls': > > 2.22 msec task-clock # 0.675 CPUs utilized > 0 context-switches # 0.000 K/sec > 0 cpu-migrations # 0.000 K/sec > 49 page-faults # 0.022 M/sec > 2150476593 cycles # 966.663 GHz > 2148588788 instructions # 1.00 insn per cycle > 2147745484 branches # 965435.074 M/sec > 2147508540 branch-misses # 99.99% of all branches > > None of the above hw event counters are correct. > > Solution: > > "value" forcibly converted to 32-bit type before being written to PMU register. > > After: > > Performance counter stats for 'ls': > > 2.09 msec task-clock # 0.681 CPUs utilized > 0 context-switches # 0.000 K/sec > 0 cpu-migrations # 0.000 K/sec > 46 page-faults # 0.022 M/sec > 2807301 cycles # 1.344 GHz > 1060159 instructions # 0.38 insn per cycle > 250496 branches # 119.914 M/sec > 23192 branch-misses # 9.26% of all branches > > Fixes: 3a95200d3f89a ("arm_pmu: Change API to support 64bit counter values") > Signed-off-by: Yang Jihong > --- > arch/arm/kernel/perf_event_v7.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm/kernel/perf_event_v7.c b/arch/arm/kernel/perf_event_v7.c > index 2924d7910b10..eb2190477da1 100644 > --- a/arch/arm/kernel/perf_event_v7.c > +++ b/arch/arm/kernel/perf_event_v7.c > @@ -773,10 +773,10 @@ static inline void armv7pmu_write_counter(struct perf_event *event, u64 value) > pr_err("CPU%u writing wrong counter %d\n", > smp_processor_id(), idx); > } else if (idx == ARMV7_IDX_CYCLE_COUNTER) { > - asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (value)); > + asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" ((u32)value)); > } else { > armv7_pmnc_select_counter(idx); > - asm volatile("mcr p15, 0, %0, c9, c13, 2" : : "r" (value)); > + asm volatile("mcr p15, 0, %0, c9, c13, 2" : : "r" ((u32)value)); > } > } > > -- > 2.30.GIT > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel