Skip to content

Commit 1ab4863

Browse files
committed
samples: net: latmon: latency monitor tool
Supports the EVL/Xenomai4 benchmarking tool as described in the documentation. 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 e90c58a commit 1ab4863

File tree

8 files changed

+937
-0
lines changed

8 files changed

+937
-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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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. 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. This provides a more accurate assessment of the system's real-time responsiveness.
14+
15+
- **Real-Time Thread Testing**: Evaluates how a user-space thread processes external interrupts.
16+
- **End-to-End Latency Measurement**: Captures delays from hardware, drivers, and user-space threads.
17+
- **Versatile Platform Support**: Works on EVL, PREEMPT_RT, and other platforms.
18+
19+
Overview
20+
--------
21+
The main program is designed to monitor latency using GPIO pins on a Zephyr-based system.
22+
It generates a pulse signal on a GPIO pin and measures the time it takes for the SUT to respond to the signal.
23+
The SUT must be running Latmus to capture the latency metrics and historgram information reported over the network .
24+
The program uses LEDS to indicate the different states, such as DHCP binding(red), waiting for the Latmus connection (blue) and sampling (green).
25+
26+
Requirements
27+
------------
28+
29+
- **Zephyr-Compatible Board**: A board with external GPIO support (e.g., FRDM-K64F).
30+
- **SUT**: A system with external GPIO pins running Latmus.
31+
- **Network Connection**: A DHCP server for IP assignment.
32+
- **Physical Connection**: GPIO wires connecting the Zephyr board to the SUT.
33+
34+
Setup and Usage
35+
---------------
36+
37+
1. Flash Latmon onto the Zephyr board.
38+
2. Connect GPIO pins for TX (Zephyr to SUT) and RX (SUT to Zephyr).
39+
3. Run Latmus on the SUT with appropriate options (e.g., ``-p`` for period, ``-g`` for histogram generation).
40+
4. Monitor results such as min, max, and average latencies.
41+
42+
Example
43+
-------
44+
45+
Run Latmon and Latmus as follows:
46+
47+
On the host and to flash the Zephyr board::
48+
49+
$ west flash
50+
51+
On the SUT, latmus **MUST** track the falling edge of the signal::
52+
53+
$ latmus -I gpiochip2,23,falling-edge -O gpiochip2,21 -z <ip_address> -g "histogram"
54+
55+
On completion, generate a latency histogram on the host (a PNG file) using gnuplot::
56+
57+
$ gnuplot plot_data.gp
58+
59+
The `plot_data.gp` script should look like this:
60+
61+
.. code-block:: gnuplot
62+
63+
set terminal pngcairo size 800,600
64+
set output 'plot.png'
65+
set title "Data Plot"
66+
set xlabel "Latency (usec)"
67+
set ylabel "Sample Count"
68+
set grid
69+
set style data linespoints
70+
plot 'histogram' using 1:2 with linespoints title "Data Points"
71+
72+
Contributions
73+
-------------
74+
75+
Contributions are welcome! Submit a pull request or open an issue.
76+
77+
---
78+
79+
With Latmon and Latmus, you can evaluate the real-time performance of any system, ensuring it meets stringent real-world application requirements.
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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_IPV4=y
14+
CONFIG_NET_IPV6=n
15+
CONFIG_NET_ARP=y
16+
CONFIG_NET_TCP=y
17+
CONFIG_NET_UDP=y
18+
CONFIG_NET_DHCPV4=y
19+
CONFIG_NET_SOCKETS=y
20+
CONFIG_NET_SOCKETS_POSIX_NAMES=y
21+
CONFIG_NET_MGMT=y
22+
CONFIG_NET_MGMT_EVENT=y
23+
CONFIG_NET_LOG=y
24+
25+
CONFIG_SLIP_STATISTICS=n
26+
CONFIG_NET_SHELL=y
27+
28+
# Network driver config
29+
CONFIG_TEST_RANDOM_GENERATOR=y

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

samples/net/latmon/src/latmon.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2020 Philippe Gerum <[email protected]>
5+
*/
6+
7+
#ifndef _EVL_ZEPHYR_LATMON_H
8+
#define _EVL_ZEPHYR_LATMON_H
9+
10+
#include <stdint.h>
11+
12+
#define LATMON_NET_PORT 2306
13+
14+
struct latmon_net_request {
15+
uint32_t period_usecs;
16+
uint32_t histogram_cells;
17+
} __attribute__((__packed__));
18+
19+
struct latmon_net_data {
20+
int32_t sum_lat_hi;
21+
int32_t sum_lat_lo;
22+
int32_t min_lat;
23+
int32_t max_lat;
24+
uint32_t overruns;
25+
uint32_t samples;
26+
} __attribute__((__packed__));
27+
28+
#endif /* !_EVL_ZEPHYR_LATMON_H */

0 commit comments

Comments
 (0)