From afce63fffce1f78e65c84f2215d9b9ea1ae7ea6d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 3 Apr 2022 16:47:38 +0100 Subject: [PATCH] Kernel: Move feature string building to ProcessorInfo Other than a dmesgln(), ProcessorInfo is the only user of this function and is already responsible for building other CPUID-related strings. --- Kernel/Arch/x86/Processor.h | 2 -- Kernel/Arch/x86/ProcessorInfo.h | 1 + Kernel/Arch/x86/common/Processor.cpp | 22 +++------------------- Kernel/Arch/x86/common/ProcessorInfo.cpp | 18 +++++++++++++++++- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Kernel/Arch/x86/Processor.h b/Kernel/Arch/x86/Processor.h index 05493f82e00..9bd13613e44 100644 --- a/Kernel/Arch/x86/Processor.h +++ b/Kernel/Arch/x86/Processor.h @@ -128,8 +128,6 @@ class Processor { void cpu_detect(); void cpu_setup(); - NonnullOwnPtr features_string() const; - public: Processor() = default; diff --git a/Kernel/Arch/x86/ProcessorInfo.h b/Kernel/Arch/x86/ProcessorInfo.h index 3f45a670783..41b537efa35 100644 --- a/Kernel/Arch/x86/ProcessorInfo.h +++ b/Kernel/Arch/x86/ProcessorInfo.h @@ -22,6 +22,7 @@ public: static NonnullOwnPtr build_vendor_id_string(); static NonnullOwnPtr build_brand_string(); + static NonnullOwnPtr build_features_string(Processor const&); StringView vendor_id_string() const { return m_vendor_id_string->view(); } StringView brand_string() const { return m_brand_string->view(); } diff --git a/Kernel/Arch/x86/common/Processor.cpp b/Kernel/Arch/x86/common/Processor.cpp index 1cf3a1e6bee..15c5be3e28d 100644 --- a/Kernel/Arch/x86/common/Processor.cpp +++ b/Kernel/Arch/x86/common/Processor.cpp @@ -596,22 +596,6 @@ UNMAP_AFTER_INIT void Processor::cpu_setup() #endif } -NonnullOwnPtr Processor::features_string() const -{ - StringBuilder builder; - bool first = true; - for (auto feature = CPUFeature::Type(1u); feature != CPUFeature::__End; feature <<= 1u) { - if (has_feature(feature)) { - if (first) - first = false; - else - MUST(builder.try_append(' ')); - MUST(builder.try_append(cpu_feature_to_string_view(feature))); - } - } - return KString::must_create(builder.string_view()); -} - UNMAP_AFTER_INIT void Processor::early_initialize(u32 cpu) { m_self = this; @@ -651,7 +635,9 @@ UNMAP_AFTER_INIT void Processor::initialize(u32 cpu) VERIFY(m_self == this); VERIFY(¤t() == this); // sanity check - dmesgln("CPU[{}]: Supported features: {}", current_id(), features_string()); + m_info = new ProcessorInfo(*this); + + dmesgln("CPU[{}]: Supported features: {}", current_id(), m_info->features_string()); if (!has_feature(CPUFeature::RDRAND)) dmesgln("CPU[{}]: No RDRAND support detected, randomness will be poor", current_id()); dmesgln("CPU[{}]: Physical address bit width: {}", current_id(), m_physical_address_bit_width); @@ -680,8 +666,6 @@ UNMAP_AFTER_INIT void Processor::initialize(u32 cpu) detect_hypervisor(); } - m_info = new ProcessorInfo(*this); - { // We need to prevent races between APs starting up at the same time VERIFY(cpu < s_processors.size()); diff --git a/Kernel/Arch/x86/common/ProcessorInfo.cpp b/Kernel/Arch/x86/common/ProcessorInfo.cpp index 6c663057197..5c6d0056a15 100644 --- a/Kernel/Arch/x86/common/ProcessorInfo.cpp +++ b/Kernel/Arch/x86/common/ProcessorInfo.cpp @@ -15,7 +15,7 @@ namespace Kernel { ProcessorInfo::ProcessorInfo(Processor const& processor) : m_vendor_id_string(build_vendor_id_string()) , m_brand_string(build_brand_string()) - , m_features_string(processor.features_string()) + , m_features_string(build_features_string(processor)) { CPUID cpuid(1); m_stepping = cpuid.eax() & 0xf; @@ -75,4 +75,20 @@ NonnullOwnPtr ProcessorInfo::build_brand_string() return KString::must_create(buffer); } +NonnullOwnPtr ProcessorInfo::build_features_string(Processor const& processor) +{ + StringBuilder builder; + bool first = true; + for (auto feature = CPUFeature::Type(1u); feature != CPUFeature::__End; feature <<= 1u) { + if (processor.has_feature(feature)) { + if (first) + first = false; + else + MUST(builder.try_append(' ')); + MUST(builder.try_append(cpu_feature_to_string_view(feature))); + } + } + return KString::must_create(builder.string_view()); +} + }