From 9e3873d1df10f780b0bf1d2c1f4e35ce27a27980 Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Sun, 12 Mar 2023 16:51:38 +0100 Subject: [PATCH] Place nvnet in its own thread --- src/common/Timer.cpp | 3 --- src/devices/network/NVNetDevice.cpp | 16 ++++++++++++---- src/devices/network/NVNetDevice.h | 2 -- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/common/Timer.cpp b/src/common/Timer.cpp index b605654a9..969308279 100644 --- a/src/common/Timer.cpp +++ b/src/common/Timer.cpp @@ -115,9 +115,6 @@ static void update_non_periodic_events() // update dsound dsound_worker(); - // check nvnet - NVNetRecv(); - // check for hw interrupts, but skip the gpu interrupt since that is serviced in vblank_next for (int i = 0; i < 3; i++) { // If the interrupt is pending and connected, process it diff --git a/src/devices/network/NVNetDevice.cpp b/src/devices/network/NVNetDevice.cpp index 72e405c22..8b6b62740 100644 --- a/src/devices/network/NVNetDevice.cpp +++ b/src/devices/network/NVNetDevice.cpp @@ -475,12 +475,19 @@ void EmuNVNet_Write(xbox::addr_xt addr, uint32_t value, int size) EmuLog(LOG_LEVEL::DEBUG, "Write%d: %s (0x%.8X) = 0x%.8X", size * 8, EmuNVNet_GetRegisterName(addr), addr, value); } -void NVNetRecv() +std::thread NVNetRecvThread; +void NVNetRecvThreadProc() { + // NOTE: profiling shows that the winpcap function can take up to 1/6th of the total cpu time of the loader process, so avoid placing + // this function in system_events + g_AffinityPolicy->SetAffinityOther(); static std::unique_ptr packet(new uint8_t[65536]); - int size = g_NVNet->PCAPReceive(packet.get(), 65536); - if (size > 0) { - EmuNVNet_DMAPacketToGuest(packet.get(), size); + while (true) { + int size = g_NVNet->PCAPReceive(packet.get(), 65536); + if (size > 0) { + EmuNVNet_DMAPacketToGuest(packet.get(), size); + } + _mm_pause(); } } @@ -523,6 +530,7 @@ void NVNetDevice::Init() }; PCAPInit(); + NVNetRecvThread = std::thread(NVNetRecvThreadProc); } void NVNetDevice::Reset() diff --git a/src/devices/network/NVNetDevice.h b/src/devices/network/NVNetDevice.h index f7a1c3e97..d2a069396 100644 --- a/src/devices/network/NVNetDevice.h +++ b/src/devices/network/NVNetDevice.h @@ -229,5 +229,3 @@ private: mac_address m_GuestMacAddress = { 0x00, 0x50, 0xF2, 0x00, 0x00, 0x34 }; mac_address m_BroadcastMacAddress = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; }; - -void NVNetRecv();