Skip to content

Commit 69edb8d

Browse files
committed
samples: net: latmon: latency monitor tool
Supports the EVL/Xenomai4 benchmarking tool as described in the documentation. The benchmarking tool is accessed via the latmon service. This code uses the J2 socket on FRDMk64-F: PIN_20: tx pulse to SUT PIN_18: rx ack from SUT The client code running on the SUT shall monitor the falling edge of PIN_20. Example usage from the latmus client running Xenomai4: $ latmus -I gpiochip2,23,falling-edge -O gpiochip2,21 .... Signed-off-by: Jorge Ramirez-Ortiz <[email protected]>
1 parent 8b1e4de commit 69edb8d

File tree

7 files changed

+515
-0
lines changed

7 files changed

+515
-0
lines changed

samples/net/latmon/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(latmon)
6+
7+
target_sources(app PRIVATE src/main.c)

samples/net/latmon/README.rst

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2024 Jorge Ramirez-Ortiz <[email protected]>
5+
*/
6+
7+
/ {
8+
latmon: latency-monitor {
9+
compatible = "latency-monitor";
10+
11+
latmon_pulse: latmon_pulse {
12+
gpios = <&gpioe 24 GPIO_ACTIVE_HIGH>;
13+
pinctrl-0 = <&pinmux_pulse>;
14+
pinctrl-names = "default";
15+
};
16+
17+
latmon_ack: latmon_ack {
18+
gpios = <&gpioe 25 GPIO_ACTIVE_HIGH>;
19+
pinctrl-0 = <&pinmux_ack>;
20+
pinctrl-names = "default";
21+
};
22+
};
23+
};
24+
25+
&pinctrl {
26+
pinmux_pulse:pinmux_pulse {
27+
group0 {
28+
pinmux = <PTE24>;
29+
drive-strength = "high";
30+
slew-rate = "slow";
31+
};
32+
};
33+
34+
pinmux_ack:pinmux_ack {
35+
group0 {
36+
pinmux = <PTE25>;
37+
drive-strength = "high";
38+
slew-rate = "slow";
39+
};
40+
};
41+
};
42+
43+
&i2c0 {
44+
status = "disabled";
45+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright (c) 2024 Jorge Ramirez-Ortiz <[email protected]>
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: GPIO latency monitor
5+
6+
compatible: "latency-monitor"
7+
8+
child-binding:
9+
properties:
10+
gpios:
11+
type: phandle-array
12+
required: true
13+
14+
pinctrl-0:
15+
type: phandle
16+
required: false
17+
18+
pinctrl-names:
19+
type: string
20+
required: false

samples/net/latmon/prj.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# General config
2+
CONFIG_LOG=y
3+
CONFIG_GPIO=y
4+
CONFIG_REBOOT=y
5+
CONFIG_TICKLESS_KERNEL=y
6+
CONFIG_CONSOLE_SUBSYS=y
7+
CONFIG_CONSOLE_GETLINE=y
8+
CONFIG_NEWLIB_LIBC=y
9+
CONFIG_INIT_STACKS=y
10+
11+
# Networking config
12+
CONFIG_NETWORKING=y
13+
CONFIG_NET_LATMON=y
14+
15+
# Heap for Latmon
16+
CONFIG_HEAP_MEM_POOL_SIZE=8192

samples/net/latmon/sample.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sample:
2+
name: Latency Benchmarking Tool
3+
tests:
4+
sample.basic.latmon
5+
tags:
6+
- gpio
7+
- devicetree
8+
integration_platforms:
9+
- frdm_k64f
10+
depends_on: gpio
11+
harness: console

0 commit comments

Comments
 (0)