Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2366912rdb; Tue, 10 Oct 2023 01:31:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRJ5UgtgyzcEueydR+2G1wtgYBGnj9q4nf/mEqPPeHE9ROnX/XlWF96G5vM/mp36teHZwE X-Received: by 2002:a17:902:d502:b0:1c9:b2c1:13aa with SMTP id b2-20020a170902d50200b001c9b2c113aamr1016750plg.68.1696926695539; Tue, 10 Oct 2023 01:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696926695; cv=none; d=google.com; s=arc-20160816; b=gi+959OC9YkRw0YQtLqumBJ0OePlcYa/NMFK+vY/HjLWy8lhlRLNXoLOzU5J+NZaMC bFvj0N3mLq8Uxqki7PrnkI9zx01SNGtS1WVoMyqJdWKTKs369hUI8foJKUTiaFcpGm/V V3vvBWF9nuB08KAozvYAeajdfbMY+bZ4lMvWpg+XMfSqtFHrlbXiII2AVVkQ9G8V9otX LCGgPS0byZ8yOWQ8ZOlTI1gO9OOhThNtMyVDEJJArCsH5JE+A2aplzu+7jx1q24v9UBO bbdCm84r65jeMZAI4VtfDt+pRGSoj2nci0AuIr7/gkNWKfebpU5Sc85VVduHA+uNkuHE xZlA== 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:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id; bh=5H5rvP90IlwOM0rhXcq1YpatQ5ShBQLOn0EGrlIfMTw=; fh=ke9zMQy17pJ/cUilhTj63oZeUT2foHxD+RCmdSlpuC8=; b=tFwBfvV5ThOUO0+J+BVOoiKKG360Q5dIYEh4y6PdUhJlR6z04KpO7I1L1Hph4vevro y88K2+s2hqPCw+7bXm1yryEEb2MFFxAZRCviJ1MlHS4M1IqVSDrKRbM/MuCOQC5cVAgH bQ2vNrj5XTBRpchf9iLRs44nF9F2i4UDo2oWAqMmPS8G/gxA7U4rIAdc+1xY7OmrdHCI S8729WRE4UBooDpMxIYvLs/j33pvgZya937/xT7egqVdcESHVwuJNMRq3pV4TtQfc5N9 aTgHt0HHNkXJaulh6WiFOT6OI8kNDiE43hhRIK42xOyRuUcjPx4WWwxbxxU8sPCCR+d4 E7QA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id h13-20020a170902f7cd00b001bf20e8f66asi1246130plw.26.2023.10.10.01.31.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 01:31:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id F02EA8028225; Tue, 10 Oct 2023 01:31:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442845AbjJJIa7 (ORCPT + 99 others); Tue, 10 Oct 2023 04:30:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344471AbjJJIa5 (ORCPT ); Tue, 10 Oct 2023 04:30:57 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CDAC1AF for ; Tue, 10 Oct 2023 01:30:54 -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 51A741FB; Tue, 10 Oct 2023 01:31:35 -0700 (PDT) Received: from [192.168.1.3] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AFAD13F7A6; Tue, 10 Oct 2023 01:30:53 -0700 (PDT) Message-ID: <72d358f1-bcee-ee6d-48ca-a38b47aadf29@arm.com> Date: Tue, 10 Oct 2023 09:30:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] drivers: perf: arm_pmuv3: Update 'pmc_width' based on actual HW event width Content-Language: en-US From: James Clark To: Anshuman Khandual , linux-arm-kernel@lists.infradead.org, Rob Herring , raphael.gault@arm.com Cc: Will Deacon , Mark Rutland , linux-kernel@vger.kernel.org References: <20231009043724.175100-1-anshuman.khandual@arm.com> <66125bc2-ff2a-a209-a753-c2e3d8310a45@arm.com> <8a5d2411-3fab-4f21-adb5-f99a2d4b3bee@arm.com> <948c6cdd-5a46-6b4b-37a9-9f971a4853a8@arm.com> In-Reply-To: <948c6cdd-5a46-6b4b-37a9-9f971a4853a8@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.5 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 10 Oct 2023 01:31:31 -0700 (PDT) On 10/10/2023 09:28, James Clark wrote: > > > On 10/10/2023 04:03, Anshuman Khandual wrote: >> Hi James, >> >> On 10/9/23 15:13, James Clark wrote: >>> >>> >>> On 09/10/2023 05:37, Anshuman Khandual wrote: >>>> This updates 'perf_event_mmap_page->pmc_width' based on actual HW event's >>>> width that are currently missing i.e ARMPMU_EVT_63BIT and ARMPMU_EVT_47BIT. >>>> >>> >>> Might be worth adding why this is needed or what the actual effect is. >> >> To have correct 'pmc_width' visible to the user space ? > > Well yeah, but for example I didn't know what that was. And it's not > clear why it needs updating at this point in time without a link to any > other commit or relevant section from the Arm ARM. So I had a kind of a > "why now" question. > > "To have correct 'pmc_width' visible to the user space" is definitely > more of a what than a why. > If anything this should at least have a fixes: tag on it. If you're saying that it's now correct. >> >>> >>>> Cc: Will Deacon >>>> Cc: Mark Rutland >>>> Cc: linux-arm-kernel@lists.infradead.org >>>> Cc: linux-kernel@vger.kernel.org >>>> Signed-off-by: Anshuman Khandual >>>> --- >>>> This applies on v6.6-rc5. >>>> >>>> drivers/perf/arm_pmuv3.c | 4 ++++ >>>> 1 file changed, 4 insertions(+) >>>> >>>> diff --git a/drivers/perf/arm_pmuv3.c b/drivers/perf/arm_pmuv3.c >>>> index fe4db1831662..94723d00548e 100644 >>>> --- a/drivers/perf/arm_pmuv3.c >>>> +++ b/drivers/perf/arm_pmuv3.c >>>> @@ -1375,6 +1375,10 @@ void arch_perf_update_userpage(struct perf_event *event, >>>> if (userpg->cap_user_rdpmc) { >>>> if (event->hw.flags & ARMPMU_EVT_64BIT) >>>> userpg->pmc_width = 64; >>>> + else if (event->hw.flags & ARMPMU_EVT_63BIT) >>>> + userpg->pmc_width = 63; >>>> + else if (event->hw.flags & ARMPMU_EVT_47BIT) >>>> + userpg->pmc_width = 47; >>> >>> Although it doesn't explicitly say it, the bit of the docs about >>> pmc_width in Documentation/arch/arm64/perf.rst loosely implies that this >>> is always either 64 or 32. Now that this isn't the case it could mislead >>> someone in userspace that they don't have to handle the now arbitrary >>> bit widths rather than just whole bytes/ints. >> >> Are you suggesting that the user space would not handle pmc_width correctly >> , once it deviates from a whole bytes/ints format ? In that case user space >> handling might need some fixing. >> > > Not really, I'm just suggesting that anyone writing a new tool and only > reading the docs could make that assumption. Seeing as only 32 and 64 > bit options are mentioned. So it's more to avoid misleading someone in > the future than about fixing any existing code, as updating the docs > wouldn't have that effect. > >>> >>> I think the fix is as simple as adding something like "the width may not >>> match the requested value or necessarily be a multiple of 8". Unless we >>> think this is already widely known and I suppose we could leave it as >>> is. (The existing bit in perf that uses it already handles it correctly). >> >> This is from perf_event_mmap_page definition where it does not assert the >> width to be multiple of bytes or ints. Hence the assumption should not be >> made into the user space tools. >> > > Yeah I know its already ok for Perf which is why I mentioned it. But > there are more tools out there than Perf, and ones that don't even exist > yet, which people would normally read the documentation before writing. > >> /* >> * If cap_user_rdpmc this field provides the bit-width of the value >> * read using the rdpmc() or equivalent instruction. This can be used >> * to sign extend the result like: >> * >> * pmc <<= 64 - width; >> * pmc >>= 64 - width; // signed shift right >> * count += pmc; >> */ >> __u16 pmc_width; >> >> Moreover, on x86 too 'userpg->pmc_width' gets assigned to different values >> although multiple of 8. >> >> userpg->pmc_width = x86_pmu.cntval_bits >> arch/x86/events/amd/core.c: .cntval_bits = 48 >> arch/x86/events/intel/knc.c: .cntval_bits = 40 >> arch/x86/events/intel/p6.c: .cntval_bits = 32 >> >>> >>>> else >>>> userpg->pmc_width = 32; >>>> } > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel