Skip to contentSkip to conversation

cxl/test: Use interleave arithmetic to sort memdevs for a region

PATCH In review [email protected] 2 participants 2 messages Aug 24, 2022 libnvdimm: non-volatile memory device

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 cxl/test: Use interleave arithmetic to sort memdevs for a region

From: Alison Schofield <[email protected]>

Test cxl-region-sysfs.sh assumes Modulo arithmetic. XOR arithmetic is being introduced and requires a different ordering of the memdevs in the region.

Update the test to sort the memdevs based on interleave arithmetic. If the interleave arithmetic attribute for the root decoder is not visible in sysfs, driver support for XOR math is not present. Default to Modulo sorting order.

---
 test/cxl-region-sysfs.sh | 44 ++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)
test/cxl-region-sysfs.sh +36 -8
index ae0f55653814..1af0ae7e632c 100644
@@ -58,15 +58,43 @@ readarray -t mem_sort1 < <($CXL list -M -p $port_dev1 | jq -r ".[] | .memdev")
 
 # TODO: add a cxl list option to list memdevs in valid region provisioning
 # order, hardcode for now.
+
+# Sort based on root decoder interleave arithmetic.
+# Default to Modulo if the sysfs attribute is not emitted.
+if [ ! -e /sys/bus/cxl/devices/$decoder/interleave_arithmetic ]; then
+	ia="0"
+else
+	ia=$(cat /sys/bus/cxl/devices/$decoder/interleave_arithmetic)
+fi
+
 mem_sort=()
-mem_sort[0]=${mem_sort0[0]}
-mem_sort[1]=${mem_sort1[0]}
-mem_sort[2]=${mem_sort0[2]}
-mem_sort[3]=${mem_sort1[2]}
-mem_sort[4]=${mem_sort0[1]}
-mem_sort[5]=${mem_sort1[1]}
-mem_sort[6]=${mem_sort0[3]}
-mem_sort[7]=${mem_sort1[3]}
+if [ $ia == "0" ]; then
+	# Modulo Arithmetic
+	mem_sort[0]=${mem_sort0[0]}
+	mem_sort[1]=${mem_sort1[0]}
+	mem_sort[2]=${mem_sort0[2]}
+	mem_sort[3]=${mem_sort1[2]}
+	mem_sort[4]=${mem_sort0[1]}
+	mem_sort[5]=${mem_sort1[1]}
+	mem_sort[6]=${mem_sort0[3]}
+	mem_sort[7]=${mem_sort1[3]}
+
+elif [ $ia == "1" ]; then
+	# XOR Arithmetic
+	mem_sort[0]=${mem_sort1[0]}
+	mem_sort[1]=${mem_sort0[0]}
+	mem_sort[2]=${mem_sort1[2]}
+	mem_sort[3]=${mem_sort0[2]}
+	mem_sort[4]=${mem_sort1[1]}
+	mem_sort[5]=${mem_sort0[1]}
+	mem_sort[6]=${mem_sort1[3]}
+	mem_sort[7]=${mem_sort0[3]}
+else
+	# Unknown Arithmetic
+	echo "Unknown interleave arithmetic: $ia for $decoder"
+	modprobe -r cxl-test
+	exit 1
+fi
 
 # TODO: use this alternative memdev ordering to validate a negative test for
 # specifying invalid positions of memdevs

base-commit: c9c9db39354ea0c3f737378186318e9b7908e3a7

Signature · 1 line
2.31.1
maintainer
#1 lore raw
Quoted 5 lines · On Wed, 2022-08-24 at 16:09 -0700, [email protected] wrote:

From: Alison Schofield <[email protected]>

Test cxl-region-sysfs.sh assumes Modulo arithmetic. XOR arithmetic is being introduced and requires a different ordering of the memdevs in the region.

Instead of 'is being introduced', maybe something like:

"In preparation for introduction of XOR arithmetic, allow for a different ordering of memdevs in the region."

Quoted 2 lines

