SPU: optimize GETLLAR (TSX)

Add an option "Accurate GETLLAR"
This commit is contained in:
Nekotekina 2018-06-02 13:45:28 +03:00
parent a5f4e6ecef
commit ec6d1fb1ba
2 changed files with 41 additions and 6 deletions

View File

@ -1155,9 +1155,8 @@ bool SPUThread::process_mfc_cmd(spu_mfc_cmd args)
if (is_polling) if (is_polling)
{ {
rtime = vm::reservation_acquire(raddr, 128); rtime = vm::reservation_acquire(raddr, 128);
_mm_lfence();
while (vm::reservation_acquire(raddr, 128) == rtime && rdata == data) while (rdata == data && vm::reservation_acquire(raddr, 128) == rtime)
{ {
if (test(state, cpu_flag::stop)) if (test(state, cpu_flag::stop))
{ {
@ -1170,7 +1169,26 @@ bool SPUThread::process_mfc_cmd(spu_mfc_cmd args)
if (LIKELY(g_use_rtm)) if (LIKELY(g_use_rtm))
{ {
const u64 count = spu_getll_tx(raddr, rdata.data(), &rtime); u64 count = 0;
if (g_cfg.core.spu_accurate_getllar)
{
count = spu_getll_tx(raddr, rdata.data(), &rtime);
}
if (count == 0)
{
for (++count;; count++, busy_wait(300))
{
rtime = vm::reservation_acquire(raddr, 128);
rdata = data;
if (LIKELY(vm::reservation_acquire(raddr, 128) == rtime))
{
break;
}
}
}
if (count > 9) if (count > 9)
{ {
@ -1180,10 +1198,26 @@ bool SPUThread::process_mfc_cmd(spu_mfc_cmd args)
else else
{ {
auto& res = vm::reservation_lock(raddr, 128); auto& res = vm::reservation_lock(raddr, 128);
if (g_cfg.core.spu_accurate_getllar)
{
vm::_ref<atomic_t<u32>>(raddr) += 0;
// Full lock (heavyweight)
// TODO: vm::check_addr
vm::writer_lock lock(1);
rtime = res & ~1ull; rtime = res & ~1ull;
rdata = data; rdata = data;
res &= ~1ull; res &= ~1ull;
} }
else
{
rtime = res & ~1ull;
rdata = data;
res &= ~1ull;
}
}
// Copy to LS // Copy to LS
_ref<decltype(rdata)>(args.lsa & 0x3ffff) = rdata; _ref<decltype(rdata)>(args.lsa & 0x3ffff) = rdata;

View File

@ -321,6 +321,7 @@ struct cfg_root : cfg::node
cfg::_bool spu_loop_detection{this, "SPU loop detection", true}; //Try to detect wait loops and trigger thread yield cfg::_bool spu_loop_detection{this, "SPU loop detection", true}; //Try to detect wait loops and trigger thread yield
cfg::_bool spu_shared_runtime{this, "SPU Shared Runtime", true}; // Share compiled SPU functions between all threads cfg::_bool spu_shared_runtime{this, "SPU Shared Runtime", true}; // Share compiled SPU functions between all threads
cfg::_enum<spu_block_size_type> spu_block_size{this, "SPU Block Size"}; cfg::_enum<spu_block_size_type> spu_block_size{this, "SPU Block Size"};
cfg::_bool spu_accurate_getllar{this, "Accurate GETLLAR", false};
cfg::_enum<lib_loading_type> lib_loading{this, "Lib Loader", lib_loading_type::liblv2only}; cfg::_enum<lib_loading_type> lib_loading{this, "Lib Loader", lib_loading_type::liblv2only};
cfg::_bool hook_functions{this, "Hook static functions"}; cfg::_bool hook_functions{this, "Hook static functions"};