summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2015-05-11 23:32:28 -0400
committerGravatar bunnei2015-05-11 23:32:28 -0400
commitcb2b2071a8740311af72b43d8f1f9be6fd0cd36f (patch)
tree4c6a14aafa398e5b93f6295e3a09476add3f0025 /src
parentMerge pull request #751 from yuriks/idle-thread (diff)
parentCore/Memory: Add TLS support for creating up to 300 threads (diff)
downloadyuzu-cb2b2071a8740311af72b43d8f1f9be6fd0cd36f.tar.gz
yuzu-cb2b2071a8740311af72b43d8f1f9be6fd0cd36f.tar.xz
yuzu-cb2b2071a8740311af72b43d8f1f9be6fd0cd36f.zip
Merge pull request #748 from Subv/tls_max
Core/Memory: Add TLS support for creating up to 300 threads
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/process.h3
-rw-r--r--src/core/hle/kernel/thread.cpp21
-rw-r--r--src/core/hle/kernel/thread.h2
-rw-r--r--src/core/mem_map.h8
4 files changed, 24 insertions, 10 deletions
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 22cd1049b..90881054c 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -74,6 +74,9 @@ public:
74 /// The id of this process 74 /// The id of this process
75 u32 process_id = next_process_id++; 75 u32 process_id = next_process_id++;
76 76
77 /// Bitmask of the used TLS slots
78 std::bitset<300> used_tls_slots;
79
77 /** 80 /**
78 * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them 81 * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them
79 * to this process. 82 * to this process.
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index c7731c9e9..afaf0cd5d 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -107,6 +107,8 @@ void Thread::Stop() {
107 for (auto& wait_object : wait_objects) { 107 for (auto& wait_object : wait_objects) {
108 wait_object->RemoveWaitingThread(this); 108 wait_object->RemoveWaitingThread(this);
109 } 109 }
110
111 Kernel::g_current_process->used_tls_slots[tls_index] = false;
110} 112}
111 113
112Thread* ArbitrateHighestPriorityThread(u32 address) { 114Thread* ArbitrateHighestPriorityThread(u32 address) {
@@ -408,12 +410,19 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point,
408 thread->name = std::move(name); 410 thread->name = std::move(name);
409 thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom(); 411 thread->callback_handle = wakeup_callback_handle_table.Create(thread).MoveFrom();
410 thread->owner_process = g_current_process; 412 thread->owner_process = g_current_process;
413 thread->tls_index = -1;
414
415 // Find the next available TLS index, and mark it as used
416 auto& used_tls_slots = Kernel::g_current_process->used_tls_slots;
417 for (unsigned int i = 0; i < used_tls_slots.size(); ++i) {
418 if (used_tls_slots[i] == false) {
419 thread->tls_index = i;
420 used_tls_slots[i] = true;
421 break;
422 }
423 }
411 424
412 VAddr tls_address = Memory::TLS_AREA_VADDR + (thread->thread_id - 1) * 0x200; 425 ASSERT_MSG(thread->tls_index != -1, "Out of TLS space");
413
414 ASSERT_MSG(tls_address < Memory::TLS_AREA_VADDR_END, "Too many threads");
415
416 thread->tls_address = tls_address;
417 426
418 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used 427 // TODO(peachum): move to ScheduleThread() when scheduler is added so selected core is used
419 // to initialize the context 428 // to initialize the context
@@ -502,7 +511,7 @@ void Thread::SetWaitSynchronizationOutput(s32 output) {
502} 511}
503 512
504VAddr Thread::GetTLSAddress() const { 513VAddr Thread::GetTLSAddress() const {
505 return tls_address; 514 return Memory::TLS_AREA_VADDR + tls_index * 0x200;
506} 515}
507 516
508//////////////////////////////////////////////////////////////////////////////////////////////////// 517////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index a06c7d4fe..6b329c12a 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -151,7 +151,7 @@ public:
151 151
152 s32 processor_id; 152 s32 processor_id;
153 153
154 VAddr tls_address; ///< Address of the Thread Local Storage of the thread 154 s32 tls_index; ///< Index of the Thread Local Storage of the thread
155 155
156 /// Mutexes currently held by this thread, which will be released when it exits. 156 /// Mutexes currently held by this thread, which will be released when it exits.
157 boost::container::flat_set<SharedPtr<Mutex>> held_mutexes; 157 boost::container::flat_set<SharedPtr<Mutex>> held_mutexes;
diff --git a/src/core/mem_map.h b/src/core/mem_map.h
index 64de76c39..71f90cb8a 100644
--- a/src/core/mem_map.h
+++ b/src/core/mem_map.h
@@ -94,10 +94,12 @@ enum : VAddr {
94 SHARED_PAGE_SIZE = 0x00001000, 94 SHARED_PAGE_SIZE = 0x00001000,
95 SHARED_PAGE_VADDR_END = SHARED_PAGE_VADDR + SHARED_PAGE_SIZE, 95 SHARED_PAGE_VADDR_END = SHARED_PAGE_VADDR + SHARED_PAGE_SIZE,
96 96
97 // TODO(yuriks): The exact location and size of this area is uncomfirmed. 97 // TODO(yuriks): The size of this area is dynamic, the kernel grows
98 // it as more and more threads are created. For now we'll just use a
99 // hardcoded value.
98 /// Area where TLS (Thread-Local Storage) buffers are allocated. 100 /// Area where TLS (Thread-Local Storage) buffers are allocated.
99 TLS_AREA_VADDR = 0x1FFA0000, 101 TLS_AREA_VADDR = 0x1FF82000,
100 TLS_AREA_SIZE = 0x00002000, // Each TLS buffer is 0x200 bytes, allows for 16 threads 102 TLS_AREA_SIZE = 0x00030000, // Each TLS buffer is 0x200 bytes, allows for 300 threads
101 TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE, 103 TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE,
102}; 104};
103 105