From fc2a33ba9450766d04ab231bfe9cb77d28f0bc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 31 Oct 2026 21:55:39 +0100 Subject: [PATCH] sceNetAdhoc: PDP and PTP sends and receives, and PollSocket, take longer the more they handle pspautotests net/adhoc/sizes measures, roughly: PdpSend takes 50 us plus 20 ns a byte (to a peer, to everyone, to nobody or to itself), PdpRecv of waiting data 15 us plus 11 ns a byte, PtpSend 95 us plus 70 ns a byte, PtpRecv 25 us plus 12 ns a byte, and PollSocket 20 us plus 1 us a socket. We charged 10-50 us whatever the size, and nothing at all for a PdpSend to a MAC nobody has. Co-Authored-By: Claude Opus 5.5 --- Core/HLE/AdhocTransport.h | 19 +++++++++++++++++++ Core/HLE/AdhocTransportNetSim.cpp | 2 +- Core/HLE/AdhocTransportP2P.cpp | 4 ++-- Core/HLE/AdhocTransportRelay.cpp | 4 ++-- Core/HLE/sceNetAdhoc.cpp | 12 +++++++----- pspautotests | 2 +- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Core/HLE/AdhocTransport.h b/Core/HLE/AdhocTransport.h index 9655184ecc..a6fdf75690 100644 --- a/Core/HLE/AdhocTransport.h +++ b/Core/HLE/AdhocTransport.h @@ -27,6 +27,25 @@ #include "Core/HLE/sceNetAdhoc.h" +// Roughly what the calls cost on a PSP when they return without waiting, by the bytes they move +// (pspautotests net/adhoc/sizes). PdpSend costs about the same to a peer, to everyone and to itself. +// PtpSend is measured over a connection to itself, receives with the data already waiting. +inline int AdhocPdpSendUs(int bytes) { + return 50 + bytes / 50; +} + +inline int AdhocPdpRecvUs(int bytes) { + return 15 + bytes / 90; +} + +inline int AdhocPtpSendUs(int bytes) { + return 95 + bytes / 14; +} + +inline int AdhocPtpRecvUs(int bytes) { + return 25 + bytes / 80; +} + // What a transport found when polling a socket. struct AdhocPollState { bool readable = false; diff --git a/Core/HLE/AdhocTransportNetSim.cpp b/Core/HLE/AdhocTransportNetSim.cpp index 7866c5eddc..558dee646b 100644 --- a/Core/HLE/AdhocTransportNetSim.cpp +++ b/Core/HLE/AdhocTransportNetSim.cpp @@ -124,7 +124,7 @@ int NetSimTransport::PtpSend(int id, const char *data, int *len, int timeout, in departureUs = std::max(departureUs, held.back().departureUs); } held.push_back({ departureUs, std::vector(data, data + *len) }); - hleEatMicro(122); + hleEatMicro(AdhocPtpSendUs(*len)); return 0; } diff --git a/Core/HLE/AdhocTransportP2P.cpp b/Core/HLE/AdhocTransportP2P.cpp index 815c991453..51bd7b3879 100644 --- a/Core/HLE/AdhocTransportP2P.cpp +++ b/Core/HLE/AdhocTransportP2P.cpp @@ -964,7 +964,7 @@ int P2PTransport::PtpSend(int id, const char *data, int *len, int timeout, int f // Success if (sent > 0) { - hleEatMicro(122); + hleEatMicro(AdhocPtpSendUs(sent)); // Save Length *len = sent; @@ -1025,7 +1025,7 @@ int P2PTransport::PtpRecv(int id, void *buf, int *len, int timeout, int flag) { // Free Network Lock // _freeNetworkLock(); - hleEatMicro(50); + hleEatMicro(AdhocPtpRecvUs(std::max(received, 0))); // Received Data if (received > 0) { diff --git a/Core/HLE/AdhocTransportRelay.cpp b/Core/HLE/AdhocTransportRelay.cpp index e31e4b0200..c2d6eab722 100644 --- a/Core/HLE/AdhocTransportRelay.cpp +++ b/Core/HLE/AdhocTransportRelay.cpp @@ -995,7 +995,7 @@ int RelayTransport::PtpSend(int id, const char *data, int *len, int timeout, int auto& ptpsocket = adhocSockets[id - 1]->data.ptp; int sent = ptp_send_postoffice(id - 1, data, len); if (sent == 0) { - hleEatMicro(122); + hleEatMicro(AdhocPtpSendUs(*len)); return 0; } if (sent == SOCKET_ERROR) { @@ -1018,7 +1018,7 @@ int RelayTransport::PtpRecv(int id, void *buf, int *len, int timeout, int flag) if (received == 0) { // we got data DEBUG_LOG(Log::sceNet, "sceNetAdhocPtpRecv[%i:%u]: Result:%i (Error:%i)", id, ptpsocket.lport, received, 0); - hleEatMicro(50); + hleEatMicro(AdhocPtpRecvUs(*len)); return 0; } if (received == SOCKET_ERROR) { diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index 4885332a7a..ae6f60d1fe 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -2161,7 +2161,7 @@ int sceNetAdhocPdpSend(MIPSState *mips, int id, const char *mac, u32 port, void // Single Target if (!isBroadcastMAC(daddr)) { if (isLocalMac(daddr)) { - hleEatMicro(21); + hleEatMicro(AdhocPdpSendUs(len)); pdpDeliverLocally(pdpsocket.lport, dport, data, len); return 0; } @@ -2206,7 +2206,7 @@ int sceNetAdhocPdpSend(MIPSState *mips, int id, const char *mac, u32 port, void // Free Network Lock //_freeNetworkLock(); - hleEatMicro(21); + hleEatMicro(AdhocPdpSendUs(len)); // Sent Data if (sent >= 0) { DEBUG_LOG(Log::sceNet, "sceNetAdhocPdpSend[%i:%u]: Sent %u bytes to %s:%u\n", id, getLocalPort(pdpsocket.id), sent, ip2str(target.sin_addr).c_str(), ntohs(target.sin_port)); @@ -2223,6 +2223,7 @@ int sceNetAdhocPdpSend(MIPSState *mips, int id, const char *mac, u32 port, void return hleLogDebug(Log::sceNet, SCE_NET_ADHOC_ERROR_TIMEOUT, "timeout?"); // SCE_NET_ADHOC_ERROR_INVALID_ADDR; } VERBOSE_LOG(Log::sceNet, "sceNetAdhocPdpSend[%i:%u]: Unknown Target Peer %s:%u (nobody there)\n", id, getLocalPort(pdpsocket.id), mac2str(daddr).c_str(), ntohs(target.sin_port)); + hleEatMicro(AdhocPdpSendUs(len)); return 0; // The PSP sends it into the air and returns 0 (pspautotests net/adhoc/pdp). } @@ -2301,7 +2302,7 @@ int sceNetAdhocPdpSend(MIPSState *mips, int id, const char *mac, u32 port, void // Free Network Lock //_freeNetworkLock(); - hleEatMicro(10); + hleEatMicro(AdhocPdpSendUs(len)); // Success, Broadcast never fails! return 0; // len; } @@ -2431,7 +2432,7 @@ int sceNetAdhocPdpRecv(MIPSState *mips, int id, void *addr, void * port, void *b if (ret == SCE_NET_ADHOC_ERROR_NOT_ENOUGH_SPACE) { return hleLogVerbose(Log::sceNet, ret, "not enough space"); } - hleEatMicro(50); + hleEatMicro(AdhocPdpRecvUs(*len)); return hleLogDebug(Log::sceNet, 0, "received %d bytes from %s", *len, mac2str(saddr).c_str()); } @@ -2624,7 +2625,8 @@ int sceNetAdhocPollSocket(MIPSState *mips, u32 socketStructAddr, int count, int } } } - hleEatMicro(18); + // About 20 us, and 1 more for each socket (pspautotests net/adhoc/sizes). + hleEatMicro(20 + count); return hleLogDebug(Log::sceNet, affectedsockets, "success"); } //else if (nonblock && affectedsockets < 0) diff --git a/pspautotests b/pspautotests index b21f4daf0f..54fa9eb4b4 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit b21f4daf0f9f0d9a784c3ca863dc2557b408cf2c +Subproject commit 54fa9eb4b4fae3cae436564ed1c8c5e3b790dd63