Skip to content

net: latmon: latency monitor service and sample #85154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 20, 2025

Conversation

ldts
Copy link
Contributor

@ldts ldts commented Feb 4, 2025

Supports the EVL/Xenomai4 gpio benchmarking tool as described in the Xenomai Latmus documentation.

The sample code for the Latmon service uses the FRDM_K64F J2 socket as follows:

  • 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 ....

Running snapshot:

  • Upper terminal: Zephyr Latmon sample
  • Lower terminal: Xenomai4 Latmus execution

image

A sample histogram plot:
image

Running Sample:
WhatsApp Image 2025-03-23 at 09 07 40

@jukkar
Copy link
Member

jukkar commented Feb 4, 2025

This sample uses networking APIs but does not seem to be a networking sample but testing gpio latency. Perhaps this should be located somewhere under samples/drivers/ instead?

Copy link
Contributor

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe this qualifies as a sample. From what I see reading the code, its an application used to calculate the latency of GPIO propagation between two systems, using a timer. For testing embedded systems, latencies are usually measured using digital analyzers to isolate the device under test, to avoid the propagated delays this application is seemingly introducing.

Samples are meant to show how to use zephyr, focusing on a specific feature like RTIO. I do not think anyone seeing this code will learn anything new about zephyr.

Why not keep this application downstream with the project it is designed for? I do not see what the zephyr project gains from adding and maintaining this application.

@ldts
Copy link
Contributor Author

ldts commented Feb 6, 2025

I do not believe this qualifies as a sample. From what I see reading the code, its an application used to calculate the latency of GPIO propagation between two systems, using a timer. For testing embedded systems, latencies are usually measured using digital analyzers to isolate the device under test, to avoid the propagated delays this application is seemingly introducing.

Samples are meant to show how to use zephyr, focusing on a specific feature like RTIO. I do not think anyone seeing this code will learn anything new about zephyr.

Why not keep this application downstream with the project it is designed for? I do not see what the zephyr project gains from adding and maintaining this application.

As I tried to explain in the README.rst, this program is designed for real-time Linux systems, assisting in the evaluation of their interrupt latencies. The client code, latmus, runs on the system under test (SUT) and has been a part of the Xenomai project for over 20 years, spanning multiple iterations. However, since it can run with minimal modifications on various systems, the goal is to extract it into a standalone project or potentially integrate it into the Linux kernel tree - maybe under linux/tools. The ultimate objective is to develop an affordable, open-source, hardware-backed solution for measuring interrupt latency in a clear and reliable manner.

It also offers an objective method for comparing PREEMPT_RT with Xenomai: Benchmark Scenarios.

I understand your concern but I was hoping we could have a discussion about this. In my opinion, given its simplicity, the code serves as a real-world example of pinctrl, GPIO, and networking usage. Additionally, it contributes to the Linux community by supporting discussions on real-time performance data. If it would be helpful, I’d be happy to be added as a maintainer for this sample code.

@ldts
Copy link
Contributor Author

ldts commented Feb 11, 2025

@jukkar @bjarki-andreasen should I add it to samples/boards instead? It seems to focus more on demonstrating functionality and hardware features. I'd like to unblock this discussion

@bjarki-andreasen
Copy link
Contributor

bjarki-andreasen commented Feb 11, 2025

@jukkar @bjarki-andreasen should I add it to samples/boards instead? It seems to focus more on demonstrating functionality and hardware features. I'd like to unblock this discussion

Could you address the main alternative to adding this as a sample, which is to maintain it as a normal application within the project it is a part of? There are an effectively never ending number of applications built to run on zephyr, projects like https://github.com/jakkra/ZSWatch and https://github.com/zmkfirmware/zmk are rather popular ones. Should we add those applications to samples as well? One could argue they demonstrate how to use many parts of zephyr as well, but that does not make them samples...

In short, samples demo and document a feature, applications solve a problem. The code in this PR is part of a larger project, solving a problem.

@ldts
Copy link
Contributor Author

ldts commented Feb 11, 2025

@bjarki-andreasen I believe I have provided some sort of justification to what you are asking; I have provided links and data backing my request and offered my support as a maintainer.

