Merge pull request #5491 from MohmadAyman/isr_stack_usage

cpu: add capability to show stack usage of ISR
pr/spi.typo
Martine Lenders 7 years ago
commit 9b1ad7820c

@ -30,6 +30,7 @@ extern "C" {
#define THREAD_EXTRA_STACKSIZE_PRINTF (8192)
#define THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT (8192)
#define THREAD_STACKSIZE_MINIMUM (8192)
#define ISR_STACKSIZE (0)
#ifdef __cplusplus
}

@ -58,6 +58,11 @@ typedef void *(*thread_task_func_t)(void *arg);
*/
char *thread_arch_stack_init(thread_task_func_t task_func, void *arg, void *stack_start, int stack_size);
/**
* @brief Get the number of bytes used on the ISR stack
*/
int thread_arch_isr_stack_usage(void);
/**
* @brief Print the current stack to stdout
*/

@ -28,6 +28,13 @@ void thread_yield_higher(void)
__asm__("svc 0\n");
}
/* This function calculates the ISR_usage */
int thread_arch_isr_stack_usage(void)
{
/* TODO */
return -1;
}
/*----------------------------------------------------------------------------
* Processor specific routine - here for ARM7
* sizeof(void*) = sizeof(int)

@ -40,6 +40,7 @@ extern "C" {
#endif
#define THREAD_STACKSIZE_IDLE (128)
#define ISR_STACKSIZE (0)
/** @} */
#ifdef __cplusplus

@ -198,6 +198,13 @@ void thread_arch_stack_print(void)
printf("stack size: %u bytes\n", size);
}
/* This function calculates the ISR_usage */
int thread_arch_isr_stack_usage(void)
{
/* TODO */
return -1;
}
void thread_arch_start_threading(void) __attribute__((naked));
void thread_arch_start_threading(void)
{

@ -48,6 +48,15 @@ extern "C" {
#define ARCH_HAS_ATOMIC_COMPARE_AND_SWAP 1
#endif
/**
* @brief Interrupt stack canary value
*
* @note 0xe7fe is the ARM Thumb machine code equivalent of asm("bl #-2\n") or
* 'while (1);', i.e. an infinite loop.
* @internal
*/
#define STACK_CANARY_WORD (0xE7FEE7FEu)
/**
* @brief Initialization of the CPU
*/

@ -100,6 +100,9 @@
#include "irq.h"
#include "cpu.h"
extern uint32_t _estack;
extern uint32_t _sstack;
/**
* @brief Noticeable marker marking the beginning of a stack segment
*
@ -251,6 +254,15 @@ void thread_arch_stack_print(void)
printf("current stack size: %i byte\n", count);
}
/* This function returns the number of bytes used on the ISR stack */
int thread_arch_isr_stack_usage(void)
{
uint32_t *ptr = &_sstack;
while (*(ptr++) == STACK_CANARY_WORD) {}
return (ISR_STACKSIZE - (ptr - &_sstack));
}
__attribute__((naked)) void NORETURN thread_arch_start_threading(void)
{
__asm__ volatile (

@ -31,14 +31,6 @@
#include "panic.h"
#include "vectors_cortexm.h"
/**
* @brief Interrupt stack canary value
*
* @note 0xe7fe is the ARM Thumb machine code equivalent of __asm__("bl #-2\n") or
* 'while (1);', i.e. an infinite loop.
*/
#define STACK_CANARY_WORD 0xE7FEE7FEu
/**
* @brief Memory markers, defined in the linker script
* @{

@ -51,6 +51,8 @@ extern "C" {
#endif
#define THREAD_STACKSIZE_IDLE (160)
#define ISR_STACKSIZE (0)
/** @} */
/**

@ -33,6 +33,13 @@ __attribute__((naked)) void thread_yield_higher(void)
UNREACHABLE();
}
/* This function calculates the ISR_usage */
int thread_arch_isr_stack_usage(void)
{
/* TODO */
return -1;
}
NORETURN void cpu_switch_context_exit(void)
{
sched_active_thread = sched_threads[0];

@ -75,7 +75,7 @@ extern volatile int __irq_is_in;
/**
* @brief Memory used as stack for the interrupt context
*/
extern char __isr_stack[MSP430_ISR_STACK_SIZE];
extern char __isr_stack[ISR_STACKSIZE];
/**
* @brief Save the current thread context from inside an ISR
@ -126,7 +126,7 @@ static inline void __attribute__((always_inline)) __restore_context(void)
static inline void __attribute__((always_inline)) __enter_isr(void)
{
__save_context();
__asm__("mov.w %0,r1" : : "i"(__isr_stack + MSP430_ISR_STACK_SIZE));
__asm__("mov.w %0,r1" : : "i"(__isr_stack + ISR_STACKSIZE));
__irq_is_in = 1;
}

@ -25,7 +25,7 @@ extern "C" {
#endif
#define THREAD_STACKSIZE_IDLE (96)
#define MSP430_ISR_STACK_SIZE (256)
#define ISR_STACKSIZE (256)
#ifndef GNRC_PKTBUF_SIZE
#define GNRC_PKTBUF_SIZE (2560) /* TODO: Make this value

@ -24,7 +24,7 @@
volatile int __irq_is_in = 0;
char __isr_stack[MSP430_ISR_STACK_SIZE];
char __isr_stack[ISR_STACKSIZE];
unsigned int irq_disable(void)
{

@ -36,7 +36,7 @@ extern "C" {
#define THREAD_STACKSIZE_MINIMUM (163840)
/* native internal */
#define THREAD_STACKSIZE_MINIMUM (163840)
#define NATIVE_ISR_STACKSIZE (163840)
#define ISR_STACKSIZE (163840)
#else /* Linux etc. */
#define THREAD_STACKSIZE_DEFAULT (8192)
@ -46,7 +46,7 @@ extern "C" {
/* for core/include/thread.h */
#define THREAD_STACKSIZE_MINIMUM (8192)
/* native internal */
#define NATIVE_ISR_STACKSIZE (8192)
#define ISR_STACKSIZE (8192)
#endif /* OS */
/** @} */

@ -74,6 +74,13 @@ void thread_print_stack(void)
return;
}
/* This function calculates the ISR_usage */
int thread_arch_isr_stack_usage(void)
{
/* TODO */
return -1;
}
char *thread_stack_init(thread_task_func_t task_func, void *arg, void *stack_start, int stacksize)
{
char *stk;

@ -0,0 +1,25 @@
/*
* Copyright (C) 2016 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @{
*
* @file
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#include "arch/thread_arch.h"
/* This function calculates the ISR_usage */
int thread_arch_isr_stack_usage(void)
{
/* TODO */
return -1;
}
/** @} */

@ -71,6 +71,16 @@ void ps(void)
#endif
"state");
#ifdef DEVELHELP
int isr_usage = thread_arch_isr_stack_usage(); /* ISR stack usage */
printf("\t - | isr_stack | - - |"
" - | %5i (%5i) | -\n", ISR_STACKSIZE, isr_usage);
overall_stacksz += ISR_STACKSIZE;
if (isr_usage > 0) {
overall_used += isr_usage;
}
#endif
for (kernel_pid_t i = KERNEL_PID_FIRST; i <= KERNEL_PID_LAST; i++) {
thread_t *p = (thread_t *)sched_threads[i];

Loading…
Cancel
Save