Files
FEX-Emu--FEX/Source/Tests/IRLoader/Loader.h
T
Ryan Houdek 753d0ede6c FEXCore: Reclaimable thread pool allocator
Creates a pool allocator for OpcodeDispatcher and IRCompaction that
shares memory allocations between threads in a pool and supports
reclaiming stale allocations from participating threads.

A thread will use a heuristic to keep its claimed memory allocation
around if it is allocating a lot of code. If it slows down then it will
start putting the memory allocation back in to the thread pool.

Additionally if the allocation has been "disowned" and gone to sleep
while still retaining the allocation, then another thread can inspect
 these stale allocations and reclaim it from the idling thread. Saving
further memory.

This needs some more work and cleanup but this is an interesting concept
that saves a decent amount of memory even in a basic test.

Causes teeworlds' title screen to go from 754MB to 599MB in my simple
test. 79.4% the memory usage is a good start.
2022-04-26 10:01:56 -07:00

48 lines
1.2 KiB
C++

#pragma once
#include <FEXCore/IR/IR.h>
#include <FEXCore/IR/IREmitter.h>
#include "HarnessHelpers.h"
#include <FEXCore/Utils/Allocator.h>
#include <map>
#include <memory>
#include <stdint.h>
#include <string>
#include <sys/mman.h>
using namespace FEXCore::IR;
namespace FEX::IRLoader {
class Loader final {
public:
Loader(std::string const &Filename, std::string const &ConfigFilename);
bool IsValid() const { return ParsedCode != nullptr; }
IREmitter* GetIREmitter() { return ParsedCode.get(); }
uint64_t GetEntryRIP() const { return EntryRIP; }
bool CompareStates(FEXCore::Core::CPUState const* State) {
return Config.CompareStates(State, nullptr);
}
void LoadMemory() {
Config.LoadMemory();
}
void MapRegions() {
for (auto& [region, size] : Config.GetMemoryRegions()) {
FEXCore::Allocator::mmap(reinterpret_cast<void*>(region), size, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
}
}
private:
uint64_t EntryRIP{};
std::unique_ptr<IREmitter> ParsedCode;
FEXCore::Utils::PooledAllocatorMalloc Allocator;
FEX::HarnessHelper::ConfigLoader Config;
};
}