You are pointing me to some neat repositories though quite frankly I fail to see their industry relevance beyond their own individuality - the problem they are trying to solve doesn't extend beyond their single use case. I also doubt they will be active in 20 years from now. I have pointed you to a project/framework that is a quarter of a century old and supporting many industrial applications (and companies).

The latmus tool - used to measure performance deviation - will help a wide range of products and markets. So with that in mind, I am still not sure why this Zephyr code can not be integrated as sample code. Is as generic as any, but it will help many.

Now, please, could you help me understand the criteria to merge code to sample/boards? what does an application need to do be be accepted there?

@jukkar
Copy link
Member

jukkar commented Feb 11, 2025

I do not have big issues with this sample, we have other samples that do somewhat similar things like zperf in networking. If this PR is accepted, then I suggest it is not placed under samples/net as it is using networking APIs but is not demonstrating some specific networking feature (we have various BSD socket samples in net already which do that).

@bjarki-andreasen
Copy link
Contributor

bjarki-andreasen commented Feb 11, 2025

@bjarki-andreasen I believe I have provided some sort of justification to what you are asking; I have provided links and data backing my request and offered my support as a maintainer.

You are pointing me to some neat repositories though quite frankly I fail to see their industry relevance beyond their own individuality - the problem they are trying to solve doesn't extend beyond their single use case. I also doubt they will be active in 20 years from now. I have pointed you to a project/framework that is a quarter of a century old and supporting many industrial applications (and companies).

The latmus tool - used to measure performance deviation - will help a wide range of products and markets. So with that in mind, I am still not sure why this Zephyr code can not be integrated as sample code. Is as generic as any, but it will help many.

Yes, "some sort of justification" has been provided, I do not find said justification sufficient.

Now, please, could you help me understand the criteria to merge code to sample/boards? what does an application need to do be be accepted there?

samples/boards is for board specific samples, demoing board/vendor specific features like vendor specific device driver APIs. Its not relevant so I did not see a reason to expand upon it.

@jukkar Just like this sample does not demo any specific networking feature, its not demoing any specific zephyr feature either. Its not a sample... The "sample" in this PR is an endpoint/client for a completely independent project, it has no utility for zephyr.

@kartben What do you think? Is this a sample in your opinion? Should it be part of the zephyr codebase somewhere in any case?

@ldts
Copy link
Contributor Author

ldts commented Feb 11, 2025

samples/boards is for board specific samples, demoing board/vendor specific features like vendor specific device driver APIs. Its not relevant so I did not see a reason to expand upon it.

If we look into samples/boards/expressif/ethernet or the rpi_pico sample it does seem relevant to me (nothing of interest from the zephyr side, just hardware validation AFAICS). But you are clearly better informed - I stopped contributing zephyr code over 8 years ago so I cant say I am up to date.

Anyway, sure please let me know if I should drop the PR.

@bjarki-andreasen
Copy link
Contributor

bjarki-andreasen commented Feb 11, 2025

Have you considered contributing latmon as a network protocol, similar to how protocols like ptp are implemented? Then the sample could demo the usage of said protocol, which would be a zephyr feature :) The protocol being part of the sample is what I believe makes this an application, rather than demoing a zephyr feature.

something like:

typedef void (*net_latmon_ack_handler)(void);
int net_latmon_start(net_latmon_ack_handler ack_handler);
int net_latmon_send_data(const struct net_latmon_data *data);

in
include/zephyr/net/latmon.h
which could be included with a kconfig like config NET_LATMON.

The sample would then be a demo of how to use the protocol.

@ldts
Copy link
Contributor Author

ldts commented Feb 12, 2025

Have you considered contributing latmon as a network protocol, similar to how protocols like ptp are implemented? Then the sample could demo the usage of said protocol, which would be a zephyr feature :) The protocol being part of the sample is what I believe makes this an application, rather than demoing a zephyr feature.

something like:

typedef void (*net_latmon_ack_handler)(void);
int net_latmon_start(net_latmon_ack_handler ack_handler);
int net_latmon_send_data(const struct net_latmon_data *data);

in include/zephyr/net/latmon.h which could be included with a kconfig like config NET_LATMON.

