Tracing: Memory Stack tracing

Add memory stack tracing, defaul trace hooks, and documentation.

Signed-off-by: Torbjörn Leksell <torbjorn.leksell@percepio.com>
This commit is contained in:
Torbjörn Leksell 2021-03-26 12:31:43 +01:00 committed by Anas Nashif
parent d765445b3b
commit 69e8869127
2 changed files with 113 additions and 0 deletions

View file

@ -909,6 +909,87 @@
*/ /* end of lifo_tracing_apis */ */ /* end of lifo_tracing_apis */
/**
* @brief Stack Tracing APIs
* @defgroup stack_tracing_apis Stack Tracing APIs
* @ingroup tracing_apis
* @{
*/
/**
* @brief Trace initialization of Stack
* @param stack Stack object
*/
#define sys_port_trace_k_stack_init(stack)
/**
* @brief Trace Stack alloc init attempt entry
* @param stack Stack object
*/
#define sys_port_trace_k_stack_alloc_init_enter(stack)
/**
* @brief Trace Stack alloc init outcome
* @param stack Stack object
* @param ret Return value
*/
#define sys_port_trace_k_stack_alloc_init_exit(stack, ret)
/**
* @brief Trace Stack cleanup attempt entry
* @param stack Stack object
*/
#define sys_port_trace_k_stack_cleanup_enter(stack)
/**
* @brief Trace Stack cleanup outcome
* @param stack Stack object
* @param ret Return value
*/
#define sys_port_trace_k_stack_cleanup_exit(stack, ret)
/**
* @brief Trace Stack push attempt entry
* @param stack Stack object
*/
#define sys_port_trace_k_stack_push_enter(stack)
/**
* @brief Trace Stack push attempt outcome
* @param stack Stack object
* @param ret Return value
*/
#define sys_port_trace_k_stack_push_exit(stack, ret)
/**
* @brief Trace Stack pop attempt entry
* @param stack Stack object
* @param timeout Timeout period
*/
#define sys_port_trace_k_stack_pop_enter(stack, timeout)
/**
* @brief Trace Stack pop attempt blocking
* @param stack Stack object
* @param timeout Timeout period
*/
#define sys_port_trace_k_stack_pop_blocking(stack, timeout)
/**
* @brief Trace Stack pop attempt outcome
* @param stack Stack object
* @param timeout Timeout period
* @param ret Return value
*/
#define sys_port_trace_k_stack_pop_exit(stack, timeout, ret)
/**
* @}
*/ /* end of stack_tracing_apis */
/** /**
* @} * @}
*/ */

View file

@ -48,6 +48,8 @@ void k_stack_init(struct k_stack *stack, stack_data_t *buffer,
stack->next = stack->base = buffer; stack->next = stack->base = buffer;
stack->top = stack->base + num_entries; stack->top = stack->base + num_entries;
SYS_PORT_TRACING_OBJ_INIT(k_stack, stack);
SYS_TRACING_OBJ_INIT(k_stack, stack); SYS_TRACING_OBJ_INIT(k_stack, stack);
z_object_init(stack); z_object_init(stack);
} }
@ -57,6 +59,8 @@ int32_t z_impl_k_stack_alloc_init(struct k_stack *stack, uint32_t num_entries)
void *buffer; void *buffer;
int32_t ret; int32_t ret;
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, alloc_init, stack);
buffer = z_thread_malloc(num_entries * sizeof(stack_data_t)); buffer = z_thread_malloc(num_entries * sizeof(stack_data_t));
if (buffer != NULL) { if (buffer != NULL) {
k_stack_init(stack, buffer, num_entries); k_stack_init(stack, buffer, num_entries);
@ -66,6 +70,8 @@ int32_t z_impl_k_stack_alloc_init(struct k_stack *stack, uint32_t num_entries)
ret = -ENOMEM; ret = -ENOMEM;
} }
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, alloc_init, stack, ret);
return ret; return ret;
} }
@ -82,7 +88,11 @@ static inline int32_t z_vrfy_k_stack_alloc_init(struct k_stack *stack,
int k_stack_cleanup(struct k_stack *stack) int k_stack_cleanup(struct k_stack *stack)
{ {
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, cleanup, stack);
CHECKIF(z_waitq_head(&stack->wait_q) != NULL) { CHECKIF(z_waitq_head(&stack->wait_q) != NULL) {
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, cleanup, stack, -EAGAIN);
return -EAGAIN; return -EAGAIN;
} }
@ -91,6 +101,9 @@ int k_stack_cleanup(struct k_stack *stack)
stack->base = NULL; stack->base = NULL;
stack->flags &= ~K_STACK_FLAG_ALLOC; stack->flags &= ~K_STACK_FLAG_ALLOC;
} }
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, cleanup, stack, 0);
return 0; return 0;
} }
@ -100,6 +113,8 @@ int z_impl_k_stack_push(struct k_stack *stack, stack_data_t data)
int ret = 0; int ret = 0;
k_spinlock_key_t key = k_spin_lock(&stack->lock); k_spinlock_key_t key = k_spin_lock(&stack->lock);
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, push, stack);
CHECKIF(stack->next == stack->top) { CHECKIF(stack->next == stack->top) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
@ -124,6 +139,8 @@ out:
k_spin_unlock(&stack->lock, key); k_spin_unlock(&stack->lock, key);
end: end:
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, push, stack, ret);
return ret; return ret;
} }
@ -145,24 +162,39 @@ int z_impl_k_stack_pop(struct k_stack *stack, stack_data_t *data,
key = k_spin_lock(&stack->lock); key = k_spin_lock(&stack->lock);
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_stack, pop, stack, timeout);
if (likely(stack->next > stack->base)) { if (likely(stack->next > stack->base)) {
stack->next--; stack->next--;
*data = *(stack->next); *data = *(stack->next);
k_spin_unlock(&stack->lock, key); k_spin_unlock(&stack->lock, key);
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, 0);
return 0; return 0;
} }
SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_stack, pop, stack, timeout);
if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) {
k_spin_unlock(&stack->lock, key); k_spin_unlock(&stack->lock, key);
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, -EBUSY);
return -EBUSY; return -EBUSY;
} }
result = z_pend_curr(&stack->lock, key, &stack->wait_q, timeout); result = z_pend_curr(&stack->lock, key, &stack->wait_q, timeout);
if (result == -EAGAIN) { if (result == -EAGAIN) {
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, -EAGAIN);
return -EAGAIN; return -EAGAIN;
} }
*data = (stack_data_t)_current->base.swap_data; *data = (stack_data_t)_current->base.swap_data;
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_stack, pop, stack, timeout, 0);
return 0; return 0;
} }