cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.h and create a shim for backward-compatibility. No functional changes to the headers. A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES. Related to #16539 Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
parent
fa1c60014b
commit
efb8df5366
21 changed files with 116 additions and 101 deletions
|
@ -15,7 +15,7 @@
|
|||
#include <drivers/uart.h>
|
||||
#include <sys/util.h>
|
||||
#include <sys/byteorder.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <sys/printk.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
92
include/debug/stack.h
Normal file
92
include/debug/stack.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
/**
|
||||
* @file stack.h
|
||||
* Stack usage analysis helpers
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DEBUG_STACK_H_
|
||||
#define ZEPHYR_INCLUDE_DEBUG_STACK_H_
|
||||
|
||||
#include <logging/log.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static inline size_t stack_unused_space_get(const char *stack, size_t size)
|
||||
{
|
||||
size_t unused = 0;
|
||||
|
||||
if (IS_ENABLED(CONFIG_INIT_STACKS)) {
|
||||
const unsigned char *checked_stack =
|
||||
(const unsigned char *)stack;
|
||||
|
||||
if (IS_ENABLED(CONFIG_STACK_SENTINEL)) {
|
||||
/* First 4 bytes of the stack buffer reserved for the
|
||||
* sentinel value, it won't be 0xAAAAAAAA for thread
|
||||
* stacks.
|
||||
*/
|
||||
checked_stack += 4;
|
||||
}
|
||||
|
||||
/* TODO Currently all supported platforms have stack growth down
|
||||
* and there is no Kconfig option to configure it so this always
|
||||
* build "else" branch.
|
||||
* When support for platform with stack direction up
|
||||
* (or configurable direction) is added this check should be
|
||||
* confirmed that correct Kconfig option is used.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_STACK_GROWS_UP)) {
|
||||
for (size_t i = size; i > 0; i--) {
|
||||
if (checked_stack[i - 1] == 0xaaU) {
|
||||
unused++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (checked_stack[i] == 0xaaU) {
|
||||
unused++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return unused;
|
||||
}
|
||||
|
||||
static inline void stack_analyze(const char *name, const char *stack,
|
||||
unsigned int size)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_INIT_STACKS)) {
|
||||
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
|
||||
|
||||
unsigned int unused = stack_unused_space_get(stack, size);
|
||||
unsigned int pcnt = ((size - unused) * 100U) / size;
|
||||
|
||||
LOG_INF("%s :\tunused %u\tusage %u / %u (%u %%)",
|
||||
name, unused, size - unused, size, pcnt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Analyze stacks.
|
||||
*
|
||||
* Use this macro to get information about stack usage.
|
||||
*
|
||||
* @param name Name of the stack
|
||||
* @param sym The symbol of the stack
|
||||
*/
|
||||
#define STACK_ANALYZE(name, sym) \
|
||||
do { \
|
||||
stack_analyze(name, \
|
||||
Z_THREAD_STACK_BUFFER(sym), \
|
||||
K_THREAD_STACK_SIZEOF(sym)); \
|
||||
} while (false)
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DEBUG_STACK_H_ */
|
|
@ -1,92 +1,15 @@
|
|||
/**
|
||||
* @file stack.h
|
||||
* Stack usage analysis helpers
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015 Intel Corporation
|
||||
* Copyright (c) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_MISC_STACK_H_
|
||||
#define ZEPHYR_INCLUDE_MISC_STACK_H_
|
||||
|
||||
#include <logging/log.h>
|
||||
#include <stdbool.h>
|
||||
#ifndef CONFIG_COMPAT_INCLUDES
|
||||
#warning "This header file has moved, include <debug/stack.h> instead."
|
||||
#endif
|
||||
|
||||
static inline size_t stack_unused_space_get(const char *stack, size_t size)
|
||||
{
|
||||
size_t unused = 0;
|
||||
|
||||
if (IS_ENABLED(CONFIG_INIT_STACKS)) {
|
||||
const unsigned char *checked_stack =
|
||||
(const unsigned char *)stack;
|
||||
|
||||
if (IS_ENABLED(CONFIG_STACK_SENTINEL)) {
|
||||
/* First 4 bytes of the stack buffer reserved for the
|
||||
* sentinel value, it won't be 0xAAAAAAAA for thread
|
||||
* stacks.
|
||||
*/
|
||||
checked_stack += 4;
|
||||
}
|
||||
|
||||
/* TODO Currently all supported platforms have stack growth down
|
||||
* and there is no Kconfig option to configure it so this always
|
||||
* build "else" branch.
|
||||
* When support for platform with stack direction up
|
||||
* (or configurable direction) is added this check should be
|
||||
* confirmed that correct Kconfig option is used.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_STACK_GROWS_UP)) {
|
||||
for (size_t i = size; i > 0; i--) {
|
||||
if (checked_stack[i - 1] == 0xaaU) {
|
||||
unused++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if (checked_stack[i] == 0xaaU) {
|
||||
unused++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return unused;
|
||||
}
|
||||
|
||||
static inline void stack_analyze(const char *name, const char *stack,
|
||||
unsigned int size)
|
||||
{
|
||||
if (IS_ENABLED(CONFIG_INIT_STACKS)) {
|
||||
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
|
||||
|
||||
unsigned int unused = stack_unused_space_get(stack, size);
|
||||
unsigned int pcnt = ((size - unused) * 100U) / size;
|
||||
|
||||
LOG_INF("%s :\tunused %u\tusage %u / %u (%u %%)",
|
||||
name, unused, size - unused, size, pcnt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Analyze stacks.
|
||||
*
|
||||
* Use this macro to get information about stack usage.
|
||||
*
|
||||
* @param name Name of the stack
|
||||
* @param sym The symbol of the stack
|
||||
*/
|
||||
#define STACK_ANALYZE(name, sym) \
|
||||
do { \
|
||||
stack_analyze(name, \
|
||||
Z_THREAD_STACK_BUFFER(sym), \
|
||||
K_THREAD_STACK_SIZEOF(sym)); \
|
||||
} while (false)
|
||||
#include <debug/stack.h>
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_MISC_STACK_H_ */
|
||||
|
|
|
@ -187,7 +187,7 @@ struct net_stack_info {
|
|||
#define NET_STACK_DEFINE_EMBEDDED(name, size) char name[size]
|
||||
|
||||
#if defined(CONFIG_INIT_STACKS)
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
static inline void net_analyze_stack_get_values(const char *stack,
|
||||
size_t size,
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <offsets_short.h>
|
||||
#include <kernel.h>
|
||||
#include <sys/printk.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <random/rand32.h>
|
||||
#include <linker/sections.h>
|
||||
#include <toolchain.h>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <kernel_structs.h>
|
||||
#include <ksched.h>
|
||||
#include <sys/atomic.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include "wrapper.h"
|
||||
|
||||
static const osThreadAttr_t init_thread_attrs = {
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <zephyr.h>
|
||||
#include <sys/byteorder.h>
|
||||
#include <logging/log.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
#include <device.h>
|
||||
#include <init.h>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <drivers/pwm.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
#include <display/mb_display.h>
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <sys/atomic.h>
|
||||
#include <sys/util.h>
|
||||
#include <sys/byteorder.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
#include <tinycrypt/constants.h>
|
||||
#include <tinycrypt/aes.h>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <sys/atomic.h>
|
||||
|
||||
#include <sys/util.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <sys/byteorder.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <sys/byteorder.h>
|
||||
#include <sys/util.h>
|
||||
#include <sys/slist.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <sys/__assert.h>
|
||||
|
||||
#include <bluetooth/hci.h>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <sys/util.h>
|
||||
#include <sys/slist.h>
|
||||
#include <sys/byteorder.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <sys/__assert.h>
|
||||
#include <soc.h>
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include <zephyr.h>
|
||||
#include <sys/atomic.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <sys/byteorder.h>
|
||||
#include <tinycrypt/constants.h>
|
||||
#include <tinycrypt/utils.h>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <sys/util.h>
|
||||
|
||||
#include <net/buf.h>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <sys/atomic.h>
|
||||
#include <sys/byteorder.h>
|
||||
#include <sys/util.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/bluetooth.h>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include <sys/atomic.h>
|
||||
#include <sys/util.h>
|
||||
#include <sys/byteorder.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
#include <net/buf.h>
|
||||
#include <bluetooth/hci.h>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <init.h>
|
||||
#include <debug/object_tracing.h>
|
||||
#include <misc/reboot.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <string.h>
|
||||
#include <device.h>
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <app_memory/app_memdomain.h>
|
||||
#include <sys/util.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
#include <syscall_handler.h>
|
||||
#include "test_syscall.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <ztest.h>
|
||||
#include <power/power.h>
|
||||
#include <irq_offload.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
#define SLEEP_MS 100
|
||||
#define NUM_OF_WORK 2
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <ztest.h>
|
||||
#include <irq_offload.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
#define STACKSIZE (256 + CONFIG_TEST_EXTRA_STACKSIZE)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <ztest.h>
|
||||
#include <irq_offload.h>
|
||||
#include <misc/stack.h>
|
||||
#include <debug/stack.h>
|
||||
|
||||
#define SLEEP_MS 100
|
||||
#define TEST_STRING "TEST"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue