Tracing: Memory Slab tracing
Add memory slab tracing, default trace hooks, and documentation.
Signed-off-by: Torbjörn Leksell <torbjorn.leksell@percepio.com>
diff --git a/include/tracing/tracing.h b/include/tracing/tracing.h
index 029d5b5..9cb36fb 100644
--- a/include/tracing/tracing.h
+++ b/include/tracing/tracing.h
@@ -1410,6 +1410,61 @@
*/ /* end of heap_tracing_apis */
+
+
+/**
+ * @brief Memory Slab Tracing APIs
+ * @defgroup mslab_tracing_apis Memory Slab Tracing APIs
+ * @ingroup tracing_apis
+ * @{
+ */
+
+/**
+ * @brief Trace initialization of Memory Slab
+ * @param slab Memory Slab object
+ * @param rc Return value
+ */
+#define sys_port_trace_k_mem_slab_init(slab, rc)
+
+/**
+ * @brief Trace Memory Slab alloc attempt entry
+ * @param slab Memory Slab object
+ * @param timeout Timeout period
+ */
+#define sys_port_trace_k_mem_slab_alloc_enter(slab, timeout)
+
+/**
+ * @brief Trace Memory Slab alloc attempt blocking
+ * @param slab Memory Slab object
+ * @param timeout Timeout period
+ */
+#define sys_port_trace_k_mem_slab_alloc_blocking(slab, timeout)
+
+/**
+ * @brief Trace Memory Slab alloc attempt outcome
+ * @param slab Memory Slab object
+ * @param timeout Timeout period
+ * @param ret Return value
+ */
+#define sys_port_trace_k_mem_slab_alloc_exit(slab, timeout, ret)
+
+/**
+ * @brief Trace Memory Slab free entry
+ * @param slab Memory Slab object
+ */
+#define sys_port_trace_k_mem_slab_free_enter(slab)
+
+/**
+ * @brief Trace Memory Slab free exit
+ * @param slab Memory Slab object
+ */
+#define sys_port_trace_k_mem_slab_free_exit(slab)
+
+/**
+ * @}
+ */ /* end of mslab_tracing_apis */
+
+
/**
* @}
*/
diff --git a/kernel/mem_slab.c b/kernel/mem_slab.c
index 883a97c..dc07082 100644
--- a/kernel/mem_slab.c
+++ b/kernel/mem_slab.c
@@ -97,11 +97,14 @@
goto out;
}
z_waitq_init(&slab->wait_q);
+
SYS_TRACING_OBJ_INIT(k_mem_slab, slab);
z_object_init(slab);
out:
+ SYS_PORT_TRACING_OBJ_INIT(k_mem_slab, slab, rc);
+
return rc;
}
@@ -110,6 +113,8 @@
k_spinlock_key_t key = k_spin_lock(&slab->lock);
int result;
+ SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_mem_slab, alloc, slab, timeout);
+
if (slab->free_list != NULL) {
/* take a free block */
*mem = slab->free_list;
@@ -127,14 +132,21 @@
*mem = NULL;
result = -ENOMEM;
} else {
+ SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_mem_slab, alloc, slab, timeout);
+
/* wait for a free block or timeout */
result = z_pend_curr(&slab->lock, key, &slab->wait_q, timeout);
if (result == 0) {
*mem = _current->base.swap_data;
}
+
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mem_slab, alloc, slab, timeout, result);
+
return result;
}
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mem_slab, alloc, slab, timeout, result);
+
k_spin_unlock(&slab->lock, key);
return result;
@@ -144,10 +156,13 @@
{
k_spinlock_key_t key = k_spin_lock(&slab->lock);
+ SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_mem_slab, free, slab);
if (slab->free_list == NULL && IS_ENABLED(CONFIG_MULTITHREADING)) {
struct k_thread *pending_thread = z_unpend_first_thread(&slab->wait_q);
if (pending_thread != NULL) {
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mem_slab, free, slab);
+
z_thread_return_value_set_with_data(pending_thread, 0, *mem);
z_ready_thread(pending_thread);
z_reschedule(&slab->lock, key);
@@ -157,5 +172,8 @@
**(char ***) mem = slab->free_list;
slab->free_list = *(char **) mem;
slab->num_used--;
+
+ SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_mem_slab, free, slab);
+
k_spin_unlock(&slab->lock, key);
}