early-access version 2667
This commit is contained in:
parent
8bdf5dbc6c
commit
ad215e0fc7
@ -1,7 +1,7 @@
|
|||||||
yuzu emulator early access
|
yuzu emulator early access
|
||||||
=============
|
=============
|
||||||
|
|
||||||
This is the source code for early-access 2666.
|
This is the source code for early-access 2667.
|
||||||
|
|
||||||
## Legal Notice
|
## Legal Notice
|
||||||
|
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/fiber.h"
|
#include "common/fiber.h"
|
||||||
#include "common/spin_lock.h"
|
|
||||||
#include "common/virtual_buffer.h"
|
#include "common/virtual_buffer.h"
|
||||||
|
|
||||||
#include <boost/context/detail/fcontext.hpp>
|
#include <boost/context/detail/fcontext.hpp>
|
||||||
@ -19,7 +20,7 @@ struct Fiber::FiberImpl {
|
|||||||
VirtualBuffer<u8> stack;
|
VirtualBuffer<u8> stack;
|
||||||
VirtualBuffer<u8> rewind_stack;
|
VirtualBuffer<u8> rewind_stack;
|
||||||
|
|
||||||
SpinLock guard{};
|
std::mutex guard;
|
||||||
std::function<void(void*)> entry_point;
|
std::function<void(void*)> entry_point;
|
||||||
std::function<void(void*)> rewind_point;
|
std::function<void(void*)> rewind_point;
|
||||||
void* rewind_parameter{};
|
void* rewind_parameter{};
|
||||||
|
@ -8,13 +8,13 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/spin_lock.h"
|
|
||||||
#include "common/thread.h"
|
#include "common/thread.h"
|
||||||
#include "common/wall_clock.h"
|
#include "common/wall_clock.h"
|
||||||
|
|
||||||
@ -149,8 +149,8 @@ private:
|
|||||||
std::shared_ptr<EventType> ev_lost;
|
std::shared_ptr<EventType> ev_lost;
|
||||||
Common::Event event{};
|
Common::Event event{};
|
||||||
Common::Event pause_event{};
|
Common::Event pause_event{};
|
||||||
Common::SpinLock basic_lock{};
|
std::mutex basic_lock;
|
||||||
Common::SpinLock advance_lock{};
|
std::mutex advance_lock;
|
||||||
std::unique_ptr<std::thread> timer_thread;
|
std::unique_ptr<std::thread> timer_thread;
|
||||||
std::atomic<bool> paused{};
|
std::atomic<bool> paused{};
|
||||||
std::atomic<bool> paused_set{};
|
std::atomic<bool> paused_set{};
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/spin_lock.h"
|
|
||||||
#include "core/hardware_properties.h"
|
#include "core/hardware_properties.h"
|
||||||
#include "core/hle/kernel/k_priority_queue.h"
|
#include "core/hle/kernel/k_priority_queue.h"
|
||||||
#include "core/hle/kernel/k_scheduler_lock.h"
|
#include "core/hle/kernel/k_scheduler_lock.h"
|
||||||
@ -80,7 +79,7 @@ private:
|
|||||||
|
|
||||||
/// Lists all thread ids that aren't deleted/etc.
|
/// Lists all thread ids that aren't deleted/etc.
|
||||||
std::vector<KThread*> thread_list;
|
std::vector<KThread*> thread_list;
|
||||||
Common::SpinLock global_list_guard{};
|
std::mutex global_list_guard;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -405,9 +405,6 @@ void KScheduler::EnableScheduling(KernelCore& kernel, u64 cores_needing_scheduli
|
|||||||
} else {
|
} else {
|
||||||
RescheduleCores(kernel, cores_needing_scheduling);
|
RescheduleCores(kernel, cores_needing_scheduling);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case to ensure dummy threads that are waiting block.
|
|
||||||
current_thread->IfDummyThreadTryWait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 KScheduler::UpdateHighestPriorityThreads(KernelCore& kernel) {
|
u64 KScheduler::UpdateHighestPriorityThreads(KernelCore& kernel) {
|
||||||
@ -705,7 +702,7 @@ void KScheduler::Unload(KThread* thread) {
|
|||||||
prev_thread = nullptr;
|
prev_thread = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
thread->context_guard.Unlock();
|
thread->context_guard.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KScheduler::Reload(KThread* thread) {
|
void KScheduler::Reload(KThread* thread) {
|
||||||
@ -794,13 +791,13 @@ void KScheduler::SwitchToCurrent() {
|
|||||||
do {
|
do {
|
||||||
auto next_thread = current_thread.load();
|
auto next_thread = current_thread.load();
|
||||||
if (next_thread != nullptr) {
|
if (next_thread != nullptr) {
|
||||||
const auto locked = next_thread->context_guard.TryLock();
|
const auto locked = next_thread->context_guard.try_lock();
|
||||||
if (state.needs_scheduling.load()) {
|
if (state.needs_scheduling.load()) {
|
||||||
next_thread->context_guard.Unlock();
|
next_thread->context_guard.unlock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (next_thread->GetActiveCore() != core_id) {
|
if (next_thread->GetActiveCore() != core_id) {
|
||||||
next_thread->context_guard.Unlock();
|
next_thread->context_guard.unlock();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!locked) {
|
if (!locked) {
|
||||||
|
@ -4,51 +4,18 @@
|
|||||||
|
|
||||||
#include "core/hle/kernel/k_spin_lock.h"
|
#include "core/hle/kernel/k_spin_lock.h"
|
||||||
|
|
||||||
#if _MSC_VER
|
|
||||||
#include <intrin.h>
|
|
||||||
#if _M_AMD64
|
|
||||||
#define __x86_64__ 1
|
|
||||||
#endif
|
|
||||||
#if _M_ARM64
|
|
||||||
#define __aarch64__ 1
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if __x86_64__
|
|
||||||
#include <xmmintrin.h>
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
void ThreadPause() {
|
|
||||||
#if __x86_64__
|
|
||||||
_mm_pause();
|
|
||||||
#elif __aarch64__ && _MSC_VER
|
|
||||||
__yield();
|
|
||||||
#elif __aarch64__
|
|
||||||
asm("yield");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
void KSpinLock::Lock() {
|
void KSpinLock::Lock() {
|
||||||
while (lck.test_and_set(std::memory_order_acquire)) {
|
lck.lock();
|
||||||
ThreadPause();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KSpinLock::Unlock() {
|
void KSpinLock::Unlock() {
|
||||||
lck.clear(std::memory_order_release);
|
lck.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KSpinLock::TryLock() {
|
bool KSpinLock::TryLock() {
|
||||||
if (lck.test_and_set(std::memory_order_acquire)) {
|
return lck.try_lock();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
#include <mutex>
|
||||||
|
|
||||||
#include "core/hle/kernel/k_scoped_lock.h"
|
#include "core/hle/kernel/k_scoped_lock.h"
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ public:
|
|||||||
[[nodiscard]] bool TryLock();
|
[[nodiscard]] bool TryLock();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::atomic_flag lck = ATOMIC_FLAG_INIT;
|
std::mutex lck;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO(bunnei): Alias for now, in case we want to implement these accurately in the future.
|
// TODO(bunnei): Alias for now, in case we want to implement these accurately in the future.
|
||||||
|
@ -1070,46 +1070,12 @@ ResultCode KThread::Sleep(s64 timeout) {
|
|||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KThread::IfDummyThreadTryWait() {
|
|
||||||
if (!IsDummyThread()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (GetState() != ThreadState::Waiting) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Block until we can grab the lock.
|
|
||||||
KScopedSpinLock lk{dummy_wait_lock};
|
|
||||||
}
|
|
||||||
|
|
||||||
void KThread::IfDummyThreadBeginWait() {
|
|
||||||
if (!IsDummyThread()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the thread will block when IfDummyThreadTryWait is called.
|
|
||||||
dummy_wait_lock.Lock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void KThread::IfDummyThreadEndWait() {
|
|
||||||
if (!IsDummyThread()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the thread will no longer block.
|
|
||||||
dummy_wait_lock.Unlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
void KThread::BeginWait(KThreadQueue* queue) {
|
void KThread::BeginWait(KThreadQueue* queue) {
|
||||||
// Set our state as waiting.
|
// Set our state as waiting.
|
||||||
SetState(ThreadState::Waiting);
|
SetState(ThreadState::Waiting);
|
||||||
|
|
||||||
// Set our wait queue.
|
// Set our wait queue.
|
||||||
wait_queue = queue;
|
wait_queue = queue;
|
||||||
|
|
||||||
// Special case for dummy threads to ensure they block.
|
|
||||||
IfDummyThreadBeginWait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void KThread::NotifyAvailable(KSynchronizationObject* signaled_object, ResultCode wait_result_) {
|
void KThread::NotifyAvailable(KSynchronizationObject* signaled_object, ResultCode wait_result_) {
|
||||||
@ -1135,9 +1101,6 @@ void KThread::EndWait(ResultCode wait_result_) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wait_queue->EndWait(this, wait_result_);
|
wait_queue->EndWait(this, wait_result_);
|
||||||
|
|
||||||
// Special case for dummy threads to wakeup if necessary.
|
|
||||||
IfDummyThreadEndWait();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/intrusive_red_black_tree.h"
|
#include "common/intrusive_red_black_tree.h"
|
||||||
|
#include "common/spin_lock.h"
|
||||||
#include "core/arm/arm_interface.h"
|
#include "core/arm/arm_interface.h"
|
||||||
#include "core/hle/kernel/k_affinity_mask.h"
|
#include "core/hle/kernel/k_affinity_mask.h"
|
||||||
#include "core/hle/kernel/k_light_lock.h"
|
#include "core/hle/kernel/k_light_lock.h"
|
||||||
@ -637,14 +638,6 @@ public:
|
|||||||
return condvar_key;
|
return condvar_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dummy threads (used for HLE host threads) cannot wait based on the guest scheduler, and
|
|
||||||
// therefore will not block on guest kernel synchronization primitives. These methods handle
|
|
||||||
// blocking as needed.
|
|
||||||
|
|
||||||
void IfDummyThreadTryWait();
|
|
||||||
void IfDummyThreadBeginWait();
|
|
||||||
void IfDummyThreadEndWait();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr size_t PriorityInheritanceCountMax = 10;
|
static constexpr size_t PriorityInheritanceCountMax = 10;
|
||||||
union SyncObjectBuffer {
|
union SyncObjectBuffer {
|
||||||
@ -762,7 +755,7 @@ private:
|
|||||||
s8 priority_inheritance_count{};
|
s8 priority_inheritance_count{};
|
||||||
bool resource_limit_release_hint{};
|
bool resource_limit_release_hint{};
|
||||||
StackParameters stack_parameters{};
|
StackParameters stack_parameters{};
|
||||||
KSpinLock context_guard{};
|
Common::SpinLock context_guard{};
|
||||||
KSpinLock dummy_wait_lock{};
|
KSpinLock dummy_wait_lock{};
|
||||||
|
|
||||||
// For emulation
|
// For emulation
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include "common/spin_lock.h"
|
|
||||||
#include "core/arm/cpu_interrupt_handler.h"
|
#include "core/arm/cpu_interrupt_handler.h"
|
||||||
#include "core/arm/dynarmic/arm_dynarmic_32.h"
|
#include "core/arm/dynarmic/arm_dynarmic_32.h"
|
||||||
#include "core/arm/dynarmic/arm_dynarmic_64.h"
|
#include "core/arm/dynarmic/arm_dynarmic_64.h"
|
||||||
@ -16,7 +15,7 @@ namespace Kernel {
|
|||||||
PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& scheduler_,
|
PhysicalCore::PhysicalCore(std::size_t core_index_, Core::System& system_, KScheduler& scheduler_,
|
||||||
Core::CPUInterrupts& interrupts_)
|
Core::CPUInterrupts& interrupts_)
|
||||||
: core_index{core_index_}, system{system_}, scheduler{scheduler_},
|
: core_index{core_index_}, system{system_}, scheduler{scheduler_},
|
||||||
interrupts{interrupts_}, guard{std::make_unique<Common::SpinLock>()} {
|
interrupts{interrupts_}, guard{std::make_unique<std::mutex>()} {
|
||||||
#ifdef ARCHITECTURE_x86_64
|
#ifdef ARCHITECTURE_x86_64
|
||||||
// TODO(bunnei): Initialization relies on a core being available. We may later replace this with
|
// TODO(bunnei): Initialization relies on a core being available. We may later replace this with
|
||||||
// a 32-bit instance of Dynarmic. This should be abstracted out to a CPU manager.
|
// a 32-bit instance of Dynarmic. This should be abstracted out to a CPU manager.
|
||||||
|
@ -6,13 +6,10 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include "core/arm/arm_interface.h"
|
#include "core/arm/arm_interface.h"
|
||||||
|
|
||||||
namespace Common {
|
|
||||||
class SpinLock;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class KScheduler;
|
class KScheduler;
|
||||||
} // namespace Kernel
|
} // namespace Kernel
|
||||||
@ -91,7 +88,7 @@ private:
|
|||||||
Core::System& system;
|
Core::System& system;
|
||||||
Kernel::KScheduler& scheduler;
|
Kernel::KScheduler& scheduler;
|
||||||
Core::CPUInterrupts& interrupts;
|
Core::CPUInterrupts& interrupts;
|
||||||
std::unique_ptr<Common::SpinLock> guard;
|
std::unique_ptr<std::mutex> guard;
|
||||||
std::unique_ptr<Core::ARM_Interface> arm_interface;
|
std::unique_ptr<Core::ARM_Interface> arm_interface;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <boost/container/flat_map.hpp>
|
#include <boost/container/flat_map.hpp>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/spin_lock.h"
|
|
||||||
#include "core/hle/kernel/hle_ipc.h"
|
#include "core/hle/kernel/hle_ipc.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -90,7 +89,7 @@ protected:
|
|||||||
using HandlerFnP = void (Self::*)(Kernel::HLERequestContext&);
|
using HandlerFnP = void (Self::*)(Kernel::HLERequestContext&);
|
||||||
|
|
||||||
/// Used to gain exclusive access to the service members, e.g. from CoreTiming thread.
|
/// Used to gain exclusive access to the service members, e.g. from CoreTiming thread.
|
||||||
[[nodiscard]] std::scoped_lock<Common::SpinLock> LockService() {
|
[[nodiscard]] std::scoped_lock<std::mutex> LockService() {
|
||||||
return std::scoped_lock{lock_service};
|
return std::scoped_lock{lock_service};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +134,7 @@ private:
|
|||||||
boost::container::flat_map<u32, FunctionInfoBase> handlers_tipc;
|
boost::container::flat_map<u32, FunctionInfoBase> handlers_tipc;
|
||||||
|
|
||||||
/// Used to gain exclusive access to the service members, e.g. from CoreTiming thread.
|
/// Used to gain exclusive access to the service members, e.g. from CoreTiming thread.
|
||||||
Common::SpinLock lock_service;
|
std::mutex lock_service;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user