Fix stuttering on AMD

Fix for #147
This commit is contained in:
Maurice Heumann 2023-02-13 18:47:22 +01:00
parent 54584b5f73
commit 65248326c1
2 changed files with 43 additions and 11 deletions

View File

@ -755,17 +755,6 @@ namespace arxan
{
search_and_patch_integrity_checks();
//restore_debug_functions();
scheduler::once([]
{
SetProcessAffinityMask(GetCurrentProcess(), 2 << (std::min(std::thread::hardware_concurrency(), 4U)));
scheduler::once([] {
DWORD_PTR affinity_proc, affinity_sys;
GetProcessAffinityMask(GetCurrentProcess(), &affinity_proc, &affinity_sys);
SetProcessAffinityMask(GetCurrentProcess(), affinity_sys);
}, scheduler::pipeline::main, 1s);
}, scheduler::pipeline::main);
}
component_priority priority() const override

View File

@ -0,0 +1,43 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "scheduler.hpp"
namespace client_patches
{
namespace
{
void reduce_process_affinity()
{
const DWORD_PTR affinity = (2ULL << (std::min(std::thread::hardware_concurrency(), 4U))) - 1;
SetProcessAffinityMask(GetCurrentProcess(), affinity);
}
void reset_process_affinity()
{
DWORD_PTR affinity_proc, affinity_sys;
GetProcessAffinityMask(GetCurrentProcess(), &affinity_proc, &affinity_sys);
SetProcessAffinityMask(GetCurrentProcess(), affinity_sys);
}
void fix_amd_cpu_stuttering()
{
scheduler::once([]
{
reduce_process_affinity();
scheduler::once(reset_process_affinity, scheduler::pipeline::main, 1s);
}, scheduler::pipeline::main);
}
}
class component final : public client_component
{
public:
void post_unpack() override
{
fix_amd_cpu_stuttering();
}
};
}
REGISTER_COMPONENT(client_patches::component)