kernel: Add names to threads
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-24 21:05:38 +01:00
parent 4d3050eaab
commit d48d0efb07
Signed by: apio
GPG Key ID: B8A7D06E42258954
6 changed files with 25 additions and 15 deletions

View File

@ -219,7 +219,8 @@ namespace CPU
void platform_finish_init() void platform_finish_init()
{ {
Scheduler::new_kernel_thread(io_thread).expect_value("Could not create the IO background thread!"); Scheduler::new_kernel_thread(io_thread, "[x86_64-io]")
.expect_value("Could not create the IO background thread!");
remap_pic(); remap_pic();
} }

View File

@ -68,7 +68,7 @@ static Result<void> try_init_userspace()
{ {
auto init = TRY(VFS::resolve_path("/bin/init")); auto init = TRY(VFS::resolve_path("/bin/init"));
TRY(Scheduler::new_userspace_thread(init)); TRY(Scheduler::new_userspace_thread(init, "/bin/init"));
return {}; return {};
} }
@ -80,7 +80,7 @@ static void init_userspace()
static void create_reaper() static void create_reaper()
{ {
Scheduler::new_kernel_thread(reap_thread).release_value(); Scheduler::new_kernel_thread(reap_thread, "[reap]").release_value();
} }
static void scan_pci() static void scan_pci()

View File

@ -81,6 +81,8 @@ Result<u64> sys_exec(Registers* regs, SyscallArgs args)
MMU::delete_userspace_page_directory(current->directory); MMU::delete_userspace_page_directory(current->directory);
current->name = argv[0].chars();
image->apply(current); image->apply(current);
MMU::switch_page_directory(current->directory); MMU::switch_page_directory(current->directory);

View File

@ -24,6 +24,7 @@ namespace Scheduler
g_idle.state = ThreadState::Idle; g_idle.state = ThreadState::Idle;
g_idle.is_kernel = true; g_idle.is_kernel = true;
g_idle.parent_id = 0; g_idle.parent_id = 0;
g_idle.name = "[idle]";
g_idle.ticks_left = 1; g_idle.ticks_left = 1;
@ -51,7 +52,7 @@ namespace Scheduler
return &g_idle; return &g_idle;
} }
Result<void> new_kernel_thread_impl(Thread* thread) Result<void> new_kernel_thread_impl(Thread* thread, const char* name)
{ {
// If anything fails, make sure to clean up. // If anything fails, make sure to clean up.
auto guard = make_scope_guard([&] { delete thread; }); auto guard = make_scope_guard([&] { delete thread; });
@ -67,6 +68,8 @@ namespace Scheduler
thread->parent_id = 0; thread->parent_id = 0;
thread->name = name;
thread->is_kernel = true; thread->is_kernel = true;
g_threads.append(thread); g_threads.append(thread);
@ -76,39 +79,40 @@ namespace Scheduler
return {}; return {};
} }
Result<void> new_kernel_thread(u64 address) Result<void> new_kernel_thread(u64 address, const char* name)
{ {
Thread* const thread = TRY(new_thread()); Thread* const thread = TRY(new_thread());
thread->init_regs_kernel(); thread->init_regs_kernel();
thread->set_ip(address); thread->set_ip(address);
return new_kernel_thread_impl(thread); return new_kernel_thread_impl(thread, name);
} }
Result<void> new_kernel_thread(void (*func)(void)) Result<void> new_kernel_thread(void (*func)(void), const char* name)
{ {
Thread* const thread = TRY(new_thread()); Thread* const thread = TRY(new_thread());
thread->init_regs_kernel(); thread->init_regs_kernel();
thread->set_ip((u64)func); thread->set_ip((u64)func);
return new_kernel_thread_impl(thread); return new_kernel_thread_impl(thread, name);
} }
Result<void> new_kernel_thread(void (*func)(void*), void* arg) Result<void> new_kernel_thread(void (*func)(void*), void* arg, const char* name)
{ {
Thread* const thread = TRY(new_thread()); Thread* const thread = TRY(new_thread());
thread->init_regs_kernel(); thread->init_regs_kernel();
thread->set_ip((u64)func); thread->set_ip((u64)func);
thread->set_arguments((u64)arg, 0, 0, 0); thread->set_arguments((u64)arg, 0, 0, 0);
return new_kernel_thread_impl(thread); return new_kernel_thread_impl(thread, name);
} }
Result<void> new_userspace_thread(SharedPtr<VFS::Inode> inode) Result<void> new_userspace_thread(SharedPtr<VFS::Inode> inode, const char* name)
{ {
Thread* const thread = TRY(new_thread()); Thread* const thread = TRY(new_thread());
thread->is_kernel = false; thread->is_kernel = false;
thread->name = name;
thread->parent_id = 0; thread->parent_id = 0;
auto guard = make_scope_guard([&] { delete thread; }); auto guard = make_scope_guard([&] { delete thread; });

View File

@ -9,11 +9,11 @@ namespace Scheduler
Thread* current(); Thread* current();
Thread* idle(); Thread* idle();
Result<void> new_kernel_thread(u64 address); Result<void> new_kernel_thread(u64 address, const char* name);
Result<void> new_kernel_thread(void (*func)(void)); Result<void> new_kernel_thread(void (*func)(void), const char* name);
Result<void> new_kernel_thread(void (*func)(void*), void* arg); Result<void> new_kernel_thread(void (*func)(void*), void* arg, const char* name);
Result<void> new_userspace_thread(SharedPtr<VFS::Inode> inode); Result<void> new_userspace_thread(SharedPtr<VFS::Inode> inode, const char* name);
void add_thread(Thread* thread); void add_thread(Thread* thread);

View File

@ -7,6 +7,7 @@
#include <luna/OwnedPtr.h> #include <luna/OwnedPtr.h>
#include <luna/Result.h> #include <luna/Result.h>
#include <luna/Stack.h> #include <luna/Stack.h>
#include <luna/StaticString.h>
#ifdef ARCH_X86_64 #ifdef ARCH_X86_64
#include "arch/x86_64/CPU.h" #include "arch/x86_64/CPU.h"
@ -68,6 +69,8 @@ struct Thread : public LinkedListNode<Thread>
u8 status { 0 }; u8 status { 0 };
StaticString<128> name;
PageDirectory* directory; PageDirectory* directory;
bool is_idle() bool is_idle()