You are here: Home / Support / HOWTOs / 
2024-12-23 - 18:26

Dates and Events:

OSADL Articles:

2024-10-02 12:00

Linux is now an RTOS!

PREEMPT_RT is mainline - What's next?


2023-11-12 12:00

Open Source License Obligations Checklists even better now

Import the checklists to other tools, create context diffs and merged lists


2023-03-01 12:00

Embedded Linux distributions

Results of the online "wish list"


2022-01-13 12:00

Phase #3 of OSADL project on OPC UA PubSub over TSN successfully completed

Another important milestone on the way to interoperable Open Source real-time Ethernet has been reached


2021-02-09 12:00

Open Source OPC UA PubSub over TSN project phase #3 launched

Letter of Intent with call for participation is now available



OSADL HOWTOs

HOWTO: Create a frequency plot from hardware latency detector tracer hwlat

Quick description with inlined code

1. Run the hwlat tracer for 30 minutes and store the result in a temporary file

cd /sys/kernel/debug/tracing
echo hwlat >current_tracer
sleep 1800
cat trace >/tmp/hwlatresult
echo nop >current_tracer
echo -n >trace
cd /tmp

2a. Extract the SMI latency values and store inner and outer data in separate files

grep -v -e "^#" -e nmi- hwlatresult | grep -o " [0-9]*/[0-9]* " | cut -d/ -f1 | tr -d " " | grep -v "^0$" | sort -n >inner
grep -v -e "^#" -e nmi- hwlatresult | grep -o " [0-9]*/[0-9]* " | cut -d/ -f2 | tr -d " " | grep -v "^0$" | sort -n >outer

2b. Alternatively, extract the NMI latency values and store inner and outer data in separate files

grep -v -e "^#" hwlatresult | grep nmi- | grep -o " [0-9]*/[0-9]* " | cut -d/ -f1 | tr -d " " | grep -v "^0$" | sort -n >inner
grep -v -e "^#" hwlatresult | grep nmi- | grep -o " [0-9]*/[0-9]* " | cut -d/ -f2 | tr -d " " | grep -v "^0$" | sort -n >outer

3. Calculate maximum value

maxinner=`tail -1 inner | tee maxinner`
maxouter=`tail -1 outer | tee maxouter`if test $maxinner -gt $maxouter
then
max=$maxinner
else
max=$maxouter
fi

4. Create two-column frequency data

echo -n >innerdata
echo -n >outerdata
for i in `seq 0 $max`
do
echo $i `grep "^$i$" inner | wc -l` >>innerdata
echo $i `grep "^$i$" outer | wc -l` >>outerdata
done

5. Create plot command header

echo -n -e "set title \"Latency\"\n\
set terminal png\n\
set xlabel \"Latency (us) - Maximum inner $maxinner/outer $maxouter us\"\n\
set logscale y\n\
set xrange [0:400]\n\
set yrange [0.8:*]\n\
set ylabel \"Number of SMI latency samples\"\n\
set output \"plot.png\"\n\
plot " >plotcmd

6. Append plot command data references

for i in inner outer
do
if test $i != inner
then
echo -n ", " >>plotcmd
fi
title=$i
echo -n "\"${i}data\" using 1:2 title \"$title\" with histeps" >>plotcmd
done

7. Execute plot command

gnuplot -persist <plotcmd

8. Enjoy

firefox plot.png

Download the script

mkhwlatplot.bash

Bash script (must be run as root)

1.5 K

Example plot

And this is how the resulting image may look like.

Example latency plot (click to enlarge)