Skip to content
Open
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
4 changes: 2 additions & 2 deletions include/zephyr/tracing/tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -876,14 +876,14 @@
* @brief Trace Conditional Variable wait enter
* @param condvar Conditional Variable object
*/
#define sys_port_trace_k_condvar_wait_enter(condvar)
#define sys_port_trace_k_condvar_wait_enter(condvar, timeout)

/**
* @brief Trace Conditional Variable wait exit
* @param condvar Conditional Variable object
* @param ret Return value
*/
#define sys_port_trace_k_condvar_wait_exit(condvar, ret)
#define sys_port_trace_k_condvar_wait_exit(condvar, timeout, ret)

/** @} */ /* end of subsys_tracing_apis_condvar */

Expand Down
4 changes: 2 additions & 2 deletions kernel/condvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ int z_impl_k_condvar_wait(struct k_condvar *condvar, struct k_mutex *mutex,
k_spinlock_key_t key;
int ret;

SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_condvar, wait, condvar);
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_condvar, wait, condvar, timeout);

key = k_spin_lock(&lock);
k_mutex_unlock(mutex);

ret = z_pend_curr(&lock, key, &condvar->wait_q, timeout);
k_mutex_lock(mutex, K_FOREVER);

SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_condvar, wait, condvar, ret);
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_condvar, wait, condvar, timeout, ret);

return ret;
}
Expand Down
13 changes: 6 additions & 7 deletions kernel/msg_q.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ int z_impl_k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size,
}

SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, alloc_init, msgq, ret);

return ret;
}

Expand All @@ -106,22 +105,22 @@ int z_vrfy_k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size,

int k_msgq_cleanup(struct k_msgq *msgq)
{
int ret = 0;
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, cleanup, msgq);

CHECKIF(z_waitq_head(&msgq->wait_q) != NULL) {
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, cleanup, msgq, -EBUSY);

return -EBUSY;
ret = -EBUSY;
goto exit;
}

if ((msgq->flags & K_MSGQ_FLAG_ALLOC) != 0U) {
k_free(msgq->buffer_start);
msgq->flags &= ~K_MSGQ_FLAG_ALLOC;
}

SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, cleanup, msgq, 0);

return 0;
exit:
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, cleanup, msgq, ret);
return ret;
}

static inline int put_msg_in_queue(struct k_msgq *msgq, const void *data,
Expand Down
67 changes: 67 additions & 0 deletions snippets/semihost-tracing/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.. _snippet-semihost-tracing:

Semihost Tracing Snippet (semihost-tracing)
###########################################

.. code-block:: console

west build -S semihost-tracing [...]

Overview
********

This snippet enables CTF Tracing using semihosting on a target that supports it.

Using Qemu, you can run the example application and generate a CTF trace file
using semihosting. The trace file can then be viewed using `Babeltrace`_.

.. code-block:: console

(gdb) dump binary memory ram_tracing.bin ram_tracing ram_tracing+8192

Using `Babeltrace`_, you can view the binary file as a CTF trace:

.. code-block:: console

[19:00:00.023530800] (+?.?????????) thread_create: { thread_id = 2147621216, name = "unknown" }
[19:00:00.023567100] (+0.000036300) thread_info: { thread_id = 2147621216, name = "unknown", stack_base = 2147705856, stack_size = 3072 }
[19:00:00.023673700] (+0.000106600) thread_name_set: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.023731100] (+0.000057400) thread_wakeup: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.023827500] (+0.000096400) thread_switched_out: { thread_id = 2147621968, name = "main" }
[19:00:00.023904500] (+0.000077000) thread_switched_in: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.024807600] (+0.000903100) thread_create: { thread_id = 2147619320, name = "unknown" }
[19:00:00.024843800] (+0.000036200) thread_info: { thread_id = 2147619320, name = "unknown", stack_base = 2147693568, stack_size = 3072 }
[19:00:00.024898700] (+0.000054900) thread_wakeup: { thread_id = 2147619320, name = "unknown" }
[19:00:00.025020000] (+0.000121300) thread_switched_out: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.025130700] (+0.000110700) thread_switched_in: { thread_id = 2147621968, name = "main" }
[19:00:00.025249900] (+0.000119200) thread_switched_out: { thread_id = 2147621968, name = "main" }
[19:00:00.025353500] (+0.000103600) thread_switched_in: { thread_id = 2147619320, name = "unknown" }
[19:00:00.026049900] (+0.000696400) thread_switched_in: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.026759200] (+0.000709300) semaphore_give_enter: { id = 2147735664 }
[19:00:00.026773600] (+0.000014400) semaphore_give_exit: { id = 2147735664 }
[19:00:00.027346600] (+0.000573000) thread_switched_out: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.027457400] (+0.000110800) thread_switched_in: { thread_id = 2147621968, name = "main" }
[19:00:00.029552800] (+0.002095400) thread_create: { thread_id = 2147621216, name = "unknown" }
[19:00:00.029589000] (+0.000036200) thread_info: { thread_id = 2147621216, name = "unknown", stack_base = 2147705856, stack_size = 3072 }
[19:00:00.029697400] (+0.000108400) thread_name_set: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.029754800] (+0.000057400) thread_wakeup: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.029851200] (+0.000096400) thread_switched_out: { thread_id = 2147621968, name = "main" }
[19:00:00.029928200] (+0.000077000) thread_switched_in: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.029968400] (+0.000040200) semaphore_init: { id = 2147623436, ret = 0 }
[19:00:00.030851900] (+0.000883500) thread_create: { thread_id = 2147619320, name = "unknown" }
[19:00:00.030888100] (+0.000036200) thread_info: { thread_id = 2147619320, name = "unknown", stack_base = 2147693568, stack_size = 3072 }
[19:00:00.030943000] (+0.000054900) thread_wakeup: { thread_id = 2147619320, name = "unknown" }
[19:00:00.030989600] (+0.000046600) semaphore_take_enter: { id = 2147623436, timeout = 4294957296 }
[19:00:00.031005800] (+0.000016200) semaphore_take_blocking: { id = 2147623436, timeout = 4294957296 }
[19:00:00.031099600] (+0.000093800) thread_switched_out: { thread_id = 2147621216, name = "test_abort_from_isr" }
[19:00:00.031210300] (+0.000110700) thread_switched_in: { thread_id = 2147621968, name = "main" }
[19:00:00.031329500] (+0.000119200) thread_switched_out: { thread_id = 2147621968, name = "main" }
[19:00:00.031433100] (+0.000103600) thread_switched_in: { thread_id = 2147619320, name = "unknown" }
[19:00:00.031469100] (+0.000036000) semaphore_give_enter: { id = 2147623436 }

