|
| 1 | +Latency Monitoring with Latmon and Latmus |
| 2 | +========================================== |
| 3 | + |
| 4 | +This project provides tools to measure the worst-case response time of a system under test (SUT) to GPIO events using: |
| 5 | + |
| 6 | +- **Latmon**: Runs on a Zephyr-based board to generate and monitor GPIO events while collecting metrics |
| 7 | +- **Latmus**: Runs on the SUT to respond to the falling edge of input GPIO event and display metrics. |
| 8 | + |
| 9 | +This project is part of the open-source initiative `EVL Project - Latmus GPIO Response Time <https://evlproject.org/core/benchmarks/#latmus-gpio-response-time>`_. |
| 10 | + |
| 11 | +Why Not Just Use a Timer? |
| 12 | +------------------------- |
| 13 | +A timer-based test only measures internal response times and often neglects external factors such as GPIO signal propagation, hardware interaction, and interrupt handling. |
| 14 | +By using Latmon and Latmus, you can simulate real-world hardware-driven scenarios, capturing comprehensive end-to-end latency metrics, including hardware, drivers, and user-space threads. |
| 15 | +This provides a more accurate assessment of the system's real-time responsiveness. |
| 16 | + |
| 17 | +- **Real-Time Thread Testing**: Evaluates how a user-space thread processes external interrupts. |
| 18 | +- **End-to-End Latency Measurement**: Captures delays from hardware, drivers, and user-space threads. |
| 19 | +- **Versatile Platform Support**: Works on EVL, PREEMPT_RT, and other platforms. |
| 20 | + |
| 21 | +Overview |
| 22 | +-------- |
| 23 | +The main program is designed to monitor latency using GPIO pins on a Zephyr-based system. |
| 24 | +It generates a pulse signal on a GPIO pin and measures the time it takes for the SUT (executing Latmus) to respond to the signal. |
| 25 | + |
| 26 | +The SUT must be running Latmus to capture the latency metrics and historgram information reported over the network . |
| 27 | +The program uses LEDS to indicate the different states, such as DHCP binding(red), waiting for the Latmus connection (blue) and sampling (green). |
| 28 | + |
| 29 | +Code Structure |
| 30 | +-------------- |
| 31 | + |
| 32 | +The Latmon sample application is divided into two main components: |
| 33 | + |
| 34 | +1. **Application Logic (`samples/net/latmon/main.c`)**: |
| 35 | + This file contains the main application logic for Latmon. It initializes the hardware, the networking interface, configures the GPIO pins, and manages the state machine for the latency monitoring process. |
| 36 | + It also handles LED indicators for different states (e.g., DHCP binding, waiting for connection, sampling). |
| 37 | + |
| 38 | +2. **Library (`subsys/net/lib/latmon/latmon.c`)**: |
| 39 | + This file provides reusable functions and abstractions for latency monitoring via Latmus. |
| 40 | + It includes the core logic for reporting latency metrics and histogram data. |
| 41 | + |
| 42 | +Requirements |
| 43 | +------------ |
| 44 | + |
| 45 | +- **Zephyr-Compatible Board**: A board with external GPIO support (e.g., FRDM-K64F). |
| 46 | +- **SUT**: A system with external GPIO pins running Latmus. |
| 47 | +- **Network Connection**: A DHCP server for IP assignment. |
| 48 | +- **Physical Connection**: GPIO wires connecting the Zephyr board to the SUT. |
| 49 | + |
| 50 | +Setup and Usage |
| 51 | +--------------- |
| 52 | + |
| 53 | +1. Flash Latmon onto the Zephyr board. |
| 54 | +2. Connect GPIO pins for TX (Zephyr to SUT) and RX (SUT to Zephyr). |
| 55 | +3. Run Latmus on the SUT with appropriate options (e.g., ``-p`` for period, ``-g`` for histogram generation). |
| 56 | +4. Monitor results such as min, max, and average latencies. |
| 57 | + |
| 58 | +Example |
| 59 | +------- |
| 60 | + |
| 61 | +Run Latmon and Latmus as follows: |
| 62 | + |
| 63 | + On the host and to flash the Zephyr board:: |
| 64 | + |
| 65 | + $ west flash |
| 66 | + |
| 67 | + On the SUT, latmus **MUST** track the falling edge of the signal:: |
| 68 | + |
| 69 | + $ latmus -I gpiochip2,23,falling-edge -O gpiochip2,21 -z <ip_address> -g "histogram" |
| 70 | + |
| 71 | +On completion, generate a latency histogram on the host (a PNG file) using gnuplot:: |
| 72 | + |
| 73 | + $ gnuplot plot_data.gp |
| 74 | + |
| 75 | +The `plot_data.gp` script should look like this: |
| 76 | + |
| 77 | +.. code-block:: gnuplot |
| 78 | +
|
| 79 | + set terminal pngcairo size 800,600 |
| 80 | + set output 'plot.png' |
| 81 | + set title "Data Plot" |
| 82 | + set xlabel "Latency (usec)" |
| 83 | + set ylabel "Sample Count" |
| 84 | + set grid |
| 85 | + set style data linespoints |
| 86 | + plot 'histogram' using 1:2 with linespoints title "Data Points" |
| 87 | +
|
| 88 | +Contributions |
| 89 | +------------- |
| 90 | + |
| 91 | +Contributions are welcome. Please submit a pull request or open an issue. |
0 commit comments