-
Notifications
You must be signed in to change notification settings - Fork 11
/
rtprio.bash
executable file
·124 lines (101 loc) · 3.04 KB
/
rtprio.bash
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
#
#
# The program is free software: you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 2 of the
# License, or any newer version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see https://www.gnu.org/licenses/gpl-2.0.txt
#
#
# - increase a IRQ thread priority of a input CMD name
#
# author : Jeong Han Lee
# email : [email protected]
# date :
# version : 0.0.1
# root@:~# chrt -m
# SCHED_OTHER min/max priority : 0/0
# SCHED_FIFO min/max priority : 1/99
# SCHED_RR min/max priority : 1/99
# SCHED_BATCH min/max priority : 0/0
# SCHED_IDLE min/max priority : 0/0
function check_PREEMPT_RT
{
local kernel_uname=$(uname -r)
local rt_patch="preempt-rt";
local kernel_status=0;
local realtime_status=$(cat /sys/kernel/realtime)
if test "${kernel_uname#*$rt_patch}" != "${kernel_uname}"; then
kernel_status=1;
else
kernel_status=0;
fi
if [[ $kernel_status && $realtime_status ]]; then
printf "This is the realtime patch system, and go further...\n";
else
printf "This is not the realtime patch system, and stop here\n";
exit;
fi
}
function return_ps
{
local cmd="$1"; shift;
local result="";
result=$(ps -eTo tid,rtprio,cls,pri,cmd c | grep ${cmd});
echo ${result};
}
printf "\n"
printf "Check whether the kernel supports realtime features\n";
declare CMD="$1";
declare NEWIRQPRIO="$2";
if [ -z "${CMD}" ]; then
echo "">&2
echo "usage: $0 <command_name> <new_irq_prio>" >&2
echo >&2
echo " command_name: " >&2
echo ""
echo " ecmc_rt ">&2
echo " ecmc_rt 90">&2
echo ""
echo >&2
exit 0
fi
if [ -z "${NEWIRQPRIO}" ]; then
NEWIRQPRIO=80;
fi
check_PREEMPT_RT
declare TID=0;
declare PS_RETURN="";
declare IRQPRIO=0;
#
# tid is the first item of ps result, so awk uses $1 in order to get tid in ps command
# ps -eTo tid,rtprio,nice,cls,pri,cmd c
#
PS_RETURN=$(return_ps "${CMD}");
if [ ! "${PS_RETURN}" ]; then
printf "There is no RT process of %s\n" "${CMD}";
exit 0
fi
TID=$(echo $PS_RETURN | awk '{print $1}');
IRQPRIO=$(echo $PS_RETURN | awk '{print $2}');
printf "\n%s IRQ thread priority : Running:%s Max:%s\n" "${CMD}" "${IRQPRIO}" "${NEWIRQPRIO}";
if [ "${TID}xxx" == "xxx" ]; then
printf "%s IRQ thread not found (OK if not PREEMPT_RT kernel)\n" "${CMD}";
else
printf "Changing the %s IRQ thread priority from %s to %s\n" "${CMD}" "${IRQPRIO}" "${NEWIRQPRIO}";
#
# -f : --fifo : set policy to SCHED_FIFO
#
chrt -f -p ${NEWIRQPRIO} ${TID};
printf "Information on the changed \n";
return_ps "$CMD"
fi
exit