The sample would then be a demo of how to use the protocol.

ah, that is a neat idea. ok let me have a look and thanks a lot for pointing it out!

@ldts
Copy link
Contributor Author

ldts commented Mar 19, 2025

keep alive.

@ldts ldts force-pushed the latmon-4.0.0-rc2 branch from 1ab4863 to 69edb8d Compare March 21, 2025 16:37
@ldts
Copy link
Contributor Author

ldts commented Mar 21, 2025

@bjarki-andreasen I still have to address issues from the original code so please do not dive into a formal review yet - could you however comment on the partitioning as a network service? is this what you had in mind when you suggested it?

@ldts ldts force-pushed the latmon-4.0.0-rc2 branch from 69edb8d to 80bd9a2 Compare March 21, 2025 16:43
@bjarki-andreasen
Copy link
Contributor

@bjarki-andreasen I still have to address issues from the original code so please do not dive into a formal review yet - could you however comment on the partitioning as a network service? is this what you had in mind when you suggested it?

Yes, this looks very much like what I envisioned :)

@ldts ldts changed the title samples: net: latmon: latency monitor tool net: latmon: latency monitor service and sample Mar 21, 2025
@ldts ldts force-pushed the latmon-4.0.0-rc2 branch 2 times, most recently from ff44fd9 to db7f7e8 Compare May 31, 2025 07:26
Copy link

@ldts
Copy link
Contributor Author

ldts commented Jun 6, 2025

AFAICS all actions have been done.

Copy link
Contributor

@bjarki-andreasen bjarki-andreasen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

jukkar
jukkar previously approved these changes Jun 10, 2025
@bjarki-andreasen
Copy link
Contributor

ping @kartben :)

@ldts
Copy link
Contributor Author

ldts commented Jun 16, 2025

@kartben ping

@ldts
Copy link
Contributor Author

ldts commented Jun 21, 2025

Maybe someone else can take over the missing reviewed by?

@kartben
Copy link
Contributor

kartben commented Jun 21, 2025

Sorry for the delay. I will make sure to come back to this within a couple days

@ldts
Copy link
Contributor Author

ldts commented Jun 22, 2025

Sorry for the delay. I will make sure to come back to this within a couple days

Cool thanks, yeah enough for me to know is being reviewed and moving along, didn't want it to stall.

@ldts ldts dismissed stale reviews from jukkar and bjarki-andreasen via de5242a July 13, 2025 10:58
@ldts
Copy link
Contributor Author

ldts commented Jul 13, 2025

@kartben when I accepted your recommendations, a Co-author tag was generated. Do these need to go into the two commits or shall I just add your Reviewed-by tags?

going to fold the commits and update the PR so please let me know

@kartben
Copy link
Contributor

kartben commented Jul 13, 2025

@kartben when I accepted your recommendations, a Co-author tag was generated. Do these need to go into the two commits or shall I just add your Reviewed-by tags?

going to fold the commits and update the PR so please let me know

Oh I didn't know it does that. No tag at all is fine as far as I'm concerned :) thanks for checking!

@ldts ldts force-pushed the latmon-4.0.0-rc2 branch 2 times, most recently from 5c0ea53 to 32ed18d Compare July 14, 2025 08:46
@ldts
Copy link
Contributor Author

ldts commented Jul 15, 2025

@kartben any other changes?

@ldts
Copy link
Contributor Author

ldts commented Jul 18, 2025

@bjarki-andreasen ping?

ldts added 2 commits July 18, 2025 18:55
Latmon service to interface with Xenomai's Latmus.

Link: https://evlproject.org/core/benchmarks/#latmus-gpio-response-time

Signed-off-by: Jorge Ramirez-Ortiz <[email protected]>
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 -g"histogram" \
          -z broadcast

Signed-off-by: Jorge Ramirez-Ortiz <[email protected]>
@ldts
Copy link
Contributor Author

ldts commented Jul 18, 2025

sorry @bjarki-andreasen I had to remove a section of the documents (I hadnt noticed @kartben last request). I hope this is all :)

Copy link

@cfriedt cfriedt merged commit f9eeefa into zephyrproject-rtos:main Jul 20, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants