Skip to content

Commit

Permalink
samples: philosophers: Enable thread awareness
Browse files Browse the repository at this point in the history
Enable thread awareness by default on philosophers sample.  It shows
gdb debugging output using the feature as reference.

Signed-off-by: Gerson Fernando Budke <[email protected]>
  • Loading branch information
nandojve authored and cfriedt committed Aug 30, 2021
1 parent 2797afb commit b6c2ae8
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
78 changes: 78 additions & 0 deletions samples/philosophers/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,81 @@ Sample Output
Philosopher 5 [C:-2] THINKING [ 1700 ms ]
Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.

Debug Threads
*************

The philosophers sample by default enables :kconfig:`CONFIG_DEBUG_THREAD_INFO`.
This allows tools like OpenOCD and J-link to inspect thread data using
``info threads``.

.. zephyr-app-commands::
:zephyr-app: samples/philosophers
:host-os: unix
:board: <board_name>
:goals: debug
:compact:


OpenOCD Sample Output
=====================

.. code-block:: console
Thread 1 received signal SIGINT, Interrupt.
[Switching to Thread 537003160]
arch_cpu_idle () at zephyr/mainline/zephyr/arch/arm/core/aarch32/cpu_idle.S:107
107 cpsie i
(gdb) i threads
Id Target Id Frame
* 1 Thread 537003160 (Name: idle 00, prio:40,useropts:1) arch_cpu_idle () at zephyr/mainline/zephyr/arch/arm/core/aarch32/cpu_idle.S:107
Info : Getting thread 537002984 reg list
2 Thread 537002984 (Name: Philosopher 5, prio:-2,useropts:4) 0x08001404 in arch_irq_unlock (key=0) at zephyr/mainline/zephyr/include/arch/arm/aarch32/asm_inline_gcc.h:95
Info : Getting thread 537002808 reg list
3 Thread 537002808 (Name: Philosopher 4, prio:-1,useropts:4) 0x08001404 in arch_irq_unlock (key=0) at zephyr/mainline/zephyr/include/arch/arm/aarch32/asm_inline_gcc.h:95
Info : Getting thread 537002632 reg list
4 Thread 537002632 (Name: Philosopher 3, prio:0,useropts:4) 0x08001404 in arch_irq_unlock (key=0) at zephyr/mainline/zephyr/include/arch/arm/aarch32/asm_inline_gcc.h:95
Info : Getting thread 537002456 reg list
5 Thread 537002456 (Name: Philosopher 2, prio:1,useropts:4) 0x08001404 in arch_irq_unlock (key=0) at zephyr/mainline/zephyr/include/arch/arm/aarch32/asm_inline_gcc.h:95
Info : Getting thread 537002280 reg list
6 Thread 537002280 (Name: Philosopher 1, prio:2,useropts:4) 0x08001404 in arch_irq_unlock (key=0) at zephyr/mainline/zephyr/include/arch/arm/aarch32/asm_inline_gcc.h:95
Info : Getting thread 537002104 reg list
7 Thread 537002104 (Name: Philosopher 0, prio:3,useropts:4) 0x08001404 in arch_irq_unlock (key=0) at zephyr/mainline/zephyr/include/arch/arm/aarch32/asm_inline_gcc.h:95
.. code-block:: console
Philosopher 0 [P: 3] STARVING
Philosopher 1 [P: 2] HOLDING ONE FORK
Philosopher 2 [P: 1] EATING [ 400 ms ]
Philosopher 3 [P: 0] THINKING [ 525 ms ]
Philosopher 4 [C:-1] HOLDING ONE FORK
Philosopher 5 [C:-2] EATING [ 625 ms ]
J-Link Sample Output
====================

.. code-block:: console
Thread 2 received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 537920592]
arch_cpu_idle () at zephyr/mainline/zephyr/arch/arm/core/aarch32/cpu_idle.S:107
107 cpsie i
(gdb) i threads
Id Target Id Frame
* 2 Thread 537920592 (idle 00 UNKNOWN PRIO 40) arch_cpu_idle () at zephyr/mainline/zephyr/arch/arm/core/aarch32/cpu_idle.S:107
3 Thread 537919536 (Philosopher 0 PENDING PRIO 3) arch_swap (key=0) at zephyr/mainline/zephyr/arch/arm/core/aarch32/swap.c:53
4 Thread 537919712 (Philosopher 1 SUSPENDED PRIO 2) arch_swap (key=key@entry=0) at zephyr/mainline/zephyr/arch/arm/core/aarch32/swap.c:53
5 Thread 537919888 (Philosopher 2 SUSPENDED PRIO 1) arch_swap (key=key@entry=0) at zephyr/mainline/zephyr/arch/arm/core/aarch32/swap.c:53
6 Thread 537920064 (Philosopher 3 SUSPENDED PRIO 0) arch_swap (key=key@entry=0) at zephyr/mainline/zephyr/arch/arm/core/aarch32/swap.c:53
7 Thread 537920240 (Philosopher 4 PENDING PRIO 255) arch_swap (key=0) at zephyr/mainline/zephyr/arch/arm/core/aarch32/swap.c:53
8 Thread 537920416 (Philosopher 5 SUSPENDED PRIO 254) arch_swap (key=key@entry=0) at zephyr/mainline/zephyr/arch/arm/core/aarch32/swap.c:53
.. code-block:: console
Philosopher 0 [P: 3] STARVING
Philosopher 1 [P: 2] EATING [ 475 ms ]
Philosopher 2 [P: 1] THINKING [ 700 ms ]
Philosopher 3 [P: 0] THINKING [ 525 ms ]
Philosopher 4 [C:-1] HOLDING ONE FORK
Philosopher 5 [C:-2] EATING [ 625 ms ]
3 changes: 3 additions & 0 deletions samples/philosophers/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ CONFIG_NUM_COOP_PRIORITIES=29
CONFIG_NUM_PREEMPT_PRIORITIES=40
CONFIG_SCHED_SCALABLE=y
CONFIG_MP_NUM_CPUS=1

#Enable thread awareness for debugging tools supporting it
CONFIG_DEBUG_THREAD_INFO=y
3 changes: 3 additions & 0 deletions samples/philosophers/prj_tickless.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ CONFIG_PM=y
CONFIG_TICKLESS_KERNEL=y

CONFIG_MP_NUM_CPUS=1

#Enable thread awareness for debugging tools supporting it
CONFIG_DEBUG_THREAD_INFO=y

0 comments on commit b6c2ae8

Please sign in to comment.