Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
orbtop-rtos Technical Documentation
Real-time RTOS Thread Profiling via ITM/DWT for ARM Cortex-M
Overview
orbtop-rtos
is a real-time thread profiling tool that monitors RTOS thread execution on ARM Cortex-M targets using ITM (Instrumentation Trace Macrocell) and DWT (Data Watchpoint and Trace) hardware debugging features. It provides live CPU usage statistics without modifying the target firmware.Architecture
How It Works
Key Components
1. ITM Configuration Requirements
The target must be configured with specific ITM settings:
ITM_TCR.TSENA
ITM_TCR.DWTENA
ITM_TCR.SYNCENA
ITM_TER
DWT_CTRL.CYCCNTENA
2. DWT Configuration (via OpenOCD Telnet)
The
rtos_dwt_config
function instm32h74x.cfg
configures DWT Comparator 1:3. RTX5 Thread Control Block Structure
The tool reads RTX5 TCB structures from target memory:
id
name
priority
thread_addr
4. Memory Reading via Telnet with Caching
The tool uses OpenOCD's telnet interface with an intelligent cache system:
This caching is critical because reading TCB fields (name, priority, function) for each thread switch would otherwise require 3+ telnet round-trips per switch.
Note: Cache is cleared ONLY when a NEW TCB is detected (not on every switch to an existing thread). This means thread properties are read once and cached indefinitely.
Output Formats
When exceptions are enabled with
-E
option, additional exception statistics are displayed:Output Formats
Console Output (Default)
Features:
[ITM OVERFLOW DETECTED!]
or timing warningsJSON Output Modes
RTOS Threads Output (
-j output.json
)Exceptions Output (when using
-E
)UDP Streaming (
-j udp:46006
)nc -lu 46006
Example UDP stream received:
When exceptions are enabled (
-E
), separate exception packets are also sent:Each packet arrives as a complete JSON object on a single line, making it easy to parse in real-time.
FTrace Output (
--ftrace trace.txt
)Generates Linux kernel ftrace text format for analysis with Eclipse TraceCompass:
Key features:
thread_name|entry_function
for easy identificationVisualization with Eclipse TraceCompass
trace.txt
fileUsage:
The FTrace output shows actual thread context switches in real-time, making it ideal for analyzing scheduling behavior, finding priority inversions, and understanding system timing.
Usage Examples
Prerequisites: OpenOCD Configuration
Use the provided
stm32h74x.cfg
from the project. Key parts for ITM/DWT configuration:Start OpenOCD with the provided cfg file:
THAT'S IT! The cfg file automatically does EVERYTHING:
From the cfg file:
THAT'S ALL! OpenOCD is ALREADY serving the ITM stream on port 46000!
The data flow is simply:
No manual telnet commands needed for ITM! Everything is automatic when you start OpenOCD with the cfg.
BUT THE MAGIC IS: The cfg file defines helper functions that orbtop-rtos WILL USE via telnet:
When orbtop-rtos starts, it:
rtos_dwt_config 0xXXXXXXXX
via telnet to configure DWT Comparator 1So the cfg provides both:
Basic RTOS Monitoring
Real-world Example
JSON UDP Output (No Console)
With Exception Tracking
orbtop-rtos \ -s localhost:46000 \ -p ITM \ -e firmware.elf \ -T rtxv5 \ -W 4444 \ -F 480000000 \ -E # Enable exception statistics
FTrace Output for TraceCompass
Thread Switch Detection and Processing
When a new TCB is detected via DWT:
Adding Support for Other RTOS
To add FreeRTOS or other RTOS support, implement the
rtosOps
interface:Example FreeRTOS implementation would:
pxCurrentTCB
symbol instead ofosRtxInfo
pxCurrentTCB
addressImplementation Flow
Technical Details
DWT Comparator Configuration
The DWT comparator monitors writes to
osRtxInfo.thread.run.curr
:ITM Timestamp Handling
ITM timestamps are incremental, not absolute. The tool accumulates them to track real time:
The ITM generates timestamp packets:
With proper prescaler settings:
Thread Statistics Calculation
ITM Overflow and Its Impact on CPU Measurements
The Problem
When ITM overflow occurs, packets are LOST, including:
Since ITM timestamps are incremental (not absolute), losing packets means:
How It Shows in Output
Or when total doesn't add up to ~100%:
Why This Happens
Solutions
Reduce ITM traffic:
-E
)-I 2000
for 2 seconds)Increase SWO bandwidth (in cfg file):
$_CHIPNAME.swo configure -protocol uart -traceclk 480000000 -pin-freq 4000000
Monitor overflow counter: Watch the
Ovf
counter in outputIMPORTANT: When overflow occurs, CPU usage percentages are UNRELIABLE! The tool shows warnings but continues running with incorrect data.
Troubleshooting
Performance Considerations
References