bitbox02-firmware icon indicating copy to clipboard operation
bitbox02-firmware copied to clipboard

simulator: fix task poll speed

Open benma opened this issue 3 months ago • 2 comments

The simulator didn't behave like the real firmware: it only polled/spun the async tasks when there was USB input available, which happens at the client poll interval during a long-running workflow.

Instead, usb_packet_process should be called if there is USB input, but the async tasks should be polled independently at max speed.

We noticed this issue when making bip39-unlock async, and it would only advance by one bip39 stretch iteration every few hundred milliseconds.

benma avatar Sep 23 '25 08:09 benma

Does this make the simulator use 100% of one cpu thread?

Maybe a quickfix could be to sleep 10 ms in the main loop?

(the real fix is to change to an event loop that blocks if there is nothing more to do)

NickeZ avatar Sep 23 '25 09:09 NickeZ

Does this make the simulator use 100% of one cpu thread?

Maybe a quickfix could be to sleep 10 ms in the main loop?

Yeah I have a version where it does a timeout like this (pushed the commit here), but there is no good balance.

  • 10ms still means an unbearably long unlock
  • 0.05ms is still slow with cpu at about 10% (for me)

(the real fix is to change to an event loop that blocks if there is nothing more to do)

That is not an easy thing to do at the moment right?

For now I am abandoning this PR and simply making bip39 unlock not yield in every iteration in the simulator.

benma avatar Sep 23 '25 11:09 benma