mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 18:00:17 +02:00
- Do compiler/architecture checks EARLY, don't waste time doing random configuration stuff if the user can't even compile in the first place - MSVC is unsupported, I assume? So add a check to disallow. There's literally no MSVC or MSC_VER checks anywhere, so... - Rather than using the MSVC architecture definitions, use our own `ARCHITECTURE_arm64` et al. Hijacking existing "standard" definitions is a very bad idea. Also makes it more readable in CMake - Change the x86 host check to `x86|amd64`. Some systems still refer to themselves as x86 despite being 64-bit for... reasons, and I saw one a very long time ago that referred to it as amd64. This should basically never come up, nor is it really relevant given that FEX is for arm64... but it kinda annoyed me so whatever. TODOs: - Should we check `CMAKE_SIZEOF_VOID_P (equal) 64`? I don't think anyone is even trying to compile this thing on armv7 or older, but might as well? maybe? - What's the status of *BSD, Solaris, macOS? Technically macOS does support Wine, not sure about the others. Signed-off-by: crueter <crueter@eden-emu.dev>
73 lines
2.5 KiB
C++
73 lines
2.5 KiB
C++
// SPDX-License-Identifier: MIT
|
|
/*
|
|
$info$
|
|
tags: Common|SHMStats
|
|
desc: Frontend profiler common code
|
|
$end_info$
|
|
*/
|
|
#pragma once
|
|
#include <FEXCore/Utils/SHMStats.h>
|
|
|
|
namespace FEXCore::Core {
|
|
struct InternalThreadState;
|
|
}
|
|
|
|
#ifdef ARCHITECTURE_arm64
|
|
static inline void store_memory_barrier() {
|
|
asm volatile("dmb ishst;" ::: "memory");
|
|
}
|
|
|
|
#else
|
|
static inline void store_memory_barrier() {
|
|
// Intentionally empty.
|
|
// x86 is strongly memory ordered with regular loadstores. No need for barrier.
|
|
}
|
|
#endif
|
|
|
|
namespace FEX::SHMStats {
|
|
class StatAllocBase {
|
|
public:
|
|
virtual ~StatAllocBase() = default;
|
|
|
|
protected:
|
|
FEXCore::SHMStats::ThreadStats* AllocateSlot(uint32_t TID);
|
|
void DeallocateSlot(FEXCore::SHMStats::ThreadStats* AllocatedSlot);
|
|
|
|
uint32_t OffsetFromStat(FEXCore::SHMStats::ThreadStats* Stat) const {
|
|
return reinterpret_cast<uint64_t>(Stat) - reinterpret_cast<uint64_t>(Base);
|
|
}
|
|
uint32_t TotalSlotsFromSize() const {
|
|
return (CurrentSize - sizeof(FEXCore::SHMStats::ThreadStatsHeader)) / sizeof(FEXCore::SHMStats::ThreadStats) - 1;
|
|
}
|
|
static uint32_t TotalSlotsFromSize(uint32_t Size) {
|
|
return (Size - sizeof(FEXCore::SHMStats::ThreadStatsHeader)) / sizeof(FEXCore::SHMStats::ThreadStats) - 1;
|
|
}
|
|
|
|
static uint32_t SlotIndexFromOffset(uint32_t Offset) {
|
|
return (Offset - sizeof(FEXCore::SHMStats::ThreadStatsHeader)) / sizeof(FEXCore::SHMStats::ThreadStats);
|
|
}
|
|
|
|
void SaveHeader(FEXCore::SHMStats::AppType AppType);
|
|
|
|
void* Base {};
|
|
uint32_t CurrentSize {};
|
|
FEXCore::SHMStats::ThreadStatsHeader* Head {};
|
|
FEXCore::SHMStats::ThreadStats* Stats {};
|
|
FEXCore::SHMStats::ThreadStats* StatTail {};
|
|
uint32_t RemainingSlots {};
|
|
|
|
// Limited to 4MB which should be a few hundred threads of tracking capability.
|
|
// I (Sonicadvance1) wanted to reserve 128MB of VA space because it's cheap, but ran in to a bug when running WINE.
|
|
// WINE allocates [0x7fff'fe00'0000, 0x7fff'ffff'0000) which /consistently/ overlaps with FEX's sigaltstack.
|
|
// This only occurs when this stat allocation size is large as the top-down allocation pushes the alt-stack further.
|
|
// Additionally, only occurs on 48-bit VA systems, as mmap on lesser VA will fail regardless.
|
|
// TODO: Bump allocation size up once FEXCore's allocator can first use the 128TB of blocked VA space on 48-bit systems.
|
|
constexpr static uint32_t MAX_STATS_SIZE = 4 * 1024 * 1024;
|
|
|
|
private:
|
|
virtual uint32_t FrontendAllocateSlots(uint32_t NewSize) = 0;
|
|
bool AllocateMoreSlots();
|
|
};
|
|
|
|
} // namespace FEX::SHMStats
|