Update the test to sort the memdevs based on interleave arithmetic.

..and then this sentence can be dropped.

Quoted 27 lines

If the interleave arithmetic attribute for the root decoder is not visible in sysfs, driver support for XOR math is not present. Default to Modulo sorting order.

---
 test/cxl-region-sysfs.sh | 44 ++++++++++++++++++++++++++++++++--------

 1 file changed, 36 insertions(+), 8 deletions(-)
test/cxl-region-sysfs.sh +0 -0
index ae0f55653814..1af0ae7e632c 100644
@@ -58,15 +58,43 @@ readarray -t mem_sort1 < <($CXL list -M -p $port_dev1 | jq -r ".[] | .memdev")


 # TODO: add a cxl list option to list memdevs in valid region provisioning # order, hardcode for now.

test/cxl-region-sysfs.sh +9 -0
+
+# Sort based on root decoder interleave arithmetic.
+# Default to Modulo if the sysfs attribute is not emitted.
+if [ ! -e /sys/bus/cxl/devices/$decoder/interleave_arithmetic ]; then
+       ia="0"
+else
+       ia=$(cat /sys/bus/cxl/devices/$decoder/interleave_arithmetic)
+fi
+

 mem_sort=()

test/cxl-region-sysfs.sh readarray -t mem_sort1 < <($CXL list -M -p $port_dev1 | jq -r ".[] | .memdev") · line 71

Quoted 9 lines
test/cxl-region-sysfs.sh +1 -8
-mem_sort[0]=${mem_sort0[0]}
-mem_sort[1]=${mem_sort1[0]}
-mem_sort[2]=${mem_sort0[2]}
-mem_sort[3]=${mem_sort1[2]}
-mem_sort[4]=${mem_sort0[1]}
-mem_sort[5]=${mem_sort1[1]}
-mem_sort[6]=${mem_sort0[3]}
-mem_sort[7]=${mem_sort1[3]}
+if [ $ia == "0" ]; then

If using '==' this should use the 'if [[' bash-style check, otherwise with a single '[', the test should use '-eq' (and quote the variable in this case).

i.e. either

if [[ $ia == "0" ]]; then ...

or

if [ "$ia" -eq "0" ]; then ...

We have bash assumptions (i.e. not restricted to posix sh) everywhere already, so the first one is preferable.

test/cxl-region-sysfs.sh

Quoted 11 lines

+       # Modulo Arithmetic
+       mem_sort[0]=${mem_sort0[0]}
+       mem_sort[1]=${mem_sort1[0]}
+       mem_sort[2]=${mem_sort0[2]}
+       mem_sort[3]=${mem_sort1[2]}
+       mem_sort[4]=${mem_sort0[1]}
+       mem_sort[5]=${mem_sort1[1]}
+       mem_sort[6]=${mem_sort0[3]}
+       mem_sort[7]=${mem_sort1[3]}

test/cxl-region-sysfs.sh +2 -0
+
+elif [ $ia == "1" ]; then

same here as above.

Quoted 6 lines

+       # XOR Arithmetic
+       mem_sort[0]=${mem_sort1[0]}
+       mem_sort[1]=${mem_sort0[0]}
+       mem_sort[2]=${mem_sort1[2]}
+       mem_sort[3]=${mem_sort0[2]}
+       mem_sort[4]=${mem_sort1[1]}

Quoted 8 lines

+       mem_sort[5]=${mem_sort0[1]}
+       mem_sort[6]=${mem_sort1[3]}
+       mem_sort[7]=${mem_sort0[3]}
+else
+       # Unknown Arithmetic
+       echo "Unknown interleave arithmetic: $ia for $decoder" +       modprobe -r cxl-test
+       exit 1

This should use the 'err "$LINENO: other-stuff"' pattern rather than echo + exit.

Quoted 6 lines

+fi

 # TODO: use this alternative memdev ordering to validate a negative test for

 # specifying invalid positions of memdevs

base-commit: c9c9db39354ea0c3f737378186318e9b7908e3a7