diff --git a/include/tracing/tracing.h b/include/tracing/tracing.h index 695dd46b10..e381bc439d 100644 --- a/include/tracing/tracing.h +++ b/include/tracing/tracing.h @@ -990,6 +990,109 @@ */ /* end of stack_tracing_apis */ + + +/** + * @brief Message Queue Tracing APIs + * @defgroup msgq_tracing_apis Message Queue Tracing APIs + * @ingroup tracing_apis + * @{ + */ + +/** + * @brief Trace initialization of Message Queue + * @param msgq Message Queue object + */ +#define sys_port_trace_k_msgq_init(msgq) + +/** + * @brief Trace Message Queue alloc init attempt entry + * @param msgq Message Queue object + */ +#define sys_port_trace_k_msgq_alloc_init_enter(msgq) + +/** + * @brief Trace Message Queue alloc init attempt outcome + * @param msgq Message Queue object + * @param ret Return value + */ +#define sys_port_trace_k_msgq_alloc_init_exit(msgq, ret) + +/** + * @brief Trace Message Queue cleanup attempt entry + * @param msgq Message Queue object + */ +#define sys_port_trace_k_msgq_cleanup_enter(msgq) + +/** + * @brief Trace Message Queue cleanup attempt outcome + * @param msgq Message Queue object + * @param ret Return value + */ +#define sys_port_trace_k_msgq_cleanup_exit(msgq, ret) + +/** + * @brief Trace Message Queue put attempt entry + * @param msgq Message Queue object + * @param timeout Timeout period + */ +#define sys_port_trace_k_msgq_put_enter(msgq, timeout) + +/** + * @brief Trace Message Queue put attempt blocking + * @param msgq Message Queue object + * @param timeout Timeout period + */ +#define sys_port_trace_k_msgq_put_blocking(msgq, timeout) + +/** + * @brief Trace Message Queue put attempt outcome + * @param msgq Message Queue object + * @param timeout Timeout period + * @param ret Return value + */ +#define sys_port_trace_k_msgq_put_exit(msgq, timeout, ret) + +/** + * @brief Trace Message Queue get attempt entry + * @param msgq Message Queue object + * @param timeout Timeout period + */ +#define sys_port_trace_k_msgq_get_enter(msgq, timeout) + +/** + * @brief Trace Message Queue get attempt blockings + * @param msgq Message Queue object + * @param timeout Timeout period + */ +#define sys_port_trace_k_msgq_get_blocking(msgq, timeout) + +/** + * @brief Trace Message Queue get attempt outcome + * @param msgq Message Queue object + * @param timeout Timeout period + * @param ret Return value + */ +#define sys_port_trace_k_msgq_get_exit(msgq, timeout, ret) + +/** + * @brief Trace Message Queue peek + * @param msgq Message Queue object + * @param ret Return value + */ +#define sys_port_trace_k_msgq_peek(msgq, ret) + +/** + * @brief Trace Message Queue purge + * @param msgq Message Queue object + */ +#define sys_port_trace_k_msgq_purge(msgq) + +/** + * @} + */ /* end of msgq_tracing_apis */ + + /** * @} */ diff --git a/kernel/msg_q.c b/kernel/msg_q.c index f888fde72e..b9899e2987 100644 --- a/kernel/msg_q.c +++ b/kernel/msg_q.c @@ -69,6 +69,9 @@ void k_msgq_init(struct k_msgq *msgq, char *buffer, size_t msg_size, #ifdef CONFIG_POLL sys_dlist_init(&msgq->poll_events); #endif /* CONFIG_POLL */ + + SYS_PORT_TRACING_OBJ_INIT(k_msgq, msgq); + SYS_TRACING_OBJ_INIT(k_msgq, msgq); z_object_init(msgq); @@ -81,6 +84,8 @@ int z_impl_k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size, int ret; size_t total_size; + SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, alloc_init, msgq); + if (size_mul_overflow(msg_size, max_msgs, &total_size)) { ret = -EINVAL; } else { @@ -94,6 +99,8 @@ 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; } @@ -110,7 +117,11 @@ int z_vrfy_k_msgq_alloc_init(struct k_msgq *msgq, size_t msg_size, int k_msgq_cleanup(struct k_msgq *msgq) { + 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; } @@ -118,6 +129,9 @@ int k_msgq_cleanup(struct k_msgq *msgq) k_free(msgq->buffer_start); msgq->flags &= ~K_MSGQ_FLAG_ALLOC; } + + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, cleanup, msgq, 0); + return 0; } @@ -132,10 +146,14 @@ int z_impl_k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t timeout key = k_spin_lock(&msgq->lock); + SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, put, msgq, timeout); + if (msgq->used_msgs < msgq->max_msgs) { /* message queue isn't full */ pending_thread = z_unpend_first_thread(&msgq->wait_q); if (pending_thread != NULL) { + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, 0); + /* give message to waiting thread */ (void)memcpy(pending_thread->base.swap_data, data, msgq->msg_size); @@ -161,11 +179,18 @@ int z_impl_k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t timeout /* don't wait for message space to become available */ result = -ENOMSG; } else { + SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, put, msgq, timeout); + /* wait for put message success, failure, or timeout */ _current->base.swap_data = (void *) data; - return z_pend_curr(&msgq->lock, key, &msgq->wait_q, timeout); + + result = z_pend_curr(&msgq->lock, key, &msgq->wait_q, timeout); + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, result); + return result; } + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, result); + k_spin_unlock(&msgq->lock, key); return result; @@ -211,6 +236,8 @@ int z_impl_k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout) key = k_spin_lock(&msgq->lock); + SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, get, msgq, timeout); + if (msgq->used_msgs > 0U) { /* take first available message from queue */ (void)memcpy(data, msgq->read_ptr, msgq->msg_size); @@ -223,6 +250,8 @@ int z_impl_k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout) /* handle first thread waiting to write (if any) */ pending_thread = z_unpend_first_thread(&msgq->wait_q); if (pending_thread != NULL) { + SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, get, msgq, timeout); + /* add thread's message to queue */ (void)memcpy(msgq->write_ptr, pending_thread->base.swap_data, msgq->msg_size); @@ -236,6 +265,9 @@ int z_impl_k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout) arch_thread_return_value_set(pending_thread, 0); z_ready_thread(pending_thread); z_reschedule(&msgq->lock, key); + + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, 0); + return 0; } result = 0; @@ -243,11 +275,18 @@ int z_impl_k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout) /* don't wait for a message to become available */ result = -ENOMSG; } else { + SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, get, msgq, timeout); + /* wait for get message success or timeout */ _current->base.swap_data = data; - return z_pend_curr(&msgq->lock, key, &msgq->wait_q, timeout); + + result = z_pend_curr(&msgq->lock, key, &msgq->wait_q, timeout); + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, result); + return result; } + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, result); + k_spin_unlock(&msgq->lock, key); return result; @@ -281,6 +320,8 @@ int z_impl_k_msgq_peek(struct k_msgq *msgq, void *data) result = -ENOMSG; } + SYS_PORT_TRACING_OBJ_FUNC(k_msgq, peek, msgq, result); + k_spin_unlock(&msgq->lock, key); return result; @@ -304,6 +345,8 @@ void z_impl_k_msgq_purge(struct k_msgq *msgq) key = k_spin_lock(&msgq->lock); + SYS_PORT_TRACING_OBJ_FUNC(k_msgq, purge, msgq); + /* wake up any threads that are waiting to write */ while ((pending_thread = z_unpend_first_thread(&msgq->wait_q)) != NULL) { arch_thread_return_value_set(pending_thread, -ENOMSG);