* [PATCH v2] x86/resctrl: Fix memory bandwidth counter width for AMD
@ 2020-06-04 19:45 Babu Moger
2020-06-15 7:42 ` [tip: x86/urgent] " tip-bot2 for Babu Moger
0 siblings, 1 reply; 2+ messages in thread
From: Babu Moger @ 2020-06-04 19:45 UTC (permalink / raw)
To: fenghua.yu, reinette.chatre, tglx, mingo, bp, x86, hpa, linux-kernel
Memory bandwidth is calculated reading the monitoring counter
at two intervals and calculating the delta. It is the software’s
responsibility to read the count often enough to avoid having
the count roll over _twice_ between reads.
The current code hardcodes the bandwidth monitoring counter's width
to 24 bits for AMD. This is due to default base counter width which
is 24. Currently, AMD does not implement the CPUID 0xF.[ECX=1]:EAX
to adjust the counter width. But, the AMD hardware supports much
wider bandwidth counter with the default width of 44 bits.
Kernel reads these monitoring counters every 1 second and adjusts the
counter value for overflow. With 24 bits and scale value of 64 for AMD,
it can only measure up to 1GB/s without overflowing. For the rates
above 1GB/s this will fail to measure the bandwidth.
Fix the issue setting the default width to 44 bits by adjusting the
offset.
AMD future products will implement the CPUID 0xF.[ECX=1]:EAX.
Fixes: 4d05bf71f157 ("x86/resctrl: Introduce AMD QOS feature")
Signed-off-by: Babu Moger <babu.moger@amd.com>
---
v2:
-Added Fixes tag. The problem was there from the day one when
AMD resctrl feature was added. So, added fixes tag when AMD
support was introduced.
-Will send separate patches for the stable kernels because this
patch does not apply on stable.
-Made changes suggested by Reinette.
v1:
https://lore.kernel.org/lkml/159105232628.48268.7763865625735367523.stgit@naples-babu.amd.com/
arch/x86/kernel/cpu/resctrl/core.c | 10 ++++++----
arch/x86/kernel/cpu/resctrl/internal.h | 1 +
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index 12f967c6b603..5e045e90877e 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -981,10 +981,12 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
c->x86_cache_max_rmid = ecx;
c->x86_cache_occ_scale = ebx;
- if (c->x86_vendor == X86_VENDOR_INTEL)
- c->x86_cache_mbm_width_offset = eax & 0xff;
- else
- c->x86_cache_mbm_width_offset = -1;
+ c->x86_cache_mbm_width_offset = eax & 0xff;
+ if (c->x86_vendor == X86_VENDOR_AMD &&
+ c->x86_cache_mbm_width_offset == 0) {
+ c->x86_cache_mbm_width_offset =
+ MBM_CNTR_WIDTH_OFFSET_AMD;
+ }
}
}
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index f20a47d120b1..5ffa32256b3b 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -37,6 +37,7 @@
#define MBA_IS_LINEAR 0x4
#define MBA_MAX_MBPS U32_MAX
#define MAX_MBA_BW_AMD 0x800
+#define MBM_CNTR_WIDTH_OFFSET_AMD 20
#define RMID_VAL_ERROR BIT_ULL(63)
#define RMID_VAL_UNAVAIL BIT_ULL(62)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [tip: x86/urgent] x86/resctrl: Fix memory bandwidth counter width for AMD
2020-06-04 19:45 [PATCH v2] x86/resctrl: Fix memory bandwidth counter width for AMD Babu Moger
@ 2020-06-15 7:42 ` tip-bot2 for Babu Moger
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Babu Moger @ 2020-06-15 7:42 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Babu Moger, Borislav Petkov, x86, LKML
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 2c18bd525c47f882f033b0a813ecd09c93e1ecdf
Gitweb: https://git.kernel.org/tip/2c18bd525c47f882f033b0a813ecd09c93e1ecdf
Author: Babu Moger <babu.moger@amd.com>
AuthorDate: Thu, 04 Jun 2020 14:45:16 -05:00
Committer: Borislav Petkov <bp@suse.de>
CommitterDate: Mon, 15 Jun 2020 09:35:38 +02:00
x86/resctrl: Fix memory bandwidth counter width for AMD
Memory bandwidth is calculated reading the monitoring counter
at two intervals and calculating the delta. It is the software’s
responsibility to read the count often enough to avoid having
the count roll over _twice_ between reads.
The current code hardcodes the bandwidth monitoring counter's width
to 24 bits for AMD. This is due to default base counter width which
is 24. Currently, AMD does not implement the CPUID 0xF.[ECX=1]:EAX
to adjust the counter width. But, the AMD hardware supports much
wider bandwidth counter with the default width of 44 bits.
Kernel reads these monitoring counters every 1 second and adjusts the
counter value for overflow. With 24 bits and scale value of 64 for AMD,
it can only measure up to 1GB/s without overflowing. For the rates
above 1GB/s this will fail to measure the bandwidth.
Fix the issue setting the default width to 44 bits by adjusting the
offset.
AMD future products will implement CPUID 0xF.[ECX=1]:EAX.
[ bp: Let the line stick out and drop {}-brackets around a single
statement. ]
Fixes: 4d05bf71f157 ("x86/resctrl: Introduce AMD QOS feature")
Signed-off-by: Babu Moger <babu.moger@amd.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/159129975546.62538.5656031125604254041.stgit@naples-babu.amd.com
---
arch/x86/kernel/cpu/resctrl/core.c | 8 ++++----
arch/x86/kernel/cpu/resctrl/internal.h | 1 +
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index 12f967c..6a9df71 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -981,10 +981,10 @@ void resctrl_cpu_detect(struct cpuinfo_x86 *c)
c->x86_cache_max_rmid = ecx;
c->x86_cache_occ_scale = ebx;
- if (c->x86_vendor == X86_VENDOR_INTEL)
- c->x86_cache_mbm_width_offset = eax & 0xff;
- else
- c->x86_cache_mbm_width_offset = -1;
+ c->x86_cache_mbm_width_offset = eax & 0xff;
+
+ if (c->x86_vendor == X86_VENDOR_AMD && !c->x86_cache_mbm_width_offset)
+ c->x86_cache_mbm_width_offset = MBM_CNTR_WIDTH_OFFSET_AMD;
}
}
diff --git a/arch/x86/kernel/cpu/resctrl/internal.h b/arch/x86/kernel/cpu/resctrl/internal.h
index f20a47d..5ffa322 100644
--- a/arch/x86/kernel/cpu/resctrl/internal.h
+++ b/arch/x86/kernel/cpu/resctrl/internal.h
@@ -37,6 +37,7 @@
#define MBA_IS_LINEAR 0x4
#define MBA_MAX_MBPS U32_MAX
#define MAX_MBA_BW_AMD 0x800
+#define MBM_CNTR_WIDTH_OFFSET_AMD 20
#define RMID_VAL_ERROR BIT_ULL(63)
#define RMID_VAL_UNAVAIL BIT_ULL(62)
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-15 7:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 19:45 [PATCH v2] x86/resctrl: Fix memory bandwidth counter width for AMD Babu Moger
2020-06-15 7:42 ` [tip: x86/urgent] " tip-bot2 for Babu Moger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).