mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 21:45:08 +00:00
Kernel: Don't make a separate allocation for thread FPU state
We were allocating thread FPU state separately in order to ensure a 16-byte alignment. There should be no need to do that. This patch makes it a regular value member of Thread instead, dodging one heap allocation during thread creation.
This commit is contained in:
parent
d5d8fba579
commit
584fa525eb
2 changed files with 7 additions and 12 deletions
|
@ -39,10 +39,6 @@ UNMAP_AFTER_INIT void Thread::initialize()
|
||||||
|
|
||||||
KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> process)
|
KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> process)
|
||||||
{
|
{
|
||||||
auto fpu_state = try_make<FPUState>();
|
|
||||||
if (!fpu_state)
|
|
||||||
return ENOMEM;
|
|
||||||
|
|
||||||
auto kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, {}, Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow);
|
auto kernel_stack_region = MM.allocate_kernel_region(default_kernel_stack_size, {}, Region::Access::Read | Region::Access::Write, AllocationStrategy::AllocateNow);
|
||||||
if (!kernel_stack_region)
|
if (!kernel_stack_region)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
@ -54,17 +50,16 @@ KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> proce
|
||||||
|
|
||||||
auto name = KString::try_create(process->name());
|
auto name = KString::try_create(process->name());
|
||||||
|
|
||||||
auto thread = adopt_ref_if_nonnull(new (nothrow) Thread(move(process), kernel_stack_region.release_nonnull(), block_timer.release_nonnull(), fpu_state.release_nonnull(), move(name)));
|
auto thread = adopt_ref_if_nonnull(new (nothrow) Thread(move(process), kernel_stack_region.release_nonnull(), block_timer.release_nonnull(), move(name)));
|
||||||
if (!thread)
|
if (!thread)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
return thread.release_nonnull();
|
return thread.release_nonnull();
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Region> kernel_stack_region, NonnullRefPtr<Timer> block_timer, NonnullOwnPtr<FPUState> fpu_state, OwnPtr<KString> name)
|
Thread::Thread(NonnullRefPtr<Process> process, NonnullOwnPtr<Region> kernel_stack_region, NonnullRefPtr<Timer> block_timer, OwnPtr<KString> name)
|
||||||
: m_process(move(process))
|
: m_process(move(process))
|
||||||
, m_kernel_stack_region(move(kernel_stack_region))
|
, m_kernel_stack_region(move(kernel_stack_region))
|
||||||
, m_fpu_state(move(fpu_state))
|
|
||||||
, m_name(move(name))
|
, m_name(move(name))
|
||||||
, m_block_timer(block_timer)
|
, m_block_timer(block_timer)
|
||||||
, m_global_procfs_inode_index(ProcFSComponentRegistry::the().allocate_inode_index())
|
, m_global_procfs_inode_index(ProcFSComponentRegistry::the().allocate_inode_index())
|
||||||
|
@ -1067,7 +1062,7 @@ RefPtr<Thread> Thread::clone(Process& process)
|
||||||
auto signal_action_data_span = m_signal_action_data.span();
|
auto signal_action_data_span = m_signal_action_data.span();
|
||||||
signal_action_data_span.copy_to(clone->m_signal_action_data.span());
|
signal_action_data_span.copy_to(clone->m_signal_action_data.span());
|
||||||
clone->m_signal_mask = m_signal_mask;
|
clone->m_signal_mask = m_signal_mask;
|
||||||
memcpy(clone->m_fpu_state, m_fpu_state, sizeof(FPUState));
|
clone->m_fpu_state = m_fpu_state;
|
||||||
clone->m_thread_specific_data = m_thread_specific_data;
|
clone->m_thread_specific_data = m_thread_specific_data;
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
@ -1267,7 +1262,7 @@ RefPtr<Thread> Thread::from_tid(ThreadID tid)
|
||||||
|
|
||||||
void Thread::reset_fpu_state()
|
void Thread::reset_fpu_state()
|
||||||
{
|
{
|
||||||
memcpy(m_fpu_state, &Processor::current().clean_fpu_state(), sizeof(FPUState));
|
memcpy(&m_fpu_state, &Processor::current().clean_fpu_state(), sizeof(FPUState));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Thread::should_be_stopped() const
|
bool Thread::should_be_stopped() const
|
||||||
|
|
|
@ -1038,7 +1038,7 @@ public:
|
||||||
u32 pending_signals() const;
|
u32 pending_signals() const;
|
||||||
u32 pending_signals_for_state() const;
|
u32 pending_signals_for_state() const;
|
||||||
|
|
||||||
FPUState& fpu_state() { return *m_fpu_state; }
|
FPUState& fpu_state() { return m_fpu_state; }
|
||||||
|
|
||||||
KResult make_thread_specific_region(Badge<Process>);
|
KResult make_thread_specific_region(Badge<Process>);
|
||||||
|
|
||||||
|
@ -1215,7 +1215,7 @@ public:
|
||||||
String backtrace();
|
String backtrace();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Thread(NonnullRefPtr<Process>, NonnullOwnPtr<Region>, NonnullRefPtr<Timer>, NonnullOwnPtr<FPUState>, OwnPtr<KString>);
|
Thread(NonnullRefPtr<Process>, NonnullOwnPtr<Region>, NonnullRefPtr<Timer>, OwnPtr<KString>);
|
||||||
|
|
||||||
IntrusiveListNode<Thread> m_process_thread_list_node;
|
IntrusiveListNode<Thread> m_process_thread_list_node;
|
||||||
int m_runnable_priority { -1 };
|
int m_runnable_priority { -1 };
|
||||||
|
@ -1344,7 +1344,7 @@ private:
|
||||||
unsigned m_ipv4_socket_read_bytes { 0 };
|
unsigned m_ipv4_socket_read_bytes { 0 };
|
||||||
unsigned m_ipv4_socket_write_bytes { 0 };
|
unsigned m_ipv4_socket_write_bytes { 0 };
|
||||||
|
|
||||||
OwnPtr<FPUState> m_fpu_state;
|
FPUState m_fpu_state {};
|
||||||
State m_state { Invalid };
|
State m_state { Invalid };
|
||||||
OwnPtr<KString> m_name;
|
OwnPtr<KString> m_name;
|
||||||
u32 m_priority { THREAD_PRIORITY_NORMAL };
|
u32 m_priority { THREAD_PRIORITY_NORMAL };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue