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 <noreply@anthropic.com>
pspautotests net/inet/sizes measures, roughly: a send over WiFi takes
125 us plus 40 ns a byte, a receive of waiting data 35 us plus 14 ns a
byte, and poll and select grow worse than linearly with the number of
sockets, from 13 us for one to about 700 us for 64. We charged a flat
4 us to receive, nothing to send, and 11-15 us to poll and select,
whatever the size. The costs are now rough functions of the bytes and
sockets, for all the send and receive calls including sendmsg and
recvmsg.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The barrier divided the cycle count by the current clock's cycles per millisecond, so a game that
changes the CPU clock (Pangya: Fantasy Golf does on its network screens) jumped its count by up to a
fifth of everything so far, and from then on ran in lockstep at the wrong ratio: the other instance
waited for up to half a minute, then the two ran 266:222 apart in emulated time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gpu.buffer.screenshot failed with "Could not download output" while a game had the display off
(sceDisplaySetFrameBuf with 0) and there was no backbuffer to read instead, as in headless Vulkan.
Pangya: Fantasy Golf does that around its loading screens, which ended the game scripts waiting
for its next screen.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pacer only slept when the emulated clock was ahead of the wall clock since the start of the run,
so any wall time it stood still (at the instance sync, waiting for the slower instance, or in the
relay's wait for a PTP connect) became credit, spent running flat out afterwards. Two instances in
step then sprinted together, and the real latency of the next exchange turned into emulated
seconds: in pair/ptppoll the client's 2 s PtpRecv timed out 7 ms of wall time after it started,
before the host had even sent. The pair tests timed out in connects and receives this way, mostly
on Windows runners.
Now the pacing baseline moves along when an instance is over 5 ms behind. Relay pair/ptppoll went
from failing 14 of 16 runs here to passing 16 of 16.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Custom drivers that target Mali's kbase kernel interface exist now, and
AdrenoTools can load them the same way it loads Turnip. Offer the driver
manager when /dev/mali0 exists, not just /dev/kgsl-3d0, like Dolphin does
(dolphin-emu/dolphin#14958).
The manager is now called "Custom driver manager", and the Turnip flags
are only shown on Adreno.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Transport() returned one of two static transports, picked on each call. Now SetupAdhocRelayMode()
makes the one for the session, wrapped in the network simulation when its options are on, and
sceNetAdhocTerm frees it after the sockets. The simulation owns the transport it wraps and no longer
needs to check each call whether it's on.
The friend finder thread binds its server connection by serverHasRelay itself, since it can run with
no transport (adhocctl stays connected through sceNetAdhocTerm), as can the adhocctl poll.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--adhoc-delay, --adhoc-jitter and --adhoc-loss (AdhocSimDelayMs, AdhocSimJitterMs and
AdhocSimLossPercent in the ini) delay and drop ad hoc traffic, in emulated time, to find games that
can't cope with a real network's latency.
They're a transport, NetSimTransport, around whichever one is in use, so they work the same for the
relay and P2P. PDP datagrams are held on arrival; PTP sends are held before they go, and a "lost" one
goes a retransmit interval later instead. PtpSendNow is new in the transports, for those delayed sends.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream main and the ppsspp branch are the same commit now. The one new
change is in the standalone server's main loop, which PPSSPP doesn't build.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It passed on the macOS runner three times out of three after the fix for
relay sends and receives off the network.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PPSSPP's built-in server doesn't support UDP, so this needs a standalone
aemu_postoffice server running.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aemu_postoffice is now at upstream main, which has the relay performance
fixes: the built-in relay server waits for traffic and pumps as soon as
it arrives instead of sleeping 1 ms between pumps, and pumps on its own
thread instead of waking three workers twice each per pump; closing a
session no longer sleeps 50 ms (the delay is now an option, 0 here,
where everything but a PTP connect's thread, which is joined before its
session closes, runs on the CPU thread); connects and blocking waits for
the server's replies wait on the socket instead of sleeping or spinning.
Unread PTP data is also delivered before a close now.
The pair tests through the relay used to barely gain from speed (29 s at
600%, 22 s at 1600%); now 19 s and 11 s, as fast as P2P at 600%.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Calls that checked one byte of a buffer, then used the game's length:
- GetPeerList and GetAddrByName cleared that many bytes; GetPdpStat and
GetPtpStat filled that many entries. Clamped to valid memory.
- PollSocket read and wrote count entries.
- GetNameByAddr, GetPeerInfo, Join, GetGameModeInfo and UpdateReplica
wrote or read whole structs.
- PtpSend and PtpRecv used the whole data length.
- PdpSend and PdpRecv took host pointers from generic wrappers. Their
syscalls now check the game's buffers and pass NULL for bad ones,
which the calls already reject, since game mode calls the functions
with host buffers.
- Matching SelectTarget, CancelTargetWithOpt and SendData copied the
whole opt or data length. GetMembers cleared a NULL buffer when given
a bad one.
Also: the matching thread list is savestated without the contexts, so a
context's index may be past its end after a load.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A 6.60 PSP returns SCE_KERNEL_ERROR_ILLEGAL_ADDR for one (checked with a
throwaway test; the other bad addresses hang the PSP, so they can't go in
pspautotests).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Calls that checked one byte of a game's buffer and then wrote or read the
whole thing, or trusted a negative length:
- sceNetEtherNtostr/Strton, the apctl BSS descriptor calls, GetState and
sceNetGetDropRate.
- sceNpAuthGetTicket wrote its whole ticket whatever the length; it's
now built locally and written once the buffer is known to hold it.
sceNpAuthGetTicketParam checked its limits after copying, and walked
ticket params past the ticket's end.
- sceNp2's communication ID and passphrase, a negative maxServerIds, and
an unchecked unknown1Ptr.
- sceParseUri's work area and scheme string, sceParseHttp's negative
header length and value address, and ReadVariableSizedStruct's size.
- sceKernelCreateLwMutex initialized the work area without checking it
at all, and the other LwMutex calls checked one byte of it.
- sceNetAdhocctlGetScanInfo cleared the length the game gave, of a
buffer checked by one byte (or any length, negative ones included).
Also: a game mode join inserted at begin() + 1 into a possibly empty
list of players.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Their first login to the server they start takes real time, a few hundred
ms on the Windows runner, and a group request gives up after 5 emulated
seconds: at 1600% every P2P one failed to create its group there.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A console that has left the network sends into the air and receives
nothing, but the relay checked whether it was disabled first. On the
Windows runner the host of pair/vanish finished and took its relay with
it, the client's reconnect failed and disabled the relay, and the
client's PTP send and recv afterwards came back DISCONNECTED.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only there, the host's matching drops the departed client without a
TIMEOUT event. The instances stay in step (no sync warnings in the log),
and it passes on a Mac and on the other runners.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed/unsigned comparisons, bool/int mixes and narrowing in our own code,
plus duplicate NOMINMAX defines. The UWP Common/Core/UI projects now define
_CRT_NO_POSIX_ERROR_CODES like the desktop ones, so SocketCompat.h no longer
redefines the errno macros there. ImMemView's byte search no longer strdup()s
the query (it leaked on the error path).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pair tests that fail only on a CI runner give nothing to go on but the
output diff. The instance sync's and the relay's warnings say where an
instance stalled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every hop through the relay waits a millisecond or so of real time, which
the speed multiplies: at 1600% on macOS CI a relay PTP receive in
pair/ptppoll timed out. Relay mode hardly gains above 800% anyway (26 s
against 22 s locally); P2P stays at 1600%.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its entry in sendTargetPeers stayed, so the next blocking connect from
the same thread on a socket that got the same id returned BUSY
(pspautotests net/adhoc/pair/basic, connect to a closed port, after a
connected socket was closed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Off the network the datagram reaches nobody and the send succeeds, but
the session was recovered first, and a send whose session wasn't up
returned WOULD_BLOCK (pspautotests net/adhoc/pair/vanish, PDP send after
leaving).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each instance paced itself against the wall clock, so on a busy machine
the one that got less CPU fell behind, and anything a test times across
instances (a peer leaving, a matching timeout) came out differently with
the load: pair/vanish and pair/matching3 failed on macOS CI.
With --sync-file and --sync-count, instances on one machine share a file
of one slot per instance. CoreTiming ends a slice at every emulated
millisecond, publishes it there, and waits until every other instance
has reached it too, so they're never more than a millisecond apart. It
works for any number of instances. One that stops moving (a debugger
pause, a crash) is waited for 2 s and then left out until it moves
again, and one that blocks the CPU thread in real time on something the
others must do (the relay PTP connect) stands aside meanwhile.
Tools/adhoc_multi.py and adhoc_session.py use it (--no-sync turns it
off). The host's 1 s head start is gone: they wait for the server's
port instead. adhoc_multi writes each instance's output to a file, as a
full pipe would now stop the other instances too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Fixes#19248
The server loop polled every socket and slept 10 ms, so it woke 100
times a second with nothing to do, and every message could wait up to
10 ms of real time before it was handled, which at a sped-up emulation
speed is many times that in game time. It now waits in select() on the
listening socket and every user, and wakes at least every 50 ms to notice
being stopped. It also no longer stops serving everyone while the hosting
instance is paused in the debugger.
pspautotests: pair/discover and pair/ptpmsg.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A PSP keeps what arrives in the socket's buffer, of the size given to
PdpCreate, and drops a datagram that doesn't fit: a buffer of 0 gets
nothing, one of 2048 bytes only some of ten 1000-byte datagrams
(pspautotests net/adhoc/pair/flow). Each transport now only hands over
the datagrams that have arrived (PdpTakeDatagram), into a queue per
socket that is filled every millisecond and whenever the game looks, and
PdpRecv, its blocking retry, GetPdpStat, PollSocket and game mode read
from that. This replaces each transport's own receive paths, so the
relay now reports the sender with NOT_ENOUGH_SPACE too, and P2P's
blocking receive no longer misreads a stale errno.
A datagram to ourselves goes straight into our own socket's queue, as on
a PSP, so it's there at once through the relay too (net/adhoc/term).
Also from comparing the transports:
- P2P: a blocking Accept of a connection from outside the group keeps
waiting instead of returning -1.
- Relay: an accepted socket gets an id of its own, not its listener's,
which blocking calls are told apart by.
- ALERT in PollSocket comes from the socket in both transports.
- No send/receive timeouts are set on the game's sockets: all host
sockets are non-blocking, and in relay mode the ids aren't host
sockets at all.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It times the socket failures from when the peer drops off the peer list,
which the ad hoc server updates in wall time, so on macOS CI at 600% the
failure lands under a second after it instead of 1-2s. The relay run
still covers it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each instance runs on its own, so on a busy runner they drift apart in
emulated time, and a real second's lag is 8 emulated seconds at 800%:
long enough for pairSync (10 s) to give up on macOS CI. ADHOC_SPEED
still overrides it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A PS1 disc can be a cue sheet, .ccd or .mds rather than an image, and
GetSizeUncompressedInBytes tried to open one as a block device. Measure the
disc the sheet describes instead, and count its image files in the size on
disk too, not just the sheet.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>