Commit Graph
6 Commits
Author SHA1 Message Date
LibretroAdmin 8f1ac4ad61 samples: compat_strl.c beside features_cpu.c
features_cpu.c copies the CPU's model name with strlcpy() on the
architectures that read it from /proc/cpuinfo, so every sample that
links it links compat_strl.c too; fast_cores_test includes it beside
features_cpu.c. They link on PowerPC and ARM as well as x86.
2026-10-28 05:43:35 +01:00
LibretroAdmin 8cbe988eaf Input: hid pads light the port they are read on
Every hid pad handler that lights the pad - the DualShock 3, DualSense
and Edge, Switch Pro, Switch 2 Pro and Wii Remote - lit its hid slot,
once, when it started. After a driver restart the pads can come back in
other slots and are moved back to the ports they had, and a port can be
pointed at another pad in the menu or by a reservation: the lights then
showed the wrong player, and a pad no port reads was still lit.

The frontend now tells the joypad driver which port reads each pad,
and the hid drivers pass it to the pad's handler, which relights from
its packet handler - the pad's own thread - so nothing waits. The lowest
port reading a pad is shown; on none, the lights go out. The Switch
pads take the console's patterns past player 4.

It costs one countdown a poll: every 32 polls the ports are compared
with what the driver was last told, and only a change, a driver start
or a pad starting beside the joypad driver tells it again. The player
is kept for each slot, so a pad plugged in is lit for its port as it
starts. A handler never told, under a hid driver that does not pass it
on, lights its slot as before.

joypad_slots covers the slot's player across pads and threads;
connect_parity the DualSense and Switch Pro relighting.
2026-10-21 07:36:04 +02:00
LibretroAdmin 21635dd171 samples: build with -g1 instead of -g
The sample and test builds used full debug info. -g1 keeps what
sanitizer reports and backtraces need - function names, files and line
numbers - and drops the variable and type information nobody reads in
CI. Objects get about 30% smaller (rh265.o under ASan+UBSan: 5.1MB to
3.7MB), so the ccache caches hold more of each job's build and are
quicker to restore and save.
2026-10-13 11:50:11 +02:00
libretroadmin afbad7a104 samples: shared sources build into each sample's own obj/
Samples compiled shared tree sources in place, so whichever sample ran
next linked those objects with the flags they were built with, as
unity_identity did with mic_handshake's ASan objects. Every sample that
builds a source from outside its directory now includes
sample_objdir.mk and maps those objects under its own obj/; its own
objects stay where they were. The rule for the mapped objects has a
slash in its target, so make 3.81 does not strip the directory.

tools/sample_objdir_check.py dry-runs every sample Makefile and fails
on an object written outside the sample; the Samples-Objdir-Check
workflow runs it.
2026-10-10 19:43:34 +02:00
LibretroAdmin 8674c1f40b libusb_hid: adapters without a lock
Reads and removal belong to the event-handling thread, so the read
path keeps its in-flight flag plainly and takes nothing per report.
Commands from any thread are pushed on a lock-free stack; whichever
sender claims the OUT transfer with an atomic exchange sends them in
order, one at a time, and looks again after letting go for one pushed
meanwhile. The queue keeps its 4 KiB bound.

An adapter counts the send_control() calls inside it and is not freed
under one; the last to leave a removed adapter wakes the poll thread
to free it.

libusb_hid_test sends from the frontend and from the pad handler at
once and checks every command goes out in each sender's order, races
thousands of hand-offs, and unplugs with a sender held inside, with
and without a send in flight.
2026-10-03 04:57:12 +02:00
LibretroAdmin a58bfddc82 libusb_hid: drive pads with asynchronous transfers instead of a thread each
Every pad had its own thread doing blocking interrupt transfers with a
one-second timeout: a read, then any queued command. So:

- A command (rumble, LEDs) waited behind the read - for the pad's next
  report, or for the second to run out on a pad that was sending
  nothing.
- Removing a pad, or freeing the driver, joined that thread, which
  took up to a second per pad, two if a send was in flight too.
- A read that failed outright (device gone, stalled endpoint) returned
  at once and was retried at once, spinning a core until hotplug got
  round to removing the pad.

There is no thread per pad now. Each pad keeps one IN transfer
submitted, with no timeout; it completes on the poll thread when the
pad sends a report, which is handed to the pad handler, and is
resubmitted from its callback. Commands go into the same queue as
before and are sent one at a time on a single OUT transfer: a command
is submitted as soon as it is queued if nothing is being sent, and the
next from the previous one's callback. They go out in order and never
wait on a read. A read that ends in anything but success or a timeout
stops, with a warning unless the device simply left.

Removal cancels whatever is in flight and parks the adapter on a
retire list; it frees nothing and waits for nothing, which it could
not do anyway from inside the hotplug callback on the very thread that
delivers the cancellations. The poll thread frees retired adapters
whose transfers have all come back, between event batches rather than
from a callback. libusb_hid_free() stops the poll thread, deregisters
hotplug so no pad arrives mid-teardown, removes every adapter, and
hands the cancellations over itself; each call returns as soon as
libusb has them. A two-second deadline only covers a device stack that
never answers, whose adapters are then left allocated rather than
freed with a transfer still in flight.

Also: a pad whose setup failed after pad_connection_pad_init() now
releases its slot, and callbacks are declared LIBUSB_CALL with a
fallback for headers that do not define it.

Nobody here has a libusb pad, so samples/input/libusb_hid runs the
driver against a fake libusb built on the real <libusb.h>. It pins
that a report reaches the pad handler and the read is resubmitted,
that a command goes out at once with no report pending and three go
out in order one at a time, that unplugging frees the adapter, closes
the handle, releases the slot and disconnects the pad, and that
freeing the driver with a send still pending returns at once, with
every transfer freed, none while in flight and none submitted twice.
Clean under ASan, UBSan and TSan; added to the samples/input job,
which now installs the libusb headers.
2026-09-18 15:56:47 +02:00