Skip to content

Commit

Permalink
lib: nrf_modem: trace: allow trace backend to return EAGAIN on retry
Browse files Browse the repository at this point in the history
Allow the trace backend to return -EAGAIN if the operation should be
retried. This is advantageous compared to the backend waiting forever
as we need to shut down the tracing if the modem is shut down.

Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
  • Loading branch information
eivindj-nordic authored and rlubos committed Jul 17, 2023
1 parent e03a608 commit 4fbf2fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,11 @@ Modem libraries

* :ref:`nrf_modem_lib_readme`:

* Fixed a rare bug that caused a deadlock between two threads when one thread sent data while the other received a lot of data quickly.
* Updated the :c:func:`nrf_modem_lib_shutdown` function to allow the modem to be in flight mode (``CFUN=4``) when shutting down the modem.
Updated:

* The :c:func:`nrf_modem_lib_shutdown` function to allow the modem to be in flight mode (``CFUN=4``) when shutting down the modem.
* The trace backends can now return ``-EAGAIN`` if the write operation can be retried.
* Fixed a rare bug that caused a deadlock between two threads when one thread sent data while the other received a lot of data quickly.

* :ref:`lib_location` library:

Expand Down
2 changes: 2 additions & 0 deletions include/modem/trace_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct nrf_modem_lib_trace_backend {
* -ENOSPC if no space is available and the backend has to be cleared before
* tracing can continue. For some trace backends, space is also cleared
* when performing the read operation.
* -EAGAIN if no data were written due to e.g. flow control and the operation
* should be retried.
*/
int (*write)(const void *data, size_t len);

Expand Down
15 changes: 15 additions & 0 deletions lib/nrf_modem_lib/nrf_modem_lib_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,21 @@ static int trace_fragment_write(struct nrf_modem_trace_data *frag)

__ASSERT(ret != 0, "Trace backend wrote 0 bytes");

/* We handle this here and not in the trace_thread_handler as we might not write the
* entire trace fragment in the same write operation. If we get EAGAIN on the
* second, third, ..., we would repeat sending the first section of the trace
* fragment.
*/
if (ret == -EAGAIN) {
/* We don't allow retrying if the modem is shut down as that can block
* a new modem init.
*/
if (!nrf_modem_is_initialized()) {
return -ESHUTDOWN;
}
continue;
}

if (ret < 0) {
LOG_ERR("trace_backend.write failed with err: %d", ret);
return ret;
Expand Down
5 changes: 5 additions & 0 deletions lib/nrf_modem_lib/trace_backends/uart/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ int trace_backend_write(const void *data, size_t len)
ret = len - remaining_bytes;
out:
k_sem_give(&tx_sem);

if (ret == 0) {
return -EAGAIN;
}

return ret;
}

Expand Down

0 comments on commit 4fbf2fc

Please sign in to comment.