Skip to content

Commit 1c1c4f6

Browse files
committed
Kernel: De-templatefy ProcessorBase
This makes ProcessorBase a non-templated class, leading to a significant reduction in LOC while also making the class (and the Processor class by extension) much more decomposable.
1 parent cef72c7 commit 1c1c4f6

File tree

9 files changed

+195
-387
lines changed

9 files changed

+195
-387
lines changed

Kernel/Arch/Processor.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ namespace Kernel {
1919
READONLY_AFTER_INIT FPUState s_clean_fpu_state;
2020
READONLY_AFTER_INIT Atomic<u32> g_total_processors;
2121

22-
template<typename T>
23-
void ProcessorBase<T>::check_invoke_scheduler()
22+
void ProcessorBase::check_invoke_scheduler()
2423
{
2524
VERIFY_INTERRUPTS_DISABLED();
2625
VERIFY(!m_in_irq);
@@ -31,10 +30,8 @@ void ProcessorBase<T>::check_invoke_scheduler()
3130
Scheduler::invoke_async();
3231
}
3332
}
34-
template void ProcessorBase<Processor>::check_invoke_scheduler();
3533

36-
template<typename T>
37-
void ProcessorBase<T>::deferred_call_queue(Function<void()> callback)
34+
void ProcessorBase::deferred_call_queue(Function<void()> callback)
3835
{
3936
// NOTE: If we are called outside of a critical section and outside
4037
// of an irq handler, the function will be executed before we return!
@@ -46,10 +43,8 @@ void ProcessorBase<T>::deferred_call_queue(Function<void()> callback)
4643

4744
cur_proc.m_deferred_call_pool.queue_entry(entry);
4845
}
49-
template void ProcessorBase<Processor>::deferred_call_queue(Function<void()>);
5046

51-
template<typename T>
52-
void ProcessorBase<T>::enter_trap(TrapFrame& trap, bool raise_irq)
47+
void ProcessorBase::enter_trap(TrapFrame& trap, bool raise_irq)
5348
{
5449
VERIFY_INTERRUPTS_DISABLED();
5550
VERIFY(&Processor::current() == this);
@@ -72,25 +67,32 @@ void ProcessorBase<T>::enter_trap(TrapFrame& trap, bool raise_irq)
7267
trap.next_trap = nullptr;
7368
}
7469
}
75-
template void ProcessorBase<Processor>::enter_trap(TrapFrame&, bool);
7670

77-
template<typename T>
78-
u64 ProcessorBase<T>::time_spent_idle() const
71+
InterruptsState ProcessorBase::interrupts_state()
72+
{
73+
return ProcessorBase::are_interrupts_enabled() ? InterruptsState::Enabled : InterruptsState::Disabled;
74+
}
75+
76+
void ProcessorBase::restore_interrupts_state(InterruptsState interrupts_state)
77+
{
78+
if (interrupts_state == InterruptsState::Enabled)
79+
ProcessorBase::enable_interrupts();
80+
else
81+
ProcessorBase::disable_interrupts();
82+
}
83+
84+
u64 ProcessorBase::time_spent_idle() const
7985
{
8086
return m_idle_thread->time_in_user() + m_idle_thread->time_in_kernel();
8187
}
82-
template u64 ProcessorBase<Processor>::time_spent_idle() const;
8388

84-
template<typename T>
85-
void ProcessorBase<T>::leave_critical()
89+
void ProcessorBase::leave_critical()
8690
{
8791
InterruptDisabler disabler;
8892
current().do_leave_critical();
8993
}
90-
template void ProcessorBase<Processor>::leave_critical();
9194

92-
template<typename T>
93-
void ProcessorBase<T>::do_leave_critical()
95+
void ProcessorBase::do_leave_critical()
9496
{
9597
VERIFY(m_in_critical > 0);
9698
if (m_in_critical == 1) {
@@ -105,7 +107,6 @@ void ProcessorBase<T>::do_leave_critical()
105107
m_in_critical = m_in_critical - 1;
106108
}
107109
}
108-
template void ProcessorBase<Processor>::do_leave_critical();
109110

