-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathirqsoff_latency_ftrc.sh
67 lines (59 loc) · 2.04 KB
/
irqsoff_latency_ftrc.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# ch4/irqsoff_latency_ftrc.sh
#----------------------------------------------------------------------
# This program is part of the source code released for the book
# "Linux Kernel Programming - Part 2"
# (c) Author: Kaiwan N Billimoria
# Publisher: Packt
# GitHub repository:
# https://github.com/PacktPublishing/Linux-Kernel-Programming-Part-2
#
# For details, refer the book, Ch 4.
#----------------------------------------------------------------------
# Brief Description:
# This is a simple wrapper script; we use it to gauge the maximum IRQs-off
# latency on the system. It exploits the kernel's Ftrace infrastructure.
# For details, refer the book, Ch 4 - Handling hardware interrupts, section
# 'Finding the interrupts disabled worst-case latency with Ftrace'.
name=$(basename $(realpath $0))
reset_ftrc()
{
[ -x trace-cmd ] || return
echo "[+] resetting ftrace..."
trace-cmd reset
}
### 'main'
if [ $(id -u) -ne 0 ] ; then
echo "${name}: must run as root."
exit 1
fi
DEBUGFS_MNT=/sys/kernel/debug
[ ! -d ${DEBUGFS_MNT} ] && {
echo "${name}: debugfs not present or mounted? aborting..."
exit 1
}
FTRC=${DEBUGFS_MNT}/tracing
[ ! -d ${FTRC} ] && {
echo "${name}: ${DEBUGFS_MNT}/tracing - ftrace - not present or mounted? aborting..."
exit 1
}
grep -w -q "irqsoff" ${FTRC}/available_tracers || {
echo "${name}: 'irqsoff' tracer not available, aborting..."
echo "This implies you will have to configure your kernel (or a custom one),
with the CONFIG_IRQSOFF_TRACER kernel config option turned on."
exit 1
}
reset_ftrc
echo "[+] 'irqsoff' tracer available, proceeding with latency test..."
echo 0 > ${FTRC}/tracing_on # turn tracing off
echo 1 > ${FTRC}/options/latency-format # turn latency format on
echo irqsoff > ${FTRC}/current_tracer
echo 1 > ${FTRC}/tracing_on # turn tracing on
echo -n "${name}: irqsoff max latency : "
cat ${FTRC}/tracing_max_latency
cp ${FTRC}/trace /tmp/mytrc.txt
ls -lh /tmp/mytrc.txt
#cat /tmp/mytrc.txt
echo "${name}: examine the trace file to see where the max latency occurred"
reset_ftrc
exit 0