Skip to content

Commit afce63f

Browse files
linusgawesomekling
authored andcommitted
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.
1 parent 53a95a5 commit afce63f

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

Kernel/Arch/x86/Processor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ class Processor {
128128
void cpu_detect();
129129
void cpu_setup();
130130

131-
NonnullOwnPtr<KString> features_string() const;
132-
133131
public:
134132
Processor() = default;
135133

Kernel/Arch/x86/ProcessorInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ProcessorInfo {
2222

2323
static NonnullOwnPtr<KString> build_vendor_id_string();
2424
static NonnullOwnPtr<KString> build_brand_string();
25+
static NonnullOwnPtr<KString> build_features_string(Processor const&);
2526

2627
StringView vendor_id_string() const { return m_vendor_id_string->view(); }
2728
StringView brand_string() const { return m_brand_string->view(); }

Kernel/Arch/x86/common/Processor.cpp

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -596,22 +596,6 @@ UNMAP_AFTER_INIT void Processor::cpu_setup()
596596
#endif
597597
}
598598

599-
NonnullOwnPtr<KString> Processor::features_string() const
600-
{
601-
StringBuilder builder;
602-
bool first = true;
603-
for (auto feature = CPUFeature::Type(1u); feature != CPUFeature::__End; feature <<= 1u) {
604-
if (has_feature(feature)) {
605-
if (first)
606-
first = false;
607-
else
608-
MUST(builder.try_append(' '));
609-
MUST(builder.try_append(cpu_feature_to_string_view(feature)));
610-
}
611-
}
612-
return KString::must_create(builder.string_view());
613-
}
614-
615599
UNMAP_AFTER_INIT void Processor::early_initialize(u32 cpu)
616600
{
617601
m_self = this;
@@ -651,7 +635,9 @@ UNMAP_AFTER_INIT void Processor::initialize(u32 cpu)
651635
VERIFY(m_self == this);
652636
VERIFY(&current() == this); // sanity check
653637

654-
dmesgln("CPU[{}]: Supported features: {}", current_id(), features_string());
638+
m_info = new ProcessorInfo(*this);
639+
640+
dmesgln("CPU[{}]: Supported features: {}", current_id(), m_info->features_string());
655641
if (!has_feature(CPUFeature::RDRAND))
656642
dmesgln("CPU[{}]: No RDRAND support detected, randomness will be poor", current_id());
657643
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)
680666
detect_hypervisor();
681667
}
682668

683-
m_info = new ProcessorInfo(*this);
684-
685669
{
686670
// We need to prevent races between APs starting up at the same time
687671
VERIFY(cpu < s_processors.size());

Kernel/Arch/x86/common/ProcessorInfo.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Kernel {
1515
ProcessorInfo::ProcessorInfo(Processor const& processor)
1616
: m_vendor_id_string(build_vendor_id_string())
1717
, m_brand_string(build_brand_string())
18-
, m_features_string(processor.features_string())
18+
, m_features_string(build_features_string(processor))
1919
{
2020
CPUID cpuid(1);
2121
m_stepping = cpuid.eax() & 0xf;
@@ -75,4 +75,20 @@ NonnullOwnPtr<KString> ProcessorInfo::build_brand_string()
7575
return KString::must_create(buffer);
7676
}
7777

78+
NonnullOwnPtr<KString> ProcessorInfo::build_features_string(Processor const& processor)
79+
{
80+
StringBuilder builder;
81+
bool first = true;
82+
for (auto feature = CPUFeature::Type(1u); feature != CPUFeature::__End; feature <<= 1u) {
83+
if (processor.has_feature(feature)) {
84+
if (first)
85+
first = false;
86+
else
87+
MUST(builder.try_append(' '));
88+
MUST(builder.try_append(cpu_feature_to_string_view(feature)));
89+
}
90+
}
91+
return KString::must_create(builder.string_view());
92+
}
93+
7894
}

0 commit comments

Comments
 (0)