Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modem backend uart async optimization #65194

Conversation

bjarki-trackunit
Copy link
Collaborator

@bjarki-trackunit bjarki-trackunit commented Nov 14, 2023

The mode UART backend implementations have been manually tested ad-hoc up until now. This PR adds a proper test suite to stress test the backends on real hardware, along with patches to the backends fixing issues found by the new tests :)

The patches to the backends are listed here, and have their own commits in this PR:

  1. When pipe close is invoked, the async UART backend will now wait for all buffers released, TX aborted, and RX disabled, before indicating it has been closed. This ensures the UART device is in a known state once the pipe is closed. In addition, the close invokation will also call uart_tx_abort().
  2. Use single RX ring buffer protected by spinlock instead of switching between two RX smaller ring buffers. The tests revealed there was no measurable performance over using a single buffer larger RX buffer, which is simpler.
  3. Flushing the UART is not the responsibility of the async UART backend when using the async UART API, so it has been removed.

The current implementation only waits for the RX disabled event
to determine if the UART is closed. It should wait for all RX
buffers to be released, and the TX to be done as well.

We now also call uart_tx_abort() when closing the pipe.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
@bjarki-trackunit bjarki-trackunit changed the title Modem backend uart async optimize Modem backend uart async optimization Nov 14, 2023
@bjarki-trackunit bjarki-trackunit self-assigned this Nov 14, 2023
@bjarki-trackunit bjarki-trackunit force-pushed the modem_backend_uart_async_optimize branch 4 times, most recently from 8c3b4de to c084e12 Compare November 16, 2023 19:37
@bjarki-trackunit bjarki-trackunit marked this pull request as ready for review November 16, 2023 19:45
Use single ring buffer and protect it with a spinlock as it is
shared between backend and UART thread (ISR). This is simpler
than the double ring buffer setup.

The receive idle timeout has also been made configurable
instead of being a hardcoded value.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
The UART flush is not relevant for the async UART implementation.
UART drivers should handle this internally.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
The UART backend test suite performs 9 iterations of:

1. Open UART backend pipe
2. Transmit 8192 bytes of pseudo random data
3. Receive and validate bytes
4. close UART backend pipe

The test is run on real hardware, with the TX/RX pins
connected to each other to provide loopback functionality.

The test suite has been run on a STM32 and an nRF5340 board.
The test suite tests both the UART interrupt driven and
async APIs.

Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
@carlescufi carlescufi merged commit d3f1003 into zephyrproject-rtos:main Nov 20, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants