mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:37:34 +00:00
Kernel: Add Processor::is_bootstrap_processor() function, and use it. (#6871)
The variety of checks for Processor::id() == 0 could use some assistance in the readability department. This change adds a new function to represent this check, and replaces the comparison everywhere it's used.
This commit is contained in:
parent
72a61fe137
commit
64b4e3f34b
4 changed files with 10 additions and 6 deletions
|
@ -823,6 +823,11 @@ public:
|
||||||
return read_fs_ptr(__builtin_offsetof(Processor, m_cpu));
|
return read_fs_ptr(__builtin_offsetof(Processor, m_cpu));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ALWAYS_INLINE static bool is_bootstrap_processor()
|
||||||
|
{
|
||||||
|
return Processor::id() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE u32 raise_irq()
|
ALWAYS_INLINE u32 raise_irq()
|
||||||
{
|
{
|
||||||
return m_in_irq++;
|
return m_in_irq++;
|
||||||
|
|
|
@ -485,7 +485,7 @@ UNMAP_AFTER_INIT APICTimer* APIC::initialize_timers(HardwareTimerBase& calibrati
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
// We should only initialize and calibrate the APIC timer once on the BSP!
|
// We should only initialize and calibrate the APIC timer once on the BSP!
|
||||||
VERIFY(Processor::id() == 0);
|
VERIFY(Processor::is_bootstrap_processor());
|
||||||
VERIFY(!m_apic_timer);
|
VERIFY(!m_apic_timer);
|
||||||
|
|
||||||
m_apic_timer = APICTimer::initialize(IRQ_APIC_TIMER, calibration_timer);
|
m_apic_timer = APICTimer::initialize(IRQ_APIC_TIMER, calibration_timer);
|
||||||
|
|
|
@ -475,7 +475,7 @@ UNMAP_AFTER_INIT Thread* Scheduler::create_ap_idle_thread(u32 cpu)
|
||||||
{
|
{
|
||||||
VERIFY(cpu != 0);
|
VERIFY(cpu != 0);
|
||||||
// This function is called on the bsp, but creates an idle thread for another AP
|
// This function is called on the bsp, but creates an idle thread for another AP
|
||||||
VERIFY(Processor::id() == 0);
|
VERIFY(Processor::is_bootstrap_processor());
|
||||||
|
|
||||||
VERIFY(s_colonel_process);
|
VERIFY(s_colonel_process);
|
||||||
Thread* idle_thread = s_colonel_process->create_kernel_thread(idle_loop, nullptr, THREAD_PRIORITY_MIN, String::formatted("idle thread #{}", cpu), 1 << cpu, false);
|
Thread* idle_thread = s_colonel_process->create_kernel_thread(idle_loop, nullptr, THREAD_PRIORITY_MIN, String::formatted("idle thread #{}", cpu), 1 << cpu, false);
|
||||||
|
@ -497,8 +497,7 @@ void Scheduler::timer_tick(const RegisterState& regs)
|
||||||
VERIFY(current_thread->current_trap()->regs == ®s);
|
VERIFY(current_thread->current_trap()->regs == ®s);
|
||||||
|
|
||||||
#if !SCHEDULE_ON_ALL_PROCESSORS
|
#if !SCHEDULE_ON_ALL_PROCESSORS
|
||||||
bool is_bsp = Processor::id() == 0;
|
if (!Processor::is_bootstrap_processor())
|
||||||
if (!is_bsp)
|
|
||||||
return; // TODO: This prevents scheduling on other CPUs!
|
return; // TODO: This prevents scheduling on other CPUs!
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -153,7 +153,7 @@ UNMAP_AFTER_INIT void TimeManagement::initialize(u32 cpu)
|
||||||
|
|
||||||
void TimeManagement::set_system_timer(HardwareTimerBase& timer)
|
void TimeManagement::set_system_timer(HardwareTimerBase& timer)
|
||||||
{
|
{
|
||||||
VERIFY(Processor::id() == 0); // This should only be called on the BSP!
|
VERIFY(Processor::is_bootstrap_processor()); // This should only be called on the BSP!
|
||||||
auto original_callback = m_system_timer->set_callback(nullptr);
|
auto original_callback = m_system_timer->set_callback(nullptr);
|
||||||
m_system_timer->disable();
|
m_system_timer->disable();
|
||||||
timer.set_callback(move(original_callback));
|
timer.set_callback(move(original_callback));
|
||||||
|
@ -269,7 +269,7 @@ UNMAP_AFTER_INIT bool TimeManagement::probe_and_set_non_legacy_hardware_timers()
|
||||||
// Update the time. We don't really care too much about the
|
// Update the time. We don't really care too much about the
|
||||||
// frequency of the interrupt because we'll query the main
|
// frequency of the interrupt because we'll query the main
|
||||||
// counter to get an accurate time.
|
// counter to get an accurate time.
|
||||||
if (Processor::id() == 0) {
|
if (Processor::is_bootstrap_processor()) {
|
||||||
// TODO: Have the other CPUs call system_timer_tick directly
|
// TODO: Have the other CPUs call system_timer_tick directly
|
||||||
increment_time_since_boot_hpet();
|
increment_time_since_boot_hpet();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue