179894
commit 38560563587ad8eafa700c56800ff844f18fbad1
179894
Author: Naohiro Tamura <naohirot@fujitsu.com>
179894
Date:   Thu May 20 07:34:37 2021 +0000
179894
179894
    aarch64: Added Vector Length Set test helper script
179894
    
179894
    This patch is a test helper script to change Vector Length for child
179894
    process. This script can be used as test-wrapper for 'make check'.
179894
    
179894
    Usage examples:
179894
    
179894
    ~/build$ make check subdirs=string \
179894
    test-wrapper='~/glibc/sysdeps/unix/sysv/linux/aarch64/vltest.py 16'
179894
    
179894
    ~/build$ ~/glibc/sysdeps/unix/sysv/linux/aarch64/vltest.py 16 \
179894
    make test t=string/test-memcpy
179894
    
179894
    ~/build$ ~/glibc/sysdeps/unix/sysv/linux/aarch64/vltest.py 32 \
179894
    ./debugglibc.sh string/test-memmove
179894
    
179894
    ~/build$ ~/glibc/sysdeps/unix/sysv/linux/aarch64/vltest.py 64 \
179894
    ./testrun.sh string/test-memset
179894
179894
diff --git a/INSTALL b/INSTALL
179894
index 065565093bd76d5b..b3a4370f592c5047 100644
179894
--- a/INSTALL
179894
+++ b/INSTALL
179894
@@ -387,6 +387,10 @@ the same syntax as 'test-wrapper-env', the only difference in its
179894
 semantics being starting with an empty set of environment variables
179894
 rather than the ambient set.
179894
 
179894
+   For AArch64 with SVE, when testing the GNU C Library, 'test-wrapper'
179894
+may be set to "SRCDIR/sysdeps/unix/sysv/linux/aarch64/vltest.py
179894
+VECTOR-LENGTH" to change Vector Length.
179894
+
179894
 Installing the C Library
179894
 ========================
179894
 
179894
diff --git a/manual/install.texi b/manual/install.texi
179894
index 7e9f2be150e6f98a..c262fd56d0cef67b 100644
179894
--- a/manual/install.texi
179894
+++ b/manual/install.texi
179894
@@ -425,6 +425,9 @@ use has the same syntax as @samp{test-wrapper-env}, the only
179894
 difference in its semantics being starting with an empty set of
179894
 environment variables rather than the ambient set.
179894
 
179894
+For AArch64 with SVE, when testing @theglibc{}, @samp{test-wrapper}
179894
+may be set to "@var{srcdir}/sysdeps/unix/sysv/linux/aarch64/vltest.py
179894
+@var{vector-length}" to change Vector Length.
179894
 
179894
 @node Running make install
179894
 @appendixsec Installing the C Library
179894
diff --git a/sysdeps/unix/sysv/linux/aarch64/vltest.py b/sysdeps/unix/sysv/linux/aarch64/vltest.py
179894
new file mode 100755
179894
index 0000000000000000..bed62ad151e06868
179894
--- /dev/null
179894
+++ b/sysdeps/unix/sysv/linux/aarch64/vltest.py
179894
@@ -0,0 +1,82 @@
179894
+#!/usr/bin/python3
179894
+# Set Scalable Vector Length test helper
179894
+# Copyright (C) 2021 Free Software Foundation, Inc.
179894
+# This file is part of the GNU C Library.
179894
+#
179894
+# The GNU C Library is free software; you can redistribute it and/or
179894
+# modify it under the terms of the GNU Lesser General Public
179894
+# License as published by the Free Software Foundation; either
179894
+# version 2.1 of the License, or (at your option) any later version.
179894
+#
179894
+# The GNU C Library is distributed in the hope that it will be useful,
179894
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
179894
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
179894
+# Lesser General Public License for more details.
179894
+#
179894
+# You should have received a copy of the GNU Lesser General Public
179894
+# License along with the GNU C Library; if not, see
179894
+# <https://www.gnu.org/licenses/>.
179894
+"""Set Scalable Vector Length test helper.
179894
+
179894
+Set Scalable Vector Length for child process.
179894
+
179894
+examples:
179894
+
179894
+~/build$ make check subdirs=string \
179894
+test-wrapper='~/glibc/sysdeps/unix/sysv/linux/aarch64/vltest.py 16'
179894
+
179894
+~/build$ ~/glibc/sysdeps/unix/sysv/linux/aarch64/vltest.py 16 \
179894
+make test t=string/test-memcpy
179894
+
179894
+~/build$ ~/glibc/sysdeps/unix/sysv/linux/aarch64/vltest.py 32 \
179894
+./debugglibc.sh string/test-memmove
179894
+
179894
+~/build$ ~/glibc/sysdeps/unix/sysv/linux/aarch64/vltest.py 64 \
179894
+./testrun.sh string/test-memset
179894
+"""
179894
+import argparse
179894
+from ctypes import cdll, CDLL
179894
+import os
179894
+import sys
179894
+
179894
+EXIT_SUCCESS = 0
179894
+EXIT_FAILURE = 1
179894
+EXIT_UNSUPPORTED = 77
179894
+
179894
+AT_HWCAP = 16
179894
+HWCAP_SVE = (1 << 22)
179894
+
179894
+PR_SVE_GET_VL = 51
179894
+PR_SVE_SET_VL = 50
179894
+PR_SVE_SET_VL_ONEXEC = (1 << 18)
179894
+PR_SVE_VL_INHERIT = (1 << 17)
179894
+PR_SVE_VL_LEN_MASK = 0xffff
179894
+
179894
+def main(args):
179894
+    libc = CDLL("libc.so.6")
179894
+    if not libc.getauxval(AT_HWCAP) & HWCAP_SVE:
179894
+        print("CPU doesn't support SVE")
179894
+        sys.exit(EXIT_UNSUPPORTED)
179894
+
179894
+    libc.prctl(PR_SVE_SET_VL,
179894
+               args.vl[0] | PR_SVE_SET_VL_ONEXEC | PR_SVE_VL_INHERIT)
179894
+    os.execvp(args.args[0], args.args)
179894
+    print("exec system call failure")
179894
+    sys.exit(EXIT_FAILURE)
179894
+
179894
+if __name__ == '__main__':
179894
+    parser = argparse.ArgumentParser(description=
179894
+            "Set Scalable Vector Length test helper",
179894
+            formatter_class=argparse.ArgumentDefaultsHelpFormatter)
179894
+
179894
+    # positional argument
179894
+    parser.add_argument("vl", nargs=1, type=int,
179894
+                        choices=range(16, 257, 16),
179894
+                        help=('vector length '\
179894
+                              'which is multiples of 16 from 16 to 256'))
179894
+    # remainDer arguments
179894
+    parser.add_argument('args', nargs=argparse.REMAINDER,
179894
+                        help=('args '\
179894
+                              'which is passed to child process'))
179894
+    args = parser.parse_args()
179894
+    main(args)