mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-05-27 06:27:03 +02:00
gido fix
This commit is contained in:
parent
60db19dca9
commit
19f414b775
5 changed files with 24 additions and 67 deletions
|
|
@ -182,8 +182,6 @@ if(ARCHITECTURE_x86_64)
|
||||||
common
|
common
|
||||||
PRIVATE x64/cpu_detect.cpp
|
PRIVATE x64/cpu_detect.cpp
|
||||||
x64/cpu_detect.h
|
x64/cpu_detect.h
|
||||||
x64/cpu_wait.cpp
|
|
||||||
x64/cpu_wait.h
|
|
||||||
x64/rdtsc.cpp
|
x64/rdtsc.cpp
|
||||||
x64/rdtsc.h
|
x64/rdtsc.h
|
||||||
x64/xbyak.h)
|
x64/xbyak.h)
|
||||||
|
|
|
||||||
|
|
@ -19,29 +19,31 @@
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
|
#include "common/windows/timer_resolution.h"
|
||||||
#else
|
#else
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
#include <sys/cpuset.h>
|
#include <sys/cpuset.h>
|
||||||
#include <sys/_cpuset.h>
|
#include <sys/_cpuset.h>
|
||||||
#include <pthread_np.h>
|
#include <pthread_np.h>
|
||||||
|
// Compatibility with CPUset
|
||||||
|
#define cpu_set_t cpuset_t
|
||||||
#elif defined(__DragonFly__) || defined(__OpenBSD__) || defined(__Bitrig__)
|
#elif defined(__DragonFly__) || defined(__OpenBSD__) || defined(__Bitrig__)
|
||||||
#include <pthread_np.h>
|
#include <pthread_np.h>
|
||||||
#endif
|
#endif
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ARCHITECTURE_x86_64
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
#else
|
#else
|
||||||
#include <x86intrin.h>
|
#include <x86intrin.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __FreeBSD__
|
|
||||||
# define cpu_set_t cpuset_t
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
@ -151,6 +153,7 @@ void PinCurrentThreadToPerformanceCore(size_t core_id) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ARCHITECTURE_x86_64
|
||||||
// On Linux and UNIX systems, a futex would nominally be used to cover the costs
|
// On Linux and UNIX systems, a futex would nominally be used to cover the costs
|
||||||
// the idea is that it's intuitivelly cheaper to use a direct instruction as opposed to a full futex call
|
// the idea is that it's intuitivelly cheaper to use a direct instruction as opposed to a full futex call
|
||||||
// the underlying libc++ implementation uses pthread_cond_timedwait which MAY invoke a futex
|
// the underlying libc++ implementation uses pthread_cond_timedwait which MAY invoke a futex
|
||||||
|
|
@ -167,7 +170,7 @@ __attribute__((target("waitpkg,mwaitx")))
|
||||||
#endif
|
#endif
|
||||||
bool Event::WaitFor(const std::chrono::nanoseconds& time) {
|
bool Event::WaitFor(const std::chrono::nanoseconds& time) {
|
||||||
auto const& caps = Common::GetCPUCaps();
|
auto const& caps = Common::GetCPUCaps();
|
||||||
auto const ns_ratio = std::max<u64>(1, caps.max_frequency / 1'000);
|
auto const ns_ratio = std::max<u64>(1, caps.base_frequency / 1'000);
|
||||||
auto const target_tsc = Common::X64::FencedRDTSC() + time.count() * ns_ratio;
|
auto const target_tsc = Common::X64::FencedRDTSC() + time.count() * ns_ratio;
|
||||||
if (caps.monitorx) {
|
if (caps.monitorx) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
@ -209,5 +212,22 @@ bool Event::WaitFor(const std::chrono::nanoseconds& time) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
bool Event::WaitFor(const std::chrono::nanoseconds& time) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
while (!IsSet() && _rdtsc() < target_tsc)
|
||||||
|
Common::Windows::SleepForOneTick();
|
||||||
|
if (event.IsSet())
|
||||||
|
event.Reset();
|
||||||
|
return true;
|
||||||
|
#else
|
||||||
|
std::unique_lock lk{mutex};
|
||||||
|
if (!condvar.wait_for(lk, time, [this] { return is_set.load(); }))
|
||||||
|
return false;
|
||||||
|
is_set = false;
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#include <intrin.h>
|
|
||||||
#else
|
|
||||||
#include <x86intrin.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "common/x64/cpu_detect.h"
|
|
||||||
#include "common/x64/cpu_wait.h"
|
|
||||||
#include "common/x64/rdtsc.h"
|
|
||||||
|
|
||||||
namespace Common::X64 {
|
|
||||||
|
|
||||||
#ifdef __clang__
|
|
||||||
__attribute__((target("waitpkg,mwaitx")))
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#pragma GCC target("waitpkg")
|
|
||||||
#pragma GCC target("mwaitx")
|
|
||||||
#endif
|
|
||||||
void MicroSleep(const CPUCaps& caps, u64 cycles) {
|
|
||||||
do {
|
|
||||||
u64 start = FencedRDTSC();
|
|
||||||
if (caps.waitpkg) {
|
|
||||||
constexpr auto RequestC02State = 0U;
|
|
||||||
_tpause(RequestC02State, start + cycles);
|
|
||||||
} else if (caps.monitorx) {
|
|
||||||
constexpr auto EnableWaitTimeFlag = 1U << 1;
|
|
||||||
constexpr auto RequestC1State = 0U;
|
|
||||||
// monitor_var should be aligned to a cache line.
|
|
||||||
alignas(64) static const u64 monitor_var{};
|
|
||||||
_mm_monitorx(const_cast<u64*>(std::addressof(monitor_var)), 0, 0);
|
|
||||||
_mm_mwaitx(EnableWaitTimeFlag, RequestC1State, cycles);
|
|
||||||
} else {
|
|
||||||
std::this_thread::yield();
|
|
||||||
}
|
|
||||||
cycles -= FencedRDTSC() - start;
|
|
||||||
} while (cycles > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Common::X64
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "common/x64/cpu_detect.h"
|
|
||||||
|
|
||||||
namespace Common::X64 {
|
|
||||||
|
|
||||||
void MicroSleep(const CPUCaps& caps, u64 cycles);
|
|
||||||
|
|
||||||
} // namespace Common::X64
|
|
||||||
|
|
@ -14,10 +14,6 @@
|
||||||
#include "common/windows/timer_resolution.h"
|
#include "common/windows/timer_resolution.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ARCHITECTURE_x86_64
|
|
||||||
#include "common/x64/cpu_wait.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "core/core_timing.h"
|
#include "core/core_timing.h"
|
||||||
#include "core/hardware_properties.h"
|
#include "core/hardware_properties.h"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue