From 24c780c884794d36fc059d768bc20a508656d912 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 7 Jan 2017 14:31:10 +0100 Subject: [PATCH] MTVU/GS: try to relax the readAmount atomic operation I suspect it to be the same on x86 The real issue is the various atomic in FinishGSPacketMTVU which I'm afraid will create some cpu stall --- pcsx2/Gif_Unit.h | 6 ++++-- pcsx2/MTGS.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pcsx2/Gif_Unit.h b/pcsx2/Gif_Unit.h index 49ab1620d1..94effe9c94 100644 --- a/pcsx2/Gif_Unit.h +++ b/pcsx2/Gif_Unit.h @@ -209,7 +209,7 @@ struct Gif_Path { } bool isMTVU() const { return !idx && THREAD_VU1; } - s32 getReadAmount() { return readAmount.load() + gsPack.readAmount; } + s32 getReadAmount() { return readAmount.load(std::memory_order_acquire) + gsPack.readAmount; } bool hasDataRemaining() const { return curOffset < curSize; } bool isDone() const { return isMTVU() ? !mtvu.fakePackets : (!hasDataRemaining() && (state == GIF_PATH_IDLE || state == GIF_PATH_WAIT)); } @@ -389,7 +389,9 @@ struct Gif_Path { // MTVU: Gets called after VU1 execution on MTVU thread void FinishGSPacketMTVU() { - readAmount.fetch_add(gsPack.size + gsPack.readAmount); + // Performance note: fetch_add atomic operation might create some stall for atomic + // operation in gsPack.push + readAmount.fetch_add(gsPack.size + gsPack.readAmount, std::memory_order_acq_rel); while (!mtvu.gsPackQueue.push(gsPack)) ; diff --git a/pcsx2/MTGS.cpp b/pcsx2/MTGS.cpp index 84bfdfa41a..3e774308e1 100644 --- a/pcsx2/MTGS.cpp +++ b/pcsx2/MTGS.cpp @@ -407,7 +407,7 @@ void SysMtgsThread::ExecuteTaskInThread() u32 offset = tag.data[0]; u32 size = tag.data[1]; if (offset != ~0u) GSgifTransfer((u32*)&path.buffer[offset], size/16); - path.readAmount.fetch_sub(size); + path.readAmount.fetch_sub(size, std::memory_order_acq_rel); break; } @@ -421,7 +421,7 @@ void SysMtgsThread::ExecuteTaskInThread() Gif_Path& path = gifUnit.gifPath[GIF_PATH_1]; GS_Packet gsPack = path.GetGSPacketMTVU(); // Get vu1 program's xgkick packet(s) if (gsPack.size) GSgifTransfer((u32*)&path.buffer[gsPack.offset], gsPack.size/16); - path.readAmount.fetch_sub(gsPack.size + gsPack.readAmount); + path.readAmount.fetch_sub(gsPack.size + gsPack.readAmount, std::memory_order_acq_rel); path.PopGSPacketMTVU(); // Should be done last, for proper Gif_MTGS_Wait() break; }