1# Thread analyzer configuration options
2
3# Copyright (c) 2015 Wind River Systems, Inc.
4# SPDX-License-Identifier: Apache-2.0
5
6menuconfig THREAD_ANALYZER
7	bool "Thread analyzer"
8	depends on !ARCH_POSIX
9	select INIT_STACKS
10	select THREAD_MONITOR
11	select THREAD_STACK_INFO
12	select THREAD_RUNTIME_STATS
13	help
14	  Enable thread analyzer functionality and all the required modules.
15	  This module may be used to debug thread configuration issues, e.g.
16	  stack size configuration to find stack overflow or to find stacks
17	  which may be optimized.
18
19if THREAD_ANALYZER
20module = THREAD_ANALYZER
21module-str = thread analyzer
22source "subsys/logging/Kconfig.template.log_config"
23
24choice
25	prompt "Thread analysis print mode"
26	default THREAD_ANALYZER_USE_PRINTK
27
28config THREAD_ANALYZER_USE_LOG
29	bool "Use logger output"
30	select LOG
31	help
32	  Use logger output to print thread information.
33
34config THREAD_ANALYZER_USE_PRINTK
35	bool "Use printk function"
36	help
37	  Use kernel printk function to print thread information.
38
39endchoice
40
41config THREAD_ANALYZER_ISR_STACK_USAGE
42	bool "Analyze interrupt stacks usage"
43	default y
44
45config THREAD_ANALYZER_PRIV_STACK_USAGE
46	bool "Analyze privileged stacks usage"
47	depends on USERSPACE
48	depends on ARCH_HAS_THREAD_PRIV_STACK_SPACE_GET
49	help
50	  Print privileged stack usage for user threads.
51
52config THREAD_ANALYZER_RUN_UNLOCKED
53	bool "Run analysis with interrupts unlocked"
54	default y
55	help
56	  The thread analysis takes quite a long time.
57	  Every thread it finds is analyzed word by word to find any that
58	  does not match the magic number.
59	  Normally while thread are analyzed the k_thread_foreach function
60	  is used.
61	  While this is a safe run from the thread list perspective it may lock
62	  the interrupts for a long time - long enough to disconnect when
63	  Bluetooth communication is used.
64	  Setting this flag will force thread analyzer to use
65	  the k_thread_foreach_unlocked function.
66	  This will allow the interrupts to be processed while the thread is
67	  analyzed.
68	  For the limitation of such configuration see the k_thread_foreach
69	  documentation.
70
71config THREAD_ANALYZER_STACK_SAFETY
72	bool "Thread analysis includes thread runtime stack safety check"
73	default n
74	select THREAD_RUNTIME_STACK_SAFETY
75	help
76	  If enabled, the stack usage analysis is enhanced by calling a customizable handler
77	  when the unused stack space of a thread falls below its configured threshold. This
78	  customized handler may take actions such as logging warnings, suspending or even
79	  aborting threads.
80
81config THREAD_ANALYZER_AUTO
82	bool "Run periodic thread analysis in a thread"
83	help
84	  Run the thread analyzer automatically, without the need to add
85	  any code to the application.
86	  Thread analysis would be called periodically.
87
88if THREAD_ANALYZER_AUTO
89
90config THREAD_ANALYZER_AUTO_SEPARATE_CORES
91	bool "Run thread analyzer separately on each core"
92	default y if KERNEL_COHERENCE
93	depends on SCHED_CPU_MASK
94	help
95	  Run the thread analyzer auto thread on each core and report
96	  cores separately. This feature is needed for platforms running
97	  on cache-incoherent architectures.
98
99config THREAD_ANALYZER_AUTO_INTERVAL
100	int "Thread analysis interval"
101	default 60
102	range 5 3600
103	help
104	  The time in seconds to call thread analyzer periodic printing function.
105
106config THREAD_ANALYZER_AUTO_STACK_SIZE
107	int "Stack size for the periodic thread analysis thread"
108	default 2048 if THREAD_ANALYZER_USE_LOG && LOG_MODE_IMMEDIATE && NO_OPTIMIZATIONS
109	default 1024
110
111config THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
112	bool "Override default thread analysis thread priority"
113	help
114	  Option to change the default value of thread analysis thread priority.
115
116if THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
117config THREAD_ANALYZER_AUTO_THREAD_PRIORITY
118	int "Thread analysis thread priority"
119	default 0
120	help
121	  Set thread priority of the thread analysis
122endif # THREAD_ANALYZER_AUTO_THREAD_PRIORITY_OVERRIDE
123
124endif # THREAD_ANALYZER_AUTO
125
126config THREAD_ANALYZER_LONG_FRAME_PER_INTERVAL
127	bool "Prints the longest frame since the last thread analyzer interval"
128	depends on SCHED_THREAD_USAGE_ANALYSIS
129	help
130	  Resets the thread longest frame field after printing so that the next print
131	  will show the longest frame during that interval.  This enables observation
132	  of what long frames come after the initial startup of a thread.
133
134endif # THREAD_ANALYZER
135