pandad: refactor to single thread
To minimize changes and avoid introducing new issues, the original C-style functions have been retained.
Main Changes
- Renamed xxx_thread() functions to xxx().
- Changed variables in the original thread functions to static to retain values across calls.
- Moved
send_peripheral_statefrompanda_state()toperipheral_state()for a better fit. - Move 'safety_future' to a global variable to ensure the
safety_setter_threadgracefully quits on exit. - Prefix all global variables with 'g_'
Additional Note
A possible better approach to eliminate the static variables is to declare classes for PeripheralState, PandaState, etc., and move the static variables to their member variables. The final code might look something like this:
void PandaD::run() {
...
panda_state.process();
peripheral_state.process();
}
However, since the pandad process always restarts after failures, keeping these variables as static in this PR is harmless.
Thanks for contributing to openpilot! In order for us to review your PR as quickly as possible, check the following:
- Convert your PR to a draft unless it's ready to review
- Read the contributing docs
- Before marking as "ready for review", ensure:
- the goal is clearly stated in the description
- all the tests are passing
- the change is something we merge
- include a route or your device' dongle ID if relevant
Nice work! I added to the 0.9.8 milestone and will try to get this merged soon.
trigger-jenkins
@Quantizr can you verify this in the testing closet and merge if it looks good?
Looks good on the testing closet, significant reduction in the variability of the timing of pandaStates messages, going from a relative standard deviation of ~0.0175 to ~0.0049 and small improvements in various other service timings.
This PR timings:
Prior timings: