Tracing: Mailbox tracing
Add Mailbox tracing, default tracing hooks, and documentation.
Signed-off-by: Torbjörn Leksell <torbjorn.leksell@percepio.com>
diff --git a/kernel/mailbox.c b/kernel/mailbox.c
index 818a9bf..3ed7116 100644
--- a/kernel/mailbox.c
+++ b/kernel/mailbox.c
@@ -102,6 +102,9 @@
z_waitq_init(&mbox->tx_msg_queue);
z_waitq_init(&mbox->rx_msg_queue);
mbox->lock = (struct k_spinlock) {};
+
+ SYS_PORT_TRACING_OBJ_INIT(k_mbox, mbox);
+
SYS_TRACING_OBJ_INIT(k_mbox, mbox);
}
@@ -248,6 +251,8 @@
/* search mailbox's rx queue for a compatible receiver */
key = k_spin_lock(&mbox->lock);
+ SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_mbox, message_put, mbox, timeout);
+
_WAIT_Q_FOR_EACH(&mbox->rx_msg_queue, receiving_thread) {
rx_msg = (struct k_mbox_msg *)receiving_thread->base.swap_data;
@@ -273,18 +278,24 @@
return 0;
}
#endif
+ SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_mbox, message_put, mbox, timeout);
/*
* synchronous send: pend current thread (unqueued)
* until the receiver consumes the message
*/
- return z_pend_curr(&mbox->lock, key, NULL, K_FOREVER);
+ int ret = z_pend_curr(&mbox->lock, key, NULL, K_FOREVER);
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, message_put, mbox, timeout, ret);
+
+ return ret;
}
}
/* didn't find a matching receiver: don't wait for one */
if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, message_put, mbox, timeout, -ENOMSG);
+
k_spin_unlock(&mbox->lock, key);
return -ENOMSG;
}
@@ -297,9 +308,14 @@
return 0;
}
#endif
+ SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_mbox, message_put, mbox, timeout);
/* synchronous send: sender waits on tx queue for receiver or timeout */
- return z_pend_curr(&mbox->lock, key, &mbox->tx_msg_queue, timeout);
+ int ret = z_pend_curr(&mbox->lock, key, &mbox->tx_msg_queue, timeout);
+
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, message_put, mbox, timeout, ret);
+
+ return ret;
}
int k_mbox_put(struct k_mbox *mbox, struct k_mbox_msg *tx_msg,
@@ -308,7 +324,13 @@
/* configure things for a synchronous send, then send the message */
tx_msg->_syncing_thread = _current;
- return mbox_message_put(mbox, tx_msg, timeout);
+ SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_mbox, put, mbox, timeout);
+
+ int ret = mbox_message_put(mbox, tx_msg, timeout);
+
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, put, mbox, timeout, ret);
+
+ return ret;
}
#if (CONFIG_NUM_MBOX_ASYNC_MSGS > 0)
@@ -317,6 +339,8 @@
{
struct k_mbox_async *async;
+ SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_mbox, async_put, mbox, sem);
+
/*
* allocate an asynchronous message descriptor, configure both parts,
* then send the message asynchronously
@@ -330,6 +354,7 @@
async->tx_msg._async_sem = sem;
(void)mbox_message_put(mbox, &async->tx_msg, K_FOREVER);
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, async_put, mbox, sem);
}
#endif
@@ -394,6 +419,8 @@
/* search mailbox's tx queue for a compatible sender */
key = k_spin_lock(&mbox->lock);
+ SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_mbox, get, mbox, timeout);
+
_WAIT_Q_FOR_EACH(&mbox->tx_msg_queue, sending_thread) {
tx_msg = (struct k_mbox_msg *)sending_thread->base.swap_data;
@@ -404,18 +431,25 @@
k_spin_unlock(&mbox->lock, key);
/* consume message data immediately, if needed */
- return mbox_message_data_check(rx_msg, buffer);
+ result = mbox_message_data_check(rx_msg, buffer);
+
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, get, mbox, timeout, result);
+ return result;
}
}
/* didn't find a matching sender */
if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, get, mbox, timeout, -ENOMSG);
+
/* don't wait for a matching sender to appear */
k_spin_unlock(&mbox->lock, key);
return -ENOMSG;
}
+ SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_mbox, get, mbox, timeout);
+
/* wait until a matching sender appears or a timeout occurs */
_current->base.swap_data = rx_msg;
result = z_pend_curr(&mbox->lock, key, &mbox->rx_msg_queue, timeout);
@@ -425,5 +459,7 @@
result = mbox_message_data_check(rx_msg, buffer);
}
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mbox, get, mbox, timeout, result);
+
return result;
}