From 22f4fd859eb0cd1dfe3d513b8e87f1a82b92f778 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Tue, 26 Apr 2022 00:09:06 +0200 Subject: [PATCH] Remove kernel thread alignment since malloc is already 16-byte aligned. --- kernel/include/sortix/kernel/thread.h | 6 +---- kernel/kernel.cpp | 4 ++-- kernel/kthread.cpp | 4 ++-- kernel/thread.cpp | 32 ++------------------------- 4 files changed, 7 insertions(+), 39 deletions(-) diff --git a/kernel/include/sortix/kernel/thread.h b/kernel/include/sortix/kernel/thread.h index 829e87e6..23827d5d 100644 --- a/kernel/include/sortix/kernel/thread.h +++ b/kernel/include/sortix/kernel/thread.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2016, 2018, 2021 Jonas 'Sortie' Termansen. + * Copyright (c) 2011-2016, 2018, 2021-2022 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -75,7 +75,6 @@ public: uintptr_t system_tid; uintptr_t yield_to_tid; struct thread_registers registers; - uint8_t* self_allocation; size_t id; Process* process; Thread* prevsibling; @@ -115,9 +114,6 @@ public: }; -Thread* AllocateThread(); -void FreeThread(Thread* thread); - Thread* CurrentThread(); } // namespace Sortix diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index 430c2d57..2f770f50 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2018, 2021 Jonas 'Sortie' Termansen. + * Copyright (c) 2011-2018, 2021-2022 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -373,7 +373,7 @@ extern "C" void KernelInit(unsigned long magic, multiboot_info_t* bootinfo_p) // create a kernel thread that is the current thread and isn't put into the // scheduler's set of runnable threads, but rather run whenever there is // _nothing_ else to run on this CPU. - Thread* idlethread = AllocateThread(); + Thread* idlethread = new Thread(); idlethread->name = "idle"; idlethread->process = system; idlethread->kernelstackpos = (addr_t) stack; diff --git a/kernel/kthread.cpp b/kernel/kthread.cpp index fe822927..20bec6d9 100644 --- a/kernel/kthread.cpp +++ b/kernel/kthread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, 2021 Jonas 'Sortie' Termansen. + * Copyright (c) 2012, 2014, 2021, 2022 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -224,7 +224,7 @@ static void kthread_do_kill_thread(void* user) Thread* thread = (Thread*) user; while ( thread->state != ThreadState::DEAD ) kthread_yield(); - FreeThread(thread); + delete thread; } void kthread_exit() diff --git a/kernel/thread.cpp b/kernel/thread.cpp index 2111be74..2d9dda73 100644 --- a/kernel/thread.cpp +++ b/kernel/thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2016, 2018, 2021 Jonas 'Sortie' Termansen. + * Copyright (c) 2011-2016, 2018, 2021-2022 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -49,36 +49,8 @@ #include "x86-family/float.h" #endif -void* operator new (size_t /*size*/, void* address) throw() -{ - return address; -} - namespace Sortix { -Thread* AllocateThread() -{ - uint8_t* allocation = (uint8_t*) malloc(sizeof(class Thread) + 16); - if ( !allocation ) - return NULL; - - uint8_t* aligned = allocation; - if ( ((uintptr_t) aligned & 0xFUL) ) - aligned = (uint8_t*) (((uintptr_t) aligned + 16) & ~0xFUL); - - assert(!((uintptr_t) aligned & 0xFUL)); - Thread* thread = new (aligned) Thread; - assert(!((uintptr_t) thread->registers.fpuenv & 0xFUL)); - return thread->self_allocation = allocation, thread; -} - -void FreeThread(Thread* thread) -{ - uint8_t* allocation = thread->self_allocation; - thread->~Thread(); - free(allocation); -} - Thread::Thread() { assert(!((uintptr_t) registers.fpuenv & 0xFUL)); @@ -152,7 +124,7 @@ Thread* CreateKernelThread(Process* process, process == CurrentProcess() || process == Scheduler::GetKernelProcess()); - Thread* thread = AllocateThread(); + Thread* thread = new Thread(); if ( !thread ) return NULL; thread->name = name;