Skip to content

Commit e6dc0d9

Browse files
committed
SPU: Optimize check for args sharing page with Effective-Address
1 parent 1250e42 commit e6dc0d9

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

rpcs3/Emu/Cell/SPUThread.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4125,7 +4125,7 @@ bool spu_thread::process_mfc_cmd()
41254125
if (raddr != addr)
41264126
{
41274127
// Last check for event before we replace the reservation with a new one
4128-
if (reservation_check(raddr, rdata))
4128+
if (~ch_events.load().events & SPU_EVENT_LR && reservation_check(raddr, rdata, addr))
41294129
{
41304130
set_events(SPU_EVENT_LR);
41314131
}
@@ -4821,7 +4821,7 @@ bool spu_thread::process_mfc_cmd()
48214821
ch_mfc_cmd.cmd, ch_mfc_cmd.lsa, ch_mfc_cmd.eal, ch_mfc_cmd.tag, ch_mfc_cmd.size);
48224822
}
48234823

4824-
bool spu_thread::reservation_check(u32 addr, const decltype(rdata)& data) const
4824+
bool spu_thread::reservation_check(u32 addr, const decltype(rdata)& data, u32 current_eal) const
48254825
{
48264826
if (!addr)
48274827
{
@@ -4840,6 +4840,21 @@ bool spu_thread::reservation_check(u32 addr, const decltype(rdata)& data) const
48404840
return !cmp_rdata(data, *vm::get_super_ptr<decltype(rdata)>(addr));
48414841
}
48424842

4843+
if ((addr >> 20) == (current_eal >> 20))
4844+
{
4845+
if (vm::check_addr(addr, vm::page_1m_size))
4846+
{
4847+
// Same random-access-memory page as the current MFC command, assume allocated
4848+
return !cmp_rdata(data, vm::_ref<decltype(rdata)>(addr));
4849+
}
4850+
4851+
if ((addr >> 16) == (current_eal >> 16) && vm::check_addr(addr, vm::page_64k_size))
4852+
{
4853+
// Same random-access-memory page as the current MFC command, assume allocated
4854+
return !cmp_rdata(data, vm::_ref<decltype(rdata)>(addr));
4855+
}
4856+
}
4857+
48434858
// Ensure data is allocated (HACK: would raise LR event if not)
48444859
// Set range_lock first optimistically
48454860
range_lock->store(u64{128} << 32 | addr | vm::range_readable);

rpcs3/Emu/Cell/SPUThread.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,8 @@ class spu_thread : public cpu_thread
901901

902902
// Returns true if reservation existed but was just discovered to be lost
903903
// It is safe to use on any address, even if not directly accessed by SPU (so it's slower)
904-
bool reservation_check(u32 addr, const decltype(rdata)& data) const;
904+
// Optionally pass a known allocated address for internal optimization (the current Effective-Address of the MFC command)
905+
bool reservation_check(u32 addr, const decltype(rdata)& data, u32 current_eal = 0) const;
905906
static bool reservation_check(u32 addr, u32 hash, atomic_t<u64, 64>* range_lock);
906907
usz register_cache_line_waiter(u32 addr);
907908
void deregister_cache_line_waiter(usz index);

0 commit comments

Comments
 (0)