diff mbox series

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

Message ID 20220824230958.125906-1-alison.schofield@intel.com
State New, archived
Headers show
Series [ndctl] cxl/test: Use interleave arithmetic to sort memdevs for a region | expand

Commit Message

Alison Schofield Aug. 24, 2022, 11:09 p.m. UTC
From: Alison Schofield <alison.schofield@intel.com>

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.

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---
 test/cxl-region-sysfs.sh | 44 ++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)


base-commit: c9c9db39354ea0c3f737378186318e9b7908e3a7

Comments

Verma, Vishal L Aug. 24, 2022, 11:28 p.m. UTC | #1
On Wed, 2022-08-24 at 16:09 -0700, alison.schofield@intel.com wrote:
> From: Alison Schofield <alison.schofield@intel.com>
> 
> 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."

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

..and then this sentence can be dropped.

> 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.
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
> ---
>  test/cxl-region-sysfs.sh | 44 ++++++++++++++++++++++++++++++++--------
>  1 file changed, 36 insertions(+), 8 deletions(-)
> 
> diff --git a/test/cxl-region-sysfs.sh b/test/cxl-region-sysfs.sh
> index ae0f55653814..1af0ae7e632c 100644
> --- a/test/cxl-region-sysfs.sh
> +++ b/test/cxl-region-sysfs.sh
> @@ -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

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.

> +       # 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

same here as above.

> +       # 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

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

> +fi
>  
>  # TODO: use this alternative memdev ordering to validate a negative test for
>  # specifying invalid positions of memdevs
> 
> base-commit: c9c9db39354ea0c3f737378186318e9b7908e3a7
diff mbox series

Patch

diff --git a/test/cxl-region-sysfs.sh b/test/cxl-region-sysfs.sh
index ae0f55653814..1af0ae7e632c 100644
--- a/test/cxl-region-sysfs.sh
+++ b/test/cxl-region-sysfs.sh
@@ -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