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

lib: nrf_modem: trace: fixes for uart trace backend++ #11708

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,13 @@ 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.
* Added CEREG event tracking to ``lte_connectivity``.

* 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.
divipillai marked this conversation as resolved.
Show resolved Hide resolved
* 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 All @@ -415,10 +420,9 @@ Modem libraries

* Updated the library to allow a ``PDP_type``-only configuration in the :c:func:`pdn_ctx_configure` function.

* :ref:`nrf_modem_lib_readme`:
* :ref:`modem_key_mgmt`:

* Updated the :c:func:`modem_key_mgmt_cmp` function to return ``1`` if the buffer length does not match the certificate length.
* Added CEREG event tracking to ``lte_connectivity``.

Libraries for networking
------------------------
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
28 changes: 28 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 Expand Up @@ -347,6 +362,19 @@ static int trace_deinit(void)
return err;
}


#if CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_BITRATE
k_work_cancel(&backend_bps_avg_update_work);
#endif

#if CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_BITRATE_LOG
k_work_cancel(&backend_bps_log_work);
#endif

#if CONFIG_NRF_MODEM_LIB_TRACE_BITRATE_LOG
k_work_cancel(&bps_log_work);
#endif

k_sem_give(&trace_done_sem);

return 0;
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ CONFIG_NRF_MODEM_LIB_TRACE_BACKEND_UART_ZEPHYR=y
# UART configuration
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
CONFIG_UART_1_ASYNC=y
CONFIG_UART_1_INTERRUPT_DRIVEN=n