Kernel: Switch Process to InstrusiveList from InlineLinkedList

This commit is contained in:
Brian Gianforcaro 2021-06-06 14:40:03 -07:00 committed by Andreas Kling
parent 252e98761a
commit 9fccbde371
Notes: sideshowbarker 2024-07-18 12:43:29 +09:00
3 changed files with 37 additions and 38 deletions

View File

@ -40,7 +40,7 @@ static void create_signal_trampoline();
RecursiveSpinLock g_processes_lock;
static Atomic<pid_t> next_pid;
READONLY_AFTER_INIT InlineLinkedList<Process>* g_processes;
READONLY_AFTER_INIT Process::List* g_processes;
READONLY_AFTER_INIT String* g_hostname;
READONLY_AFTER_INIT Lock* g_hostname_lock;
READONLY_AFTER_INIT HashMap<String, OwnPtr<Module>>* g_modules;
@ -61,7 +61,7 @@ UNMAP_AFTER_INIT void Process::initialize()
g_modules = new HashMap<String, OwnPtr<Module>>;
next_pid.store(0, AK::MemoryOrder::memory_order_release);
g_processes = new InlineLinkedList<Process>;
g_processes = new Process::List();
g_process_groups = new ProcessGroup::List();
g_hostname = new String("courage");
g_hostname_lock = new Lock;
@ -165,9 +165,9 @@ RefPtr<Process> Process::create_user_process(RefPtr<Thread>& first_thread, const
}
{
ScopedSpinLock lock(g_processes_lock);
g_processes->prepend(process);
process->ref();
ScopedSpinLock lock(g_processes_lock);
g_processes->prepend(*process);
}
error = 0;
return process;
@ -182,9 +182,9 @@ RefPtr<Process> Process::create_kernel_process(RefPtr<Thread>& first_thread, Str
first_thread->tss().esp = FlatPtr(entry_data); // entry function argument is expected to be in tss.esp
if (process->pid() != 0) {
ScopedSpinLock lock(g_processes_lock);
g_processes->prepend(process);
process->ref();
ScopedSpinLock lock(g_processes_lock);
g_processes->prepend(*process);
}
ScopedSpinLock lock(g_scheduler_lock);
@ -270,8 +270,8 @@ Process::~Process()
{
ScopedSpinLock processes_lock(g_processes_lock);
if (prev() || next())
g_processes->remove(this);
if (m_list_node.is_in_list())
g_processes->remove(*this);
}
}
@ -571,17 +571,16 @@ void Process::die()
{
ScopedSpinLock lock(g_processes_lock);
for (auto* process = g_processes->head(); process;) {
auto* next_process = process->next();
if (process->has_tracee_thread(pid())) {
dbgln_if(PROCESS_DEBUG, "Process {} ({}) is attached by {} ({}) which will exit", process->name(), process->pid(), name(), pid());
process->stop_tracing();
auto err = process->send_signal(SIGSTOP, this);
for (auto it = g_processes->begin(); it != g_processes->end();) {
auto& process = *it;
++it;
if (process.has_tracee_thread(pid())) {
dbgln_if(PROCESS_DEBUG, "Process {} ({}) is attached by {} ({}) which will exit", process.name(), process.pid(), name(), pid());
process.stop_tracing();
auto err = process.send_signal(SIGSTOP, this);
if (err.is_error())
dbgln("Failed to send the SIGSTOP signal to {} ({})", process->name(), process->pid());
dbgln("Failed to send the SIGSTOP signal to {} ({})", process.name(), process.pid());
}
process = next_process;
}
}

View File

@ -9,7 +9,7 @@
#include <AK/Checked.h>
#include <AK/Concepts.h>
#include <AK/HashMap.h>
#include <AK/InlineLinkedList.h>
#include <AK/IntrusiveList.h>
#include <AK/NonnullOwnPtrVector.h>
#include <AK/NonnullRefPtrVector.h>
#include <AK/String.h>
@ -117,7 +117,6 @@ static_assert(sizeof(ProcessBase) == PAGE_SIZE);
class Process
: public ProcessBase
, public RefCounted<Process>
, public InlineLinkedListNode<Process>
, public Weakable<Process> {
AK_MAKE_NONCOPYABLE(Process);
@ -125,7 +124,6 @@ class Process
MAKE_ALIGNED_ALLOCATED(Process, PAGE_SIZE);
friend class InlineLinkedListNode<Process>;
friend class Thread;
friend class CoreDump;
@ -569,8 +567,7 @@ private:
return nullptr;
}
Process* m_prev { nullptr };
Process* m_next { nullptr };
IntrusiveListNode<Process> m_list_node;
String m_name;
@ -649,9 +646,12 @@ private:
HashMap<String, String> m_coredump_metadata;
NonnullRefPtrVector<Thread> m_threads_for_coredump;
public:
using List = IntrusiveList<Process, RawPtr<Process>, &Process::m_list_node>;
};
extern InlineLinkedList<Process>* g_processes;
extern Process::List* g_processes;
extern RecursiveSpinLock g_processes_lock;
template<IteratorFunction<Process&> Callback>
@ -659,11 +659,11 @@ inline void Process::for_each(Callback callback)
{
VERIFY_INTERRUPTS_DISABLED();
ScopedSpinLock lock(g_processes_lock);
for (auto* process = g_processes->head(); process;) {
auto* next_process = process->next();
if (callback(*process) == IterationDecision::Break)
for (auto it = g_processes->begin(); it != g_processes->end();) {
auto& process = *it;
++it;
if (callback(process) == IterationDecision::Break)
break;
process = next_process;
}
}
@ -673,13 +673,13 @@ inline void Process::for_each_child(Callback callback)
VERIFY_INTERRUPTS_DISABLED();
ProcessID my_pid = pid();
ScopedSpinLock lock(g_processes_lock);
for (auto* process = g_processes->head(); process;) {
auto* next_process = process->next();
if (process->ppid() == my_pid || process->has_tracee_thread(pid())) {
if (callback(*process) == IterationDecision::Break)
for (auto it = g_processes->begin(); it != g_processes->end();) {
auto& process = *it;
++it;
if (process.ppid() == my_pid || process.has_tracee_thread(pid())) {
if (callback(process) == IterationDecision::Break)
break;
}
process = next_process;
}
}
@ -712,13 +712,13 @@ inline void Process::for_each_in_pgrp(ProcessGroupID pgid, Callback callback)
{
VERIFY_INTERRUPTS_DISABLED();
ScopedSpinLock lock(g_processes_lock);
for (auto* process = g_processes->head(); process;) {
auto* next_process = process->next();
if (!process->is_dead() && process->pgid() == pgid) {
if (callback(*process) == IterationDecision::Break)
for (auto it = g_processes->begin(); it != g_processes->end();) {
auto& process = *it;
++it;
if (!process.is_dead() && process.pgid() == pgid) {
if (callback(process) == IterationDecision::Break)
break;
}
process = next_process;
}
}

View File

@ -82,7 +82,7 @@ KResultOr<pid_t> Process::sys$fork(RegisterState& regs)
}
ScopedSpinLock processes_lock(g_processes_lock);
g_processes->prepend(child);
g_processes->prepend(*child);
}
PerformanceManager::add_process_created_event(*child);