os/kernel: Update sysdbg availabe in current TizenRT#7141
os/kernel: Update sysdbg availabe in current TizenRT#7141seokhun-eom24 wants to merge 2 commits intoSamsung:masterfrom
Conversation
7f37403 to
1c5cc8c
Compare
| #include <errno.h> | ||
|
|
||
| #ifdef CONFIG_SEMAPHORE_HISTORY | ||
| #if defined(CONFIG_SEMAPHORE_HISTORY) && defined(__KERNEL__) |
There was a problem hiding this comment.
Then, sysdbg cannot track sem_init of user-space semaphores.
You should mention this I think.
There was a problem hiding this comment.
That's right. As you mentioned, currently, sem_init calls from user-space may not be tracked.
Moving sem_init to the kernel and calling it via a syscall would solve this problem, but it would impact performance.
We need to discuss whether it's necessary to add tracking for sem_init in user-space.
And I updated this limitation in save_semaphore_history's explanation.
1c5cc8c to
34f974f
Compare
os/kernel/debug/sysdbg.c
Outdated
| saved_state = spin_lock_irqsave(&g_sysdbg_lock); | ||
| if (!sysdbg_monitor || !sysdbg_struct) { | ||
| spin_unlock_irqrestore(&g_sysdbg_lock, saved_state); | ||
| return; | ||
| } | ||
|
|
||
| /* Set the flag first to avoid any race condition */ | ||
| sysdbg_monitor = false; | ||
| #ifdef CONFIG_TASK_SCHED_HISTORY | ||
| /* Free the memory allocated for sched struct */ | ||
| if (sysdbg_struct->sched) { | ||
| kmm_free(sysdbg_struct->sched); | ||
| sysdbg_struct->sched = NULL; | ||
| /* Free the memory allocated for sched struct */ | ||
| #ifdef CONFIG_SMP | ||
| for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++) { | ||
| if (sysdbg_struct->sched[cpu]) { | ||
| kmm_free(sysdbg_struct->sched[cpu]); |
There was a problem hiding this comment.
it can cause deadlock
spinlock range should be minimum, and it has to not include context switching.
the kmm_free can make context switching
There was a problem hiding this comment.
Thank you for find out.
I moved blocking functions(lldbg, kmm_free, kmm_zalloc) outside spinlock.
Inside spinlock just copy the data and handle it outside spinlock.
- Update include condition to prevent unnecessary inclusion of debugging features in non-kernel builds. - save_semaphore_history is in os/kernel, So it's only available in kernel not in libc. Signed-off-by: seokhun-eom <seokhun.eom@samsung.com>
02abd20 to
c56f565
Compare
- Modified sysdbg structures to support multiple CPUs by adding arrays for scheduling and IRQ history.
- Modified sysdbg_print to display task and IRQ scheduling history per CPU.
- Modified sysdbg to use spin_lock_irqsave() instead of enter_critical_section(), because enter_critical_section makes recursive call.
- enter_critical_section() -> up_cpu_paused_restore() -> up_restoretask() -> save_task_scheduling_status() -> enter_critical_section()
- spin_lock_irqsave blocks interrupt and provides SMP-safe protection for sysdbg_struct without the enter_critical_section()
- Modified to call blocking functions(lldbg, kmm_free, kmm_zalloc) outside of spinlock to avoid deadlock.
- This patch makes sysdbg available in current TizenRT system.
[Configuration Example]
```
CONFIG_DEBUG_SYSTEM=y
CONFIG_IRQ_SCHED_HISTORY=y
CONFIG_SEMAPHORE_HISTORY=y
CONFIG_TASK_SCHED_HISTORY=y
CONFIG_DEBUG_IRQ_MAX_COUNT=0x20
CONFIG_DEBUG_SEM_MAX_COUNT=0x20
CONFIG_DEBUG_TASK_MAX_COUNT=0x20
CONFIG_DEBUG_SYSTEM_APP=y
```
[Log Example]
```
TASH>>sysdbg help
TASH>>show_usage: USAGE:
show_usage: sysdbg enable_monitor /* Allocates memory and enables monitoring */
show_usage: sysdbg disable_monitor /* Frees the memory and disables monitoring */
show_usage: sysdbg read /* Reads /dev/sysdbg to view debug information*/
show_usage: sysdbg max_task_count <count> /* Enter max_task_count */
show_usage: sysdbg max_irq_count <count> /* Enter max_irq_count */
show_usage: sysdbg max_sem_count <count> /* Enter max_sem_count */
show_usage: sysdbg data_abort /* Simulate data abort */
show_usage: sysdbg prefetch_abort /* Simulate Prefetch abort */
show_usage: sysdbg undef_abort /* Simulate Undefined abort */
show_usage: sysdbg usr_assert /* Simulate User Assert */
show_usage: sysdbg dump_stack /* Dumps the current task stack */
show_usage: sysdbg dump_allstack /* Dumps the stack of all tasks */
show_usage: sysdbg help /* Display the help */
TASH>>sysdbg read
TASH>>sysdbg_print: Displaying the TASK SCHEDULING HISTORY for 16 count
sysdbg_print: *****************************************************************************
sysdbg_print: * CPU TASK_SCHEDTIME TASK_NAME PID PRIORITY TCB
sysdbg_print: *****************************************************************************
sysdbg_print: ******************************* CPU0 History *******************************
sysdbg_print: 0 8828 sysdbg 29 100 601356C0
sysdbg_print: 0 8828 sysdbg 29 100 601356C0
sysdbg_print: 0 8828 tash 20 125 601347D0
sysdbg_print: 0 8801 CPU0 IDLE 0 0 6010BF94
sysdbg_print: 0 8801 CPU0 IDLE 0 0 6010BF94
sysdbg_print: 0 8801 LWIP_TCP/IP 12 105 601D46F0
sysdbg_print: 0 8701 CPU0 IDLE 0 0 6010BF94
sysdbg_print: 0 8701 CPU0 IDLE 0 0 6010BF94
sysdbg_print: 0 8701 LWIP_TCP/IP 12 105 601D46F0
sysdbg_print: 0 8694 CPU0 IDLE 0 0 6010BF94
sysdbg_print: 0 8694 CPU0 IDLE 0 0 6010BF94
sysdbg_print: 0 8694 tash 20 125 601347D0
sysdbg_print: 0 8603 CPU0 IDLE 0 0 6010BF94
sysdbg_print: 0 8603 CPU0 IDLE 0 0 6010BF94
sysdbg_print: 0 8603 tash 20 125 601347D0
sysdbg_print: 0 8601 CPU0 IDLE 0 0 6010BF94
sysdbg_print: ******************************* CPU1 History *******************************
sysdbg_print: 1 1615 CPU1 IDLE 1 0 6010C098
sysdbg_print: 1 1615 CPU1 IDLE 1 0 6010C098
sysdbg_print: 1 1612 binary_manager 15 203 601DB550
sysdbg_print: 1 1612 LWIP_TCP/IP 12 105 601D46F0
sysdbg_print: 1 1612 LWIP_TCP/IP 12 105 601D46F0
sysdbg_print: 1 1611 log_dump 14 200 601D7E10
sysdbg_print: 1 1611 LWIP_TCP/IP 12 105 601D46F0
sysdbg_print: 1 1611 CPU1 IDLE 1 0 6010C098
sysdbg_print: 1 1589 CPU1 IDLE 1 0 6010C098
sysdbg_print: 1 1587 CPU1 IDLE 1 0 6010C098
sysdbg_print: 1 1587 CPU1 IDLE 1 0 6010C098
sysdbg_print: 1 1587 hpwork 2 201 60130550
sysdbg_print: 1 1587 hpwork 2 201 60130550
sysdbg_print: 1 1587 CPU1 IDLE 1 0 6010C098
sysdbg_print: 1 1587 CPU1 IDLE 1 0 6010C098
sysdbg_print: 1 1587 NDP_health_chec 11 100 601C1E20
sysdbg_print: Displaying the IRQ SCHEDULING HISTORY for 16 count
sysdbg_print: *****************************************************************************
sysdbg_print: * CPU IRQ_TIME IRQ_NUMBER ISR_ADDRESS
sysdbg_print: *****************************************************************************
sysdbg_print: ******************************* CPU0 History *******************************
sysdbg_print: 0 8828 40 E00B0E9
sysdbg_print: 0 8828 40 E00B0E9
sysdbg_print: 0 8828 40 E00B0E9
sysdbg_print: 0 8827 27 E02F12D
sysdbg_print: 0 8826 27 E02F12D
sysdbg_print: 0 8825 27 E02F12D
sysdbg_print: 0 8824 27 E02F12D
sysdbg_print: 0 8823 27 E02F12D
sysdbg_print: 0 8822 27 E02F12D
sysdbg_print: 0 8821 27 E02F12D
sysdbg_print: 0 8820 27 E02F12D
sysdbg_print: 0 8819 27 E02F12D
sysdbg_print: 0 8818 27 E02F12D
sysdbg_print: 0 8817 27 E02F12D
sysdbg_print: 0 8816 27 E02F12D
sysdbg_print: 0 8815 27 E02F12D
sysdbg_print: *****************************************************************************
sysdbg_print: 1 1612 2 60102271
sysdbg_print: 1 1611 2 60102271
sysdbg_print: 1 1611 2 60102271
sysdbg_print: 1 1611 2 60102271
sysdbg_print: 1 1589 2 60102271
sysdbg_print: 1 1587 2 60102271
sysdbg_print: 1 1587 2 60102271
sysdbg_print: 1 1503 2 60102271
sysdbg_print: 1 1503 2 60102271
sysdbg_print: 1 1501 2 60102271
sysdbg_print: 1 1501 2 60102271
sysdbg_print: 1 1499 2 60102271
sysdbg_print: 1 1497 2 60102271
sysdbg_print: 1 1495 2 60102271
sysdbg_print: 1 1493 2 60102271
sysdbg_print: 1 1491 2 60102271
sysdbg_print: Displaying the SEMAPHORE HISTORY for 16 count
sysdbg_print: IN:INIT AQ:ACQUIRED RL:RELEASED WT:WAITING DR:DESTROY UN:UNKNOWN
sysdbg_print: PID : -1 indicates that, it's a ISR, for ISR, TCB field gives reference of ISR
sysdbg_print: *****************************************************************************
sysdbg_print: * SEMAPHORE_TIME STATUS TASK_NAME SEMAPHORE TCB PID
sysdbg_print: *****************************************************************************
sysdbg_print: 8828 RL sysdbg 601E3B60 601356C0 29
sysdbg_print: 8828 AQ sysdbg 601E3B60 601356C0 29
sysdbg_print: 8828 RL sysdbg 60121760 601356C0 29
sysdbg_print: 8828 AQ sysdbg 60121760 601356C0 29
sysdbg_print: 8828 WT tash 63A87B6C 601347D0 20
sysdbg_print: 8828 RL tash 60103218 601347D0 20
sysdbg_print: 8828 RL tash 6010323C 601347D0 20
sysdbg_print: 8828 AQ tash 6010323C 601347D0 20
sysdbg_print: 8828 RL tash 60103224 601347D0 20
sysdbg_print: 8828 AQ tash 60103224 601347D0 20
sysdbg_print: 8828 AQ tash 60103218 601347D0 20
sysdbg_print: 8828 IN tash 63A87B6C 601347D0 20
sysdbg_print: 8828 RL tash 601166E8 601347D0 20
sysdbg_print: 8828 AQ tash 601166E8 601347D0 20
sysdbg_print: 8828 RL tash 63A80020 601347D0 20
sysdbg_print: 8828 AQ tash 63A80020 601347D0 20
```
Signed-off-by: seokhun-eom <seokhun.eom@samsung.com>
c56f565 to
ca99142
Compare
[Configuration Example]
[Log Example]
libc/semaphore: Update semaphore initialization condition