[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8c90563c-cc2b-4234-946c-39bcb1554dff@open-hieco.net>
Date: Sun, 7 Dec 2025 08:56:43 +0800
From: Xiaochen Shen <shenxiaochen@...n-hieco.net>
To: "Luck, Tony" <tony.luck@...el.com>,
"Chatre, Reinette" <reinette.chatre@...el.com>, "bp@...en8.de"
<bp@...en8.de>, "fenghuay@...dia.com" <fenghuay@...dia.com>
Cc: "babu.moger@....com" <babu.moger@....com>,
"james.morse@....com" <james.morse@....com>,
"Dave.Martin@....com" <Dave.Martin@....com>, "x86@...nel.org"
<x86@...nel.org>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>, shenxiaochen@...n-hieco.net
Subject: Re: [PATCH 2/2] x86/resctrl: Fix memory bandwidth counter width for
Hygon
Hi Tony,
(Sorry to resent. The previous thread sent to some recipients was bounced by Recipient System)
On 12/6/2025 4:33 AM, Luck, Tony wrote:
> Clearly something is going wrong, and you sometime see enormous values for
> memory bandwidth. But I'm still puzzled about what is going wrong.
>
> I pasted the resctrl wraparound function into a small user-mode test, and it
> seems to be able to ignore bits above the width used.
>
> The test below prints "2" when told the width is either 24 or 32.
>
> Your patch to use width = 32 is good, but if the problem isn't in the mbm_overflow_count()
> function, then you might just have made the problem 256X harder to hit.#include <stdio.h>
>
> typedef unsigned long long u64;
>
> static u64 mbm_overflow_count(u64 prev_msr, u64 cur_msr, unsigned int width)
> {
> u64 shift = 64 - width, chunks;
>
> chunks = (cur_msr << shift) - (prev_msr << shift);
> return chunks >> shift;
> }
>
> int main(void)
> {
> u64 prev, cur;
>
> prev = 0xffffff;
> cur = 0x1000001;
>
> printf("width = 24 %lld\n", mbm_overflow_count(prev, cur, 24));
>
> printf("width = 32 %lld\n", mbm_overflow_count(prev, cur, 32));
>
> return 0;
> }
I think, this issue could be reproduced by your test program with a minor change (e.g., cur.bits[31:24] > 1):
- cur = 0x1000001;
+ cur = 0xf000001;
// The calculated value 2 is incorrrect with passing 24 bits counter width:
# ./counter_width
width = 24 2
width = 32 234881026
Thank you!
Best regards,
Xiaochen Shen
Powered by blists - more mailing lists