Merge pull request #22873 from hrydgard/adhoc-size-timing

sceNetAdhoc: PDP, PTP and PollSocket: Time cost approximations
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2026-10-31 22:50:45 +01:00
commit fd42bb6dcb
6 files changed
+32 -11

No files matched your search

+19
View File
@@ -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;
+1 -1
View File
@@ -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<u8>(data, data + *len) });
hleEatMicro(122);
hleEatMicro(AdhocPtpSendUs(*len));
return 0;
}
+2 -2
View File
@@ -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) {
+2 -2
View File
@@ -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) {
+7 -5
View File
@@ -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)