xref: /linux/tools/perf/tests/shell/sched.sh (revision f4f346c3465949ebba80c6cc52cd8d2eeaa545fd)
10e22c5caSIan Rogers#!/bin/bash
20e22c5caSIan Rogers# perf sched tests
30e22c5caSIan Rogers# SPDX-License-Identifier: GPL-2.0
40e22c5caSIan Rogers
50e22c5caSIan Rogersset -e
60e22c5caSIan Rogers
70e22c5caSIan Rogersif [ "$(id -u)" != 0 ]; then
80e22c5caSIan Rogers  echo "[Skip] No root permission"
90e22c5caSIan Rogers  exit 2
100e22c5caSIan Rogersfi
110e22c5caSIan Rogers
120e22c5caSIan Rogerserr=0
130e22c5caSIan Rogersperfdata=$(mktemp /tmp/__perf_test_sched.perf.data.XXXXX)
140e22c5caSIan RogersPID1=0
150e22c5caSIan RogersPID2=0
160e22c5caSIan Rogers
170e22c5caSIan Rogerscleanup() {
180e22c5caSIan Rogers  rm -f "${perfdata}"
190e22c5caSIan Rogers  rm -f "${perfdata}".old
200e22c5caSIan Rogers
210e22c5caSIan Rogers  trap - EXIT TERM INT
220e22c5caSIan Rogers}
230e22c5caSIan Rogers
240e22c5caSIan Rogerstrap_cleanup() {
250e22c5caSIan Rogers  echo "Unexpected signal in ${FUNCNAME[1]}"
260e22c5caSIan Rogers  cleanup
270e22c5caSIan Rogers  exit 1
280e22c5caSIan Rogers}
290e22c5caSIan Rogerstrap trap_cleanup EXIT TERM INT
300e22c5caSIan Rogers
310e22c5caSIan Rogersstart_noploops() {
320e22c5caSIan Rogers  # Start two noploop workloads on CPU0 to trigger scheduling.
330e22c5caSIan Rogers  perf test -w noploop 10 &
340e22c5caSIan Rogers  PID1=$!
350e22c5caSIan Rogers  taskset -pc 0 $PID1
360e22c5caSIan Rogers  perf test -w noploop 10 &
370e22c5caSIan Rogers  PID2=$!
380e22c5caSIan Rogers  taskset -pc 0 $PID2
390e22c5caSIan Rogers
400e22c5caSIan Rogers  if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID1/status"
410e22c5caSIan Rogers  then
420e22c5caSIan Rogers    echo "Sched [Error taskset did not work for the 1st noploop ($PID1)]"
430e22c5caSIan Rogers    grep Cpus_allowed /proc/$PID1/status
440e22c5caSIan Rogers    err=1
450e22c5caSIan Rogers  fi
460e22c5caSIan Rogers
470e22c5caSIan Rogers  if ! grep -q 'Cpus_allowed_list:\s*0$' "/proc/$PID2/status"
480e22c5caSIan Rogers  then
490e22c5caSIan Rogers    echo "Sched [Error taskset did not work for the 2nd noploop ($PID2)]"
500e22c5caSIan Rogers    grep Cpus_allowed /proc/$PID2/status
510e22c5caSIan Rogers    err=1
520e22c5caSIan Rogers  fi
530e22c5caSIan Rogers}
540e22c5caSIan Rogers
550e22c5caSIan Rogerscleanup_noploops() {
560e22c5caSIan Rogers  kill "$PID1" "$PID2"
570e22c5caSIan Rogers}
580e22c5caSIan Rogers
59*cc4b3927SNamhyung Kimtest_sched_record() {
60*cc4b3927SNamhyung Kim  echo "Sched record"
610e22c5caSIan Rogers
620e22c5caSIan Rogers  start_noploops
630e22c5caSIan Rogers
640e22c5caSIan Rogers  perf sched record --no-inherit -o "${perfdata}" sleep 1
65*cc4b3927SNamhyung Kim
66*cc4b3927SNamhyung Kim  cleanup_noploops
67*cc4b3927SNamhyung Kim}
68*cc4b3927SNamhyung Kim
69*cc4b3927SNamhyung Kimtest_sched_latency() {
70*cc4b3927SNamhyung Kim  echo "Sched latency"
71*cc4b3927SNamhyung Kim
720e22c5caSIan Rogers  if ! perf sched latency -i "${perfdata}" | grep -q perf-noploop
730e22c5caSIan Rogers  then
740e22c5caSIan Rogers    echo "Sched latency [Failed missing output]"
750e22c5caSIan Rogers    err=1
760e22c5caSIan Rogers  fi
770e22c5caSIan Rogers}
780e22c5caSIan Rogers
790e22c5caSIan Rogerstest_sched_script() {
800e22c5caSIan Rogers  echo "Sched script"
810e22c5caSIan Rogers
820e22c5caSIan Rogers  if ! perf sched script -i "${perfdata}" | grep -q perf-noploop
830e22c5caSIan Rogers  then
840e22c5caSIan Rogers    echo "Sched script [Failed missing output]"
850e22c5caSIan Rogers    err=1
860e22c5caSIan Rogers  fi
870e22c5caSIan Rogers}
880e22c5caSIan Rogers
89*cc4b3927SNamhyung Kimtest_sched_map() {
90*cc4b3927SNamhyung Kim  echo "Sched map"
91*cc4b3927SNamhyung Kim
92*cc4b3927SNamhyung Kim  if ! perf sched map -i "${perfdata}" | grep -q perf-noploop
93*cc4b3927SNamhyung Kim  then
94*cc4b3927SNamhyung Kim    echo "Sched map [Failed missing output]"
95*cc4b3927SNamhyung Kim    err=1
96*cc4b3927SNamhyung Kim  fi
97*cc4b3927SNamhyung Kim}
98*cc4b3927SNamhyung Kim
99*cc4b3927SNamhyung Kimtest_sched_timehist() {
100*cc4b3927SNamhyung Kim  echo "Sched timehist"
101*cc4b3927SNamhyung Kim
102*cc4b3927SNamhyung Kim  if ! perf sched timehist -i "${perfdata}" | grep -q perf-noploop
103*cc4b3927SNamhyung Kim  then
104*cc4b3927SNamhyung Kim    echo "Sched timehist [Failed missing output]"
105*cc4b3927SNamhyung Kim    err=1
106*cc4b3927SNamhyung Kim  fi
107*cc4b3927SNamhyung Kim}
108*cc4b3927SNamhyung Kim
109*cc4b3927SNamhyung Kimtest_sched_record
1100e22c5caSIan Rogerstest_sched_latency
1110e22c5caSIan Rogerstest_sched_script
112*cc4b3927SNamhyung Kimtest_sched_map
113*cc4b3927SNamhyung Kimtest_sched_timehist
1140e22c5caSIan Rogers
1150e22c5caSIan Rogerscleanup
1160e22c5caSIan Rogersexit $err
117