110111
void exit_kernel_thread(void)
111112
{
@@ -135,8 +136,7 @@ void do_context_first_init(Thread* from_thread, Thread* to_thread)
135136
Scheduler::leave_on_first_switch(InterruptsState::Disabled);
136137
}
137138

138-
template<typename T>
139-
ErrorOr<Vector<FlatPtr, 32>> ProcessorBase<T>::capture_stack_trace(Thread& thread, size_t max_frames)
139+
ErrorOr<Vector<FlatPtr, 32>> ProcessorBase::capture_stack_trace(Thread& thread, size_t max_frames)
140140
{
141141
FlatPtr frame_ptr = 0, pc = 0;
142142
Vector<FlatPtr, 32> stack_trace;
@@ -264,6 +264,5 @@ ErrorOr<Vector<FlatPtr, 32>> ProcessorBase<T>::capture_stack_trace(Thread& threa
264264

265265
return stack_trace;
266266
}
267-
template ErrorOr<Vector<FlatPtr, 32>> ProcessorBase<Processor>::capture_stack_trace(Thread&, size_t);
268267

269268
}

Kernel/Arch/Processor.h

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ extern "C" void thread_context_first_enter(void);
4848
extern "C" void do_assume_context(Thread* thread, u32 flags);
4949
extern "C" FlatPtr do_init_context(Thread* thread, u32) __attribute__((used));
5050

51-
template<typename ProcessorT>
5251
class ProcessorBase {
5352
public:
5453
template<typename T>
@@ -80,7 +79,7 @@ class ProcessorBase {
8079
ALWAYS_INLINE static void pause();
8180
ALWAYS_INLINE static void wait_check();
8281

83-
ALWAYS_INLINE static ProcessorT& current();
82+
ALWAYS_INLINE static Processor& current();
8483
static Processor& by_id(u32);
8584

8685
ALWAYS_INLINE u32 id() const
@@ -94,7 +93,10 @@ class ProcessorBase {
9493
}
9594

9695
ALWAYS_INLINE static u32 current_id();
97-
ALWAYS_INLINE static bool is_bootstrap_processor();
96+
ALWAYS_INLINE static bool is_bootstrap_processor()
97+
{
98+
return current_id() == 0;
99+
}
98100
ALWAYS_INLINE bool has_nx() const;
99101
ALWAYS_INLINE bool has_feature(CPUFeature::Type const& feature) const
100102
{
@@ -174,7 +176,7 @@ class ProcessorBase {
174176
static ErrorOr<Vector<FlatPtr, 32>> capture_stack_trace(Thread& thread, size_t max_frames = 0);
175177

176178
protected:
177-
ProcessorT* m_self;
179+
Processor* m_self;
178180
CPUFeature::Type m_features;
179181

180182
Atomic<bool> m_halt_requested;
@@ -203,8 +205,6 @@ class ProcessorBase {
203205
DeferredCallPool m_deferred_call_pool {};
204206
};
205207

206-
template class ProcessorBase<Processor>;
207-
208208
}
209209

210210
#if ARCH(X86_64)
@@ -219,27 +219,6 @@ template class ProcessorBase<Processor>;
219219

220220
namespace Kernel {
221221

222-
template<typename T>
223-
ALWAYS_INLINE bool ProcessorBase<T>::is_bootstrap_processor()
224-
{
225-
return current_id() == 0;
226-
}
227-
228-
template<typename T>
229-
InterruptsState ProcessorBase<T>::interrupts_state()
230-
{
231-
return Processor::are_interrupts_enabled() ? InterruptsState::Enabled : InterruptsState::Disabled;
232-
}
233-
234-
template<typename T>
235-
void ProcessorBase<T>::restore_interrupts_state(InterruptsState interrupts_state)
236-
{
237-
if (interrupts_state == InterruptsState::Enabled)
238-
Processor::enable_interrupts();
239-
else
240-
Processor::disable_interrupts();
241-
}
242-
243222
struct ProcessorMessageEntry;
244223
struct ProcessorMessage {
245224
using CallbackFunction = Function<void()>;

Kernel/Arch/ProcessorFunctions.include

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)