Browse Source

debug: thread_analyzer: move thread analyzer to own folder

Move to own directory to prepare for new related code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
pull/88172/head
Anas Nashif 3 months ago committed by Benjamin Cabé
parent
commit
7c68855053
  1. 4
      subsys/debug/CMakeLists.txt
  2. 113
      subsys/debug/Kconfig
  3. 5
      subsys/debug/thread_analyzer/CMakeLists.txt
  4. 116
      subsys/debug/thread_analyzer/Kconfig
  5. 6
      subsys/debug/thread_analyzer/thread_analyzer.c

4
subsys/debug/CMakeLists.txt

@ -10,9 +10,9 @@ zephyr_sources_ifdef( @@ -10,9 +10,9 @@ zephyr_sources_ifdef(
asan_hacks.c
)
zephyr_sources_ifdef(
add_subdirectory_ifdef(
CONFIG_THREAD_ANALYZER
thread_analyzer.c
thread_analyzer
)
add_subdirectory_ifdef(

113
subsys/debug/Kconfig

@ -6,118 +6,7 @@ @@ -6,118 +6,7 @@
menu "System Monitoring Options"
menuconfig THREAD_ANALYZER
bool "Thread analyzer"
depends on !ARCH_POSIX
select INIT_STACKS
select THREAD_MONITOR
select THREAD_STACK_INFO
select THREAD_RUNTIME_STATS
help
Enable thread analyzer functionality and all the required modules.
This module may be used to debug thread configuration issues, e.g.
stack size configuration to find stack overflow or to find stacks
which may be optimized.
if THREAD_ANALYZER
module = THREAD_ANALYZER
module-str = thread analyzer
source "subsys/logging/Kconfig.template.log_config"
choice
prompt "Thread analysis print mode"
default THREAD_ANALYZER_USE_PRINTK
config THREAD_ANALYZER_USE_LOG
bool "Use logger output"
select LOG
help
Use logger output to print thread information.
config THREAD_ANALYZER_USE_PRINTK
bool "Use printk function"
help
Use kernel printk function to print thread information.
endchoice
config THREAD_ANALYZER_ISR_STACK_USAGE
bool "Analyze interrupt stacks usage"
default y
config THREAD_ANALYZER_PRIV_STACK_USAGE
bool "Analyze privileged stacks usage"
depends on USERSPACE
depends on ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET
help
Print privileged stack usage for user threads.
config THREAD_ANALYZER_RUN_UNLOCKED
bool "Run analysis with interrupts unlocked"
default y
help
The thread analysis takes quite a long time.
Every thread it finds is analyzed word by word to find any that
does not match the magic number.
Normally while thread are analyzed the k_thread_foreach function
is used.
While this is a safe run from the thread list perspective it may lock
the interrupts for a long time - long enough to disconnect when
Bluetooth communication is used.
Setting this flag will force thread analyzer to use
the k_thread_foreach_unlocked function.
This will allow the interrupts to be processed while the thread is
analyzed.
For the limitation of such configuration see the k_thread_foreach
documentation.
config THREAD_ANALYZER_AUTO
bool "Run periodic thread analysis in a thread"
help
Run the thread analyzer automatically, without the need to add
any code to the application.
Thread analysis would be called periodically.
if THREAD_ANALYZER_AUTO
config THREAD_ANALYZER_AUTO_SEPARATE_CORES
bool "Run thread analyzer separately on each core"
default y if KERNEL_COHERENCE
depends on SCHED_CPU_MASK
help
Run the thread analyzer auto thread on each core and report
cores separately. This feature is needed for platforms running
on cache-incoherent architectures.
config THREAD_ANALYZER_AUTO_INTERVAL
int "Thread analysis interval"
default 60
range 5 3600
help
The time in seconds to call thread analyzer periodic printing function.
config THREAD_ANALYZER_AUTO_STACK_SIZE
int "Stack size for the periodic thread analysis thread"
default 2048 if THREAD_ANALYZER_USE_LOG && LOG_MODE_IMMEDIATE && NO_OPTIMIZATIONS
default 1024
config THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
bool "Override default thread analysis thread priority"
help
Option to change the default value of thread analysis thread priority.
if THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
config THREAD_ANALYZER_AUTO_THREAD_PRIORITY
int "Thread analysis thread priority"
default 0
help
Set thread priority of the thread analysis
endif # THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
endif # THREAD_ANALYZER_AUTO
endif # THREAD_ANALYZER
source "subsys/debug/thread_analyzer/Kconfig"
endmenu

5
subsys/debug/thread_analyzer/CMakeLists.txt

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
zephyr_sources(
thread_analyzer.c
)

116
subsys/debug/thread_analyzer/Kconfig

@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
# Thread analyzer configuration options
# Copyright (c) 2015 Wind River Systems, Inc.
# SPDX-License-Identifier: Apache-2.0
menuconfig THREAD_ANALYZER
bool "Thread analyzer"
depends on !ARCH_POSIX
select INIT_STACKS
select THREAD_MONITOR
select THREAD_STACK_INFO
select THREAD_RUNTIME_STATS
help
Enable thread analyzer functionality and all the required modules.
This module may be used to debug thread configuration issues, e.g.
stack size configuration to find stack overflow or to find stacks
which may be optimized.
if THREAD_ANALYZER
module = THREAD_ANALYZER
module-str = thread analyzer
source "subsys/logging/Kconfig.template.log_config"
choice
prompt "Thread analysis print mode"
default THREAD_ANALYZER_USE_PRINTK
config THREAD_ANALYZER_USE_LOG
bool "Use logger output"
select LOG
help
Use logger output to print thread information.
config THREAD_ANALYZER_USE_PRINTK
bool "Use printk function"
help
Use kernel printk function to print thread information.
endchoice
config THREAD_ANALYZER_ISR_STACK_USAGE
bool "Analyze interrupt stacks usage"
default y
config THREAD_ANALYZER_PRIV_STACK_USAGE
bool "Analyze privileged stacks usage"
depends on USERSPACE
depends on ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET
help
Print privileged stack usage for user threads.
config THREAD_ANALYZER_RUN_UNLOCKED
bool "Run analysis with interrupts unlocked"
default y
help
The thread analysis takes quite a long time.
Every thread it finds is analyzed word by word to find any that
does not match the magic number.
Normally while thread are analyzed the k_thread_foreach function
is used.
While this is a safe run from the thread list perspective it may lock
the interrupts for a long time - long enough to disconnect when
Bluetooth communication is used.
Setting this flag will force thread analyzer to use
the k_thread_foreach_unlocked function.
This will allow the interrupts to be processed while the thread is
analyzed.
For the limitation of such configuration see the k_thread_foreach
documentation.
config THREAD_ANALYZER_AUTO
bool "Run periodic thread analysis in a thread"
help
Run the thread analyzer automatically, without the need to add
any code to the application.
Thread analysis would be called periodically.
if THREAD_ANALYZER_AUTO
config THREAD_ANALYZER_AUTO_SEPARATE_CORES
bool "Run thread analyzer separately on each core"
default y if KERNEL_COHERENCE
depends on SCHED_CPU_MASK
help
Run the thread analyzer auto thread on each core and report
cores separately. This feature is needed for platforms running
on cache-incoherent architectures.
config THREAD_ANALYZER_AUTO_INTERVAL
int "Thread analysis interval"
default 60
range 5 3600
help
The time in seconds to call thread analyzer periodic printing function.
config THREAD_ANALYZER_AUTO_STACK_SIZE
int "Stack size for the periodic thread analysis thread"
default 2048 if THREAD_ANALYZER_USE_LOG && LOG_MODE_IMMEDIATE && NO_OPTIMIZATIONS
default 1024
config THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
bool "Override default thread analysis thread priority"
help
Option to change the default value of thread analysis thread priority.
if THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
config THREAD_ANALYZER_AUTO_THREAD_PRIORITY
int "Thread analysis thread priority"
default 0
help
Set thread priority of the thread analysis
endif # THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
endif # THREAD_ANALYZER_AUTO
endif # THREAD_ANALYZER

6
subsys/debug/thread_analyzer.c → subsys/debug/thread_analyzer/thread_analyzer.c

@ -9,12 +9,14 @@ @@ -9,12 +9,14 @@
*/
#include <zephyr/kernel.h>
/* For z_stack_space_get() */
#include <kernel_internal.h>
#include <zephyr/debug/thread_analyzer.h>
#include <zephyr/debug/stack.h>
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <stdio.h>
#include <zephyr/init.h>
LOG_MODULE_REGISTER(thread_analyzer, CONFIG_THREAD_ANALYZER_LOG_LEVEL);
@ -112,8 +114,6 @@ static void thread_analyze_cb(const struct k_thread *cthread, void *user_data) @@ -112,8 +114,6 @@ static void thread_analyze_cb(const struct k_thread *cthread, void *user_data)
int err;
int ret;
name = k_thread_name_get((k_tid_t)thread);
if (!name || name[0] == '\0') {
name = hexname;
@ -270,7 +270,7 @@ static int thread_analyzer_init(void) @@ -270,7 +270,7 @@ static int thread_analyzer_init(void)
tid = k_thread_create(&analyzer_thread[i], analyzer_thread_stacks[i],
CONFIG_THREAD_ANALYZER_AUTO_STACK_SIZE,
thread_analyzer_auto,
(void *) (uint32_t) i, NULL, NULL,
(void *) (uintptr_t) i, NULL, NULL,
AUTO_THREAD_PRIO, 0, K_FOREVER);
if (!tid) {
LOG_ERR("k_thread_create() failed for core %u", i);
Loading…
Cancel
Save