From 6c4c20fe3e7978cf1d0e08cfd077dd4217cc26a4 Mon Sep 17 00:00:00 2001 From: PSI-Rockin Date: Thu, 9 May 2024 20:35:28 -0400 Subject: [PATCH] Memory: Make TLS only 0x200 bytes for each thread Also move TLS to Base region --- include/memory.hpp | 4 ++-- src/core/memory.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/memory.hpp b/include/memory.hpp index f2bc8383..a9af0c6b 100644 --- a/include/memory.hpp +++ b/include/memory.hpp @@ -47,9 +47,9 @@ namespace VirtualAddrs { LinearHeapStartNew = 0x30000000, LinearHeapEndNew = 0x40000000, - // Start of TLS for first thread. Next thread's storage will be at TLSBase + 0x1000, and so on + // Start of TLS for first thread. Next thread's storage will be at TLSBase + 0x200, and so on TLSBase = 0x1FF82000, - TLSSize = 0x1000, + TLSSize = 0x200, VramStart = 0x1F000000, VramSize = 0x00600000, diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 80c2c531..2ff196fb 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -37,10 +37,10 @@ void Memory::reset() { paddrTable[i] = 0; } - // Map 4 KB of FCRAM for each thread - // TODO: the region should be taken from the exheader - // TODO: each thread should only have 512 bytes - an FCRAM page should account for 8 threads - assert(allocMemory(VirtualAddrs::TLSBase, appResourceLimits.maxThreads, FcramRegion::App, true, true, false, MemoryState::Locked)); + // Allocate 512 bytes of TLS for each thread. Since the smallest allocatable unit is 4 KB, that means allocating one page for every 8 threads + // Note that TLS is always allocated in the Base region + s32 tlsPages = (appResourceLimits.maxThreads + 7) >> 3; + allocMemory(VirtualAddrs::TLSBase, tlsPages, FcramRegion::Base, true, true, false, MemoryState::Locked); // Initialize shared memory blocks and reserve memory for them for (auto& e : sharedMemBlocks) {