From 293755790176a75fb985e50300c4f3e5d1728066 Mon Sep 17 00:00:00 2001 From: Swapnil Gaikwad Date: Tue, 16 Apr 2024 12:08:39 +0100 Subject: [PATCH] Add option to change SVE vector length for current and children processes. TEST_LABEL: ent-arch-aarch64 TEST_IMG: ubuntu/dotnet-build TEST_CMD: safe ./projects/dotnet/test-runtime.sh --scope coreclr,libs Jira: ENTLLT-7328 Change-Id: I727edf8652a5c8648e7008d4ca47e7a4f36d5a1e --- src/coreclr/inc/clrconfigvalues.h | 4 ++++ src/coreclr/vm/codeman.cpp | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index ddc7c79506ad4..acf983668b3ee 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -790,6 +790,10 @@ RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Sha256, W("EnableArm64Sh RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Rcpc, W("EnableArm64Rcpc"), 1, "Allows Arm64 Rcpc+ hardware intrinsics to be disabled") RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Rcpc2, W("EnableArm64Rcpc2"), 1, "Allows Arm64 Rcpc2+ hardware intrinsics to be disabled") RETAIL_CONFIG_DWORD_INFO(EXTERNAL_EnableArm64Sve, W("EnableArm64Sve"), 1, "Allows Arm64 SVE hardware intrinsics to be disabled") +#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) +// TODO-SVE: Once coreclr supports vector lengths >16bytes, the default should be -1. +RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_MaxVectorLength, W("MaxVectorLength"), 16, "Specifies maximum size of the vector length in bytes while using SVE on Arm64", CLRConfig::LookupOptions::ParseIntegerAsBase10) +#endif //defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) #endif /// diff --git a/src/coreclr/vm/codeman.cpp b/src/coreclr/vm/codeman.cpp index 3bb10ac6c6bb6..e1b52ec336b46 100644 --- a/src/coreclr/vm/codeman.cpp +++ b/src/coreclr/vm/codeman.cpp @@ -4,7 +4,10 @@ // // codeman.cpp - a managment class for handling multiple code managers // - +#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) +#include +#include +#endif // defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) #include "common.h" #include "jitinterface.h" #include "corjit.h" @@ -1525,6 +1528,18 @@ void EEJitManager::SetCpuInfo() if (((cpuFeatures & ARM64IntrinsicConstants_Sve) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableArm64Sve)) { +#if defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) + int maxVectorLength = CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_MaxVectorLength); + + // Limit the SVE vector length to 'maxVectorLength' if the underlying hardware offers longer vectors. + if ((prctl(PR_SVE_GET_VL, 0,0,0,0) & PR_SVE_VL_LEN_MASK) > maxVectorLength) + { + if (prctl(PR_SVE_SET_VL, (maxVectorLength | PR_SVE_VL_INHERIT), 0, 0, 0) == -1) + { + LogErrorToHost("LoadAndInitializeJIT: prctl() FAILED - unable to set maxVectorLength to %d", maxVectorLength); + } + } +#endif // defined(TARGET_LINUX) && (defined(DEBUG) || defined(_DEBUG)) CPUCompileFlags.Set(InstructionSet_Sve); }