From d1ace374b62fd083e0f8a6445a9fbd95d50a68bf Mon Sep 17 00:00:00 2001 From: Drew Galbraith Date: Fri, 24 Nov 2023 16:04:40 -0800 Subject: [PATCH] [Zion] Return freed kernel stacks to pool. --- zion/memory/kernel_stack_manager.cpp | 10 ++++++++-- zion/memory/kernel_stack_manager.h | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/zion/memory/kernel_stack_manager.cpp b/zion/memory/kernel_stack_manager.cpp index d7ec980..31ca839 100644 --- a/zion/memory/kernel_stack_manager.cpp +++ b/zion/memory/kernel_stack_manager.cpp @@ -15,6 +15,9 @@ void KernelStackManager::SetupInterruptStack() { } uint64_t KernelStackManager::AllocateKernelStack() { + if (!free_stacks_.empty()) { + return free_stacks_.PopFront(); + } next_stack_addr_ += kKernelStackOffset; if (next_stack_addr_ >= kKernelStackEnd) { panic("No more kernel stack space"); @@ -24,6 +27,9 @@ uint64_t KernelStackManager::AllocateKernelStack() { } void KernelStackManager::FreeKernelStack(uint64_t stack_base) { - freed_stack_cnt_++; - dbgln("Freed kernel stacks using {} KiB", freed_stack_cnt_ * 12); + // TODO: Validate this value. + if ((stack_base & 0x3FF8) != 0x3FF8) { + dbgln("Odd kernel stack free {x}", stack_base); + } + free_stacks_.PushFront(stack_base); } diff --git a/zion/memory/kernel_stack_manager.h b/zion/memory/kernel_stack_manager.h index b331c92..3cd9187 100644 --- a/zion/memory/kernel_stack_manager.h +++ b/zion/memory/kernel_stack_manager.h @@ -1,5 +1,6 @@ #pragma once +#include #include // KernelStackManager doles out kernel stacks. @@ -24,5 +25,6 @@ class KernelStackManager { private: uint64_t next_stack_addr_; - uint64_t freed_stack_cnt_ = 0; + + glcr::LinkedList free_stacks_; };