From 03cc2a7f25a13fb3e4b156f3062cefbdc7bb1761 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Wed, 10 Nov 2021 18:19:34 +0000 Subject: [PATCH] reduce kernel stack size --- kernel/scheduler.cpp | 6 +++--- kernel/syscall.cpp | 50 +++++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/kernel/scheduler.cpp b/kernel/scheduler.cpp index aeb887c..a48497c 100644 --- a/kernel/scheduler.cpp +++ b/kernel/scheduler.cpp @@ -405,12 +405,12 @@ Thread *Scheduler::SpawnThread(const char *cName, uintptr_t startAddress, uintpt // Allocate the thread's stacks. #if defined(ES_BITS_64) - uintptr_t kernelStackSize = userland ? 0x4000 /* 16KB */ : 0x10000 /* 64KB */; + uintptr_t kernelStackSize = 0x5000 /* 20KB */; #elif defined(ES_BITS_32) - uintptr_t kernelStackSize = userland ? 0x3000 /* 12KB */ : 0x8000 /* 32KB */; + uintptr_t kernelStackSize = 0x4000 /* 16KB */; #endif uintptr_t userStackReserve = userland ? 0x400000 /* 4MB */ : kernelStackSize; - uintptr_t userStackCommit = userland ? 0x20000 /* 128KB */ : 0; + uintptr_t userStackCommit = userland ? 0x10000 /* 64KB */ : 0; uintptr_t stack = 0, kernelStack = 0; if (flags & SPAWN_THREAD_IDLE) goto skipStackAllocation; diff --git a/kernel/syscall.cpp b/kernel/syscall.cpp index df51fc8..86c288c 100644 --- a/kernel/syscall.cpp +++ b/kernel/syscall.cpp @@ -1621,15 +1621,39 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_DEVICE_CONTROL) { } SYSCALL_IMPLEMENT(ES_SYSCALL_DEBUG_COMMAND) { + SYSCALL_PERMISSION(ES_PERMISSION_TAKE_SYSTEM_SNAPSHOT); + + // TODO Temporary: moved out of the DEBUG_BUILD block. + if (argument0 == 3) { - SYSCALL_PERMISSION(ES_PERMISSION_TAKE_SYSTEM_SNAPSHOT); - // TODO Temporary: moved out of the DEBUG_BUILD block. extern char kernelLog[]; extern uintptr_t kernelLogPosition; size_t bytes = kernelLogPosition; if (argument2 < bytes) bytes = argument2; EsMemoryCopy((void *) argument1, kernelLog, bytes); SYSCALL_RETURN(bytes, false); + } else if (argument0 == 12) { + EsMemoryStatistics statistics; + EsMemoryZero(&statistics, sizeof(statistics)); + statistics.fixedHeapAllocationCount = K_FIXED->allocationsCount; + statistics.fixedHeapTotalSize = K_FIXED->size; + statistics.coreHeapAllocationCount = K_CORE->allocationsCount; + statistics.coreHeapTotalSize = K_CORE->size; + statistics.cachedNodes = fs.bootFileSystem->cachedNodes.count; + statistics.cachedDirectoryEntries = fs.bootFileSystem->cachedDirectoryEntries.count; + statistics.totalSurfaceBytes = graphics.totalSurfaceBytes; + statistics.commitPageable = pmm.commitPageable; + statistics.commitFixed = pmm.commitFixed; + statistics.commitLimit = pmm.commitLimit; + statistics.commitFixedLimit = pmm.commitFixedLimit; + statistics.commitRemaining = MM_REMAINING_COMMIT(); + statistics.maximumObjectCachePages = MM_OBJECT_CACHE_PAGES_MAXIMUM(); + statistics.approximateObjectCacheSize = pmm.approximateTotalObjectCacheBytes; + statistics.countZeroedPages = pmm.countZeroedPages; + statistics.countFreePages = pmm.countFreePages; + statistics.countStandbyPages = pmm.countStandbyPages; + statistics.countActivePages = pmm.countActivePages; + SYSCALL_WRITE(argument1, &statistics, sizeof(statistics)); } #ifdef DEBUG_BUILD @@ -1668,28 +1692,6 @@ SYSCALL_IMPLEMENT(ES_SYSCALL_DEBUG_COMMAND) { KEventWait(&event, 1000); EsHeapFree(scheduler.threadEventLog, 0, K_FIXED); scheduler.threadEventLog = nullptr; - } else if (argument0 == 12) { - EsMemoryStatistics statistics; - EsMemoryZero(&statistics, sizeof(statistics)); - statistics.fixedHeapAllocationCount = K_FIXED->allocationsCount; - statistics.fixedHeapTotalSize = K_FIXED->size; - statistics.coreHeapAllocationCount = K_CORE->allocationsCount; - statistics.coreHeapTotalSize = K_CORE->size; - statistics.cachedNodes = fs.bootFileSystem->cachedNodes.count; - statistics.cachedDirectoryEntries = fs.bootFileSystem->cachedDirectoryEntries.count; - statistics.totalSurfaceBytes = graphics.totalSurfaceBytes; - statistics.commitPageable = pmm.commitPageable; - statistics.commitFixed = pmm.commitFixed; - statistics.commitLimit = pmm.commitLimit; - statistics.commitFixedLimit = pmm.commitFixedLimit; - statistics.commitRemaining = MM_REMAINING_COMMIT(); - statistics.maximumObjectCachePages = MM_OBJECT_CACHE_PAGES_MAXIMUM(); - statistics.approximateObjectCacheSize = pmm.approximateTotalObjectCacheBytes; - statistics.countZeroedPages = pmm.countZeroedPages; - statistics.countFreePages = pmm.countFreePages; - statistics.countStandbyPages = pmm.countStandbyPages; - statistics.countActivePages = pmm.countActivePages; - SYSCALL_WRITE(argument1, &statistics, sizeof(statistics)); } #endif