[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <SJ1PR11MB608379B89FA5ECC8646C72A2FCA7A@SJ1PR11MB6083.namprd11.prod.outlook.com>
Date: Fri, 5 Dec 2025 20:33:48 +0000
From: "Luck, Tony" <tony.luck@...el.com>
To: Xiaochen Shen <shenxiaochen@...n-hieco.net>, "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>
Subject: RE: [PATCH 2/2] x86/resctrl: Fix memory bandwidth counter width for
Hygon
> > I *think* you'd get the right results if the h/w counter is wider
> > than s/w expects. You'd just need to keep polling fast enough
> > (and we never adjusted the MBM polling rate from the original
> > 1 HZ.)
>
> Thank you very much for code review!
>
> We have observed a test case where an incorrect counter width leads to random unexpected memory bandwidth readings:
> https://github.com/shenxiaochen/my_documents/blob/main/memory_bandwidth_counter_width_and_overflow_issue_steps_to_reproduce.txt
>
> The issue was resolved by applying this patch.
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.
Question: What is the value of "hw_res->mon_scale" on a Hygon system?
-Tony
#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;
}
Powered by blists - more mailing lists