commaai / msgq

MSGQ: A lock free single producer multi consumer message queue
175 stars 252 forks source link

use futex for IPC notifications #625

Open deanlee opened 2 months ago

deanlee commented 2 months ago

This PR replaces the use of std::signalwith futex for inter-process notifications between publishers and subscribers. improving the robustness and performance of IPC notifications. Tested on PC and c3x device.

Benefits:

  1. Futex provides a cleaner and more reliable synchronization mechanism than signals. Signals can interrupt system calls across all subscriber processes, adding complexity and impacting overall system performance.
  2. Futex minimizes context switches and eliminates signal handler overhead, thereby reducing synchronization latency. It primarily operates in user space and enters kernel space only when necessary, unlike std::signal, which always involves kernel space operations.
  3. Futex provides a more reliable and easier-to-debug synchronization mechanism than signals, ensuring robust inter-process communication.
adeebshihadeh commented 1 month ago

This is a pretty core change to msgq. I'd like to do it, but we need to make sure that it hits all of our goals. Fixing the EINTR spam is great, but let's also make sure it'll work on macOS.