diff options
author | 2022-02-03 13:45:56 +0000 | |
---|---|---|
committer | 2022-02-04 14:13:59 +0000 | |
commit | 3b76ab46081304d6847b0d27e26aa4e0da24e673 (patch) | |
tree | f21cbada02814850dc0dda7c956a25b4f4b76522 | |
parent | 92138f0dae9348a9ce90bd91ef34341efefc74d5 (diff) |
Add known instruction set variants to logging strings
If a user had a wrong variant, they would get a message like
`Unexpected CPU variant for X86 using defaults: x86` but they
wouldn't know which ones we accept, unless they take a look at
the code.
This change comes after a developer's suggestion when encountering
said warning string.
Test: Presubmit tests
Change-Id: I3a7b9408cf55114229843f6ff6013999350d7185
-rw-r--r-- | runtime/arch/arm64/instruction_set_features_arm64.cc | 4 | ||||
-rw-r--r-- | runtime/arch/instruction_set_features.cc | 10 | ||||
-rw-r--r-- | runtime/arch/instruction_set_features.h | 5 | ||||
-rw-r--r-- | runtime/arch/x86/instruction_set_features_x86.cc | 8 |
4 files changed, 25 insertions, 2 deletions
diff --git a/runtime/arch/arm64/instruction_set_features_arm64.cc b/runtime/arch/arm64/instruction_set_features_arm64.cc index cef35fc355..e65514e709 100644 --- a/runtime/arch/arm64/instruction_set_features_arm64.cc +++ b/runtime/arch/arm64/instruction_set_features_arm64.cc @@ -147,7 +147,9 @@ Arm64FeaturesUniquePtr Arm64InstructionSetFeatures::FromVariant( }; if (!FindVariantInArray(arm64_known_variants, arraysize(arm64_known_variants), variant)) { std::ostringstream os; - os << "Unexpected CPU variant for Arm64: " << variant; + os << "Unexpected CPU variant for Arm64: " << variant << ".\n"; + os << "Known variants: "; + CommaSeparateVariants(os, arm64_known_variants, arraysize(arm64_known_variants)); *error_msg = os.str(); return nullptr; } diff --git a/runtime/arch/instruction_set_features.cc b/runtime/arch/instruction_set_features.cc index ec1e340245..5ae920bef1 100644 --- a/runtime/arch/instruction_set_features.cc +++ b/runtime/arch/instruction_set_features.cc @@ -267,6 +267,16 @@ bool InstructionSetFeatures::FindVariantInArray(const char* const variants[], si return std::find(begin, end, variant) != end; } +void InstructionSetFeatures::CommaSeparateVariants(std::ostream& os, + const char* const variants[], + size_t num_variants) { + std::string separator = ""; + for (size_t i = 0u; i < num_variants; ++i) { + os << separator << variants[i]; + separator = ", "; + } +} + std::unique_ptr<const InstructionSetFeatures> InstructionSetFeatures::AddRuntimeDetectedFeatures( const InstructionSetFeatures *features ATTRIBUTE_UNUSED) const { UNIMPLEMENTED(FATAL) << kRuntimeISA; diff --git a/runtime/arch/instruction_set_features.h b/runtime/arch/instruction_set_features.h index b80d36f153..4fd96566ed 100644 --- a/runtime/arch/instruction_set_features.h +++ b/runtime/arch/instruction_set_features.h @@ -130,6 +130,11 @@ class InstructionSetFeatures { static bool FindVariantInArray(const char* const variants[], size_t num_variants, const std::string& variant); + // Comma separates the variants and adds them to the `os` buffer. + static void CommaSeparateVariants(std::ostream& os, + const char* const variants[], + size_t num_variants); + // Add architecture specific features in sub-classes. virtual std::unique_ptr<const InstructionSetFeatures> AddFeaturesFromSplitString(const std::vector<std::string>& features, diff --git a/runtime/arch/x86/instruction_set_features_x86.cc b/runtime/arch/x86/instruction_set_features_x86.cc index d2dbe1dde3..11cfbc9469 100644 --- a/runtime/arch/x86/instruction_set_features_x86.cc +++ b/runtime/arch/x86/instruction_set_features_x86.cc @@ -133,7 +133,13 @@ X86FeaturesUniquePtr X86InstructionSetFeatures::FromVariant( bool known_variant = FindVariantInArray(x86_known_variants, arraysize(x86_known_variants), variant); if (!known_variant && variant != "default") { - LOG(WARNING) << "Unexpected CPU variant for X86 using defaults: " << variant; + std::ostringstream os; + os << "Unexpected CPU variant for x86: " << variant << ".\n"; + os << "Known variants: "; + CommaSeparateVariants(os, x86_known_variants, arraysize(x86_known_variants)); + // `default` is a valid variant too. + os << ", default"; + LOG(WARNING) << os.str(); } return Create(x86_64, has_SSSE3, has_SSE4_1, has_SSE4_2, has_AVX, has_AVX2, has_POPCNT); |