bakerstu / openmrn

OpenMRN (Open Model Railroad Network)
BSD 2-Clause "Simplified" License
57 stars 29 forks source link

priority inversion in CAN packet receive for ESP32 #238

Open balazsracz opened 5 years ago

balazsracz commented 5 years ago

Currently the CAN packet reception path for ESP32 is the following:

The result of this priority inversion is that when the CAN bus sends many back to back packets, we are piling up packets in the DeviceBuffer for RX, and a high priority task is stuffing them in while a low priority task is supposed to consume them. There is no pushback mechanism there, so we get a lot of packets dropped.

This may or may not be a symptom for the CPU having not enough juice to process the packets at full wire speed, but we need to look at the priorities of these buffers.

Steps to reproduce:

balazsracz commented 5 years ago

@atanisoft WDYT

atanisoft commented 5 years ago

This is possibly why during CDI load I see occasional timeouts being reported. Though, I thought the BG task for executor was also for the CanBridge code? If not, we do need to increase priority of the CanBridge code somehow to bring it closer to the CanAdapter code.

balazsracz commented 5 years ago

This is possibly why during CDI load I see occasional timeouts being reported.

I don't think so. The CDI load does not exercise the RX buffer any heavily, because the traffic is point-to-point and throttled by the target node. At any point in time there is only one packet that is in flight to the node. Also you would be seeing the serial output messages loudly complaining about buffer overflow.

Though, I thought the BG task for executor was also for the CanBridge code?

no, the CanBridge is a loop() model. The BG executor is a stateflow model (sleeping with select() when nothing to do).

If not, we do need to increase priority of the CanBridge code somehow to bring it closer to the CanAdapter code.

unfortunately that's not an option, because we cannot increase the loop task's priority. It eats all CPU if we do that.