selftests/resctrl: Fix resctrl selftests issues on aarch64
Subsystems (2)
v2 cover selftests/resctrl: Fix resctrl selftests issues on aarch64
This series fixes numerous issues in the resctrl selftests on aarch64, where they currently misreport failures.
Patch 1 adds aarch64 implementations of cl_flush() and sb() in fill_buf.c so cache flushes are no longer silent no-ops.
Patch 2 teaches detect_vendor() about aarch64 (which exposes no vendor_id in /proc/cpuinfo) and lets arch_supports_noncont_cat() return true for ARM, fixing spurious L3_NONCONT_CAT failures.
Patch 3 skips L3_CAT at feature-check time when MPAM legitimately reports every CBM bit as shareable, instead of failing the test.
Changes since v1:
- Make the 3 patches into a series
Richard Cheng (3):
selftests/resctrl: Skip L3_CAT when no exclusive cache portion exists selftests/resctrl: Implement cl_flush() and sb() for aarch64 selftests/resctrl: Recognise aarch64 as a vendor for L3_NONCONT_CAT
tools/testing/selftests/resctrl/cat_test.c | 32 +++++++++++++++++-- tools/testing/selftests/resctrl/fill_buf.c | 6 ++++ tools/testing/selftests/resctrl/resctrl.h | 1 + .../testing/selftests/resctrl/resctrl_tests.c | 11 +++++++ 4 files changed, 47 insertions(+), 3 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/3 selftests/resctrl: Skip L3_CAT when no exclusive cache portion exists
L3_CAT measures cache isolation, which requires at least one cache bit that is not shared with non-CPU agents, i.e. cbm_mask & ~shareable_bits must be non-zero. On MPAM, shareable_bits == cbm_mask is a legitimate state, so there are situations in which no bit can be reported as exclusive.
Previously get_mask_no_shareable() was invoked inside cat_run_test() and silently returned -1, which surfaced as a test failure on arm64 MPAM systems.
Implement cat_feature_check() to perform the same check at feature-check time. It prints a diagnostic and returns false so the test case is skipped instead of failing.
--- tools/testing/selftests/resctrl/cat_test.c | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
tools/testing/selftests/resctrl/cat_test.c +22 -1
@@ -378,11 +378,32 @@ static bool noncont_cat_feature_check(const struct resctrl_test *test)return resource_info_file_exists (test->resource,"sparse_masks" ); } +static bool cat_feature_check (const struct resctrl_test *test) +{ +unsigned long mask; + +if (!test_resource_feature_check (test)) +return false; + +/* +* The CAT isolation measurement needs a cache portion that no +* other agent shares. On MPAM the kernel may legitimately report +* all bits as shareable; skip the test if that is the case. +*/ +if (get_mask_no_shareable (test->resource, &mask)) { +ksft_print_msg ("All %s bits are shareable; cannot measure CAT isolation\n" , + test->resource); +return false; + } + +return true; +} +struct resctrl_test l3_cat_test = { .name ="L3_CAT" , .group ="CAT" , .resource ="L3" , - .feature_check = test_resource_feature_check, + .feature_check = cat_feature_check, .run_test = cat_run_test, .cleanup = cat_test_cleanup, };
Signature · 1 line
2.43.0
Re: [PATCH v2 1/3] selftests/resctrl: Skip L3_CAT when no exclusive cache portion exists
Quoted 49 lines · Richard Cheng
L3_CATmeasures cache isolation, which requires at least one cache bit that is not shared with non-CPU agents, i.e.cbm_mask& ~shareable_bits must be non-zero. On MPAM,shareable_bits==cbm_maskis a legitimate state, so there are situations in which no bit can be reported as exclusive.Previously
get_mask_no_shareable()was invoked insidecat_run_test()and silently returned -1, which surfaced as a test failure on arm64 MPAM systems.Implement
cat_feature_check()to perform the same check at feature-check time. It prints a diagnostic and returns false so the test case is skipped instead of failing.Tested-by Chen Yu <[email protected]>Signed-off-by Richard Cheng <[email protected]>--- tools/testing/selftests/resctrl/cat_test.c | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)tools/testing/selftests/resctrl/cat_test.c +20
-0@@ -378,11 +378,32 @@ static bool noncont_cat_feature_check(const struct resctrl_test *test)return resource_info_file_exists (test->resource,"sparse_masks" ); } +static bool cat_feature_check (const struct resctrl_test *test) +{ +unsigned long mask; + +if (!test_resource_feature_check (test)) +return false; + +/* +* The CAT isolation measurement needs a cache portion that no +* other agent shares. On MPAM the kernel may legitimately report +* all bits as shareable; skip the test if that is the case. +*/ +if (get_mask_no_shareable (test->resource, &mask)) { +ksft_print_msg ("All %s bits are shareable; cannot measure CAT isolation\n" , + test->resource); +return false; + } + +return true; +}
tools/testing/selftests/resctrl/cat_test.c static bool noncont_cat_feature_check(const struct resctrl_test *test) · line 409
Quoted 10 lines
tools/testing/selftests/resctrl/cat_test.c +2
-1+struct resctrl_test l3_cat_test = { .name ="L3_CAT" , .group ="CAT" , .resource ="L3" , - .feature_check = test_resource_feature_check, + .feature_check = cat_feature_check, .run_test = cat_run_test, .cleanup = cat_test_cleanup, };
Nit, the patch numbering and the numbering used in the coverletter did not match.
Signature · 1 line
i.
PATCH v2 2/3 selftests/resctrl: Implement cl_flush() and sb() for aarch64
In reply to Richard Chengcl_flush() and sb() in fill_buf.c only have implementations for i386 and x86_64, so on aarch64 both compile to empty functions. mem_flush() then walks the buffer calling a no-op cl_flush() per cache line and finishes with a no-op sb(), leaving any caller that expects a flushed buffer (e.g. CMT, L3_CAT) operating on unflushed state with no warning.
Add an aarch64 code block using the ARM equivalents:
* "dc civac, %0" for cl_flush()
* "dsb sy" for sb()
Both instructions are EL0-accessible on Linux aarch64.
--- tools/testing/selftests/resctrl/fill_buf.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/testing/selftests/resctrl/fill_buf.c +6 -0
@@ -27,6 +27,9 @@ static void sb(void)#if defined(__i386) || defined(__x86_64) asmvolatile ("sfence\n\t" : : :"memory" ); +#elif defined(__aarch64__) + asmvolatile ("dsb sy\n\t" + : : :"memory" );#endif }
@@ -35,6 +38,9 @@ static void cl_flush(void *p)#if defined(__i386) || defined(__x86_64) asmvolatile ("clflush (%0)\n\t" : :"r" (p) :"memory" ); +#elif defined(__aarch64__) + asmvolatile ("dc civac, %0\n\t" + : :"r" (p) :"memory" );#endif }
Signature · 1 line
2.43.0
PATCH v2 3/3 selftests/resctrl: Recognise aarch64 as a vendor for L3_NONCONT_CAT
In reply to Richard Chengaarch64 has no vendor_id in /proc/cpuinfo, so detect_vendor() returns 0 and arch_supports_noncont_cat() falls through to "return false". L3_NONCONT_CAT therefore spuriously fails on every ARM MPAM platform.
Define ARCH_ARM, short-circuit detect_vendor() to it on aarch64, and add it to the AMD/Hygon always-supports early-out in arch_supports_noncont_cat().
aarch64 has many implementers (ARM 0x41, NVIDIA 0x43, etc.), but MPAM mandates non-contiguous CPBM uniformly, so per-implementer handling is not needed here.
--- tools/testing/selftests/resctrl/cat_test.c | 9 +++++++-- tools/testing/selftests/resctrl/resctrl.h | 1 + tools/testing/selftests/resctrl/resctrl_tests.c | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-)
tools/testing/selftests/resctrl/cat_test.c +7 -2
@@ -292,8 +292,13 @@ static bool arch_supports_noncont_cat(const struct resctrl_test *test) {unsigned int vendor_id =get_vendor (); -/* AMD and Hygon always support non-contiguous CBM. */ -if (vendor_id ==ARCH_AMD || vendor_id ==ARCH_HYGON ) +/* +* AMD and Hygon always support non-contiguous CBM. ARM/MPAM defines +* MPAMCFG_CPBM as a bitmap with no contiguity constraint per ARM +* DDI 0598. +*/ +if (vendor_id ==ARCH_AMD || vendor_id ==ARCH_HYGON || + vendor_id ==ARCH_ARM )return true;#if defined(__i386__) || defined(__x86_64__)/* arch */
tools/testing/selftests/resctrl/resctrl.h +1 -0
@@ -40,6 +40,7 @@#define ARCH_INTEL BIT(0)#define ARCH_AMD BIT(1)#define ARCH_HYGON BIT(2) +#define ARCH_ARM BIT(3)#define END_OF_TESTS 1
tools/testing/selftests/resctrl/resctrl_tests.c +11 -0
@@ -34,6 +34,17 @@ static unsigned int detect_vendor(void)if (initialized)return vendor_id; +#if defined(__aarch64__) +/* +* aarch64 has no userspace vendor_id in /proc/cpuinfo. MPAM-capable +* ARM implementations follow ARM DDI 0598; treat all aarch64 builds +* as a single vendor for the purposes of resctrl selftests. +*/ + vendor_id =ARCH_ARM ; + initialized = true; +return vendor_id; +#endif + inf =fopen ("/proc/cpuinfo" ,"r" );if (!inf) { vendor_id =0 ;
Signature · 1 line
2.43.0
Re: [PATCH v2 3/3] selftests/resctrl: Recognise aarch64 as a vendor for L3_NONCONT_CAT
Quoted 59 lines · Richard Cheng
aarch64 has no
vendor_idin/proc/cpuinfo, sodetect_vendor()returns 0 andarch_supports_noncont_cat()falls through to "return false".L3_NONCONT_CATtherefore spuriously fails on every ARM MPAM platform.Define
ARCH_ARM, short-circuitdetect_vendor()to it on aarch64, and add it to the AMD/Hygon always-supports early-out inarch_supports_noncont_cat().aarch64 has many implementers (ARM
0x41, NVIDIA0x43, etc.), but MPAM mandates non-contiguous CPBM uniformly, so per-implementer handling is not needed here.Signed-off-by Richard Cheng <[email protected]>--- tools/testing/selftests/resctrl/cat_test.c | 9 +++++++-- tools/testing/selftests/resctrl/resctrl.h | 1 + tools/testing/selftests/resctrl/resctrl_tests.c | 11 +++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-)tools/testing/selftests/resctrl/cat_test.c +7
-2@@ -292,8 +292,13 @@ static bool arch_supports_noncont_cat(const struct resctrl_test *test) {unsigned int vendor_id =get_vendor (); -/* AMD and Hygon always support non-contiguous CBM. */ -if (vendor_id ==ARCH_AMD || vendor_id ==ARCH_HYGON ) +/* +* AMD and Hygon always support non-contiguous CBM. ARM/MPAM defines +* MPAMCFG_CPBM as a bitmap with no contiguity constraint per ARM +* DDI 0598. +*/ +if (vendor_id ==ARCH_AMD || vendor_id ==ARCH_HYGON || + vendor_id ==ARCH_ARM )return true;#if defined(__i386__) || defined(__x86_64__)/* arch */ tools/testing/selftests/resctrl/resctrl.h +1
-0@@ -40,6 +40,7 @@#define ARCH_INTEL BIT(0)#define ARCH_AMD BIT(1)#define ARCH_HYGON BIT(2) +#define ARCH_ARM BIT(3)#define END_OF_TESTS 1tools/testing/selftests/resctrl/resctrl_tests.c +0
-0@@ -34,6 +34,17 @@ static unsigned int detect_vendor(void)if (initialized)return vendor_id;
tools/testing/selftests/resctrl/resctrl_tests.c static unsigned int detect_vendor(void) · line 46
Quoted 10 lines
tools/testing/selftests/resctrl/resctrl_tests.c +10
-0+#if defined(__aarch64__) +/* +* aarch64 has no userspace vendor_id in /proc/cpuinfo. MPAM-capable +* ARM implementations follow ARM DDI 0598; treat all aarch64 builds +* as a single vendor for the purposes of resctrl selftests. +*/ + vendor_id =ARCH_ARM ; + initialized = true; +return vendor_id; +#endif
It would be better to create a detect_aarch64() function and put the ifdeffery inside it so it returns either true or false here.
Quoted 5 lines
tools/testing/selftests/resctrl/resctrl_tests.c +1
-0+ inf =fopen ("/proc/cpuinfo" ,"r" );if (!inf) { vendor_id =0 ;
Signature · 1 line
i.