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
This commit is contained in:
Gregory Hainaut 2017-01-07 14:31:10 +01:00
parent e3d1871f86
commit 24c780c884
2 changed files with 6 additions and 4 deletions

View File

@ -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))
;

View File

@ -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;
}