diff --git a/drivers/bluetooth/hci/h5.c b/drivers/bluetooth/hci/h5.c index 3b3ccf45d98..a3c5b64bad0 100644 --- a/drivers/bluetooth/hci/h5.c +++ b/drivers/bluetooth/hci/h5.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/debug/stack.h b/include/debug/stack.h new file mode 100644 index 00000000000..f5cec22a7a6 --- /dev/null +++ b/include/debug/stack.h @@ -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 +#include + +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_ */ diff --git a/include/misc/stack.h b/include/misc/stack.h index 776c7b34c90..113239bbaa7 100644 --- a/include/misc/stack.h +++ b/include/misc/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 -#include +#ifndef CONFIG_COMPAT_INCLUDES +#warning "This header file has moved, include 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 #endif /* ZEPHYR_INCLUDE_MISC_STACK_H_ */ diff --git a/include/net/net_core.h b/include/net/net_core.h index f008e865087..dae57714831 100644 --- a/include/net/net_core.h +++ b/include/net/net_core.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 +#include static inline void net_analyze_stack_get_values(const char *stack, size_t size, diff --git a/kernel/init.c b/kernel/init.c index b7434094848..67b8e96dbcf 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/lib/cmsis_rtos_v2/thread.c b/lib/cmsis_rtos_v2/thread.c index 7441e348f4a..e251e9eed81 100644 --- a/lib/cmsis_rtos_v2/thread.c +++ b/lib/cmsis_rtos_v2/thread.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include "wrapper.h" static const osThreadAttr_t init_thread_attrs = { diff --git a/samples/bluetooth/hci_spi/src/main.c b/samples/bluetooth/hci_spi/src/main.c index 7387975c0cf..00fe0177bf7 100644 --- a/samples/bluetooth/hci_spi/src/main.c +++ b/samples/bluetooth/hci_spi/src/main.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include diff --git a/samples/boards/bbc_microbit/pong/src/main.c b/samples/boards/bbc_microbit/pong/src/main.c index b7e7722727a..6db106f2101 100644 --- a/samples/boards/bbc_microbit/pong/src/main.c +++ b/samples/boards/bbc_microbit/pong/src/main.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include diff --git a/subsys/bluetooth/common/rpa.c b/subsys/bluetooth/common/rpa.c index 36ce67dfa03..56f63dee926 100644 --- a/subsys/bluetooth/common/rpa.c +++ b/subsys/bluetooth/common/rpa.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/controller/hci/hci_driver.c b/subsys/bluetooth/controller/hci/hci_driver.c index 0b342c2856d..814a3d20fa9 100644 --- a/subsys/bluetooth/controller/hci/hci_driver.c +++ b/subsys/bluetooth/controller/hci/hci_driver.c @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 6ce0cb4a133..924d49da710 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 45fe48b7c09..8b2fcb9bd2a 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/host/hci_ecc.c b/subsys/bluetooth/host/hci_ecc.c index ccb22aebce3..a907583ec11 100644 --- a/subsys/bluetooth/host/hci_ecc.c +++ b/subsys/bluetooth/host/hci_ecc.c @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include diff --git a/subsys/bluetooth/host/mesh/adv.c b/subsys/bluetooth/host/mesh/adv.c index 403c71a426a..84adbe6b0ad 100644 --- a/subsys/bluetooth/host/mesh/adv.c +++ b/subsys/bluetooth/host/mesh/adv.c @@ -8,7 +8,7 @@ */ #include -#include +#include #include #include diff --git a/subsys/bluetooth/host/rfcomm.c b/subsys/bluetooth/host/rfcomm.c index fe5e58d3a43..a8a123cbe86 100644 --- a/subsys/bluetooth/host/rfcomm.c +++ b/subsys/bluetooth/host/rfcomm.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 1e4fec3ac8c..a4b9a9d34d5 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include diff --git a/subsys/shell/modules/kernel_service.c b/subsys/shell/modules/kernel_service.c index 00f2ae126c8..5a9bab8e0e8 100644 --- a/subsys/shell/modules/kernel_service.c +++ b/subsys/shell/modules/kernel_service.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c index ffa08603364..2d01276ff7f 100644 --- a/tests/kernel/mem_protect/userspace/src/main.c +++ b/tests/kernel/mem_protect/userspace/src/main.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include "test_syscall.h" diff --git a/tests/kernel/profiling/profiling_api/src/main.c b/tests/kernel/profiling/profiling_api/src/main.c index 3682a766507..62e764081c8 100644 --- a/tests/kernel/profiling/profiling_api/src/main.c +++ b/tests/kernel/profiling/profiling_api/src/main.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #define SLEEP_MS 100 #define NUM_OF_WORK 2 diff --git a/tests/kernel/threads/dynamic_thread/src/main.c b/tests/kernel/threads/dynamic_thread/src/main.c index ac1651a7793..e4515e8dfc0 100644 --- a/tests/kernel/threads/dynamic_thread/src/main.c +++ b/tests/kernel/threads/dynamic_thread/src/main.c @@ -6,7 +6,7 @@ #include #include -#include +#include #define STACKSIZE (256 + CONFIG_TEST_EXTRA_STACKSIZE) diff --git a/tests/kernel/threads/thread_apis/src/test_kthread_for_each.c b/tests/kernel/threads/thread_apis/src/test_kthread_for_each.c index 62d97af84e0..01d795dd4ba 100644 --- a/tests/kernel/threads/thread_apis/src/test_kthread_for_each.c +++ b/tests/kernel/threads/thread_apis/src/test_kthread_for_each.c @@ -6,7 +6,7 @@ #include #include -#include +#include #define SLEEP_MS 100 #define TEST_STRING "TEST"