We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4868

Summary: [PATCH] Optimization for non-libudev joystick detection
Product: SDL Reporter: Cameron Gutman <cameron.gutman>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   
Attachments: Patch

Description Cameron Gutman 2019-11-21 04:31:01 UTC
Currently, we attempt to open() everything in the /dev/input folder every 3 seconds looking for joystick (if we don't have udev, like with Flatpaks). This is problematic because opening an input device can result in I/O which may block the main thread for a short while, causing dropped frames. The delay (or lack thereof) depends on whether other processes on the system already have a fd open and what each input device driver actually does on open.

The attached patch implements a simple stat() mtime check to avoid opening devices if /dev/input hasn't changed since last time we checked. I could have gone with something more fancy like inotify, but it didn't seem worth the complexity for the (hopefully rare) non-udev codepath.
Comment 1 Cameron Gutman 2019-11-21 04:31:41 UTC
Created attachment 4064 [details]
Patch
Comment 2 Sam Lantinga 2019-12-04 05:24:18 UTC
Good change, thanks!
https://hg.libsdl.org/SDL/rev/f9a9707ff56d