References
**********

.. target-notes::

.. _Babeltrace: https://babeltrace.org/
12 changes: 12 additions & 0 deletions snippets/semihost-tracing/semihost-tracing.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright Zephyr Project Contributors
# SPDX-License-Identifier: Apache-2.0


CONFIG_DEBUG_OPTIMIZATIONS=n
CONFIG_DEBUG_THREAD_INFO=y

CONFIG_TRACING=y
CONFIG_TRACING_CTF=y
CONFIG_TRACING_BACKEND_SEMIHOST=y
CONFIG_SEMIHOST=y
CONFIG_TRACING_SYNC=y
6 changes: 6 additions & 0 deletions snippets/semihost-tracing/snippet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright Zephyr Project Contributors
# SPDX-License-Identifier: Apache-2.0

name: semihost-tracing
append:
EXTRA_CONF_FILE: semihost-tracing.conf
5 changes: 5 additions & 0 deletions subsys/tracing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ zephyr_sources_ifdef(
tracing_backend_usb.c
)

zephyr_sources_ifdef(
CONFIG_TRACING_BACKEND_SEMIHOST
tracing_backend_semihosting.c
)

zephyr_sources_ifdef(
CONFIG_TRACING_BACKEND_UART
tracing_backend_uart.c
Expand Down
8 changes: 8 additions & 0 deletions subsys/tracing/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ config TRACING_BACKEND_RAM
be dumped to a file at runtime with a debugger.
See gdb dump binary memory documentation for example.

config TRACING_BACKEND_SEMIHOST
bool "Semihost backend"
depends on SEMIHOST
help
Use semihosting to output tracing data. This is useful
for debugging on a host machine, such as when using QEMU.

config TRACING_BACKEND_ADSP_MEMORY_WINDOW
bool "Memory window in RAM"
depends on SOC_FAMILY_INTEL_ADSP
Expand All @@ -174,6 +181,7 @@ config TRACING_BACKEND_NAME
default "tracing_backend_usb" if TRACING_BACKEND_USB
default "tracing_backend_posix" if TRACING_BACKEND_POSIX
default "tracing_backend_ram" if TRACING_BACKEND_RAM
default "tracing_backend_semihost" if TRACING_BACKEND_SEMIHOST
default "tracing_backend_adsp_memory_window" if TRACING_BACKEND_ADSP_MEMORY_WINDOW

config RAM_TRACING_BUFFER_SIZE
Expand Down
Loading
Loading